home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / toolkit.jar / content / global / bindings / notification.xml < prev    next >
Encoding:
Extensible Markup Language  |  2008-04-29  |  15.3 KB  |  425 lines

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