common/bindings/menubutton.xml
author aceman <acelists@atlas.sk>
Tue, 12 Mar 2019 14:34:00 +0100
changeset 32312 60230bc80b9448241b98ce046f1ae092715f0fd4
parent 32260 5e366aafa2d5b8501ab9558a41d1b8e0c7123ca7
child 32425 470f4c1ed97e2d69806d1be58b5e342fa5d825d4
permissions -rw-r--r--
Bug 1534530 - remove mensions of RDF in ldap. r=jorgk

<?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="menubuttonBindings"
   xmlns="http://www.mozilla.org/xbl"
   xmlns:html="http://www.w3.org/1999/xhtml"
   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
   xmlns:xbl="http://www.mozilla.org/xbl">

  <binding id="menu-button-base"
           extends="chrome://global/content/bindings/button.xml#button-base">
    <implementation>
      <constructor>
        this.init();
      </constructor>

      <method 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\"";

          var menubuttonParent = this;
          btn.addEventListener("mouseover", function() {
            if (!this.disabled)
              menubuttonParent.buttonover = true;
          }, true);
          btn.addEventListener("mouseout", function() {
            menubuttonParent.buttonover = false;
          }, true);
          btn.addEventListener("mousedown", function() {
            if (!this.disabled) {
              menubuttonParent.buttondown = true;
              document.addEventListener("mouseup", menubuttonParent, true);
            }
          }, true);
        ]]>
        </body>
      </method>

      <property name="buttonover" 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 name="buttondown" 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 name="_pendingActive">false</field>

      <method name="handleEvent">
        <parameter name="aEvent"/>
        <body>
        <![CDATA[
          this._pendingActive = false;
          this.buttondown = false;
          document.removeEventListener("mouseup", this, true);
        ]]>
        </body>
      </method>

    </implementation>

    <handlers>
      <handler event="keypress" keycode="VK_RETURN">
        if (event.originalTarget == this)
          this.open = true;
      </handler>
      <handler event="keypress" key=" ">
        if (event.originalTarget == this) {
          this.open = true;
          // Prevent page from scrolling on the space key.
          event.preventDefault();
        }
      </handler>
    </handlers>
  </binding>

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

    <content>
      <children includes="observes|template|menupopup|panel|tooltip"/>
      <xul:button class="box-inherit button-menubutton-button"
                  anonid="button" flex="1" allowevents="true"
                  xbl:inherits="disabled,crop,image,label,accesskey,command,
                                buttonover,buttondown,align,dir,pack,orient">
        <children/>
      </xul:button>
      <xul:dropmarker class="button-menubutton-dropmarker" xbl:inherits="open,disabled,label"/>
    </content>
  </binding>

</bindings>