DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (5b81998bb7ab)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
<?xml version="1.0"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->


<bindings id="tabBindings"
          xmlns="http://www.mozilla.org/xbl"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
          xmlns:xbl="http://www.mozilla.org/xbl">

  <binding id="tab-base">
    <resources>
      <stylesheet src="chrome://global/skin/tabbox.css"/>
    </resources>
  </binding>

  <binding id="tabbox"
           extends="chrome://global/content/bindings/tabbox.xml#tab-base">
    <implementation implements="nsIDOMEventListener">
      <property name="handleCtrlTab">
        <setter>
        <![CDATA[
          this.setAttribute("handleCtrlTab", val);
          return val;
        ]]>
        </setter>
        <getter>
        <![CDATA[
          return (this.getAttribute("handleCtrlTab") != "false");
        ]]>
        </getter>
      </property>
      
      <property name="handleCtrlPageUpDown">
        <setter>
        <![CDATA[
          this.setAttribute("handleCtrlPageUpDown", val);
          return val;
        ]]>
        </setter>
        <getter>
        <![CDATA[
          return (this.getAttribute("handleCtrlPageUpDown") != "false");
        ]]>
        </getter>
      </property>

      <field name="_handleMetaAltArrows" readonly="true">
#ifdef XP_MACOSX
        true
#else
        false
