!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 //@line 38 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/toolkit/components/alerts/resources/content/alert.js"
2
3 // Copied from nsILookAndFeel.h, see comments on eMetric_AlertNotificationOrigin
4 const NS_ALERT_HORIZONTAL = 1;
5 const NS_ALERT_LEFT = 2;
6 const NS_ALERT_TOP = 4;
7
8 var gFinalSize;
9 var gCurrentSize = 1;
10
11 var gSlideIncrement = 1;
12 var gSlideTime = 10;
13 var gOpenTime = 3000; // total time the alert should stay up once we are done animating.
14 var gOrigin = 0; // Default value: alert from bottom right, sliding in vertically.
15
16 var gAlertListener = null;
17 var gAlertTextClickable = false;
18 var gAlertCookie = "";
19
prefillAlertInfo
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
20 function prefillAlertInfo()
21 {
22 // unwrap all the args....
23 // arguments[0] --> the image src url
24 // arguments[1] --> the alert title
25 // arguments[2] --> the alert text
26 // arguments[3] --> is the text clickable?
27 // arguments[4] --> the alert cookie to be passed back to the listener
28 // arguments[5] --> the alert origin reported by the look and feel
29 // arguments[6] --> an optional callback listener (nsIObserver)
30
31 switch (window.arguments.length)
32 {
33 default:
34 case 7:
35 gAlertListener = window.arguments[6];
36 case 6:
37 gOrigin = window.arguments[5];
38 case 5:
39 gAlertCookie = window.arguments[4];
40 case 4:
41 gAlertTextClickable = window.arguments[3];
42 if (gAlertTextClickable)
43 document.getElementById('alertTextLabel').setAttribute('clickable', true);
44 case 3:
45 document.getElementById('alertTextLabel').setAttribute('value', window.arguments[2]);
46 case 2:
47 document.getElementById('alertTitleLabel').setAttribute('value', window.arguments[1]);
48 case 1:
49 document.getElementById('alertImage').setAttribute('src', window.arguments[0]);
50 case 0:
51 break;
52 }
53 }
54
onAlertLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
55 function onAlertLoad()
56 {
57 // Read out our initial settings from prefs.
58 try
59 {
60 var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService();
61 prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
62 var prefBranch = prefService.getBranch(null);
63 gSlideIncrement = prefBranch.getIntPref("alerts.slideIncrement");
64 gSlideTime = prefBranch.getIntPref("alerts.slideIncrementTime");
65 gOpenTime = prefBranch.getIntPref("alerts.totalOpenTime");
66 }
67 catch (ex)
68 {
69 }
70
71 // Make sure that the contents are fixed at the window edge facing the
72 // screen's center so that the window looks like "sliding in" and not
73 // like "unfolding". The default packing of "start" only works for
74 // vertical-bottom and horizontal-right positions, so we change it here.
75 if (gOrigin & NS_ALERT_HORIZONTAL)
76 {
77 if (gOrigin & NS_ALERT_LEFT)
78 document.documentElement.pack = "end";
79
80 // Additionally, change the orientation so the packing works as intended
81 document.documentElement.orient = "horizontal";
82 }
83 else
84 {
85 if (gOrigin & NS_ALERT_TOP)
86 document.documentElement.pack = "end";
87 }
88
89 var alertBox = document.getElementById("alertBox");
90 alertBox.orient = (gOrigin & NS_ALERT_HORIZONTAL) ? "vertical" : "horizontal";
91
92 // The above doesn't cause the labels in alertTextBox to reflow,
93 // see bug 311557. As the theme's -moz-box-align css rule gets ignored,
94 // we work around the bug by setting the align property.
95 if (gOrigin & NS_ALERT_HORIZONTAL)
96 {
97 document.getElementById("alertTextBox").align = "center";
98 }
99
100 sizeToContent();
101
102 // Work around a bug where sizeToContent() leaves a border outside of the content
103 var contentDim = document.getElementById("alertBox").boxObject;
104 if (window.innerWidth == contentDim.width + 1)
105 --window.innerWidth;
106
107 // Start with a 1px width/height, because 0 causes trouble with gtk1/2
108 gCurrentSize = 1;
109
110 // Determine final size
111 if (gOrigin & NS_ALERT_HORIZONTAL)
112 {
113 gFinalSize = window.outerWidth;
114 window.outerWidth = gCurrentSize;
115 }
116 else
117 {
118 gFinalSize = window.outerHeight;
119 window.outerHeight = gCurrentSize;
120 }
121
122 // Determine position
123 var x = gOrigin & NS_ALERT_LEFT ? screen.availLeft :
124 screen.availLeft + screen.availWidth - window.outerWidth;
125 var y = gOrigin & NS_ALERT_TOP ? screen.availTop :
126 screen.availTop + screen.availHeight - window.outerHeight;
127
128 // Offset the alert by 10 pixels from the edge of the screen
129 if (gOrigin & NS_ALERT_HORIZONTAL)
130 y += gOrigin & NS_ALERT_TOP ? 10 : -10;
131 else
132 x += gOrigin & NS_ALERT_LEFT ? 10 : -10;
133
134 window.moveTo(x, y);
135
136 setTimeout(animateAlert, gSlideTime);
137 }
138
animate
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
139 function animate(step)
140 {
141 gCurrentSize += step;
142
143 if (gOrigin & NS_ALERT_HORIZONTAL)
144 {
145 if (!(gOrigin & NS_ALERT_LEFT))
146 window.screenX -= step;
147 window.outerWidth = gCurrentSize;
148 }
149 else
150 {
151 if (!(gOrigin & NS_ALERT_TOP))
152 window.screenY -= step;
153 window.outerHeight = gCurrentSize;
154 }
155 }
156
animateAlert
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
157 function animateAlert()
158 {
159 if (gCurrentSize < gFinalSize)
160 {
161 animate(gSlideIncrement);
162 setTimeout(animateAlert, gSlideTime);
163 }
164 else
165 setTimeout(closeAlert, gOpenTime);
166 }
167
closeAlert
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
168 function closeAlert()
169 {
170 if (gCurrentSize > 1)
171 {
172 animate(-gSlideIncrement);
173 setTimeout(closeAlert, gSlideTime);
174 }
175 else
176 {
177 if (gAlertListener)
178 gAlertListener.observe(null, "alertfinished", gAlertCookie);
179 window.close();
180 }
181 }
182
onAlertClick
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
183 function onAlertClick()
184 {
185 if (gAlertListener && gAlertTextClickable)
186 gAlertListener.observe(null, "alertclickcallback", gAlertCookie);
187 }