<?xml version="1.0" encoding="UTF-8"?><RDF:RDF 
xmlns="http://www.xul.org#" 
xmlns:XUL="http://www.xul.org#" 
xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
xmlns:NC="http://home.netscape.com/NC-rdf#"> <bindings XUL:id="buttonBindings" XUL:xmlns="http://www.mozilla.org/xbl" xmlns:xbl="http://www.mozilla.org/xbl" xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <binding XUL:extends="chrome://global/content/bindings/general.xml#basetext" XUL:id="button-base">
    <implementation XUL:implements="nsIDOMXULButtonElement, nsIAccessibleProvider">
      <property XUL:name="accessible">
        <getter>
          <![CDATA[
            var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
            return accService.createXULButtonAccessible(this);
          ]]>
        </getter>
      </property>

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

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

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

      <property XUL:name="open" XUL:onget="return this.hasAttribute('open');" XUL:onset="if (val) this.setAttribute('open', 'true');                        else this.removeAttribute('open'); return val;"></property>

      <property XUL:name="checked" XUL:onget="return this.hasAttribute('checked');">
        <setter><![CDATA[
          if (this.type == "checkbox") {
            this.checkState = val ? 1 : 0;
          } else if (this.type == "radio" && val) {
            var sibs = this.parentNode.getElementsByAttribute("group", this.group);
            for (var i = 0; i < sibs.length; ++i)
              if (sibs[i].checked)
                sibs[i].checked = false;
          }

          if (val)
            this.setAttribute("checked", "true");
          else
            this.removeAttribute("checked");
          
          return val;
        ]]></setter>
      </property>
      
      <property XUL:name="checkState">
        <getter><![CDATA[
          var state = this.getAttribute("checkState");
          if (state == "")
            return this.checked ? 1 : 0;
          else
            return state == "0" ? 0 : (state == "2" ? 2 : 1);
        ]]></getter>
        <setter><![CDATA[
          this.setAttribute("checkState", val);
          return val;
        ]]></setter>
      </property>
      
      <property XUL:name="autoCheck" XUL:onget="return this.getAttribute('autoCheck') == 'true';" XUL:onset="this.setAttribute('autoCheck', val); return val;"></property>

      <method XUL:name="filterButtons">
        <parameter XUL:name="node"></parameter>
        <body>
        <![CDATA[
          if (node.localName == "button" && node.accessKey &&
            !node.disabled && !node.collapsed && !node.hidden)
            return NodeFilter.FILTER_ACCEPT;
          return NodeFilter.FILTER_SKIP;
        ]]>
        </body>
      </method>

      <method XUL:name="fireAccessKeyButton">
        <parameter XUL:name="aSubtree"></parameter>
        <parameter XUL:name="aAccessKeyLower"></parameter>
        <body>
        <![CDATA[
          var iterator = aSubtree.ownerDocument.createTreeWalker(aSubtree, 
                                                                 NodeFilter.SHOW_ELEMENT, 
                                                                 this.filterButtons, false);
          while (iterator.nextNode()) {
            var test = iterator.currentNode;
            if (test.accessKey.toLowerCase() == aAccessKeyLower && 
                !test.disabled && !test.collapsed && !test.hidden) {
              test.focus();
              test.click();
              return true;
            }
          }
          return false;
        ]]>
        </body>
      </method>
    </implementation>

    <handlers>
      <handler XUL:event="command">
      <![CDATA[
        if (this.autoCheck || !this.hasAttribute("autoCheck")) {
          if (this.type == "checkbox") {
            this.checked = !this.checked;
          } else if (this.type == "radio") {
            this.checked = true;
          }
        }
      ]]>
      </handler>

      <handler XUL:event="keypress">
      <![CDATA[
        if (event.keyCode == KeyEvent.DOM_VK_UP ||
            event.keyCode == KeyEvent.DOM_VK_LEFT)
          return window.document.commandDispatcher.rewindFocus();

        if (event.keyCode == KeyEvent.DOM_VK_DOWN ||
            event.keyCode == KeyEvent.DOM_VK_RIGHT)
          return window.document.commandDispatcher.advanceFocus();

        if (event.keyCode || event.charCode <= 32 || event.altKey || 
            event.ctrlKey || event.metaKey)
          return;  // No printable char pressed, not a potential accesskey

        // Possible accesskey pressed
        var charPressedLower = String.fromCharCode(event.charCode).toLowerCase();

        // If the accesskey of the current button is pressed, just activate it
        if (this.accessKey.toLowerCase() == charPressedLower) {
          this.click();
          return;
        }

        // Search for accesskey in the list of buttons for this doc and each subdoc
        // Get the buttons for the main document and all sub-frames
        for (var frameCount = -1; frameCount < window.top.frames.length; frameCount++) {
          var doc = (frameCount == -1)? window.top.document: 
            window.top.frames[frameCount].document
          if (this.fireAccessKeyButton(doc.documentElement, charPressedLower))
            return;
        }

        // Test anonymous buttons
        var dlg = window.top.document;
        var buttonBox = dlg.getAnonymousElementByAttribute(dlg.documentElement,
                                                         "anonid", "buttons");
        if (buttonBox)
          this.fireAccessKeyButton(buttonBox, charPressedLower);
      ]]>
      </handler>

    </handlers>
  </binding>

  <binding XUL:display="xul:button" XUL:extends="chrome://global/content/bindings/button.xml#button-base" XUL:id="button">
    <resources>
      <stylesheet XUL:src="chrome://global/skin/button.css"></stylesheet>
    </resources>

    <content>
      <children XUL:includes="observes|template|menupopup|tooltip"></children>
      <xul:hbox XUL:align="center" XUL:class="box-inherit button-box" XUL:flex="1" XUL:pack="center" xbl:inherits="align,dir,pack,orient">
        <children>
          <xul:image XUL:class="button-icon" xbl:inherits="src=image"></xul:image>
          <xul:label XUL:class="button-text" XUL:flex="1" xbl:inherits="value=label,accesskey,crop"></xul:label>
        </children>
      </xul:hbox>
    </content>
  </binding>

  <binding XUL:display="xul:menu" XUL:extends="chrome://global/content/bindings/button.xml#button" XUL:id="menu">
    <content>
      <children XUL:includes="observes|template|menupopup|tooltip"></children>
      <xul:hbox XUL:align="center" XUL:class="box-inherit button-box" XUL:flex="1" XUL:pack="center" xbl:inherits="align,dir,pack,orient">
        <children>
          <xul:image XUL:class="button-icon" xbl:inherits="src=image"></xul:image>
          <xul:label XUL:class="button-text" XUL:flex="1" xbl:inherits="value=label,accesskey,crop"></xul:label>
          <xul:dropmarker XUL:class="button-menu-dropmarker" xbl:inherits="open,disabled"></xul:dropmarker>
        </children>
      </xul:hbox>
    </content>
  </binding>           

  <binding XUL:extends="chrome://global/content/bindings/button.xml#button-base" XUL:id="menu-button-base">
    <implementation>
      <constructor>
        this.init();
      </constructor>
      
      <method XUL:name="init">
        <body>
        <![CDATA[
          var btn = document.getAnonymousElementByAttribute(this, "anonid", "button");
          if (!btn)
            throw "XBL binding for <button type=\"menu-button\"/> binding must contain an element with anonid=\"button\"";
          
          btn._menubuttonParent = this;
          btn.addEventListener("mouseover", function() { 
            if (!this.disabled)
              this._menubuttonParent.buttonover = true; 
          }, true);
          btn.addEventListener("mouseout", function() {
            this._menubuttonParent.buttonover = false;
           }, true);
          btn.addEventListener("mousedown", function() {
            if (!this.disabled) {
              this._menubuttonParent.buttondown = true;
              this._menubuttonParent._captureMouseUp();
            }
          }, true);
        ]]>
        </body>
      </method>
      
      <property XUL:name="buttonover" XUL:onget="return this.getAttribute('buttonover');">
        <setter>
        <![CDATA[
          var v = val || val == "true";
          if (!v && this.buttondown) { 
            this.buttondown = false;
            this._pendingActive = true;
          } 
          else {
            if (this._pendingActive) {
              this.buttondown = true;
              this._pendingActive = false;
            }
          }

          if (v)
            this.setAttribute("buttonover", "true");
          else
            this.removeAttribute("buttonover");
          return val;
        ]]>
        </setter>
      </property>
      
      <property XUL:name="buttondown" XUL:onget="return this.getAttribute('buttondown') == 'true';">
        <setter>
        <![CDATA[
          if (val || val == "true")
            this.setAttribute("buttondown", "true");
          else
            this.removeAttribute("buttondown");
          return val;
        ]]>
        </setter>
      </property>
      
      <field XUL:name="_pendingActive">false</field>

      <method XUL:name="_captureMouseUp">
        <body>
        <![CDATA[
          document.__ButtonMenuMouseDown__ = this;
          document.addEventListener("mouseup", this._onGlobalMouseUp, true);
        ]]>
        </body>
      </method>

      <method XUL:name="_onGlobalMouseUp" XUL:readonly="true">
        <body>
        <![CDATA[
          var btn = document.__ButtonMenuMouseDown__;
          btn._onMouseReallyUp();
          document.removeEventListener("mouseup", btn._onGlobalMouseUp, true);
          delete document.__ButtonMenuMouseDown__;
        ]]>
        </body>
      </method>

      <method XUL:name="_onMouseReallyUp">
        <body>
        <![CDATA[
          this._pendingActive = false;
          this.buttondown = false;
        ]]>
        </body>
      </method>

    </implementation>
  </binding>

  <binding XUL:display="xul:menu" XUL:extends="chrome://global/content/bindings/button.xml#menu-button-base" XUL:id="menu-button">
    <resources>
      <stylesheet XUL:src="chrome://global/skin/button.css"></stylesheet>
    </resources>

    <content>
      <children XUL:includes="observes|template|menupopup|tooltip"></children>
      <xul:button XUL:allowevents="true" XUL:anonid="button" XUL:class="box-inherit button-menubutton-button" XUL:flex="1" xbl:inherits="disabled,crop,image,label,accessKey,command,                                 buttonover,buttondown,align,dir,pack,orient">
        <children></children>
      </xul:button>
      <xul:dropmarker XUL:class="button-menubutton-dropmarker" xbl:inherits="open,disabled"></xul:dropmarker>
    </content>
  </binding>
  
  <binding XUL:display="xul:button" XUL:extends="chrome://global/content/bindings/button.xml#button" XUL:id="button-image">
    <content>
      <xul:image XUL:class="button-image-icon" xbl:inherits="src=image"></xul:image>
    </content>
  </binding>
  
</bindings>
</RDF:RDF>