#endif
      </field>

      <!-- _tabs and _tabpanels are deprecated, they exist only for
           backwards compatibility. -->
      <property name="_tabs" readonly="true" onget="return this.tabs;"/>
      <property name="_tabpanels" readonly="true" onget="return this.tabpanels;"/>

      <property name="tabs" readonly="true">
        <getter>
        <![CDATA[
          return this.getElementsByTagNameNS(
              "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
              "tabs").item(0);
        ]]>
        </getter>
      </property>

      <property name="tabpanels" readonly="true">
        <getter>
        <![CDATA[
          return this.getElementsByTagNameNS(
              "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
              "tabpanels").item(0);
        ]]>
        </getter>
      </property>
      
      <property name="selectedIndex">
        <getter>
        <![CDATA[
          var tabs = this.tabs;
          return tabs ? tabs.selectedIndex : -1;
        ]]>
        </getter>

        <setter>
        <![CDATA[
          var tabs = this.tabs;
          if (tabs)
            tabs.selectedIndex = val;
          this.setAttribute("selectedIndex", val);
          return val;
        ]]>
        </setter>
      </property>

      <property name="selectedTab">
        <getter>
        <![CDATA[
          var tabs = this.tabs;
          return tabs && tabs.selectedItem;
        ]]>
        </getter>

        <setter>
        <![CDATA[
          if (val) {
            var tabs = this.tabs;
            if (tabs)
              tabs.selectedItem = val;
          }
          return val;
        ]]>
        </setter>
      </property>

      <property name="selectedPanel">
        <getter>
        <![CDATA[
          var tabpanels = this.tabpanels;
          return tabpanels && tabpanels.selectedPanel;
        ]]>
        </getter>

        <setter>
        <![CDATA[
          if (val) {
            var tabpanels = this.tabpanels;
            if (tabpanels)
              tabpanels.selectedPanel = val;
          }
          return val;
        ]]>
        </setter>
      </property>

      <method name="handleEvent">
        <parameter name="event"/>
        <body>
        <![CDATA[
          if (!event.isTrusted) {
            // Don't let untrusted events mess with tabs.
            return;
          }

          switch (event.keyCode) {
            case event.DOM_VK_TAB:
              if (event.ctrlKey && !event.altKey && !event.metaKey)
                if (this.tabs && this.handleCtrlTab) {
                  this.tabs.advanceSelectedTab(event.shiftKey ? -1 : 1, true);
                  event.stopPropagation();
                  event.preventDefault();
                }
              break;
            case event.DOM_VK_PAGE_UP:
              if (event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey)
                if (this.tabs && this.handleCtrlPageUpDown) {
                  this.tabs.advanceSelectedTab(-1, true);
                  event.stopPropagation();
                  event.preventDefault();
                }
              break;
            case event.DOM_VK_PAGE_DOWN:
              if (event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey)
                if (this.tabs && this.handleCtrlPageUpDown) {
                  this.tabs.advanceSelectedTab(1, true);
                  event.stopPropagation();
                  event.preventDefault();
                }
              break;
            case event.DOM_VK_LEFT:
              if (event.metaKey && event.altKey && !event.shiftKey && !event.ctrlKey)
                if (this.tabs && this._handleMetaAltArrows) {
                  var offset = window.getComputedStyle(this, "")
                                     .direction == "ltr" ? -1 : 1;
                  this.tabs.advanceSelectedTab(offset, true);
                  event.stopPropagation();
                  event.preventDefault();
                }
              break;
            case event.DOM_VK_RIGHT:
              if (event.metaKey && event.altKey && !event.shiftKey && !event.ctrlKey)
                if (this.tabs && this._handleMetaAltArrows) {
                  var offset = window.getComputedStyle(this, "")
                                     .direction == "ltr" ? 1 : -1;
                  this.tabs.advanceSelectedTab(offset, true);
                  event.stopPropagation();
                  event.preventDefault();
                }
              break;
          }
        ]]>
        </body>
      </method>

      <field name="_eventNode">this</field>

      <property name="eventNode" onget="return this._eventNode;">
        <setter>
          <![CDATA[
            if (val != this._eventNode) {
              val.addEventListener("keypress", this, false);
              this._eventNode.removeEventListener("keypress", this, false);
              this._eventNode = val;
            }
            return val;
          ]]>
        </setter>
      </property>

      <constructor>
        switch (this.getAttribute("eventnode")) {
          case "parent": this._eventNode = this.parentNode; break;
          case "window": this._eventNode = window; break;
          case "document": this._eventNode = document; break;
        }
        this._eventNode.addEventListener("keypress", this, false);
      </constructor>

      <destructor>
        this._eventNode.removeEventListener("keypress", this, false);
      </destructor>
    </implementation>
  </binding>

  <binding id="tabs"
           extends="chrome://global/content/bindings/general.xml#basecontrol">
    <resources>
      <stylesheet src="chrome://global/skin/tabbox.css"/>
    </resources>

    <content>
      <xul:spacer class="tabs-left"/>
      <children/>
      <xul:spacer class="tabs-right" flex="1"/>
    </content>
    
    <implementation implements="nsIDOMXULSelectControlElement, nsIDOMXULRelatedElement, nsIAccessibleProvider">
      <constructor>
      <![CDATA[
        // first and last tabs need to be able to have unique styles
        // and also need to select first tab on startup.
        if (this.firstChild)
          this.firstChild.setAttribute("first-tab", "true");
        if (this.lastChild)
          this.lastChild.setAttribute("last-tab", "true");

        if (!this.hasAttribute("orient"))
          this.setAttribute("orient", "horizontal");

        if (this.tabbox && this.tabbox.hasAttribute("selectedIndex")) {
          let selectedIndex = parseInt(this.tabbox.getAttribute("selectedIndex"));
          this.selectedIndex = selectedIndex > 0 ? selectedIndex : 0;
          return;
        }

        var children = this.childNodes;
        var length = children.length;
        for (var i = 0; i < length; i++) {
          if (children[i].getAttribute("selected") == "true") {
            this.selectedIndex = i;
            return;
          }
        }

        var value = this.value;
        if (value)
          this.value = value;
        else
          this.selectedIndex = 0;
      ]]>
      </constructor>

      <!-- nsIAccessibleProvider -->
      <property name="accessibleType" readonly="true">
        <getter>
          <![CDATA[
            return Components.interfaces.nsIAccessibleProvider.XULTabs;
          ]]>
        </getter>
      </property>

      <!-- nsIDOMXULRelatedElement -->
      <method name="getRelatedElement">
        <parameter name="aTabElm"/>
        <body>
        <![CDATA[
          if (!aTabElm)
            return null;

          let tabboxElm = this.tabbox;
          if (!tabboxElm)
            return null;

          let tabpanelsElm = tabboxElm.tabpanels;
          if (!tabpanelsElm)
            return null;

          // Get linked tab panel by 'linkedpanel' attribute on the given tab
          // element.
          let linkedPanelElm = null;

          let linkedPanelId = aTabElm.linkedPanel;
          if (linkedPanelId) {
            let ownerDoc = this.ownerDocument;

            // XXX bug 565858: if XUL tab element is anonymous element then
            // suppose linked tab panel is hosted within the same XBL binding
            // and search it by ID attribute inside an anonymous content of
            // the binding. This is not robust assumption since tab elements may
            // live outside a tabbox element so that for example tab elements
            // can be explicit content but tab panels can be anonymous.

            let bindingParent = ownerDoc.getBindingParent(aTabElm);
            if (bindingParent)
              return ownerDoc.getAnonymousElementByAttribute(bindingParent,
                                                             "id",
                                                             linkedPanelId);

            return ownerDoc.getElementById(linkedPanelId);
          }

          // otherwise linked tabpanel element has the same index as the given
          // tab element.
          let tabElmIdx = this.getIndexOfItem(aTabElm);
          return tabpanelsElm.childNodes[tabElmIdx];
        ]]>
        </body>
      </method>

      <!-- nsIDOMXULSelectControlElement -->
      <property name="itemCount" readonly="true"
                onget="return this.childNodes.length"/>

      <property name="value" onget="return this.getAttribute('value');">
        <setter>
          <![CDATA[
            this.setAttribute("value", val);
            var children = this.childNodes;
            for (var c = children.length - 1; c >= 0; c--) {
              if (children[c].value == val) {
                this.selectedIndex = c;
                break;
              }
            }
            return val;
          ]]>
        </setter>
      </property>

      <field name="tabbox" readonly="true"><![CDATA[
        var parent = this.parentNode;
        while (parent) {
          if (parent.localName == "tabbox")
            break;
          parent = parent.parentNode;
        }
        parent;
      ]]></field>

      <!-- _tabbox is deprecated, it exists only for backwards compatibility. -->
      <field name="_tabbox" readonly="true"><![CDATA[
        this.tabbox;
      ]]></field>

      <property name="selectedIndex">
        <getter>
        <![CDATA[
          const tabs = this.childNodes;
          for (var i = 0; i < tabs.length; i++) {
            if (tabs[i].selected)
              return i;
          }
          return -1;
        ]]>
        </getter>
        
        <setter>
        <![CDATA[
          var tab = this.getItemAtIndex(val);
          if (tab) {
            var alreadySelected = tab.selected;

            Array.forEach(this.childNodes, function (aTab) {
              if (aTab.selected && aTab != tab)
                aTab._selected = false;
            });
            tab._selected = true;

            this.setAttribute("value", tab.value);

            let linkedPanel = this.getRelatedElement(tab);
            if (linkedPanel) {
              this.tabbox.setAttribute("selectedIndex", val);

              // This will cause an onselect event to fire for the tabpanel
              // element.
              this.tabbox.tabpanels.selectedPanel = linkedPanel;
            }

            if (!alreadySelected) {
              // Fire an onselect event for the tabs element.
              var event = document.createEvent('Events');
              event.initEvent('select', true, true);
              this.dispatchEvent(event);
            }
          }
          return val;
        ]]>
        </setter>
      </property>

      <property name="selectedItem">
        <getter>
        <![CDATA[
          const tabs = this.childNodes;
          for (var i = 0; i < tabs.length; i++) {
            if (tabs[i].selected)
              return tabs[i];
          }
          return null;
        ]]>
        </getter>

        <setter>
        <![CDATA[
          if (val && !val.selected)
            // The selectedIndex setter ignores invalid values
            // such as -1 if |val| isn't one of our child nodes.
            this.selectedIndex = this.getIndexOfItem(val);
          return val;
        ]]>
        </setter>
      </property>

      <method name="getIndexOfItem">
        <parameter name="item"/>
        <body>
        <![CDATA[
          return Array.indexOf(this.childNodes, item);
        ]]>
        </body>
      </method>

      <method name="getItemAtIndex">
        <parameter name="index"/>
        <body>
        <![CDATA[
          return this.childNodes.item(index);
        ]]>
        </body>
      </method>

      <method name="_selectNewTab">
        <parameter name="aNewTab"/>
        <parameter name="aFallbackDir"/>
        <parameter name="aWrap"/>
        <body>
        <![CDATA[
          var requestedTab = aNewTab;
          while (aNewTab.hidden || aNewTab.disabled || !this._canAdvanceToTab(aNewTab)) {
            aNewTab = aFallbackDir == -1 ? aNewTab.previousSibling : aNewTab.nextSibling;
            if (!aNewTab && aWrap)
              aNewTab = aFallbackDir == -1 ? this.childNodes[this.childNodes.length - 1] :
                                             this.childNodes[0];
            if (!aNewTab || aNewTab == requestedTab)
              return;
          }

          var isTabFocused = false;
          try {
            isTabFocused =
              (document.commandDispatcher.focusedElement == this.selectedItem);
          } catch (e) {}
          this.selectedItem = aNewTab;
          if (isTabFocused) {
            aNewTab.focus();
          }
          else if (this.getAttribute("setfocus") != "false") {
            let selectedPanel = this.tabbox.selectedPanel;
            document.commandDispatcher.advanceFocusIntoSubtree(selectedPanel);

            // Make sure that the focus doesn't move outside the tabbox
            if (this.tabbox) {
              try {
                let el = document.commandDispatcher.focusedElement;
                while (el && el != this.tabbox.tabpanels) {
                  if (el == this.tabbox || el == selectedPanel)
                    return;
                  el = el.parentNode;
                }
                aNewTab.focus();
              } catch(e) {
              }
            }
          }
        ]]>
        </body>
      </method>

      <method name="_canAdvanceToTab">
        <parameter name="aTab"/>
        <body>
        <![CDATA[
          return true;
        ]]>
        </body>
      </method>

      <method name="advanceSelectedTab">
        <parameter name="aDir"/>
        <parameter name="aWrap"/>
        <body>
        <![CDATA[
          var startTab = this.selectedItem;
          var next = startTab[aDir == -1 ? "previousSibling" : "nextSibling"];
          if (!next && aWrap) {
            next = aDir == -1 ? this.childNodes[this.childNodes.length - 1] :
                                this.childNodes[0];
          }
          if (next && next != startTab) {
            this._selectNewTab(next, aDir, aWrap);
          }
        ]]>
        </body>
      </method>

      <method name="appendItem">
        <parameter name="label"/>
        <parameter name="value"/>
        <body>
        <![CDATA[
          var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
          var tab = document.createElementNS(XULNS, "tab");
          tab.setAttribute("label", label);
          tab.setAttribute("value", value);
          this.appendChild(tab);
          return tab;
        ]]>
        </body>
      </method>
      
      <method name="insertItemAt">
        <parameter name="index"/>
        <parameter name="label"/>
        <parameter name="value"/>
        <body>
        <![CDATA[
          var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
          var tab = document.createElementNS(XULNS, "tab");
          tab.setAttribute("label", label);
          tab.setAttribute("value", value);
          var before = this.getItemAtIndex(index);
          if (before)
            this.insertBefore(tab, before);
          else
            this.appendChild(tab);
          return tab;
        ]]>
        </body>
      </method>

      <method name="removeItemAt">
        <parameter name="index"/>
        <body>
        <![CDATA[
          var remove = this.getItemAtIndex(index);
          if (remove)
            this.removeChild(remove);
          return remove;
        ]]>
        </body>
      </method>
    </implementation>

