home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / toolkit.jar / content / global / bindings / tabbox.xml < prev    next >
Extensible Markup Language  |  2002-11-11  |  17KB  |  525 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="tabBindings"
  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="tab-base">
  9.     <resources>
  10.       <stylesheet src="chrome://global/skin/tabbox.css"/>
  11.     </resources>
  12.   </binding>
  13.  
  14.   <binding id="tabbox" display="xul:box"
  15.            extends="chrome://global/content/bindings/tabbox.xml#tab-base">
  16.     <implementation implements="nsIAccessibleProvider">
  17.       <property name="accessible">
  18.         <getter>
  19.           <![CDATA[
  20.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  21.             return accService.createXULTabBoxAccessible(this);
  22.           ]]>
  23.         </getter>
  24.       </property>
  25.  
  26.       <property name="handleCtrlTab">
  27.         <setter>
  28.         <![CDATA[
  29.           this.setAttribute("handleCtrlTab", val);
  30.           return val;
  31.         ]]>
  32.         </setter>
  33.         <getter>
  34.         <![CDATA[
  35.           return (this.getAttribute("handleCtrlTab") != "false");
  36.         ]]>
  37.         </getter>
  38.       </property>
  39.       
  40.       <property name="handleCtrlPageUpDown">
  41.         <setter>
  42.         <![CDATA[
  43.           this.setAttribute("handleCtrlPageUpDown", val);
  44.           return val;
  45.         ]]>
  46.         </setter>
  47.         <getter>
  48.         <![CDATA[
  49.           return (this.getAttribute("handleCtrlPageUpDown") != "false");
  50.         ]]>
  51.         </getter>
  52.       </property>
  53.  
  54.       <property name="_tabs">
  55.         <getter>
  56.         <![CDATA[
  57.           var tabs = this.getElementsByTagNameNS(
  58.               "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  59.               "tabs");
  60.           return tabs.length ? tabs[0] : null;
  61.         ]]>
  62.         </getter>
  63.       </property>
  64.  
  65.       <property name="_tabpanels">
  66.         <getter>
  67.         <![CDATA[
  68.           var tabpanels = this.getElementsByTagNameNS(
  69.               "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  70.               "tabpanels");
  71.           return tabpanels.length ? tabpanels[0] : null;
  72.         ]]>
  73.         </getter>
  74.       </property>
  75.       
  76.       <property name="selectedIndex"
  77.                 onget="return this._tabs ? this._tabs.selectedIndex : null;">
  78.         <setter>
  79.         <![CDATA[
  80.           if (this._tabs)
  81.             this._tabs.selectedIndex = val;
  82.           return val;
  83.         ]]>
  84.         </setter>
  85.       </property>
  86.  
  87.       <property name="selectedTab"
  88.                 onget="return this._tabs ? this._tabs.selectedItem : null;">
  89.         <setter>
  90.         <![CDATA[
  91.           if (!val)
  92.             throw Components.results.NS_ERROR_NULL_POINTER;
  93.           if (this._tabs)
  94.             this._tabs.selectedItem = val;
  95.           return val;
  96.         ]]>
  97.         </setter>
  98.       </property>
  99.  
  100.       <property name="selectedPanel"
  101.                 onget="return this._tabpanels ? this._tabpanels.selectedPanel : null;">
  102.         <setter>
  103.         <![CDATA[
  104.           if (!val)
  105.             throw Components.results.NS_ERROR_NULL_POINTER;
  106.           if (this._tabpanels)
  107.             this._tabpanels.selectedPanel = val;
  108.           return val;
  109.         ]]>
  110.         </setter>
  111.       </property>
  112.  
  113.       <field name="_keyEventHandler" readonly="true">
  114.       <![CDATA[({
  115.         tabbox: this,
  116.         handleEvent: function handleEvent(event) {
  117.           switch (event.keyCode) {
  118.             case event.DOM_VK_TAB:
  119.               if (event.ctrlKey && !event.altKey && !event.metaKey)
  120.                 if (this.tabbox._tabs && this.tabbox.handleCtrlTab) {
  121.                   this.tabbox._tabs.advanceSelectedTab(event.shiftKey ? -1 : 1);
  122.                   event.stopPropagation();
  123.                   event.preventDefault();
  124.                 }
  125.               break;
  126.             case event.DOM_VK_PAGE_UP:
  127.               if (event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey)
  128.                 if (this.tabbox._tabs && this.tabbox.handleCtrlPageUpDown) {
  129.                   this.tabbox._tabs.advanceSelectedTab(-1);
  130.                   event.stopPropagation();
  131.                   event.preventDefault();
  132.                 }
  133.               break;
  134.             case event.DOM_VK_PAGE_DOWN:
  135.               if (event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey)
  136.                 if (this.tabbox._tabs && this.tabbox.handleCtrlPageUpDown) {
  137.                   this.tabbox._tabs.advanceSelectedTab(1);
  138.                   event.stopPropagation();
  139.                   event.preventDefault();
  140.                 }
  141.               break;
  142.           }
  143.         }
  144.       })]]>
  145.       </field>
  146.  
  147.       <field name="_eventNode">
  148.         var eventNode = this;
  149.         switch (this.getAttribute("eventnode")) {
  150.           case "parent": eventNode = this.parentNode; break;
  151.           case "window": eventNode = window; break;
  152.           case "document": eventNode = document; break;
  153.         }
  154.         eventNode;
  155.       </field>
  156.  
  157.       <property name="eventNode" onget="return this._eventNode;">
  158.         <setter>
  159.           <![CDATA[
  160.             if (val != this._eventNode) {
  161.               val.addEventListener("keypress", this._keyEventHandler, false);
  162.               this._eventNode.removeEventListener("keypress", this._keyEventHandler, false);
  163.               this._eventNode = val;
  164.             }
  165.             return val;
  166.           ]]>
  167.         </setter>
  168.       </property>
  169.  
  170.       <constructor>
  171.         this._eventNode.addEventListener("keypress", this._keyEventHandler, false);
  172.       </constructor>
  173.  
  174.       <destructor>
  175.         this._eventNode.removeEventListener("keypress", this._keyEventHandler, false);
  176.       </destructor>
  177.     </implementation>
  178.   </binding>
  179.  
  180.   <binding id="tabs" display="xul:box"
  181.            extends="chrome://global/content/bindings/tabbox.xml#tab-base">
  182.     <content>
  183.       <xul:spacer class="tabs-left"/>
  184.       <children/>
  185.       <xul:spacer class="tabs-right" flex="1"/>
  186.     </content>
  187.     
  188.     <implementation implements="nsIDOMXULSelectControlElement, nsIAccessibleProvider">
  189.       <constructor>
  190.       <![CDATA[
  191.         // first and last tabs need to be able to have unique styles
  192.         // and also need to select first tab on startup.
  193.         if (this.firstChild)
  194.           this.firstChild.setAttribute("first-tab", "true");
  195.         if (this.lastChild)
  196.           this.lastChild.setAttribute("last-tab", "true");
  197.         this.selectedIndex = 0;
  198.         var o = this.getAttribute("orient");
  199.         if (!o)
  200.           this.setAttribute("orient", "horizontal");
  201.       ]]>
  202.       </constructor>
  203.       
  204.       <property name="accessible">
  205.         <getter>
  206.           <![CDATA[
  207.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  208.             return accService.createXULTabsAccessible(this);
  209.           ]]>
  210.         </getter>
  211.       </property>
  212.  
  213.       <property name="selectedIndex">
  214.         <getter>
  215.         <![CDATA[
  216.           const tabs = this.childNodes;
  217.           for (var i = 0; i < tabs.length; i++) {
  218.             if (tabs[i].selected)
  219.               return i;
  220.           }
  221.           // throw an exception when no tab is selected (we shouldn't get here)
  222.           throw Components.results.NS_ERROR_FAILURE;
  223.         ]]>
  224.         </getter>
  225.         
  226.         <setter>
  227.         <![CDATA[
  228.           const tabs = this.childNodes;
  229.           if (0 <= val && val < tabs.length && !tabs[val].selected) {
  230.  
  231.             for (var i = 0; i < tabs.length; i++)
  232.               if (i != val && tabs[i].selected)
  233.                 tabs[i].selected = false;
  234.  
  235.             tabs[val].selected = true;
  236.   
  237.             for (var parent = this.parentNode; parent; parent = parent.parentNode) {
  238.               if (parent.localName == 'tabbox') {
  239.                 var tabpanels = parent._tabpanels;
  240.                 // This will cause an onselect event to fire for the tabpanel element.
  241.                 if (tabpanels)
  242.                   tabpanels.selectedIndex = val;
  243.                 break;
  244.               }
  245.             }
  246.             
  247.             // Fire an onselect event for the tabs element.
  248.             var event = document.createEvent('Events');
  249.             event.initEvent('select', false, true);
  250.             this.dispatchEvent(event);
  251.           }
  252.           return val;
  253.         ]]>
  254.         </setter>
  255.       </property>
  256.  
  257.       <property name="selectedItem">
  258.         <getter>
  259.         <![CDATA[
  260.           const tabs = this.childNodes;
  261.           for (var i = 0; i < tabs.length; i++) {
  262.             if (tabs[i].selected)
  263.               return tabs[i];
  264.           }
  265.           // throw an exception when no tab is selected (we shouldn't get here)
  266.           throw Components.results.NS_ERROR_FAILURE;
  267.         ]]>
  268.         </getter>
  269.         
  270.         <setter>
  271.         <![CDATA[
  272.           if (!val)
  273.             throw Components.results.NS_ERROR_NULL_POINTER;
  274.           if (!val.selected) {
  275.             const tabs = this.childNodes;
  276.             for (var i = 0; i < tabs.length; i++)
  277.               if (tabs[i] == val)
  278.                 this.selectedIndex = i;
  279.           }
  280.           return val;
  281.         ]]>
  282.         </setter>
  283.       </property>
  284.     
  285.       <method name="advanceSelectedTab">
  286.         <parameter name="aDir"/>
  287.         <body>
  288.         <![CDATA[
  289.           var startTab = this.selectedItem;
  290.           var next = startTab[aDir == -1 ? "previousSibling" : "nextSibling"];
  291.  
  292.           while (next != startTab && (!next || next.getAttribute("hidden"))) {
  293.             if (next && next.getAttribute("hidden"))
  294.               next = next[aDir == -1 ? "previousSibling" : "nextSibling"];
  295.             if (!next)
  296.               next = aDir == 1 ? this.childNodes[0] : this.childNodes[this.childNodes.length - 1];
  297.           }
  298.  
  299.           if (next && next != startTab) {
  300.             this.selectedItem = next;
  301.             next.focus();
  302.             document.commandDispatcher.advanceFocusIntoSubtree(next);
  303.           }
  304.         ]]>
  305.         </body>
  306.       </method>
  307.  
  308.       <method name="appendItem">
  309.         <parameter name="label"/>
  310.         <parameter name="value"/>
  311.         <body>
  312.         <![CDATA[
  313.           var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  314.           var tab = document.createElementNS(XULNS, "tab");
  315.           tab.setAttribute("label", label);
  316.           tab.setAttribute("value", value);
  317.           this.appendChild(tab);
  318.           return tab;
  319.         ]]>
  320.         </body>
  321.       </method>
  322.       
  323.       <method name="insertItemAt">
  324.         <parameter name="index"/>
  325.         <parameter name="label"/>
  326.         <parameter name="value"/>
  327.         <body>
  328.         <![CDATA[
  329.           var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  330.           var tab = document.createElementNS(XULNS, "tab");
  331.           tab.setAttribute("label", label);
  332.           tab.setAttribute("value", value);
  333.           var before = this.childNodes[index];
  334.           if (before)
  335.             this.insertBefore(tab, before);
  336.           else
  337.             this.appendChild(tab);
  338.           return tab;
  339.         ]]>
  340.         </body>
  341.       </method>
  342.  
  343.       <method name="removeItemAt">
  344.         <parameter name="index"/>
  345.         <body>
  346.         <![CDATA[
  347.           var remove = this.childNodes[index];
  348.           if (remove)
  349.             this.removeChild(remove);
  350.           return remove;
  351.         ]]>
  352.         </body>
  353.       </method>
  354.     </implementation>
  355.   </binding>
  356.   
  357.   <binding id="tabs-closebutton" 
  358.            extends="chrome://global/content/bindings/tabbox.xml#tabs">
  359.     <content>
  360.       <xul:stack>
  361.         <xul:spacer class="tabs-left"/>
  362.         <xul:toolbarbutton class="tabs-newbutton" xbl:inherits="oncommand=onnewtab,tooltiptext=tooltiptextnew"/>
  363.       </xul:stack>
  364.       <xul:hbox flex="1" style="min-width: 1px;">
  365.         <children/>
  366.         <xul:spacer class="tabs-right" flex="1"/>
  367.       </xul:hbox>
  368.       <xul:stack>
  369.         <xul:spacer class="tabs-right"/>
  370.         <xul:hbox class="tabs-closebutton-box" align="center" pack="end">
  371.           <xul:toolbarbutton class="tabs-closebutton close-button" xbl:inherits="disabled=disableclose,oncommand=onclosetab"/>
  372.         </xul:hbox>
  373.       </xul:stack>
  374.     </content>
  375.   </binding>
  376.   
  377.   <binding id="tabpanels"
  378.            extends="chrome://global/content/bindings/tabbox.xml#tab-base">
  379.     <implementation implements="nsIAccessibleProvider">
  380.       <property name="accessible">
  381.         <getter>
  382.           <![CDATA[
  383.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  384.             return accService.createXULTabPanelsAccessible(this);
  385.           ]]>
  386.         </getter>
  387.       </property>
  388.  
  389.       <field name="_selectedPanel">null</field>
  390.  
  391.       <property name="selectedIndex">
  392.         <getter>
  393.         <![CDATA[
  394.           var indexStr = this.getAttribute("selectedIndex");
  395.           return indexStr ? parseInt(indexStr) : -1;
  396.         ]]>
  397.         </getter>
  398.                         
  399.         <setter>
  400.         <![CDATA[
  401.           var panel = this._selectedPanel;
  402.           this._selectedPanel = this.childNodes[val];
  403.           this.setAttribute("selectedIndex", val);
  404.           if (this._selectedPanel != panel) {
  405.             var event = document.createEvent("Events");
  406.             event.initEvent("select", false, true);
  407.             this.dispatchEvent(event);
  408.           }
  409.           return val;
  410.         ]]>
  411.         </setter>
  412.       </property>
  413.  
  414.  
  415.       <property name="selectedPanel">
  416.         <getter>
  417.           <![CDATA[
  418.             return this._selectedPanel;
  419.           ]]>
  420.         </getter>
  421.  
  422.         <setter>
  423.           <![CDATA[
  424.             var selectedIndex = -1;
  425.             for (var panel = val; panel != null; panel = panel.previousSibling)
  426.               ++selectedIndex;
  427.             this.selectedIndex = selectedIndex;
  428.             return val;
  429.           ]]>
  430.         </setter>
  431.       </property>
  432.     </implementation>
  433.   </binding>
  434.  
  435.   <binding id="tab" display="xul:button"
  436.            extends="chrome://global/content/bindings/tabbox.xml#tab-base">
  437.     <content>
  438.       <xul:image class="tab-icon" xbl:inherits="validate,src=image"/>
  439.       <xul:label class="tab-text" xbl:inherits="value=label,accesskey,crop,disabled" flex="1"/>
  440.     </content>
  441.     
  442.     <implementation implements="nsIDOMXULSelectControlItemElement, nsIAccessibleProvider">
  443.       <property name="accessible">
  444.         <getter>
  445.           <![CDATA[
  446.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  447.             return accService.createXULTabAccessible(this);
  448.           ]]>
  449.         </getter>
  450.       </property>
  451.  
  452.       <property name="label">
  453.         <getter>
  454.           return this.getAttribute("label");
  455.         </getter>
  456.         <setter>  
  457.           this.setAttribute("label", val);
  458.           return val;
  459.         </setter>
  460.       </property>
  461.  
  462.       <property name="tabs" 
  463.                 onget="return this.getAttribute('tabs');"
  464.                 onset="this.setAttribute('tabs', val); return val;"/>
  465.  
  466.       <!-- XXX -->                
  467.       <property name="selected">
  468.         <getter>
  469.           return this.getAttribute("selected") == "true" ? true : false;
  470.         </getter>
  471.         <setter>
  472.           this.setAttribute("selected", val);
  473.           if (this.previousSibling) {
  474.             if (val)
  475.               this.previousSibling.setAttribute("beforeselected", val);
  476.             else
  477.               this.previousSibling.removeAttribute("beforeselected");
  478.           }
  479.           if (this.nextSibling) {
  480.             if (val)
  481.               this.nextSibling.setAttribute("afterselected", val);
  482.             else
  483.               this.nextSibling.removeAttribute("afterselected");
  484.           }
  485.           return val;
  486.         </setter>
  487.       </property>
  488.     </implementation>
  489.     
  490.     <handlers>
  491.       <handler event="click" button="0">
  492.       <![CDATA[
  493.         this.parentNode.selectedItem = this;
  494.       ]]>
  495.       </handler>
  496.       
  497.       <handler event="keypress" keycode="vk_left">
  498.       <![CDATA[
  499.         this.parentNode.advanceSelectedTab(-1);
  500.       ]]>
  501.       </handler>
  502.       
  503.       <handler event="keypress" keycode="vk_right">
  504.       <![CDATA[
  505.         this.parentNode.advanceSelectedTab(1);
  506.       ]]>
  507.       </handler>
  508.       
  509.       <handler event="keypress" keycode="vk_up">
  510.       <![CDATA[
  511.         this.parentNode.advanceSelectedTab(-1);
  512.       ]]>
  513.       </handler>
  514.       
  515.       <handler event="keypress" keycode="vk_down">
  516.       <![CDATA[
  517.         this.parentNode.advanceSelectedTab(1);
  518.       ]]>
  519.       </handler>
  520.     </handlers>
  521.   </binding>
  522.   
  523. </bindings>
  524.  
  525.