Source code

Revision control

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
<?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="radioBindings"
   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="radio"
    extends="chrome://global/content/bindings/general.xml#basetext">
    <content>
      <xul:image class="radio-check" xbl:inherits="disabled,selected"/>
      <xul:hbox class="radio-label-box" align="center" flex="1">
        <xul:image class="radio-icon" xbl:inherits="src"/>
        <xul:label class="radio-label" xbl:inherits="xbl:text=label,accesskey,crop" flex="1"/>
      </xul:hbox>
    </content>

    <implementation implements="nsIDOMXULSelectControlItemElement">
      <constructor>
        <![CDATA[
          // Just clear out the parent's cached list of radio children
          var control = this.control;
          window.customElements.upgrade(control);
          if (control)
            control.radioChildConstructed(this);
        ]]>
      </constructor>
      <destructor>
        <![CDATA[
          if (!this.control)
            return;

          var radioList = this.control._radioChildren;
          if (!radioList)
            return;
          for (var i = 0; i < radioList.length; ++i) {
            if (radioList[i] == this) {
              radioList.splice(i, 1);
              return;
            }
          }
        ]]>
      </destructor>
      <property name="value" onset="this.setAttribute('value', val); return val;"
                             onget="return this.getAttribute('value');"/>
      <property name="selected" readonly="true">
        <getter>
          <![CDATA[
            return this.hasAttribute("selected");
          ]]>
        </getter>
      </property>
      <property name="radioGroup" readonly="true" onget="return this.control"/>
      <property name="control" readonly="true">
        <getter>
        <![CDATA[
          var radiogroup = this.closest("radiogroup");
          if (radiogroup) {
            return radiogroup;
          }

          var group = this.getAttribute("group");
          if (!group) {
            return null;
          }

          var parent = this.ownerDocument.getElementById(group);
          if (!parent || parent.localName != "radiogroup") {
            parent = null;
          }
          return parent;
        ]]>
        </getter>
      </property>
    </implementation>
    <handlers>
      <handler event="click" button="0">
        <![CDATA[
          if (!this.disabled)
            this.control.selectedItem = this;
         ]]>
      </handler>

      <handler event="mousedown" button="0">
        <![CDATA[
          if (!this.disabled)
            this.control.focusedItem = this;
         ]]>
      </handler>
    </handlers>
  </binding>
</bindings>