!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 <?xml version="1.0"?>
2
3 <!DOCTYPE bindings [
4 <!ENTITY % notificationDTD SYSTEM "chrome://global/locale/notification.dtd">
5 %notificationDTD;
6 ]>
7
8 <bindings id="notificationBindings"
9 xmlns="http://www.mozilla.org/xbl"
10 xmlns:xbl="http://www.mozilla.org/xbl"
11 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
12
13 <binding id="notificationbox">
14 <content>
15 <xul:stack xbl:inherits="hidden=notificationshidden">
16 <xul:spacer/>
17 <children includes="notification"/>
18 </xul:stack>
19 <children/>
20 </content>
21
22 <implementation>
field_PRIORITY_INFO_LOW
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
23 <field name="PRIORITY_INFO_LOW" readonly="true">1</field>
field_PRIORITY_INFO_MEDIUM
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
24 <field name="PRIORITY_INFO_MEDIUM" readonly="true">2</field>
field_PRIORITY_INFO_HIGH
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
25 <field name="PRIORITY_INFO_HIGH" readonly="true">3</field>
field_PRIORITY_WARNING_LOW
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
26 <field name="PRIORITY_WARNING_LOW" readonly="true">4</field>
field_PRIORITY_WARNING_MEDIUM
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
27 <field name="PRIORITY_WARNING_MEDIUM" readonly="true">5</field>
field_PRIORITY_WARNING_HIGH
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
28 <field name="PRIORITY_WARNING_HIGH" readonly="true">6</field>
field_PRIORITY_CRITICAL_LOW
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
29 <field name="PRIORITY_CRITICAL_LOW" readonly="true">7</field>
field_PRIORITY_CRITICAL_MEDIUM
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
30 <field name="PRIORITY_CRITICAL_MEDIUM" readonly="true">8</field>
field_PRIORITY_CRITICAL_HIGH
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
31 <field name="PRIORITY_CRITICAL_HIGH" readonly="true">9</field>
field_PRIORITY_CRITICAL_BLOCK
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
32 <field name="PRIORITY_CRITICAL_BLOCK" readonly="true">10</field>
33
field_currentNotification
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
34 <field name="currentNotification">null</field>
field_slideSteps
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
35 <field name="slideSteps">4</field>
36
field__timer
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
37 <field name="_timer">null</field>
field__closedNotification
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
38 <field name="_closedNotification">null</field>
field__blockingCanvas
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
39 <field name="_blockingCanvas">null</field>
40
get_notificationsHidden
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
41 <property name="notificationsHidden"
42 onget="return this.getAttribute('notificationshidden') == 'true';">
set_notificationsHidden
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
43 <setter>
44 if (val)
45 this.setAttribute('notificationshidden', true);
46 else this.removeAttribute('notificationshidden');
47 return val;
48 </setter>
49 </property>
50
get_allNotifications
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
51 <property name="allNotifications" readonly="true"
52 onget="return this.getElementsByTagName('notification');"/>
53
54 <method name="getNotificationWithValue">
55 <parameter name="aValue"/>
getNotificationWithValue
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
56 <body>
57 <![CDATA[
58 var notifications = this.allNotifications;
59 for (var n = notifications.length - 1; n >= 0; n--) {
60 if (aValue == notifications[n].value)
61 return notifications[n];
62 }
63 return null;
64 ]]>
65 </body>
66 </method>
67
68 <method name="appendNotification">
69 <parameter name="aLabel"/>
70 <parameter name="aValue"/>
71 <parameter name="aImage"/>
72 <parameter name="aPriority"/>
73 <parameter name="aButtons"/>
appendNotification
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
74 <body>
75 <![CDATA[
76 if (aPriority < this.PRIORITY_INFO_LOW ||
77 aPriority > this.PRIORITY_CRITICAL_BLOCK)
78 throw "Invalid notification priority " + aPriority;
79
80 // check for where the notification should be inserted according to
81 // priority. If two are equal, the existing one appears on top.
82 var notifications = this.allNotifications;
83 var insertPos = null;
84 for (var n = notifications.length - 1; n >= 0; n--) {
85 if (notifications[n].priority < aPriority)
86 break;
87 insertPos = notifications[n];
88 }
89
90 const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
91 var newitem = document.createElementNS(XULNS, "notification");
92 newitem.setAttribute("label", aLabel);
93 newitem.setAttribute("value", aValue);
94 newitem.setAttribute("image", aImage);
95 if (!insertPos) {
96 newitem.style.position = "fixed";
97 newitem.style.top = "100%";
98 }
99 this.insertBefore(newitem, insertPos);
100
101 if (aButtons) {
102 for (var b = 0; b < aButtons.length; b++) {
103 var button = aButtons[b];
104 var buttonElem = document.createElementNS(XULNS, "button");
105 buttonElem.setAttribute("label", button.label);
106 buttonElem.setAttribute("accesskey", button.accessKey);
107
108 newitem.appendChild(buttonElem);
109 buttonElem.buttonInfo = button;
110 }
111 }
112
113 newitem.priority = aPriority;
114 if (aPriority >= this.PRIORITY_CRITICAL_LOW)
115 newitem.type = "critical";
116 else if (aPriority <= this.PRIORITY_INFO_HIGH)
117 newitem.type = "info";
118 else
119 newitem.type = "warning";
120
121 if (!insertPos)
122 this._showNotification(newitem, true);
123
124 // Fire event for accessibility APIs
125 var event = document.createEvent("Events");
126 event.initEvent("AlertActive", true, true);
127 newitem.dispatchEvent(event);
128
129 return newitem;
130 ]]>
131 </body>
132 </method>
133
134 <method name="removeNotification">
135 <parameter name="aItem"/>
removeNotification
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
136 <body>
137 <![CDATA[
138 if (aItem == this.currentNotification)
139 this.removeCurrentNotification();
140 else
141 this.removeChild(aItem);
142 return aItem;
143 ]]>
144 </body>
145 </method>
146
147 <method name="removeCurrentNotification">
removeCurrentNotification
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
148 <body>
149 <![CDATA[
150 this._showNotification(this.currentNotification, false);
151 return null;
152 ]]>
153 </body>
154 </method>
155
156 <method name="removeAllNotifications">
157 <parameter name="aImmediate"/>
removeAllNotifications
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
158 <body>
159 <![CDATA[
160 var notifications = this.allNotifications;
161 for (var n = notifications.length - 1; n >= 0; n--) {
162 if (aImmediate)
163 this.removeChild(notifications[n]);
164 else
165 this.removeNotification(notifications[n]);
166 }
167 this.currentNotification = null;
168 ]]>
169 </body>
170 </method>
171
172 <method name="removeTransientNotifications">
removeTransientNotifications
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
173 <body>
174 <![CDATA[
175 var notifications = this.allNotifications;
176 for (var n = notifications.length - 1; n >= 0; n--) {
177 var notification = notifications[n];
178 if (notification.persistence)
179 notification.persistence--;
180 else if (Date.now() > notification.timeout)
181 this.removeNotification(notification);
182 }
183 ]]>
184 </body>
185 </method>
186
187 <method name="_showNotification">
188 <parameter name="aNotification"/>
189 <parameter name="aSlideIn"/>
_showNotification
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
190 <body>
191 <![CDATA[
192 if (this._timer) {
193 clearInterval(this._timer);
194 if (this.currentNotification) {
195 this.currentNotification.style.marginTop = "0px";
196 this.currentNotification.style.opacity = 1;
197 }
198 if (this._closedNotification)
199 this._closedNotification.parentNode.
200 removeChild(this._closedNotification);
201 this._setBlockingState(this.currentNotification);
202 }
203
204 var height = aNotification.boxObject.height;
205 var change = height / this.slideSteps;
206 if (aSlideIn) {
207 if (this.currentNotification &&
208 this.currentNotification.boxObject.height > height)
209 height = this.currentNotification.boxObject.height;
210
211 this.currentNotification = aNotification;
212 this._closedNotification = null;
213 aNotification.style.removeProperty("position");
214 aNotification.style.removeProperty("top");
215 aNotification.style.marginTop = -height + "px";
216 aNotification.style.opacity = 0;
217 }
218 else {
219 change = -change;
220 this._closedNotification = aNotification;
221 var notifications = this.allNotifications;
222 var idx = notifications.length - 2;
223 if (idx >= 0)
224 this.currentNotification = notifications[idx];
225 else
226 this.currentNotification = null;
227 }
228 var opacitychange = change / height;
229
230 var self = this;
slideInFn
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
231 var slide = function slideInFn()
232 {
233 var done = false;
234
235 var style = window.getComputedStyle(aNotification, null);
236 var margin = style.getPropertyCSSValue("margin-top").
237 getFloatValue(CSSPrimitiveValue.CSS_PX);
238
239 if (change > 0 && margin + change >= 0) {
240 aNotification.style.marginTop = "0px";
241 aNotification.style.opacity = 1;
242 done = true;
243 }
244 else if (change < 0 && margin + change <= -height) {
245 aNotification.style.marginTop = -height + "px";
246 done = true;
247 }
248 else {
249 aNotification.style.marginTop = (margin + change).toFixed(4) + "px";
250 if (opacitychange)
251 aNotification.style.opacity =
252 Number(aNotification.style.opacity) + opacitychange;
253 }
254
255 if (done) {
256 clearInterval(self._timer);
257 self._timer = null;
258 if (self._closedNotification)
259 self._closedNotification.parentNode.
260 removeChild(self._closedNotification);
261 self._setBlockingState(self.currentNotification);
262 }
263 }
264
265 this._timer = setInterval(slide, 50);
266 ]]>
267 </body>
268 </method>
269
270 <method name="_setBlockingState">
271 <parameter name="aNotification"/>
_setBlockingState
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
272 <body>
273 <![CDATA[
274 var isblock = aNotification &&
275 aNotification.priority == this.PRIORITY_CRITICAL_BLOCK;
276 var canvas = this._blockingCanvas;
277 if (isblock) {
278 if (!canvas)
279 canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
280 const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
281 var content = this.firstChild;
282 if (!content ||
283 content.namespaceURI != XULNS ||
284 content.localName != "browser")
285 return;
286
287 var width = content.boxObject.width;
288 var height = content.boxObject.height;
289 content.collapsed = true;
290
291 canvas.setAttribute("width", width);
292 canvas.setAttribute("height", height);
293 canvas.setAttribute("flex", "1");
294
295 this.appendChild(canvas);
296 this._blockingCanvas = canvas;
297
298 var bgcolor = "white";
299 try {
300 var prefService = Components.classes["@mozilla.org/preferences-service;1"].
301 getService(Components.interfaces.nsIPrefBranch);
302 bgcolor = prefService.getCharPref("browser.display.background_color");
303
304 var win = content.contentWindow;
305 var context = canvas.getContext("2d");
306 context.globalAlpha = 0.5;
307 context.drawWindow(win, win.scrollX, win.scrollY,
308 width, height, bgcolor);
309 }
310 catch(ex) { };
311 }
312 else if (canvas) {
313 canvas.parentNode.removeChild(canvas);
314 this._blockingCanvas = null;
315 var content = this.firstChild;
316 if (content)
317 content.collapsed = false;
318 }
319 ]]>
320 </body>
321 </method>
322
323 </implementation>
324 </binding>
325
326 <binding id="notification">
327 <content>
328 <xul:hbox class="notification-inner outset" flex="1" xbl:inherits="type">
329 <xul:hbox anonid="details" align="center" flex="1"
330 oncommand="this.parentNode.parentNode._doButtonCommand(event);">
331 <xul:image anonid="messageImage" class="messageImage" xbl:inherits="src=image"/>
332 <xul:description anonid="messageText" class="messageText" flex="1" xbl:inherits="xbl:text=label"/>
333 <xul:spacer flex="1"/>
334 <children/>
335 </xul:hbox>
336 <xul:toolbarbutton ondblclick="event.stopPropagation();"
337 class="messageCloseButton tabbable"
338 xbl:inherits="hidden=hideclose"
339 tooltiptext="&closeNotification.tooltip;"
340 oncommand="document.getBindingParent(this).close();"/>
341 </xul:hbox>
342 </content>
343 <resources>
344 <stylesheet src="chrome://global/skin/notification.css"/>
345 </resources>
346 <implementation implements="nsIAccessibleProvider">
347 <property name="accessibleType" readonly="true">
get_accessibleType
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
348 <getter>
349 <![CDATA[
350 return Components.interfaces.nsIAccessibleProvider.XULAlert;
351 ]]>
352 </getter>
353 </property>
354
get_label
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
set_label
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
355 <property name="label" onset="this.setAttribute('label', val); return val;"
356 onget="return this.getAttribute('label');"/>
get_value
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
set_value
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
357 <property name="value" onset="this.setAttribute('value', val); return val;"
358 onget="return this.getAttribute('value');"/>
get_image
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
set_image
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
359 <property name="image" onset="this.setAttribute('image', val); return val;"
360 onget="return this.getAttribute('image');"/>
get_type
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
set_type
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
361 <property name="type" onset="this.setAttribute('type', val); return val;"
362 onget="return this.getAttribute('type');"/>
get_priority
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
set_priority
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
363 <property name="priority" onget="return parseInt(this.getAttribute('priority')) || 0;"
364 onset="this.setAttribute('priority', val); return val;"/>
get_persistence
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
set_persistence
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
365 <property name="persistence" onget="return parseInt(this.getAttribute('persistence')) || 0;"
366 onset="this.setAttribute('persistence', val); return val;"/>
field_timeout
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
367 <field name="timeout">0</field>
368
369 <property name="control" readonly="true">
get_control
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
370 <getter>
371 <![CDATA[
372 var parent = this.parentNode;
373 while (parent) {
374 if (parent.localName == "notificationbox")
375 return parent;
376 parent = parent.parentNode;
377 }
378 return null;
379 ]]>
380 </getter>
381 </property>
382
383 <method name="close">
close
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
384 <body>
385 <![CDATA[
386 var control = this.control;
387 if (control)
388 control.removeNotification(this);
389 else
390 this.hidden = true;
391 ]]>
392 </body>
393 </method>
394
395 <method name="_doButtonCommand">
396 <parameter name="aEvent"/>
_doButtonCommand
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
397 <body>
398 <![CDATA[
399 if (!("buttonInfo" in aEvent.target))
400 return;
401
402 var button = aEvent.target.buttonInfo;
403 if (button.popup) {
404 document.popupNode = aEvent.target;
405 document.getElementById(button.popup).
406 showPopup(aEvent.originalTarget, -1, -1, "popup", "bottomleft", "topleft");
407 aEvent.stopPropagation();
408 }
409 else {
410 var callback = button.callback;
411 if (callback) {
412 var result = callback(this, button);
413 if (!result)
414 this.close();
415 aEvent.stopPropagation();
416 }
417 }
418 ]]>
419 </body>
420 </method>
421 </implementation>
422 </binding>
423 </bindings>