#ifdef MOZ_WIDGET_GTK
    <handlers>
      <handler event="DOMMouseScroll">
      <![CDATA[
        if (event.detail > 0)
          this.advanceSelectedTab(1, false);
        else
          this.advanceSelectedTab(-1, false);

        event.stopPropagation();
      ]]>
      </handler>
    </handlers>
#endif
  </binding>

  <binding id="tabpanels"
           extends="chrome://global/content/bindings/tabbox.xml#tab-base">
    <implementation implements="nsIAccessibleProvider, nsIDOMXULRelatedElement">

      <!-- nsIAccessibleProvider -->
      <property name="accessibleType" readonly="true">
        <getter>
          <![CDATA[
            return Components.interfaces.nsIAccessibleProvider.XULTabpanels;
          ]]>
        </getter>
      </property>

      <!-- nsIDOMXULRelatedElement -->
      <method name="getRelatedElement">
        <parameter name="aTabPanelElm"/>
        <body>
        <![CDATA[
          if (!aTabPanelElm)
            return null;

          let tabboxElm = this.tabbox;
          if (!tabboxElm)
            return null;

          let tabsElm = tabboxElm.tabs;
          if (!tabsElm)
            return null;

          // Return tab element having 'linkedpanel' attribute equal to the id
          // of the tab panel or the same index as the tab panel element.
          let tabpanelIdx = Array.indexOf(this.childNodes, aTabPanelElm);
          if (tabpanelIdx == -1)
            return null;

          let tabElms = tabsElm.childNodes;
          let tabElmFromIndex = tabElms[tabpanelIdx];

          let tabpanelId = aTabPanelElm.id;
          if (tabpanelId) {
            for (let idx = 0; idx < tabElms.length; idx++) {
              var tabElm = tabElms[idx];
              if (tabElm.linkedPanel == tabpanelId)
                return tabElm;
            }
          }

          return tabElmFromIndex;
        ]]>
        </body>
      </method>

      <!-- public -->
      <field name="tabbox" readonly="true"><![CDATA[
        var parent = this.parentNode;
        while (parent) {
          if (parent.localName == "tabbox")
            break;
          parent = parent.parentNode;
        }
        parent;
      ]]></field>

      <field name="_selectedPanel">this.childNodes.item(this.selectedIndex)</field>

      <property name="selectedIndex">
        <getter>
        <![CDATA[
          var indexStr = this.getAttribute("selectedIndex");
          return indexStr ? parseInt(indexStr) : -1;
        ]]>
        </getter>

        <setter>
        <![CDATA[
          if (val < 0 || val >= this.childNodes.length)
            return val;
          var panel = this._selectedPanel;
          this._selectedPanel = this.childNodes[val];
          this.setAttribute("selectedIndex", val);
          if (this._selectedPanel != panel) {
            var event = document.createEvent("Events");
            event.initEvent("select", true, true);
            this.dispatchEvent(event);
          }
          return val;
        ]]>
        </setter>
      </property>

      <property name="selectedPanel">
        <getter>
          <![CDATA[
            return this._selectedPanel;
          ]]>
        </getter>

        <setter>
          <![CDATA[
            var selectedIndex = -1;
            for (var panel = val; panel != null; panel = panel.previousSibling)
              ++selectedIndex;
            this.selectedIndex = selectedIndex;
            return val;
          ]]>
        </setter>
      </property>
    </implementation>
  </binding>

  <binding id="tab" display="xul:button"
           extends="chrome://global/content/bindings/general.xml#control-item">
    <resources>
      <stylesheet src="chrome://global/skin/tabbox.css"/>
    </resources>

    <content>
      <xul:hbox class="tab-middle box-inherit" xbl:inherits="align,dir,pack,orient,selected" flex="1">
        <xul:image class="tab-icon"
                   xbl:inherits="validate,src=image"
                   role="presentation"/>
        <xul:label class="tab-text"
                   xbl:inherits="value=label,accesskey,crop,disabled"
                   flex="1"
                   role="presentation"/>
      </xul:hbox>
    </content>

    <implementation implements="nsIDOMXULSelectControlItemElement, nsIAccessibleProvider">
      <property name="accessibleType" readonly="true">
        <getter>
          <![CDATA[
            return Components.interfaces.nsIAccessibleProvider.XULTab;
          ]]>
        </getter>
      </property>

      <property name="control" readonly="true">
        <getter>
          <![CDATA[
            var parent = this.parentNode;
            if (parent instanceof Components.interfaces.nsIDOMXULSelectControlElement)
              return parent;
            return null;
          ]]>
        </getter>
      </property>

      <property name="selected" readonly="true"
                onget="return this.getAttribute('selected') == 'true';"/>

      <property name="_selected">
        <setter>
          <![CDATA[
          if (val)
            this.setAttribute("selected", "true");
          else
            this.removeAttribute("selected");

          if (this.previousSibling && this.previousSibling.localName == "tab") {
            if (val)
              this.previousSibling.setAttribute("beforeselected", "true");
            else
              this.previousSibling.removeAttribute("beforeselected");
            this.removeAttribute("first-tab");
          }
          else
            this.setAttribute("first-tab", "true");

          if (this.nextSibling && this.nextSibling.localName == "tab") {
            if (val)
              this.nextSibling.setAttribute("afterselected", "true");
            else
              this.nextSibling.removeAttribute("afterselected");
            this.removeAttribute("last-tab");
          }
          else
            this.setAttribute("last-tab", "true");
          return val;
        ]]>
        </setter>
      </property>

      <property name="linkedPanel" onget="return this.getAttribute('linkedpanel')"
                                   onset="this.setAttribute('linkedpanel', val); return val;"/>

      <field name="arrowKeysShouldWrap" readonly="true">
