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 / toolbar.xml < prev    next >
Encoding:
Extensible Markup Language  |  2008-04-21  |  12.9 KB  |  352 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="toolbarBindings"
  4.           xmlns="http://www.mozilla.org/xbl"
  5.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  6.           xmlns:xbl="http://www.mozilla.org/xbl">
  7.  
  8.   <binding id="toolbar-base">
  9.     <resources>
  10.       <stylesheet src="chrome://global/skin/toolbar.css"/>
  11.     </resources>
  12.   </binding>
  13.   
  14.   <binding id="toolbox" extends="chrome://global/content/bindings/toolbar.xml#toolbar-base">
  15.     <implementation>
  16.       <field name="palette">
  17.         null
  18.       </field>
  19.  
  20.       <field name="toolbarset">
  21.         null
  22.       </field>
  23.       
  24.       <field name="customToolbarCount">
  25.         0
  26.       </field>
  27.       
  28.       <constructor>
  29.         <![CDATA[
  30.           // Look to see if there is a toolbarset.
  31.           this.toolbarset = this.firstChild;
  32.           while (this.toolbarset && this.toolbarset.localName != "toolbarset")
  33.             this.toolbarset = toolbarset.nextSibling;
  34.           
  35.           if (this.toolbarset) {
  36.             // Create each toolbar described by the toolbarset.
  37.             var index = 0;
  38.             while (toolbarset.hasAttribute("toolbar"+(++index))) {
  39.               var toolbarInfo = toolbarset.getAttribute("toolbar"+index);
  40.               var infoSplit = toolbarInfo.split(":");
  41.               this.appendCustomToolbar(infoSplit[0], infoSplit[1]);
  42.             }
  43.           }
  44.         ]]>
  45.       </constructor>
  46.       
  47.       <method name="appendCustomToolbar">
  48.         <parameter name="aName"/>
  49.         <parameter name="aCurrentSet"/>
  50.         <body>
  51.           <![CDATA[            
  52.             var toolbar = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  53.                                                   "toolbar");
  54.             toolbar.id = "__customToolbar_" + aName.replace(" ", "_");
  55.             toolbar.setAttribute("customizable", "true");
  56.             toolbar.setAttribute("customindex", ++this.customToolbarCount);
  57.             toolbar.setAttribute("toolbarname", aName);
  58.             toolbar.setAttribute("currentset", aCurrentSet);
  59.             toolbar.setAttribute("mode", this.getAttribute("mode"));
  60.             toolbar.setAttribute("iconsize", this.getAttribute("iconsize"));
  61.             toolbar.setAttribute("context", this.toolbarset.getAttribute("context"));
  62.             toolbar.setAttribute("class", "chromeclass-toolbar");
  63.             
  64.             this.insertBefore(toolbar, this.toolbarset);
  65.             return toolbar;
  66.           ]]>
  67.         </body>
  68.       </method>
  69.     </implementation>
  70.   </binding>
  71.   
  72.   <binding id="toolbar" extends="chrome://global/content/bindings/toolbar.xml#toolbar-base">
  73.     <implementation implements="nsIAccessibleProvider">
  74.       <property name="accessibleType" readonly="true">
  75.         <getter>
  76.           return Components.interfaces.nsIAccessibleProvider.XULToolbar;
  77.         </getter>
  78.       </property>
  79.       <field name="firstPermanentChild">
  80.         null
  81.       </field>
  82.       <field name="lastPermanentChild">
  83.         null
  84.       </field>
  85.       
  86.       <property name="toolbarName"
  87.                 onget="return this.getAttribute('toolbarname');"
  88.                 onset="this.setAttribute('toolbarname', val); return val;"/>
  89.       
  90.       <constructor>
  91.         <![CDATA[
  92.           this.firstPermanentChild = this.firstChild;
  93.           this.lastPermanentChild = this.lastChild;
  94.           
  95.           // Searching for the toolbox palette in the toolbar binding because
  96.           // toolbars are constructed first.
  97.           var toolbox = this.parentNode;
  98.           
  99.           if (!toolbox.palette) {
  100.             // Look to see if there is a toolbarpalette.
  101.             var node = toolbox.firstChild;
  102.             while (node) {
  103.               if (node.localName == "toolbarpalette")
  104.                 break;
  105.               node = node.nextSibling;
  106.             }
  107.             
  108.             if (!node)
  109.               return;
  110.  
  111.             // Hold on to the palette but remove it from the document.
  112.             toolbox.palette = node;       
  113.             toolbox.removeChild(node);
  114.           }
  115.           
  116.           // Build up our contents from the palette.
  117.           var currentSet = this.getAttribute("currentset");
  118.           if (!currentSet)
  119.             currentSet = this.getAttribute("defaultset");
  120.           if (currentSet)
  121.             this.currentSet = currentSet;
  122.         ]]>
  123.       </constructor>
  124.  
  125.       <property name="currentSet">
  126.         <getter>
  127.           <![CDATA[
  128.             var node = this.firstChild;
  129.             var currentSet = "";
  130.             while (node) {
  131.               if (node.id &&
  132.                   node.localName == "toolbaritem" || 
  133.                   node.localName == "toolbarbutton" ||
  134.                   node.localName == "toolbarseparator" ||
  135.                   node.localName == "toolbarspring" ||
  136.                   node.localName == "toolbarspacer")
  137.               {
  138.                 if (currentSet)
  139.                   currentSet += ",";
  140.  
  141.                 if (node.localName == "toolbarseparator")
  142.                   currentSet += "separator";
  143.                 else if (node.localName == "toolbarspring")
  144.                   currentSet += "spring";
  145.                 else if (node.localName == "toolbarspacer")
  146.                   currentSet += "spacer";
  147.                 else
  148.                   currentSet += node.id;
  149.               }
  150.               node = node.nextSibling;
  151.             }
  152.             
  153.             return currentSet ? currentSet : "__empty";
  154.           ]]>
  155.         </getter>
  156.         
  157.         <setter>
  158.           <![CDATA[
  159.             // Remove all items before the first permanent child and after the last permanent child.
  160.             while (this.lastChild) {
  161.               if (this.lastChild == this.lastPermanentChild ||
  162.                   (this.lastChild.localName == "toolbarpaletteitem" &&
  163.                   this.lastChild.firstChild == this.lastPermanentChild))
  164.                 break;
  165.               this.removeChild(this.lastChild);
  166.             }
  167.  
  168.             while (this.firstChild) {
  169.               if (this.firstChild == this.firstPermanentChild ||
  170.                   (this.firstChild.localName == "toolbarpaletteitem" &&
  171.                   this.firstChild.firstChild == this.firstPermanentChild))
  172.                 break;
  173.               this.removeChild(this.firstChild);
  174.             }
  175.  
  176.             var firstChildID = this.firstPermanentChild ? this.firstPermanentChild.id : "";
  177.             var lastChildID = this.lastPermanentChild ? this.lastPermanentChild.id : "";
  178.  
  179.             if (val && val != "__empty") {
  180.               var itemIds = val.split(",");
  181.               var before = true;
  182.               this._trackInserted = {};
  183.               for (var i = 0; i < itemIds.length; i++) {
  184.                 if (itemIds[i] == firstChildID || itemIds[i] == lastChildID)
  185.                   before = false;
  186.                 else
  187.                   this.insertItem(itemIds[i], null, null, before);
  188.               }
  189.               delete this._trackInserted;
  190.             }
  191.  
  192.             return val;
  193.           ]]>
  194.         </setter>
  195.       </property>
  196.       
  197.       <method name="insertItem">
  198.         <parameter name="aId"/>
  199.         <parameter name="aBeforeElt"/>
  200.         <parameter name="aWrapper"/>
  201.         <parameter name="aBeforePermanent"/>
  202.         <body>
  203.           <![CDATA[
  204.             var newItem = null;
  205.             
  206.             // Create special cases of palette items.
  207.             var uniqueId;
  208.             if (aId == "separator") {
  209.               newItem = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  210.                                                  "toolbarseparator");
  211.               uniqueId = (new Date()).getTime()+this.childNodes.length;
  212.               newItem.id = "separator" + uniqueId;
  213.               newItem.className = "chromeclass-toolbar-additional";
  214.             } else if (aId == "spring") {
  215.               newItem = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  216.                                                  "toolbarspring");
  217.               uniqueId = (new Date()).getTime()+this.childNodes.length;
  218.               newItem.flex = 1;
  219.               newItem.id = "spring" + uniqueId;
  220.               newItem.className = "chromeclass-toolbar-additional";
  221.             } else if (aId == "spacer") {
  222.               newItem = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  223.                                                  "toolbarspacer");
  224.               uniqueId = (new Date()).getTime()+this.childNodes.length;
  225.               newItem.id = "spacer" + uniqueId;
  226.               newItem.className = "chromeclass-toolbar-additional";
  227.             } else if (this.parentNode.localName == "toolbox") {
  228.               if (this._trackInserted) {
  229.                 // Protect against creating an item with the given id more than once.
  230.                 if (aId in this._trackInserted)
  231.                   return false;
  232.                 this._trackInserted[aId] = null;
  233.               }
  234.               // Attempt to locate an item with a matching id within palette.
  235.               var paletteItem = this.parentNode.palette.firstChild;
  236.               while (paletteItem) {
  237.                 var paletteId = paletteItem.id;
  238.                 if (paletteId == aId) {
  239.                   newItem = paletteItem.cloneNode(true);
  240.                   break;
  241.                 }
  242.                 paletteItem = paletteItem.nextSibling;
  243.               }
  244.             }
  245.             
  246.             if (!newItem)
  247.               return false;
  248.  
  249.             var insertItem = newItem;
  250.             
  251.             // Wrap the item in another node if so inclined.
  252.             if (aWrapper) {
  253.               aWrapper.appendChild(newItem);
  254.               insertItem = aWrapper;
  255.             }
  256.             
  257.             // Insert the palette item into the toolbar.
  258.             if (aBeforeElt)
  259.               this.insertBefore(insertItem, aBeforeElt);
  260.             else if (aBeforePermanent && this.firstPermanentChild)
  261.               this.insertBefore(insertItem, this.firstPermanentChild);
  262.             else
  263.               this.appendChild(insertItem);
  264.                
  265.             return newItem;
  266.           ]]>
  267.         </body>
  268.       </method>      
  269.     </implementation>
  270.   </binding>
  271.  
  272.   <binding id="menubar" extends="chrome://global/content/bindings/toolbar.xml#toolbar-base" display="xul:menubar">
  273.     <implementation implements="nsIAccessibleProvider">
  274.       <property name="accessibleType" readonly="true">
  275.         <getter>
  276.           <![CDATA[
  277.             return Components.interfaces.nsIAccessibleProvider.XULMenubar;
  278.           ]]>
  279.         </getter>
  280.        </property>
  281.        <field name="_active">false</field>
  282.        <field name="_statusbar">null</field>
  283.        <field name="_originalStatusText">null</field>
  284.        <property name="statusbar" onget="return this.getAttribute('statusbar');"
  285.                                   onset="this.setAttribute('statusbar', val); return val;"/>
  286.        <method name="_updateStatusText">
  287.           <parameter name="itemText"/>
  288.           <body>
  289.            <![CDATA[
  290.             if (!this._active)
  291.                 return;
  292.             var newText = itemText ? itemText : this._originalStatusText;
  293.             if (newText != this._statusbar.label)
  294.                 this._statusbar.label = newText;
  295.            ]]>
  296.           </body>
  297.         </method>
  298.     </implementation>
  299.     <handlers>
  300.         <handler event="DOMMenuBarActive">
  301.           <![CDATA[
  302.             if (!this.statusbar) return;
  303.             this._statusbar = document.getElementById(this.statusbar);
  304.             if (!this._statusbar)
  305.               return;
  306.             this._active = true;
  307.             this._originalStatusText = this._statusbar.label;
  308.           ]]>
  309.         </handler>
  310.         <handler event="DOMMenuBarInactive">
  311.           <![CDATA[
  312.             if (!this._active)
  313.               return;
  314.             this._active = false;
  315.             this._statusbar.label = this._originalStatusText;
  316.           ]]>
  317.         </handler>
  318.         <handler event="DOMMenuItemActive">this._updateStatusText(event.target.statusText);</handler>
  319.         <handler event="DOMMenuItemInactive">this._updateStatusText("");</handler>
  320.     </handlers>
  321.   </binding>
  322.  
  323.   <binding id="toolbardecoration" extends="chrome://global/content/bindings/toolbar.xml#toolbar-base">
  324.     <implementation implements="nsIAccessibleProvider">
  325.       <property name="accessibleType" readonly="true">
  326.         <getter>
  327.           return Components.interfaces.nsIAccessibleProvider.XULToolbarSeparator;
  328.         </getter>
  329.       </property>
  330.     </implementation>
  331.   </binding>
  332.  
  333.   <binding id="toolbarpaletteitem" extends="chrome://global/content/bindings/toolbar.xml#toolbar-base" display="xul:button">
  334.     <content>
  335.       <xul:hbox class="toolbarpaletteitem-box" flex="1" xbl:inherits="type,place">
  336.         <children/>
  337.       </xul:hbox>
  338.     </content>
  339.   </binding>
  340.     
  341.   <binding id="toolbarpaletteitem-palette" extends="chrome://global/content/bindings/toolbar.xml#toolbarpaletteitem">
  342.     <content>
  343.       <xul:hbox class="toolbarpaletteitem-box" xbl:inherits="type,place">
  344.         <children/>
  345.       </xul:hbox>
  346.       <xul:label xbl:inherits="value=title"/>
  347.     </content>
  348.   </binding>
  349.  
  350. </bindings>          
  351.  
  352.