1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/content/bindings/notification.xml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,158 @@ 1.4 +<?xml version="1.0"?> 1.5 + 1.6 +<!-- This Source Code Form is subject to the terms of the Mozilla Public 1.7 + - License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 1.9 + 1.10 +<!DOCTYPE bindings [ 1.11 +<!ENTITY % notificationDTD SYSTEM "chrome://global/locale/notification.dtd"> 1.12 +%notificationDTD; 1.13 +]> 1.14 + 1.15 +<bindings id="notificationBindings" 1.16 + xmlns="http://www.mozilla.org/xbl" 1.17 + xmlns:xbl="http://www.mozilla.org/xbl" 1.18 + xmlns:html="http://www.w3.org/1999/xhtml" 1.19 + xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.20 + 1.21 + <binding id="notificationbox" extends="chrome://global/content/bindings/notification.xml#notificationbox"> 1.22 + <content> 1.23 + <xul:stack xbl:inherits="hidden=notificationshidden" 1.24 + class="notificationbox-stack"> 1.25 + <xul:spacer/> 1.26 + <children includes="notification"/> 1.27 + </xul:stack> 1.28 + <html:div anonid="layer1" class="notification-layer"></html:div> 1.29 + <html:div anonid="layer2" class="notification-layer"></html:div> 1.30 + <children/> 1.31 + </content> 1.32 + 1.33 + <implementation> 1.34 + <constructor> 1.35 + <![CDATA[ 1.36 + this.addEventListener("AlertActive", this.handleEvent, true); 1.37 + this.addEventListener("AlertClose", this.handleEvent, true); 1.38 + this.setAttribute("count", 0); 1.39 + ]]> 1.40 + </constructor> 1.41 + <destructor> 1.42 + <![CDATA[ 1.43 + this.removeEventListener("AlertActive", this.handleEvent, true); 1.44 + this.removeEventListener("AlertClose", this.handleEvent, true); 1.45 + ]]> 1.46 + </destructor> 1.47 + <method name="adoptNotification"> 1.48 + <parameter name="aItem"/> 1.49 + <body> 1.50 + <![CDATA[ 1.51 + // insert an existing notification element 1.52 + // XXX: borrows code from appendNotification in toolkit/content/widgets/notification.xml 1.53 + // if this sticks around, we'll want to refactor both to eliminate duplication 1.54 + 1.55 + let priority = aItem.priority; 1.56 + // check for where the notification should be inserted according to 1.57 + // priority. If two are equal, the existing one appears on top. 1.58 + let notifications = this.allNotifications; 1.59 + let insertPos = null; 1.60 + for (let n = notifications.length - 1; n >= 0; n--) { 1.61 + if (notifications[n].priority < priority) 1.62 + break; 1.63 + insertPos = notifications[n]; 1.64 + } 1.65 + if (!insertPos) { 1.66 + aItem.style.position = "fixed"; 1.67 + aItem.style.top = "100%"; 1.68 + aItem.style.marginTop = "-15px"; 1.69 + aItem.style.opacity = "0"; 1.70 + } 1.71 + let label = aItem.label; 1.72 + this.insertBefore(aItem, insertPos); 1.73 + aItem.label = label; 1.74 + 1.75 + if (!insertPos) 1.76 + this._showNotification(aItem, true, true); 1.77 + 1.78 + // Fire event for accessibility APIs 1.79 + var event = document.createEvent("Events"); 1.80 + event.initEvent("AlertActive", true, true); 1.81 + aItem.dispatchEvent(event); 1.82 + 1.83 + return aItem; 1.84 + ]]> 1.85 + </body> 1.86 + </method> 1.87 + <method name="removeNotification"> 1.88 + <parameter name="aItem"/> 1.89 + <parameter name="aSkipAnimation"/> 1.90 + <body> 1.91 + <![CDATA[ 1.92 + if (aItem == this.currentNotification) 1.93 + this.removeCurrentNotification(aSkipAnimation); 1.94 + else if (aItem != this._closedNotification) 1.95 + this._removeNotificationElement(aItem); 1.96 + 1.97 + // Fire notification closed event. 1.98 + let event = new Event('AlertClose'); 1.99 + event.notification = aItem; 1.100 + this.dispatchEvent(event); 1.101 + 1.102 + return aItem; 1.103 + ]]> 1.104 + </body> 1.105 + </method> 1.106 + <method name="handleEvent"> 1.107 + <parameter name="aEvent"/> 1.108 + <body> 1.109 + <![CDATA[ 1.110 + switch (aEvent.type) { 1.111 + case "AlertActive": 1.112 + case "AlertClose": 1.113 + this.setAttribute("count", this.allNotifications.length); 1.114 + break; 1.115 + } 1.116 + ]]> 1.117 + </body> 1.118 + </method> 1.119 + </implementation> 1.120 + </binding> 1.121 + 1.122 + <binding id="notification" role="xul:alert" extends="chrome://global/content/bindings/notification.xml#notification"> 1.123 + <implementation> 1.124 + <property name="_messageContainer" onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'messageText');"/> 1.125 + <property name="label"> 1.126 + <getter><![CDATA[ 1.127 + if (this._messageContainer.childElementCount) { 1.128 + // return a document fragment when our label is a complex value containing elements 1.129 + // by cloning childNodes into a document fragment, the returned value 1.130 + // is *not* live and will survive unbinding of this notification 1.131 + let frag = this.ownerDocument.createDocumentFragment(); 1.132 + let containerNode = this._messageContainer; 1.133 + for(let cnode of containerNode.childNodes) { 1.134 + frag.appendChild(cnode.cloneNode(true)); 1.135 + } 1.136 + return frag; 1.137 + } else { 1.138 + return String.trim(this._messageContainer.textContent) || 1.139 + this.getAttribute("label"); 1.140 + } 1.141 + ]]></getter> 1.142 + <setter><![CDATA[ 1.143 + // accept a string or node (e.g. document fragment, element or text node) as label value 1.144 + if (val && "object" == typeof val && ('nodeType' in val)) { 1.145 + let containerNode = this._messageContainer; 1.146 + let cnode; 1.147 + while((cnode = containerNode.firstChild)) { 1.148 + cnode.remove(); 1.149 + } 1.150 + if (val.ownerDocument !== this.ownerDocument) { 1.151 + val = this.ownerDocument.importNode(val, true); 1.152 + } 1.153 + return containerNode.appendChild(val); 1.154 + } else { 1.155 + return (this._messageContainer.textContent = val); 1.156 + } 1.157 + ]]></setter> 1.158 + </property> 1.159 + </implementation> 1.160 + </binding> 1.161 +</bindings>