home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / toolkit.jar / content / global / bindings / toolbar.xml < prev    next >
Encoding:
Extensible Markup Language  |  2001-09-24  |  9.3 KB  |  265 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.  
  7.   <binding id="toolbar-base">
  8.     <resources>
  9.       <stylesheet src="chrome://global/skin/toolbar.css"/>
  10.     </resources>
  11.   </binding>
  12.  
  13.   <binding id="toolbox" extends="chrome://global/content/bindings/toolbar.xml#toolbar-base">
  14.     <content orient="vertical">
  15.       <xul:vbox flex="1" class="toolbar-internal-box">
  16.         <children/>
  17.       </xul:vbox>
  18.       <xul:hbox tbattr="collapsed-tray-holder" class="collapsed-tray-holder" moz-collapsed="true">
  19.         <xul:hbox tbattr="collapsed-tray" class="collapsed-tray"/>
  20.         <xul:spring flex="1" class="collapsed-tray-spring"/>
  21.       </xul:hbox>
  22.     </content>
  23.     
  24.     <implementation>
  25.       <method name="collapseToolbar">
  26.         <parameter name="toolbar"/>
  27.         <body>
  28.         <![CDATA[
  29.           const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  30.           try {
  31.             this.createCollapsedGrippy(toolbar);
  32.             toolbar.setAttribute("moz-collapsed", "true");
  33.             document.persist(toolbar.id, "moz-collapsed");
  34.           }
  35.           catch(e) {
  36.           }
  37.         ]]>
  38.         </body>
  39.       </method>
  40.       
  41.       <method name="expandToolbar">
  42.         <parameter name="aGrippyID"/>
  43.         <body>
  44.         <![CDATA[
  45.           var idString = aGrippyID.substring("moz_tb_collapsed_".length, aGrippyID.length);
  46.           var toolbar = document.getElementById(idString);
  47.           toolbar.setAttribute("moz-collapsed", "false");
  48.           var collapsedTray = this.findNodeByAttribute("tbattr", "collapsed-tray");
  49.           var collapsedToolbar = document.getElementById("moz_tb_collapsed_" + toolbar.id);
  50.           collapsedTray.removeChild(collapsedToolbar);
  51.           if (!collapsedTray.hasChildNodes()) 
  52.             this.findNodeByAttribute("tbattr", "collapsed-tray-holder").setAttribute("moz-collapsed", "true");
  53.           document.persist(toolbar.id, "moz-collapsed");
  54.         ]]>
  55.         </body>
  56.       </method>
  57.       
  58.       <method name="findNodeByAttribute">
  59.         <parameter name="aAttribute"/>
  60.         <parameter name="aValue"/>
  61.         <body>
  62.         <![CDATA[
  63.           var nodes = document.getAnonymousNodes(this);
  64.           for (var i = 0; i < nodes.length; i++) {
  65.             if (nodes[i].getAttribute(aAttribute) == aValue)
  66.               return nodes[i];
  67.             else {
  68.               var subnodes = nodes[i].getElementsByAttribute(aAttribute, aValue);
  69.               if (!subnodes.length) continue;
  70.               return subnodes[0];
  71.             }
  72.           }
  73.           return null;
  74.         ]]>
  75.         </body>
  76.       </method>
  77.       
  78.       <method name="createCollapsedGrippy">
  79.         <parameter name="aToolbar"/>
  80.         <body>
  81.         <![CDATA[
  82.           const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  83.           try {
  84.             var grippy = aToolbar.findNodeByAttribute("tbattr", "toolbar-grippy");
  85.             var boxObject = grippy.boxObject.QueryInterface(Components.interfaces.nsIBoxObject);
  86.             var collapsedGrippy = document.createElementNS(XUL_NS, "toolbargrippy");
  87.             if (collapsedGrippy) {
  88.               var width = boxObject.height > 20 ? boxObject.height : 23;
  89.               var height = boxObject.width > 10 ? boxObject.width : 12;
  90.               var styleString = "width: " + width + "px; height: " + height + "px;";
  91.               collapsedGrippy.setAttribute("style", styleString);
  92.               collapsedGrippy.setAttribute("tooltip", aToolbar.getAttribute("grippytooltip"));
  93.               collapsedGrippy.setAttribute("tooltiptext", aToolbar.getAttribute("grippytooltiptext"));
  94.               collapsedGrippy.setAttribute("id", "moz_tb_collapsed_" + aToolbar.id);
  95.               collapsedGrippy.setAttribute("moz_grippy_collapsed", "true"); 
  96.               collapsedGrippy.setAttribute("tbgrippy-collapsed", "true");
  97.               var collapsedTrayHolder = this.findNodeByAttribute("tbattr", "collapsed-tray-holder");
  98.               if (collapsedTrayHolder.getAttribute("moz-collapsed") == "true")
  99.                 collapsedTrayHolder.removeAttribute("moz-collapsed");
  100.               this.findNodeByAttribute("tbattr", "collapsed-tray").appendChild(collapsedGrippy);
  101.               collapsedGrippy = document.getElementById("moz_tb_collapsed_" + aToolbar.id);
  102.             }
  103.           }
  104.           catch (e) {
  105.             throw e;
  106.           }
  107.         ]]>        
  108.         </body>
  109.       </method>
  110.  
  111.       <property name="deferAttached">
  112.         <getter>
  113.           return this.getAttribute("deferattached");
  114.         </getter>
  115.         <setter>
  116.           this.setAttribute("deferattached", val);
  117.           return val;
  118.         </setter>
  119.       </property>
  120.       
  121.     </implementation>
  122.   </binding>
  123.  
  124.   <binding id="toolbar" extends="chrome://global/content/bindings/toolbar.xml#toolbar-base">
  125.     <content>
  126.       <xul:toolbargrippy inherits="tooltiptext=grippytooltiptext,tooltip=grippytooltip,last-toolbar,hidden=grippyhidden"
  127.                          tbattr="toolbar-grippy"
  128.                          class="toolbar-grippy"/>
  129.       <xul:hbox flex="1" class="toolbar-holder" align="center"
  130.                inherits="collapsed,last-toolbar,orient=tborient,align=tbalign,pack=tbpack">
  131.         <children/>
  132.       </xul:hbox>
  133.     </content>
  134.     
  135.     <implementation>
  136.       <constructor>
  137.         <![CDATA[
  138.           if (this.getAttribute("moz-collapsed") == "true" &&
  139.               this.parentNode.localName == "toolbox")
  140.             this.parentNode.createCollapsedGrippy(this);
  141.         ]]>
  142.       </constructor>
  143.  
  144.       <method name="findNodeByAttribute">
  145.         <parameter name="aAttribute"/>
  146.         <parameter name="aValue"/>
  147.         <body>
  148.         <![CDATA[
  149.           var nodes = document.getAnonymousNodes(this);
  150.           for (var i = 0; i < nodes.length; i++) {
  151.             if (nodes[i].getAttribute(aAttribute) == aValue)
  152.               return nodes[i];
  153.             else {
  154.               var subnodes = nodes[i].getElementsByAttribute(aAttribute, aValue);
  155.               return subnodes.length ? subnodes[0] : null;
  156.             }
  157.           }
  158.           return null;
  159.         ]]>
  160.         </body>
  161.       </method>
  162.     </implementation>
  163.   </binding>
  164.  
  165.   <binding id="menubar" extends="xul:menubar">
  166.     <resources>
  167.       <stylesheet src="chrome://global/skin/toolbar.css"/>
  168.     </resources>
  169.  
  170.     <content>
  171.       <xul:toolbargrippy inherits="tooltiptext=grippytooltiptext,tooltip=grippytooltip,last-toolbar,hidden=grippyhidden"
  172.                          tbattr="toolbar-grippy" class="toolbar-grippy"/>
  173.       <xul:hbox flex="1" class="toolbar-holder" inherits="collapsed,last-toolbar" align="center">
  174.         <children/>
  175.       </xul:hbox>
  176.     </content>
  177.     
  178.     <implementation>
  179.       <constructor>
  180.         <![CDATA[
  181.           if (this.getAttribute("moz-collapsed") == "true" &&
  182.               this.parentNode.localName == "toolbox")
  183.             this.parentNode.createCollapsedGrippy(this);
  184.         ]]>
  185.       </constructor>
  186.  
  187.       <method name="findNodeByAttribute">
  188.         <parameter name="aAttribute"/>
  189.         <parameter name="aValue"/>
  190.         <body>
  191.         <![CDATA[
  192.           var nodes = document.getAnonymousNodes(this);
  193.           for (var i = 0; i < nodes.length; i++) {
  194.             if (nodes[i].getAttribute(aAttribute) == aValue)
  195.               return nodes[i];
  196.             else {
  197.               var subnodes = nodes[i].getElementsByAttribute(aAttribute, aValue);
  198.               return subnodes.length ? subnodes[0] : null;
  199.             }
  200.           }
  201.           return null;
  202.         ]]>
  203.         </body>
  204.       </method>
  205.     </implementation>
  206.   </binding>
  207.  
  208.   <binding id="toolbargrippy" extends="xul:button">
  209.     <resources>
  210.       <stylesheet src="chrome://global/skin/toolbar.css"/>
  211.     </resources>
  212.  
  213.     <implementation>
  214.       <property name="collapsed">
  215.         <getter>
  216.           return this.getAttribute("moz_grippy_collapsed");
  217.         </getter>
  218.         <setter>
  219.           this.setAttribute("moz_grippy_collapsed", val);
  220.           return val;
  221.         </setter>
  222.       </property>
  223.       
  224.       <method name="returnNode">
  225.         <parameter name="aNodeA"/>
  226.         <parameter name="aNodeB"/>
  227.         <body>
  228.         <![CDATA[
  229.           var node = this.parentNode;
  230.           while (node && node.localName != "window" && 
  231.                  (node.localName != aNodeA && (node.localName != aNodeB)))  {
  232.             node = node.parentNode;
  233.           }
  234.           return node;
  235.         ]]>
  236.         </body>
  237.       </method>
  238.       
  239.       <method name="grippyTriggered">
  240.         <body>
  241.         <![CDATA[
  242.           var toolbox = this.returnNode("toolbox");
  243.           var toolbar = this.returnNode("toolbar", "menubar");
  244.           if (this.collapsed) 
  245.             toolbox.expandToolbar(this.id);
  246.           else
  247.             toolbox.collapseToolbar(toolbar);
  248.         ]]>
  249.         </body>
  250.       </method>
  251.     </implementation>  
  252.     
  253.     <handlers>
  254.       <handler event="command">
  255.       <![CDATA[
  256.         this.grippyTriggered();
  257.       ]]>
  258.       </handler>
  259.     </handlers>
  260.   </binding>  
  261.  
  262.   <binding id="toolbarseparator" extends="chrome://global/content/bindings/toolbar.xml#toolbar-base"/>
  263.  
  264. </bindings>          
  265.