4
<!ENTITY % notificationDTD SYSTEM "chrome://global/locale/notification.dtd">
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">
13
<binding id="notificationbox">
15
<xul:stack xbl:inherits="hidden=notificationshidden">
17
<children includes="notification"/>
23
<field name="PRIORITY_INFO_LOW" readonly="true">1</field>
24
<field name="PRIORITY_INFO_MEDIUM" readonly="true">2</field>
25
<field name="PRIORITY_INFO_HIGH" readonly="true">3</field>
26
<field name="PRIORITY_WARNING_LOW" readonly="true">4</field>
27
<field name="PRIORITY_WARNING_MEDIUM" readonly="true">5</field>
28
<field name="PRIORITY_WARNING_HIGH" readonly="true">6</field>
29
<field name="PRIORITY_CRITICAL_LOW" readonly="true">7</field>
30
<field name="PRIORITY_CRITICAL_MEDIUM" readonly="true">8</field>
31
<field name="PRIORITY_CRITICAL_HIGH" readonly="true">9</field>
32
<field name="PRIORITY_CRITICAL_BLOCK" readonly="true">10</field>
34
<field name="currentNotification">null</field>
35
<field name="slideSteps">4</field>
37
<field name="_timer">null</field>
38
<field name="_closedNotification">null</field>
39
<field name="_blockingCanvas">null</field>
41
<property name="notificationsHidden"
42
onget="return this.getAttribute('notificationshidden') == 'true';">
45
this.setAttribute('notificationshidden', true);
46
else this.removeAttribute('notificationshidden');
51
<property name="allNotifications" readonly="true"
52
onget="return this.getElementsByTagName('notification');"/>
54
<method name="getNotificationWithValue">
55
<parameter name="aValue"/>
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];
68
<method name="appendNotification">
69
<parameter name="aLabel"/>
70
<parameter name="aValue"/>
71
<parameter name="aImage"/>
72
<parameter name="aPriority"/>
73
<parameter name="aButtons"/>
76
if (aPriority < this.PRIORITY_INFO_LOW ||
77
aPriority > this.PRIORITY_CRITICAL_BLOCK)
78
throw "Invalid notification priority " + aPriority;
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;
84
for (var n = notifications.length - 1; n >= 0; n--) {
85
if (notifications[n].priority < aPriority)
87
insertPos = notifications[n];
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);
96
newitem.style.position = "fixed";
97
newitem.style.top = "100%";
99
this.insertBefore(newitem, insertPos);
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);
108
newitem.appendChild(buttonElem);
109
buttonElem.buttonInfo = button;
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";
119
newitem.type = "warning";
122
this._showNotification(newitem, true);
124
// Fire event for accessibility APIs
125
var event = document.createEvent("Events");
126
event.initEvent("AlertActive", true, true);
127
newitem.dispatchEvent(event);
134
<method name="removeNotification">
135
<parameter name="aItem"/>
138
if (aItem == this.currentNotification)
139
this.removeCurrentNotification();
141
this.removeChild(aItem);
147
<method name="removeCurrentNotification">
150
this._showNotification(this.currentNotification, false);
156
<method name="removeAllNotifications">
157
<parameter name="aImmediate"/>
160
var notifications = this.allNotifications;
161
for (var n = notifications.length - 1; n >= 0; n--) {
163
this.removeChild(notifications[n]);
165
this.removeNotification(notifications[n]);
167
this.currentNotification = null;
172
<method name="_showNotification">
173
<parameter name="aNotification"/>
174
<parameter name="aSlideIn"/>
178
clearInterval(this._timer);
179
if (this.currentNotification) {
180
this.currentNotification.style.marginTop = "0px";
181
this.currentNotification.style.opacity = 1;
183
if (this._closedNotification)
184
this._closedNotification.parentNode.
185
removeChild(this._closedNotification);
186
this._setBlockingState(this.currentNotification);
189
var height = aNotification.boxObject.height;
190
var change = height / this.slideSteps;
192
if (this.currentNotification &&
193
this.currentNotification.boxObject.height > height)
194
height = this.currentNotification.boxObject.height;
196
this.currentNotification = aNotification;
197
this._closedNotification = null;
198
aNotification.style.removeProperty("position");
199
aNotification.style.removeProperty("top");
200
aNotification.style.marginTop = -height + "px";
201
aNotification.style.opacity = 0;
205
this._closedNotification = aNotification;
206
var notifications = this.allNotifications;
207
var idx = notifications.length - 2;
209
this.currentNotification = notifications[idx];
211
this.currentNotification = null;
213
var opacitychange = change / height;
216
var slide = function slideInFn()
220
var style = window.getComputedStyle(aNotification, null);
221
var margin = style.getPropertyCSSValue("margin-top").
222
getFloatValue(CSSPrimitiveValue.CSS_PX);
224
if (change > 0 && margin + change >= 0) {
225
aNotification.style.marginTop = "0px";
226
aNotification.style.opacity = 1;
229
else if (change < 0 && margin + change <= -height) {
230
aNotification.style.marginTop = -height + "px";
234
aNotification.style.marginTop = (margin + change).toFixed(4) + "px";
236
aNotification.style.opacity =
237
Number(aNotification.style.opacity) + opacitychange;
241
clearInterval(self._timer);
243
if (self._closedNotification)
244
self._closedNotification.parentNode.
245
removeChild(self._closedNotification);
246
self._setBlockingState(self.currentNotification);
250
this._timer = setInterval(slide, 50);
255
<method name="_setBlockingState">
256
<parameter name="aNotification"/>
259
var isblock = aNotification &&
260
aNotification.priority == this.PRIORITY_CRITICAL_BLOCK;
261
var canvas = this._blockingCanvas;
264
canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
265
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
266
var content = this.firstChild;
268
content.namespaceURI != XULNS ||
269
content.localName != "browser")
272
var width = content.boxObject.width;
273
var height = content.boxObject.height;
274
content.collapsed = true;
276
canvas.setAttribute("width", width);
277
canvas.setAttribute("height", height);
278
canvas.setAttribute("flex", "1");
280
this.appendChild(canvas);
281
this._blockingCanvas = canvas;
283
var bgcolor = "white";
285
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
286
getService(Components.interfaces.nsIPrefBranch);
287
bgcolor = prefService.getCharPref("browser.display.background_color");
289
var win = content.contentWindow;
290
var context = canvas.getContext("2d");
291
context.globalAlpha = 0.5;
292
context.drawWindow(win, win.scrollX, win.scrollY,
293
width, height, bgcolor);
298
canvas.parentNode.removeChild(canvas);
299
this._blockingCanvas = null;
300
var content = this.firstChild;
302
content.collapsed = false;
311
<binding id="notification">
313
<xul:hbox class="notification-inner outset" flex="1" xbl:inherits="type">
314
<xul:hbox anonid="details" align="center" flex="1"
315
oncommand="this.parentNode.parentNode._doButtonCommand(event);">
316
<xul:image anonid="messageImage" class="messageImage" xbl:inherits="src=image"/>
317
<xul:description anonid="messageText" class="messageText" flex="1" xbl:inherits="xbl:text=label"/>
318
<xul:spacer flex="1"/>
321
<xul:toolbarbutton ondblclick="event.stopPropagation();"
322
class="messageCloseButton tabbable"
323
xbl:inherits="hidden=hideclose"
324
tooltiptext="&closeNotification.tooltip;"
325
oncommand="document.getBindingParent(this).close();"/>
329
<stylesheet src="chrome://global/skin/notification.css"/>
331
<implementation implements="nsIAccessibleProvider">
332
<property name="accessibleType" readonly="true">
335
return Components.interfaces.nsIAccessibleProvider.XULAlert;
340
<property name="label" onset="this.setAttribute('label', val); return val;"
341
onget="return this.getAttribute('label');"/>
342
<property name="value" onset="this.setAttribute('value', val); return val;"
343
onget="return this.getAttribute('value');"/>
344
<property name="image" onset="this.setAttribute('image', val); return val;"
345
onget="return this.getAttribute('image');"/>
346
<property name="type" onset="this.setAttribute('type', val); return val;"
347
onget="return this.getAttribute('type');"/>
348
<property name="priority" onget="return parseInt(this.getAttribute('priority')) || 0;"
349
onset="this.setAttribute('priority', val); return val;"/>
351
<property name="control" readonly="true">
354
var parent = this.parentNode;
356
if (parent.localName == "notificationbox")
358
parent = parent.parentNode;
365
<method name="close">
368
var control = this.control;
370
control.removeNotification(this);
377
<method name="_doButtonCommand">
378
<parameter name="aEvent"/>
381
if (!("buttonInfo" in aEvent.target))
384
var button = aEvent.target.buttonInfo;
386
document.popupNode = aEvent.target;
387
document.getElementById(button.popup).
388
showPopup(aEvent.originalTarget, -1, -1, "popup", "bottomleft", "topleft");
389
aEvent.stopPropagation();
392
var callback = button.callback;
394
var result = callback(this, button);
397
aEvent.stopPropagation();