home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / toolkit.jar / content / global / bindings / tabbox.xml < prev    next >
Extensible Markup Language  |  2005-07-29  |  39KB  |  1,042 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE bindings [
  4. <!ENTITY % tabBrowserDTD SYSTEM "chrome://global/locale/tabbrowser.dtd" >
  5. %tabBrowserDTD;
  6. ]>
  7.  
  8. <bindings id="tabBindings"
  9.           xmlns="http://www.mozilla.org/xbl"
  10.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  11.           xmlns:xbl="http://www.mozilla.org/xbl">
  12.  
  13.   <binding id="tab-base">
  14.     <resources>
  15.       <stylesheet src="chrome://global/skin/tabbox.css"/>
  16.     </resources>
  17.   </binding>
  18.  
  19.   <binding id="tabbox" display="xul:box"
  20.            extends="chrome://global/content/bindings/tabbox.xml#tab-base">
  21.     <implementation implements="nsIAccessibleProvider">
  22.       <property name="accessible">
  23.         <getter>
  24.           <![CDATA[
  25.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  26.             return accService.createXULTabBoxAccessible(this);
  27.           ]]>
  28.         </getter>
  29.       </property>
  30.  
  31.       <property name="handleCtrlTab">
  32.         <setter>
  33.         <![CDATA[
  34.           this.setAttribute("handleCtrlTab", val);
  35.           return val;
  36.         ]]>
  37.         </setter>
  38.         <getter>
  39.         <![CDATA[
  40.           return (this.getAttribute("handleCtrlTab") != "false");
  41.         ]]>
  42.         </getter>
  43.       </property>
  44.  
  45.       <property name="handleCtrlPageUpDown">
  46.         <setter>
  47.         <![CDATA[
  48.           this.setAttribute("handleCtrlPageUpDown", val);
  49.           return val;
  50.         ]]>
  51.         </setter>
  52.         <getter>
  53.         <![CDATA[
  54.           return (this.getAttribute("handleCtrlPageUpDown") != "false");
  55.         ]]>
  56.         </getter>
  57.       </property>
  58.  
  59.       <property name="_tabs">
  60.         <getter>
  61.         <![CDATA[
  62.           var tabs = this.getElementsByTagNameNS(
  63.               "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  64.               "tabs");
  65.           return tabs.length ? tabs[0] : null;
  66.         ]]>
  67.         </getter>
  68.       </property>
  69.  
  70.       <property name="_tabpanels">
  71.         <getter>
  72.         <![CDATA[
  73.           var tabpanels = this.getElementsByTagNameNS(
  74.               "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  75.               "tabpanels");
  76.           return tabpanels.length ? tabpanels[0] : null;
  77.         ]]>
  78.         </getter>
  79.       </property>
  80.  
  81.       <property name="selectedIndex"
  82.                 onget="return this._tabs ? this._tabs.selectedIndex : null;">
  83.         <setter>
  84.         <![CDATA[
  85.           if (this._tabs)
  86.             this._tabs.selectedIndex = val;
  87.           return val;
  88.         ]]>
  89.         </setter>
  90.       </property>
  91.  
  92.       <property name="selectedTab"
  93.                 onget="return this._tabs ? this._tabs.selectedItem : null;">
  94.         <setter>
  95.         <![CDATA[
  96.           if (!val)
  97.             throw Components.results.NS_ERROR_NULL_POINTER;
  98.           if (this._tabs)
  99.             this._tabs.selectedItem = val;
  100.           return val;
  101.         ]]>
  102.         </setter>
  103.       </property>
  104.  
  105.       <property name="selectedPanel"
  106.                 onget="return this._tabpanels ? this._tabpanels.selectedPanel : null;">
  107.         <setter>
  108.         <![CDATA[
  109.           if (!val)
  110.             throw Components.results.NS_ERROR_NULL_POINTER;
  111.           if (this._tabpanels)
  112.             this._tabpanels.selectedPanel = val;
  113.           return val;
  114.         ]]>
  115.         </setter>
  116.       </property>
  117.  
  118.       <!-- store the last time CTRL-TAB was pressed -->
  119.       <field name="_lastCtrlTabTime">
  120.         null
  121.       </field>
  122.  
  123.       <field name="_keyEventHandler" readonly="true">
  124.       <![CDATA[({
  125.         tabbox: this,
  126.         handleEvent: function handleEvent(event) {
  127.       if (!event.isTrusted) {
  128.         // Don't let untrusted events mess with tabs.
  129.         return;
  130.       }
  131.  
  132.           switch (event.keyCode) {
  133.             case event.DOM_VK_TAB:
  134.               if (event.ctrlKey && !event.altKey && !event.metaKey) {
  135.                        // MERC (rpaul) hide the statusbar current engine menu popup and current tabs popup
  136.                        document.getElementById('currentEngineStatusbarPopup').hidePopup();
  137.                   document.getAnonymousElementByAttribute(this.tabbox._tabs, 'class', 'tabs-dropdown').firstChild.hidePopup();
  138.  
  139.                   // MERC (DP): hide the site control popup (if it's open) before switching tabs
  140.                   document.getElementById('SiteControlsPopup').hidePopup();
  141.  
  142.                 // MERC (DP): if last CTRL_TAB was more than threshold time (2 secs)
  143.                 // then go to last selected tab. otherwise cycle thru tabs.
  144.                 var now = new Date();
  145.                 if (this.tabbox._tabs && this.tabbox.handleCtrlTab) {
  146.                   if(!this.tabbox._tabs.lastSelectedTab) {
  147.                     this.tabbox._tabs.advanceSelectedTab(event.shiftKey ? -1 : 1);
  148.                   } else {
  149.                     if(!this._lastCtrlTabTime) {
  150.                       this.tabbox._tabs.selectedItem = this.tabbox._tabs.lastSelectedTab;
  151.                     } else {
  152.                       // threshold time is 2 seconds
  153.                       if(now - this._lastCtrlTabTime <= 2000) {
  154.                         this.tabbox._tabs.advanceSelectedTab(event.shiftKey ? -1 : 1);
  155.                       } else {
  156.                         this.tabbox._tabs.selectedItem = this.tabbox._tabs.lastSelectedTab;
  157.                       }
  158.                     }
  159.                   }
  160.  
  161.                   // store the time ctrl-tab pressed
  162.                   this._lastCtrlTabTime = now.getTime();
  163.  
  164.                   event.stopPropagation();
  165.                   event.preventDefault();
  166.                 }
  167.               }
  168.               break;
  169.             case event.DOM_VK_PAGE_UP:
  170.               if (event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey)
  171.                 if (this.tabbox._tabs && this.tabbox.handleCtrlPageUpDown) {
  172.                   // MERC (rpaul) hide the statusbar current engine menu popup and current tabs popup
  173.                   document.getElementById('currentEngineStatusbarPopup').hidePopup();
  174.                   document.getAnonymousElementByAttribute(this.tabbox._tabs, 'class', 'tabs-dropdown').firstChild.hidePopup();
  175.                   // MERC (DP): hide the site control popup (if it's open) before switching tabs
  176.                   document.getElementById('SiteControlsPopup').hidePopup();
  177.                   this.tabbox._tabs.advanceSelectedTab(-1);
  178.                   event.stopPropagation();
  179.                   event.preventDefault();
  180.                 }
  181.               break;
  182.             case event.DOM_VK_PAGE_DOWN:
  183.               if (event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey)
  184.                 if (this.tabbox._tabs && this.tabbox.handleCtrlPageUpDown) {
  185.                   // MERC (rpaul) hide the statusbar current engine menu popup and current tabs popup
  186.                   document.getElementById('currentEngineStatusbarPopup').hidePopup();
  187.                   document.getAnonymousElementByAttribute(this.tabbox._tabs, 'class', 'tabs-dropdown').firstChild.hidePopup();
  188.                   // MERC (DP): hide the site control popup (if it's open) before switching tabs
  189.                   document.getElementById('SiteControlsPopup').hidePopup();
  190.  
  191.                   // MERC (DP): hide the site control popup (if it's open) before switching tabs
  192.                   document.getElementById('SiteControlsPopup').hidePopup();
  193.  
  194.                   this.tabbox._tabs.advanceSelectedTab(1);
  195.                   event.stopPropagation();
  196.                   event.preventDefault();
  197.                 }
  198.               break;
  199.           }
  200.         }
  201.       })]]>
  202.       </field>
  203.  
  204.       <field name="_eventNode">this</field>
  205.  
  206.       <property name="eventNode" onget="return this._eventNode;">
  207.         <setter>
  208.           <![CDATA[
  209.             if (val != this._eventNode) {
  210.               val.addEventListener("keypress", this._keyEventHandler, true);
  211.               this._eventNode.removeEventListener("keypress", this._keyEventHandler, true);
  212.               this._eventNode = val;
  213.             }
  214.             return val;
  215.           ]]>
  216.         </setter>
  217.       </property>
  218.  
  219.       <constructor>
  220.         switch (this.getAttribute("eventnode")) {
  221.           case "parent": this._eventNode = this.parentNode; break;
  222.           case "window": this._eventNode = window; break;
  223.           case "document": this._eventNode = document; break;
  224.         }
  225.         this._eventNode.addEventListener("keypress", this._keyEventHandler, true);
  226.       </constructor>
  227.  
  228.       <destructor>
  229.         this._eventNode.removeEventListener("keypress", this._keyEventHandler, true);
  230.       </destructor>
  231.     </implementation>
  232.   </binding>
  233.  
  234.   <binding id="tabs" display="xul:box"
  235.            extends="chrome://global/content/bindings/tabbox.xml#tab-base">
  236.     <content>
  237.       <xul:spacer class="tabs-left"/>
  238.       <children/>
  239.       <xul:spacer class="tabs-right" flex="1"/>
  240.     </content>
  241.  
  242.     <implementation implements="nsIDOMXULSelectControlElement, nsIAccessibleProvider">
  243.       <constructor>
  244.       <![CDATA[
  245.         var prefs = Components.classes["@mozilla.org/preferences-service;1"]
  246.                                     .getService(Components.interfaces.nsIPrefService);
  247.         prefs = prefs.getBranch(null);
  248.  
  249.         // this attribute detemines whether or not the close button appears on the tab
  250.         if(prefs.getBoolPref("browser.tabs.showCloseButtonOnTab"))
  251.           this.setAttribute("showCloseButton", "true");
  252.  
  253.         // this attribute detemines whether or not the site control button appears on the tab
  254.         if(prefs.getBoolPref("browser.tabs.showSiteControlButtonOnTab"))
  255.           this.setAttribute("showSiteControlButton", "true");
  256.  
  257.         // first and last tabs need to be able to have unique styles
  258.         // and also need to select first tab on startup.
  259.         if (this.firstChild)
  260.           this.firstChild.setAttribute("first-tab", "true");
  261.         if (this.lastChild)
  262.           this.lastChild.setAttribute("last-tab", "true");
  263.         this.selectedIndex = 0;
  264.         var o = this.getAttribute("orient");
  265.         if (!o)
  266.           this.setAttribute("orient", "horizontal");
  267.       ]]>
  268.       </constructor>
  269.  
  270.       <property name="accessible">
  271.         <getter>
  272.           <![CDATA[
  273.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  274.             return accService.createXULTabsAccessible(this);
  275.           ]]>
  276.         </getter>
  277.       </property>
  278.  
  279.       <field name="lastSelectedTab">null</field>
  280.  
  281.       <property name="selectedIndex">
  282.         <getter>
  283.         <![CDATA[
  284.           const tabs = this.childNodes;
  285.           for (var i = 0; i < tabs.length; i++) {
  286.             if (tabs[i].selected)
  287.               return i;
  288.           }
  289.           // throw an exception when no tab is selected (we shouldn't get here)
  290.           throw Components.results.NS_ERROR_FAILURE;
  291.         ]]>
  292.         </getter>
  293.  
  294.         <setter>
  295.         <![CDATA[
  296.           const tabs = this.childNodes;
  297.           for (var i = 0; i < tabs.length; i++) {
  298.             if (tabs[i].selected)
  299.               this.lastSelectedTab = tabs[i];
  300.           }
  301.  
  302.           if (0 <= val && val < tabs.length && !tabs[val].selected) {
  303.  
  304.             for (var i = 0; i < tabs.length; i++)
  305.               if (i != val && tabs[i].selected)
  306.                 tabs[i].selected = false;
  307.  
  308.             tabs[val].selected = true;
  309.  
  310.             for (var parent = this.parentNode; parent; parent = parent.parentNode) {
  311.               if (parent.localName == 'tabbox') {
  312.                 var tabpanels = parent._tabpanels;
  313.                 // This will cause an onselect event to fire for the tabpanel element.
  314.                 if (tabpanels) {
  315.                   // find an id
  316.                   var linkedPanelId = tabs[val].linkedPanel;
  317.                   var linkedPanel = linkedPanelId ? document.getElementById(linkedPanelId) : null;
  318.                   if (linkedPanel) {
  319.                     tabpanels.selectedPanel = linkedPanel;
  320.                   } else
  321.                     tabpanels.selectedIndex = val;
  322.                 }
  323.                 break;
  324.               }
  325.             }
  326.  
  327.             // Fire an onselect event for the tabs element.
  328.             var event = document.createEvent('Events');
  329.             event.initEvent('select', false, true);
  330.             this.dispatchEvent(event);
  331.           }
  332.           return val;
  333.         ]]>
  334.         </setter>
  335.       </property>
  336.  
  337.       <property name="selectedItem">
  338.         <getter>
  339.         <![CDATA[
  340.           const tabs = this.childNodes;
  341.           for (var i = 0; i < tabs.length; i++) {
  342.             if (tabs[i].selected)
  343.               return tabs[i];
  344.           }
  345.           // throw an exception when no tab is selected (we shouldn't get here)
  346.           throw Components.results.NS_ERROR_FAILURE;
  347.         ]]>
  348.         </getter>
  349.  
  350.         <setter>
  351.         <![CDATA[
  352.           if (!val)
  353.             throw Components.results.NS_ERROR_NULL_POINTER;
  354.           if (!val.selected) {
  355.             const tabs = this.childNodes;
  356.             for (var i = 0; i < tabs.length; i++)
  357.               if (tabs[i] == val)
  358.                 this.selectedIndex = i;
  359.           }
  360.           return val;
  361.         ]]>
  362.         </setter>
  363.       </property>
  364.  
  365.       <method name="advanceSelectedTab">
  366.         <parameter name="aDir"/>
  367.         <body>
  368.         <![CDATA[
  369.           var startTab = this.selectedItem;
  370.           var next = startTab[aDir == -1 ? "previousSibling" : "nextSibling"];
  371.  
  372.           while (next != startTab && (!next || next.getAttribute("hidden"))) {
  373.             if (next && next.getAttribute("hidden"))
  374.               next = next[aDir == -1 ? "previousSibling" : "nextSibling"];
  375.             if (!next)
  376.               next = aDir == 1 ? this.childNodes[0] : this.childNodes[this.childNodes.length - 1];
  377.           }
  378.  
  379.           if (next && next != startTab) {
  380.             this.selectedItem = next;
  381.             if (this.getAttribute("setfocus") != "false") {
  382.               next.focus();
  383.               document.commandDispatcher.advanceFocusIntoSubtree(next);
  384.             }
  385.           }
  386.         ]]>
  387.         </body>
  388.       </method>
  389.  
  390.       <method name="selectTabByIndex">
  391.         <parameter name="aIndex"/>
  392.         <body>
  393.         <![CDATA[
  394.           this.selectedItem = this.childNodes[aIndex];
  395.         ]]>
  396.         </body>
  397.       </method>
  398.  
  399.       <method name="appendItem">
  400.         <parameter name="label"/>
  401.         <parameter name="value"/>
  402.         <body>
  403.         <![CDATA[
  404.           var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  405.           var tab = document.createElementNS(XULNS, "tab");
  406.           tab.setAttribute("label", label);
  407.           tab.setAttribute("value", value);
  408.           this.appendChild(tab);
  409.           return tab;
  410.         ]]>
  411.         </body>
  412.       </method>
  413.  
  414.       <method name="insertItemAt">
  415.         <parameter name="index"/>
  416.         <parameter name="label"/>
  417.         <parameter name="value"/>
  418.         <body>
  419.         <![CDATA[
  420.           var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  421.           var tab = document.createElementNS(XULNS, "tab");
  422.           tab.setAttribute("label", label);
  423.           tab.setAttribute("value", value);
  424.           var before = this.childNodes[index];
  425.           if (before)
  426.             this.insertBefore(tab, before);
  427.           else
  428.             this.appendChild(tab);
  429.           return tab;
  430.         ]]>
  431.         </body>
  432.       </method>
  433.  
  434.       <method name="removeItemAt">
  435.         <parameter name="index"/>
  436.         <body>
  437.         <![CDATA[
  438.           var remove = this.childNodes[index];
  439.           if (remove)
  440.             this.removeChild(remove);
  441.           return remove;
  442.         ]]>
  443.         </body>
  444.       </method>
  445.     </implementation>
  446.   </binding>
  447.  
  448.   <binding id="tabs-closebutton"
  449.            extends="chrome://global/content/bindings/tabbox.xml#tabs">
  450.     <implementation>
  451.       <property name="inHandleResize"/>
  452.       <property name="lastWidth"/>
  453.       <method name="handleResize">
  454.         <body>
  455.           <![CDATA[
  456.           // If the toolbar has not actually changed width, bail out.
  457.           // This helps avoid too-frequent calls.
  458.  
  459.           // MERC (DP) redraw was not happening if you delete a tab
  460.           //if (this.boxObject.width == this.lastWidth) return;
  461.  
  462.           this.lastWidth = this.boxObject.width;
  463.  
  464.           // Function is not re-entrant
  465.           if (this.inHandleResize) return;
  466.           this.inHandleResize = true;
  467.  
  468.           // Iterate through the tabs
  469.           var tabContainer = document.getAnonymousElementByAttribute(this,'anonid','tabcontainer');
  470.           var containerRightExtent = tabContainer.boxObject.x + tabContainer.boxObject.width;
  471.           var tab = this.firstChild;
  472.           while (tab) {
  473.             var tabRightExtent = tab.boxObject.x + tab.boxObject.width;
  474.             if (tabRightExtent > containerRightExtent) {
  475.               tab.setAttribute('taboverflow','true');
  476.             } else {
  477.               tab.removeAttribute('taboverflow');
  478.             }
  479.             tab = tab.nextSibling;
  480.           }
  481.  
  482.           this.inHandleResize = false;
  483.           ]]>
  484.         </body>
  485.       </method>
  486.     </implementation>
  487.     <content>
  488.       <xul:toolbarbutton class="sidebar-button" anonid="sidebar-button" command="toggleSidebar"/>
  489.       <!--MERC (rpaul) moving new tab button and drop to left of tab strip -->
  490.       <xul:stack class="tabs-newbutton-stack" id="new-tab-button-container">
  491.         <xul:toolbarbutton id="tabNewButton" class="tabs-newbutton" top="0" left="0"
  492.                            onmouseover="if (event.target.parentNode.parentNode.parentNode.
  493.                            firstChild.localName == 'tooltip') { event.target.parentNode.
  494.                            parentNode.parentNode.firstChild.setAttribute('label', 'Open a new tab');};"
  495.                            label="&tabs-newbutton.label;"
  496.                            xbl:inherits="oncommand=onnewpreftab"/>
  497.         <xul:toolbarbutton id="tabs-newdropdown"
  498.                            class="tabs-newdropdown"
  499.                            onmouseover="if (event.target.parentNode.parentNode.parentNode.
  500.                            firstChild.localName == 'tooltip') { event.target.parentNode.
  501.                            parentNode.parentNode.firstChild.setAttribute('label', 'Select a new tab from list');};"
  502.                            left="24" top="14"/>
  503.       </xul:stack>
  504.  
  505.       <xul:hbox anonid="tabcontainer" flex="1" style="min-width: 1px; overflow: hidden !important;">
  506.         <children/>
  507.       </xul:hbox>
  508.  
  509.       <xul:spacer class="tabs-right" flex="0"/>
  510.  
  511.       <!-- MERC (DP): this menu contains the list of all tabs open. the menuitems will
  512.            be populated inside updateTabListMenu().
  513.       -->
  514.       <xul:toolbarbutton anonid="tabs-dropdown" type="menu" class="tabs-dropdown"
  515.         onmouseover="if (event.target.parentNode.parentNode.firstChild.localName == 'tooltip') 
  516.                                     { event.target.parentNode.parentNode.
  517.                                     firstChild.setAttribute('label', 'List open tabs');};"
  518.         orient="horizontal" align="end">
  519.         <xul:menupopup position="at_pointer" anonid="tabsDropDownMenu"
  520.                        onpopupshowing="tabbrowser = this.parentNode;
  521.                                        while (tabbrowser.localName != 'tabbrowser')
  522.                                          tabbrowser = tabbrowser.parentNode;
  523.                                        tabbrowser.updateTabListMenu(this);">
  524.         </xul:menupopup>
  525.       </xul:toolbarbutton>
  526.     </content>
  527.     <handlers>
  528.       <handler event="overflow">this.handleResize();</handler>
  529.       <handler event="underflow">this.handleResize();</handler>
  530.     </handlers>
  531.   </binding>
  532.  
  533.   <binding id="tabpanels"
  534.            extends="chrome://global/content/bindings/tabbox.xml#tab-base">
  535.     <implementation implements="nsIAccessibleProvider">
  536.       <property name="accessible">
  537.         <getter>
  538.           <![CDATA[
  539.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  540.             return accService.createXULTabPanelsAccessible(this);
  541.           ]]>
  542.         </getter>
  543.       </property>
  544.  
  545.       <field name="_selectedPanel">null</field>
  546.  
  547.       <property name="selectedIndex">
  548.         <getter>
  549.         <![CDATA[
  550.           var indexStr = this.getAttribute("selectedIndex");
  551.           return indexStr ? parseInt(indexStr) : -1;
  552.         ]]>
  553.         </getter>
  554.  
  555.         <setter>
  556.         <![CDATA[
  557.  
  558.           var panel = this._selectedPanel;
  559.           this._selectedPanel = this.childNodes[val];
  560.           this.setAttribute("selectedIndex", val);
  561.           if (this._selectedPanel != panel) {
  562.             var event = document.createEvent("Events");
  563.             event.initEvent("select", false, true);
  564.             this.dispatchEvent(event);
  565.                 //MERC - JA this attribute is called always when tab selection is changed from UI
  566.                 //if(this._selectedPanel.localName == 'browser')//JA changed after ff5->vulp
  567.                 var browser = this._selectedPanel.firstChild.nextSibling;//from getBrowserAtIndex
  568.                 if(browser && browser.localName == 'browser')
  569.                 {
  570.  
  571.                     BrowserStoreTabCharset();//Sliu, save current document character set for openPopupInTab
  572.                     window.onTabAction(2,val,null);//notify about new selected tab
  573.                     try{
  574.                         var hpDoc = browser.contentDocument.QueryInterface(Components.interfaces.nsIHTMLPluginDocument);
  575.                         if(hpDoc)
  576.                             hpDoc.setPluginFocus();
  577.                     }
  578.                     catch (e) {}
  579.                 }
  580.                 ///JA
  581.           }
  582.           return val;
  583.         ]]>
  584.         </setter>
  585.       </property>
  586.  
  587.  
  588.       <property name="selectedPanel">
  589.         <getter>
  590.           <![CDATA[
  591.             return this._selectedPanel;
  592.           ]]>
  593.         </getter>
  594.  
  595.         <setter>
  596.           <![CDATA[
  597.             var selectedIndex = -1;
  598.             for (var panel = val; panel != null; panel = panel.previousSibling)
  599.               ++selectedIndex;
  600.             this.selectedIndex = selectedIndex;
  601.             return val;
  602.           ]]>
  603.         </setter>
  604.       </property>
  605.     </implementation>
  606.   </binding>
  607.  
  608.   <binding id="tab" display="xul:button"
  609.            extends="chrome://global/content/bindings/tabbox.xml#tab-base">
  610.    <content>
  611.     <xul:box class="tab-left"/>
  612.     <xul:stack class="tab-content" flex="1"
  613.                xbl:inherits="validate,image,label,accesskey,crop,disabled">
  614.      <xul:hbox class="tab-content-bg" align="stretch">
  615.        <xul:image class="tab-content-bgimage" flex="1"/>
  616.      </xul:hbox>
  617.      <xul:hbox class="tab-content-fg" align="end"
  618.                xbl:inherits="validate,image,label,accesskey,crop,disabled">
  619.       <xul:image class="tab-icon" xbl:inherits="validate,src=image"/>
  620.       <xul:label class="tab-text" xbl:inherits="value=label,accesskey,crop,disabled" flex="1"/>
  621.       <xul:toolbarbutton type="menu" class="tab-popupmenu-button" anonid="menubutton">
  622.  
  623.       </xul:toolbarbutton>
  624.  
  625.       <xul:hbox class="tab-closebutton-container">
  626.         <xul:stack class="tab-closebutton-stack">
  627.           <xul:hbox class="tab-closebutton-box" align="right" pack="end" anonid="closebutton-box">
  628.             <xul:toolbarbutton anonid="closebutton"
  629.                                class="tab-closebutton close-button"
  630.                                ondblclick="event.preventBubble();"
  631.                                xbl:inherits="disabled=disableclose,oncommand=onclosetab"/>
  632.           </xul:hbox>
  633.         </xul:stack>
  634.  
  635.        </xul:hbox>
  636.       </xul:hbox>
  637.      </xul:stack>
  638.      <xul:box class="tab-right"/>
  639.     </content>
  640.  
  641.     <implementation implements="nsIDOMXULSelectControlItemElement, nsIAccessibleProvider">
  642.       <method name="toggleDisplayEngineSiteControl">
  643.         <body>
  644.           <![CDATA[
  645.             //dump('tabbox.xml: toggleDisplayEngineSiteControl()\n');
  646.  
  647.             var tabbrowser = this;
  648.             while (tabbrowser.localName != 'tabbrowser') tabbrowser = tabbrowser.parentNode;
  649.             var url = tabbrowser.currentURI.spec;
  650.             var sc = sitecontrols.SCSVC;
  651.  
  652.             // To allow engine toggling, the URI must either be for a controllable site
  653.             // (including local files) or else 'about:blank'.  Otherwise, bail out...
  654.             if ((url != 'about:blank') && (!sc.isControllableURI(url))) {
  655.               dump('*** bailing out of toggleEngine\n');
  656.               return;
  657.             }
  658.             // So now we know the site is either a controllable URI or 'about:blank'
  659.  
  660.             // Grab the RDF resource for this site
  661.             var site;
  662.             if (url == 'about:blank') {
  663.               // We will treat this as if it's a DEFAULT site
  664.               // This should be SiteControls:Default resource
  665.               site = sc.getResourceForURI('');
  666.             } else {
  667.               site = sc.getResourceForURI(url);
  668.             }
  669.  
  670.             // If the site being toggled is not handled by an *explicit* site
  671.             // control, then we will want to add a new site control for it.
  672.             if ((site.Value != sitecontrols.SC_LOCAL) && (url != 'about:blank'))
  673.             {
  674.               var host = sitecontrols.getStrippedHostFromURL(url);
  675.               var pattern = sitecontrols.SCSVC.getControlledSite(host);
  676.               if ((pattern != null) || (host && (host != "") && (host != pattern)))
  677.               {
  678.                 sitecontrols.SCSVC.addControlledSite(host);
  679.                 site = sitecontrols.SCSVC.getResourceForURI(host);
  680.  
  681.                 // we need to set the engine of the newly added SC for the redirect case
  682.                 //var currentEngine = tabbrowser.mCurrentBrowser.webNavigation.browserEngine;
  683.                 //sitecontrols.SCSVC.updateSiteControlResource(site, 'displayEngine', currentEngine);
  684.               }
  685.             }
  686.  
  687.             // Toggle the engine
  688.             var currentEngine = tabbrowser.getBrowserForTab(tabbrowser.mCurrentTab).docShell.browserEngine;
  689.             if (currentEngine == "Gecko") {
  690.               // Changing from Gecko to Trident
  691.               currentEngine = "Trident";
  692.             } else {
  693.               // Changing from Trident to Gecko
  694.               currentEngine = "Gecko";
  695.             }
  696.             sc.updateSiteControlResource(site, 'displayEngine', currentEngine);
  697.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  698.  
  699.                         gBrowser = document.getElementById('content');
  700.                         gBrowser.mCurrentTab.removeAttribute("engine");
  701.             UpdateStatusBarEngineIcon();
  702.             BrowserReload();
  703.             
  704.             // Debug output
  705.             var siteStr = site.Value;
  706.             if (host) siteStr = host;
  707.           ]]>
  708.         </body>
  709.       </method>
  710.  
  711.       <!-- MERC - JCH : init special pop-up tab property and popup counter property -->
  712.       <constructor>
  713.          this.setAttribute('isNonUserInitPopupTab', false);
  714.          this.setAttribute('isClosing', false);//JA
  715.       </constructor>
  716.  
  717.       <method name="changeSiteControl">
  718.         <parameter name="menuitemId"/>
  719.         <parameter name="aPopupMenu"/>
  720.         <body>
  721.           <![CDATA[
  722.             //dump('tabbox.xml: changeSiteControl()\n');
  723.  
  724.             //var menuitem = document.getAnonymousElementByAttribute(this, 'anonid', menuitemId);
  725.             var tabbrowser = this;
  726.             while (tabbrowser.localName != 'tabbrowser')
  727.               tabbrowser = tabbrowser.parentNode;
  728.  
  729.             var menuitem;
  730.             if(tabbrowser.mPrefs.getBoolPref("browser.tabs.showSiteControlButtonOnTab")) {
  731.               menuitem = document.getAnonymousElementByAttribute(this, 'anonid', menuitemId);
  732.             } else {
  733.               menuitem = aPopupMenu.getElementsByAttribute("anonid", menuitemId);
  734.               menuitem = menuitem[0];
  735.             }
  736.  
  737.  
  738.             var url = tabbrowser.currentURI.spec;
  739.  
  740.             // Bail if it's not a controllable URI
  741.             if (!sitecontrols.SCSVC.isControllableURI(url)) return;
  742.  
  743.             // Get SC resource
  744.             var site = sitecontrols.SCSVC.getResourceForURI(url);
  745.  
  746.             var host = sitecontrols.getStrippedHostFromURL(url);
  747.             var pattern = sitecontrols.SCSVC.getControlledSite(host);
  748.  
  749.             if ((pattern!=null || host!=pattern) && (site.Value != sitecontrols.SC_LOCAL)) {
  750.               sitecontrols.SCSVC.addControlledSite(host);
  751.               site = sitecontrols.SCSVC.getResourceForURI(host);
  752.  
  753.               // we need to set the engine of the newly added SC for the redirect case
  754.               var currentEngine = tabbrowser.mCurrentBrowser.webNavigation.browserEngine;
  755.               sitecontrols.SCSVC.updateSiteControlResource(site, 'displayEngine', currentEngine);
  756.             }
  757.  
  758.             var anonid = menuitem.getAttribute('anonid');
  759.             var type = menuitem.getAttribute('type');
  760.  
  761.             if (type == 'checkbox') {
  762.               var checked = menuitem.getAttribute('checked');
  763.               if (!checked) checked = 'false';
  764.               sitecontrols.SCSVC.updateSiteControlResource(site, anonid, checked);
  765.             }
  766.  
  767.             //sitecontrols.SCSVC.writeSiteControls();
  768.  
  769.             // if we changed allow JS, Java, ActiveX, reload the browser
  770.             // so changes take affect immediately
  771.             if( (anonid == 'enableJavaScript') ||
  772.                 (anonid == 'enableJava') ||
  773.                 (anonid == 'enableActiveX') )
  774.             {
  775.               updateSCSecurityLevel();
  776.               //getWebNavigation().reload(nsIWebNavigation.LOAD_FLAGS_NONE);
  777.               BrowserReload();
  778.             }
  779.           ]]>
  780.         </body>
  781.       </method>
  782.  
  783.       <method name="updateSiteControlSecurityLevel">
  784.         <parameter name="level"/>
  785.         <body>
  786.           <![CDATA[
  787.             //dump('tabbox.xml: updateSiteControlSecurityLevel()\n');
  788.  
  789.             var tabbrowser = this;
  790.             while (tabbrowser.localName != 'tabbrowser')
  791.               tabbrowser = tabbrowser.parentNode;
  792.             var url = tabbrowser.currentURI.spec;
  793.  
  794.             // Bail if it's not a controllable URI
  795.             if (!sitecontrols.SCSVC.isControllableURI(url)) return;
  796.  
  797.             // Get SC resource
  798.             var site = sitecontrols.SCSVC.getResourceForURI(url);
  799.  
  800.             var host = sitecontrols.getStrippedHostFromURL(url);
  801.             var pattern = sitecontrols.SCSVC.getControlledSite(host);
  802.             if ((pattern!=null || host!=pattern) && (site.Value != sitecontrols.SC_LOCAL)) {
  803.               sitecontrols.SCSVC.addControlledSite(host);
  804.               site = sitecontrols.SCSVC.getResourceForURI(host);
  805.  
  806.               // we need to set the engine of the newly added SC for the redirect case
  807.               var currentEngine = tabbrowser.mCurrentBrowser.webNavigation.browserEngine;
  808.               sitecontrols.SCSVC.updateSiteControlResource(site, 'displayEngine', currentEngine);
  809.             }
  810.             sitecontrols.setSecurityLevel(site, level);
  811.           ]]>
  812.         </body>
  813.       </method>
  814.  
  815.       <property name="accessible">
  816.         <getter>
  817.           <![CDATA[
  818.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  819.             return accService.createXULTabAccessible(this);
  820.           ]]>
  821.         </getter>
  822.       </property>
  823.  
  824.       <property name="label">
  825.         <getter>
  826.           return this.getAttribute("label");
  827.         </getter>
  828.         <setter>
  829.           this.setAttribute("label", val);
  830.           return val;
  831.         </setter>
  832.       </property>
  833.  
  834.       <property name="tabs"
  835.                 onget="return this.getAttribute('tabs');"
  836.                 onset="this.setAttribute('tabs', val); return val;"/>
  837.  
  838.       <!-- MERC - JCH : boolean to indicate whether the tab holds non-user-initiated pop-ups -->
  839.       <property name="isNonUserInitPopupTab">
  840.             <getter>
  841.                 var v = this.getAttribute("isClosing")!="true";
  842.                 if(this.getAttribute("isNonUserInitPopupTab")=="true")
  843.                 {
  844.                     if(v)
  845.                         return true;
  846.                 }
  847.                 return false;
  848.             </getter>
  849.             <setter>
  850.                 this.setAttribute("isNonUserInitPopupTab", val); return val;
  851.             </setter>
  852.       </property>
  853.  
  854.       <!-- JA -->
  855.       <property name="isClosing">
  856.        <getter>
  857.          return this.getAttribute('isClosing') == 'true'?true:false;
  858.          </getter>
  859.         <setter>
  860.             this.setAttribute('isClosing', val); return val;
  861.           </setter>
  862.       </property>
  863.  
  864.       <!-- XXX -->
  865.       <property name="selected">
  866.         <getter>
  867.           return this.getAttribute("selected") == "true" ? true : false;
  868.         </getter>
  869.         <setter>
  870.           this.setAttribute("selected", val);
  871.           if (this.previousSibling) {
  872.             if (val)
  873.               this.previousSibling.setAttribute("beforeselected", val);
  874.             else
  875.               this.previousSibling.removeAttribute("beforeselected");
  876.           }
  877.           if (this.nextSibling) {
  878.             if (val)
  879.               this.nextSibling.setAttribute("afterselected", val);
  880.             else
  881.               this.nextSibling.removeAttribute("afterselected");
  882.           }
  883.           return val;
  884.         </setter>
  885.       </property>
  886.  
  887.       <property name="linkedPanel" onget="return this.getAttribute('linkedpanel')"
  888.                                    onset="this.setAttribute('linkedpanel', val); return val;"/>
  889.  
  890.       <!-- MERC - JCH: Needed to avoid sitecontrols dialog from opening on dbl clicks -->
  891.       <field name="_lastClickTime">0</field>
  892.  
  893.     </implementation>
  894.  
  895.     <handlers>
  896.       <!-- MERC (DP): close tab on double click -->
  897.       <handler event="click" clickcount="2" button="0">
  898.       <![CDATA[
  899.         // we need this if statement since tabbox.xml is used in places other than the browser
  900.         // tabs area e.g. Page Info. so do the following code only if we are in the browser tabs
  901.         if(this.parentNode.hasAttribute('browsertabs')) {
  902.           var tabbrowser = this.parentNode;
  903.           while(tabbrowser.localName != 'tabbrowser')
  904.             tabbrowser = tabbrowser.parentNode;
  905.  
  906.           var doubleClickToCloseTab = tabbrowser.mPrefs.getBoolPref("browser.tabs.doubleClickToClose");
  907.           if(doubleClickToCloseTab)
  908.             tabbrowser.removeCurrentTab();
  909.         }
  910.       ]]>
  911.       </handler>
  912.  
  913.       <handler event="click" button="0">
  914.       <![CDATA[
  915.         var updateSelected = true;
  916.         var tabParent = this.parentNode;
  917.         
  918.         // we need this if statement since tabbox.xml is used in places other than the browser
  919.         // tabs area e.g. Page Info. so do the following code only if we are in the browser tabs
  920.         if (tabParent.hasAttribute('browsertabs')) {
  921.  
  922.           //JA add notification about selected tab
  923.           var menubutton = document.getAnonymousElementByAttribute(this, 'anonid', 'menubutton');
  924.           var closebutton = document.getAnonymousElementByAttribute(this, 'anonid', 'closebutton');
  925.           var popup;
  926.           if ((menubutton.boxObject.screenX <= event.screenX)
  927.               && (event.screenX - menubutton.boxObject.screenX <= menubutton.boxObject.width)
  928.               && (menubutton.boxObject.screenY <= event.screenY)
  929.               && (event.screenY - menubutton.boxObject.screenY <= menubutton.boxObject.height))
  930.           {
  931.  
  932.                 // MERC - JCH: Addressing BLT #158887. Prevent opening SC popup
  933.                 // when double clicking on SC icon. If click is less than or 
  934.                 // equal to a second apart from previous, don't open the popup.
  935.                   var currentTime = new Date();
  936.  
  937.                 var elapsedTime = currentTime.getTime() - _lastClickTime;
  938.                 _lastClickTime  = currentTime.getTime();
  939.  
  940.                 if (elapsedTime > 1000) {
  941.                     showSiteControlsPopup(0,0);
  942.                 }
  943.           }
  944.           else if ((closebutton.boxObject.screenX <= event.screenX)
  945.               && (event.screenX - closebutton.boxObject.screenX <= closebutton.boxObject.width)
  946.               && (closebutton.boxObject.screenY <= event.screenY)
  947.               && (event.screenY - closebutton.boxObject.screenY <= closebutton.boxObject.height))
  948.           {
  949.             // get handle to tabbrowser object
  950.             var tabbrowser = this.parentNode;
  951.             while (tabbrowser.localName != 'tabbrowser')
  952.               tabbrowser = tabbrowser.parentNode;
  953.  
  954.             tabbrowser.removeTab(this);
  955.             updateSelected = false;
  956.           }
  957.         }
  958.  
  959.         if (updateSelected) {
  960.           tabParent.selectedItem = this;
  961.         }
  962.       ]]>
  963.       </handler>
  964.       <handler event="mousemove">
  965.       <![CDATA[
  966.         // MERC (rpaul) event handler to get the tooltips of the close button, site controls
  967.         // and the tab title
  968.  
  969.         var tabParent = this.parentNode;
  970.         var gBrowser = document.getElementById('content');
  971.  
  972.         // we need this if statement since tabbox.xml is used in places other than the browser
  973.         // tabs area e.g. Page Info. so do the following code only if we are in the browser tabs
  974.         if (tabParent.hasAttribute('browsertabs')) {
  975.           var tooltipNode = event.target.parentNode.parentNode.firstChild;
  976.                    if (!tooltipNode) return;       
  977.             tooltipNode.hidePopup();  
  978.           //JA add notification about selected tab
  979.           var menubutton = document.getAnonymousElementByAttribute(this, 'anonid', 'menubutton');
  980.           var closebutton = document.getAnonymousElementByAttribute(this, 'anonid', 'closebutton');
  981.           if ((menubutton.boxObject.screenX <= event.screenX)
  982.               && (event.screenX - menubutton.boxObject.screenX <= menubutton.boxObject.width)
  983.               && (menubutton.boxObject.screenY <= event.screenY)
  984.               && (event.screenY - menubutton.boxObject.screenY <= menubutton.boxObject.height))
  985.           {               
  986.                  tooltipNode.setAttribute('label', 'Open Site Controls');
  987.                  return;                
  988.           }
  989.           else if ((closebutton.boxObject.screenX <= event.screenX)
  990.               && (event.screenX - closebutton.boxObject.screenX <= closebutton.boxObject.width)
  991.               && (closebutton.boxObject.screenY <= event.screenY)
  992.               && (event.screenY - closebutton.boxObject.screenY <= closebutton.boxObject.height))
  993.           {
  994.              // only set tooltip for site controls if the tab is active
  995.                if (event.target.getAttribute("selected") == "true") {
  996.                 tooltipNode.setAttribute('label', 'Close this tab');
  997.                 return;
  998.                }
  999.           } 
  1000.           else if (event.target.localName == "tab"){
  1001.               if (event.target.hasAttribute('label')) {
  1002.                   var tabToolTip = event.target.getAttribute('label');
  1003.                   tooltipNode.setAttribute('label', tabToolTip);
  1004.                   return;
  1005.               }
  1006.           }
  1007.           else {
  1008.               tooltipNode.removeAttribute('label');
  1009.           }              
  1010.         }
  1011.      
  1012.       ]]>
  1013.       </handler>
  1014.       <!-- /MERC -->
  1015.  
  1016.       <handler event="keypress" keycode="vk_left">
  1017.       <![CDATA[
  1018.         this.parentNode.advanceSelectedTab(-1);
  1019.       ]]>
  1020.       </handler>
  1021.  
  1022.       <handler event="keypress" keycode="vk_right">
  1023.       <![CDATA[
  1024.         this.parentNode.advanceSelectedTab(1);
  1025.       ]]>
  1026.       </handler>
  1027.  
  1028.       <handler event="keypress" keycode="vk_up">
  1029.       <![CDATA[
  1030.         this.parentNode.advanceSelectedTab(-1);
  1031.       ]]>
  1032.       </handler>
  1033.  
  1034.       <handler event="keypress" keycode="vk_down">
  1035.       <![CDATA[
  1036.         this.parentNode.advanceSelectedTab(1);
  1037.       ]]>
  1038.       </handler>
  1039.     </handlers>
  1040.   </binding>
  1041.  
  1042. </bindings>