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