toolkit/content/widgets/spinbuttons.xml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/widgets/spinbuttons.xml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +<?xml version="1.0" encoding="UTF-8"?>
     1.5 +
     1.6 +<!-- This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +   - License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 +   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     1.9 +
    1.10 +<bindings id="spinbuttonsBindings"
    1.11 +   xmlns="http://www.mozilla.org/xbl"
    1.12 +   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.13 +   xmlns:xbl="http://www.mozilla.org/xbl">
    1.14 +
    1.15 +  <binding id="spinbuttons"
    1.16 +           extends="chrome://global/content/bindings/general.xml#basecontrol">
    1.17 +
    1.18 +    <resources>
    1.19 +      <stylesheet src="chrome://global/skin/spinbuttons.css"/>
    1.20 +    </resources>
    1.21 +
    1.22 +    <content>
    1.23 +      <xul:vbox class="spinbuttons-box" flex="1">
    1.24 +        <xul:button anonid="increaseButton" type="repeat" flex="1"
    1.25 +                    class="spinbuttons-button spinbuttons-up"
    1.26 +                    xbl:inherits="disabled,disabled=increasedisabled"/>
    1.27 +        <xul:button anonid="decreaseButton" type="repeat" flex="1"
    1.28 +                    class="spinbuttons-button spinbuttons-down"
    1.29 +                    xbl:inherits="disabled,disabled=decreasedisabled"/>
    1.30 +      </xul:vbox>
    1.31 +    </content>
    1.32 +
    1.33 +    <implementation>
    1.34 +      <property name="_increaseButton" readonly="true">
    1.35 +        <getter>
    1.36 +          return document.getAnonymousElementByAttribute(this, "anonid", "increaseButton");
    1.37 +        </getter>
    1.38 +      </property>
    1.39 +      <property name="_decreaseButton" readonly="true">
    1.40 +        <getter>
    1.41 +          return document.getAnonymousElementByAttribute(this, "anonid", "decreaseButton");
    1.42 +        </getter>
    1.43 +      </property>
    1.44 +
    1.45 +      <property name="increaseDisabled"
    1.46 +                onget="return this._increaseButton.getAttribute('disabled') == 'true';"
    1.47 +                onset="if (val) this._increaseButton.setAttribute('disabled', 'true');
    1.48 +                       else this._increaseButton.removeAttribute('disabled'); return val;"/>
    1.49 +      <property name="decreaseDisabled"
    1.50 +                onget="return this._decreaseButton.getAttribute('disabled') == 'true';"
    1.51 +                onset="if (val) this._decreaseButton.setAttribute('disabled', 'true');
    1.52 +                       else this._decreaseButton.removeAttribute('disabled'); return val;"/>
    1.53 +    </implementation>
    1.54 +
    1.55 +    <handlers>
    1.56 +      <handler event="mousedown">
    1.57 +        <![CDATA[
    1.58 +          // on the Mac, the native theme draws the spinbutton as a single widget
    1.59 +          // so a state attribute is set based on where the mouse button was pressed
    1.60 +          if (event.originalTarget == this._increaseButton)
    1.61 +            this.setAttribute("state", "up");
    1.62 +          else if (event.originalTarget == this._decreaseButton)
    1.63 +            this.setAttribute("state", "down");
    1.64 +        ]]>
    1.65 +      </handler>
    1.66 +      
    1.67 +      <handler event="mouseup">
    1.68 +        this.removeAttribute("state");
    1.69 +      </handler>
    1.70 +      <handler event="mouseout">
    1.71 +        this.removeAttribute("state");
    1.72 +      </handler>
    1.73 +
    1.74 +      <handler event="command">
    1.75 +        <![CDATA[
    1.76 +          var eventname;
    1.77 +          if (event.originalTarget == this._increaseButton)
    1.78 +            eventname = "up";
    1.79 +          else if (event.originalTarget == this._decreaseButton)
    1.80 +            eventname = "down";
    1.81 +
    1.82 +          var evt = document.createEvent("Events");
    1.83 +          evt.initEvent(eventname, true, true);
    1.84 +          var cancel = this.dispatchEvent(evt);
    1.85 +          
    1.86 +          if (this.hasAttribute("on" + eventname)) {
    1.87 +            var fn = new Function("event", this.getAttribute("on" + eventname));
    1.88 +            if (fn.call(this, event) == false)
    1.89 +              cancel = true;
    1.90 +          }
    1.91 +
    1.92 +          return !cancel;
    1.93 +        ]]>
    1.94 +      </handler>
    1.95 +
    1.96 +    </handlers>
    1.97 +  </binding>
    1.98 +
    1.99 +</bindings>

mercurial