#ifdef XP_MACOSX
        true
#else
        false
#endif
      </field>
      <field name="TelemetryStopwatch" readonly="true">
        let tmp = {};
        Cu.import("resource://gre/modules/TelemetryStopwatch.jsm", tmp);
        tmp.TelemetryStopwatch;
      </field>
    </implementation>

    <handlers>
      <handler event="mousedown" button="0">
      <![CDATA[
        if (this.disabled)
          return;

        if (this != this.parentNode.selectedItem) { // Not selected yet
          let stopwatchid = this.parentNode.getAttribute("stopwatchid");
          if (stopwatchid) {
            this.TelemetryStopwatch.start(stopwatchid);
          }

          // Call this before setting the 'ignorefocus' attribute because this
          // will pass on focus if the formerly selected tab was focused as well.
          this.parentNode._selectNewTab(this);

          var isTabFocused = false;
          try {
            isTabFocused = (document.commandDispatcher.focusedElement == this);
          } catch (e) {}

          // Set '-moz-user-focus' to 'ignore' so that PostHandleEvent() can't
          // focus the tab; we only want tabs to be focusable by the mouse if
          // they are already focused. After a short timeout we'll reset
          // '-moz-user-focus' so that tabs can be focused by keyboard again.
          if (!isTabFocused) {
            this.setAttribute("ignorefocus", "true");
            setTimeout(function (tab) tab.removeAttribute("ignorefocus"), 0, this);
          }

          if (stopwatchid) {
            this.TelemetryStopwatch.finish(stopwatchid);
          }
        }
        // Otherwise this tab is already selected and we will fall
        // through to mousedown behavior which sets focus on the current tab,
        // Only a click on an already selected tab should focus the tab itself.
      ]]>
      </handler>

      <handler event="keypress" keycode="VK_LEFT">
      <![CDATA[
        var direction = window.getComputedStyle(this.parentNode, null).direction;
        this.parentNode.advanceSelectedTab(direction == 'ltr' ? -1 : 1, this.arrowKeysShouldWrap);
      ]]>
      </handler>

      <handler event="keypress" keycode="VK_RIGHT">
      <![CDATA[
        var direction = window.getComputedStyle(this.parentNode, null).direction;
        this.parentNode.advanceSelectedTab(direction == 'ltr' ? 1 : -1, this.arrowKeysShouldWrap);
      ]]>
      </handler>

      <handler event="keypress" keycode="VK_UP">
      <![CDATA[
        this.parentNode.advanceSelectedTab(-1, this.arrowKeysShouldWrap);
      ]]>
      </handler>

      <handler event="keypress" keycode="VK_DOWN">
      <![CDATA[
        this.parentNode.advanceSelectedTab(1, this.arrowKeysShouldWrap);
      ]]>
      </handler>

      <handler event="keypress" keycode="VK_HOME">
      <![CDATA[
        this.parentNode._selectNewTab(this.parentNode.childNodes[0]);
      ]]>
      </handler>

      <handler event="keypress" keycode="VK_END">
      <![CDATA[
        var tabs = this.parentNode.childNodes;
        this.parentNode._selectNewTab(tabs[tabs.length - 1], -1);
      ]]>
      </handler>
    </handlers>
  </binding>

</bindings>