home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / toolkit.jar / content / global / widgets / tabbox.xml < prev    next >
Extensible Markup Language  |  2002-11-04  |  16KB  |  524 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/widgets/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.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:hbox flex="1" style="min-width: 1px;">
  361.         <children/>
  362.         <xul:spacer class="tabs-right" flex="1"/>
  363.       </xul:hbox>
  364.       <xul:stack>
  365.         <xul:spacer class="tabs-right"/>
  366.         <xul:hbox class="tabs-closebutton-box" align="center" pack="end">
  367.           <xul:toolbarbutton ondblclick="event.preventBubble();" class="tabs-closebutton close-button" xbl:inherits="disabled=disableclose,oncommand=onclosetab"/>
  368.         </xul:hbox>
  369.       </xul:stack>
  370.     </content>
  371.   </binding>
  372.   
  373.   <binding id="tabpanels"
  374.            extends="chrome://global/content/bindings/tabbox.xml#tab-base">
  375.     <implementation implements="nsIAccessibleProvider">
  376.       <property name="accessible">
  377.         <getter>
  378.           <![CDATA[
  379.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  380.             return accService.createXULTabPanelsAccessible(this);
  381.           ]]>
  382.         </getter>
  383.       </property>
  384.  
  385.       <property name="selectedIndex">
  386.         <getter>
  387.         <![CDATA[
  388.           var indexStr = this.getAttribute("selectedIndex");
  389.           return indexStr ? parseInt(indexStr) : -1;
  390.         ]]>
  391.         </getter>
  392.                         
  393.         <setter>
  394.         <![CDATA[
  395.           if (this.selectedIndex == val)
  396.             return val;
  397.           this.setAttribute("selectedIndex", val);
  398.           var event = document.createEvent("Events");
  399.           event.initEvent("select", false, true);
  400.           this.dispatchEvent(event);
  401.           return val;
  402.         ]]>
  403.         </setter>
  404.       </property>
  405.  
  406.  
  407.       <property name="selectedPanel">
  408.         <getter>
  409.           <![CDATA[
  410.             return this.childNodes[this.selectedIndex];
  411.           ]]>
  412.         </getter>
  413.  
  414.         <setter>
  415.           <![CDATA[
  416.             var selectedIndex = -1;
  417.             for (var panel = val; panel != null; panel = panel.previousSibling)
  418.               ++selectedIndex;
  419.             this.selectedIndex = selectedIndex;
  420.             return val;
  421.           ]]>
  422.         </setter>
  423.       </property>
  424.     </implementation>
  425.   </binding>
  426.  
  427.   <binding id="tab" display="xul:button"
  428.            extends="chrome://global/content/bindings/tabbox.xml#tab-base">
  429.     <content>
  430.       <xul:image class="tab-icon" xbl:inherits="validate,src=image"/>
  431.       <xul:label class="tab-text" xbl:inherits="value=label,accesskey,crop,disabled" flex="1"/>
  432.     </content>
  433.     
  434.     <implementation implements="nsIDOMXULSelectControlItemElement, nsIAccessibleProvider">
  435.       <property name="accessible">
  436.         <getter>
  437.           <![CDATA[
  438.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  439.             return accService.createXULTabAccessible(this);
  440.           ]]>
  441.         </getter>
  442.       </property>
  443.  
  444.       <property name="label">
  445.         <getter>
  446.           return this.getAttribute("label");
  447.         </getter>
  448.         <setter>  
  449.           this.setAttribute("label", val);
  450.           return val;
  451.         </setter>
  452.       </property>
  453.  
  454.       <property name="tabs" 
  455.                 onget="return this.getAttribute('tabs');"
  456.                 onset="this.setAttribute('tabs', val); return val;"/>
  457.  
  458.       <!-- XXX -->                
  459.       <property name="selected">
  460.         <getter>
  461.           return this.getAttribute("selected") == "true" ? true : false;
  462.         </getter>
  463.         <setter>
  464.           this.setAttribute("selected", val);
  465.           if (this.previousSibling) {
  466.             if (val)
  467.               this.previousSibling.setAttribute("beforeselected", val);
  468.             else
  469.               this.previousSibling.removeAttribute("beforeselected");
  470.           }
  471.           if (this.nextSibling) {
  472.             if (val)
  473.               this.nextSibling.setAttribute("afterselected", val);
  474.             else
  475.               this.nextSibling.removeAttribute("afterselected");
  476.           }
  477.           return val;
  478.         </setter>
  479.       </property>
  480.     </implementation>
  481.     
  482.     <handlers>
  483.       <handler event="click" button="0">
  484.       <![CDATA[
  485.         var tabs = this.parentNode;
  486.         do {
  487.           if (tabs.localName == "tabs")
  488.             break;
  489.           tabs = tabs.parentNode;
  490.         } while(tabs.localName != "tabbox");
  491.         tabs.selectedItem = this;
  492.         if (!this.selected) this.selected = true;
  493.       ]]>
  494.       </handler>
  495.       
  496.       <handler event="keypress" keycode="vk_left">
  497.       <![CDATA[
  498.         this.parentNode.advanceSelectedTab(-1);
  499.       ]]>
  500.       </handler>
  501.       
  502.       <handler event="keypress" keycode="vk_right">
  503.       <![CDATA[
  504.         this.parentNode.advanceSelectedTab(1);
  505.       ]]>
  506.       </handler>
  507.       
  508.       <handler event="keypress" keycode="vk_up">
  509.       <![CDATA[
  510.         this.parentNode.advanceSelectedTab(-1);
  511.       ]]>
  512.       </handler>
  513.       
  514.       <handler event="keypress" keycode="vk_down">
  515.       <![CDATA[
  516.         this.parentNode.advanceSelectedTab(1);
  517.       ]]>
  518.       </handler>
  519.     </handlers>
  520.   </binding>
  521.   
  522. </bindings>
  523.  
  524.