Bug 371260, cleanup of <radio> code, r=neil
authorenndeakin@sympatico.ca
Wed, 09 May 2007 06:43:26 -0700
changeset 1315 b6e526741263a65d46284c08ad9527c2eae9b4ef
parent 1314 956b2d44a6c7061af7dd3c3e030d9d1502dbd779
child 1316 3f59bb958e54edb8081eeb196e98264f0a411af3
push idunknown
push userunknown
push dateunknown
reviewersneil
bugs371260
milestone1.9a5pre
Bug 371260, cleanup of <radio> code, r=neil
toolkit/content/widgets/radio.xml
xpfe/global/jar.mn
--- a/toolkit/content/widgets/radio.xml
+++ b/toolkit/content/widgets/radio.xml
@@ -6,16 +6,38 @@
    xmlns:xbl="http://www.mozilla.org/xbl">
 
   <binding id="radiogroup" extends="chrome://global/content/bindings/general.xml#basecontrol">
     <resources>
       <stylesheet src="chrome://global/skin/radio.css"/>
     </resources>
 
     <implementation implements="nsIDOMXULSelectControlElement, nsIAccessibleProvider">
+      <constructor>
+        <![CDATA[
+          if (this.getAttribute("disabled") == "true")
+            this.disabled = true;
+
+          var children = this._getRadioChildren();
+          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>
+
       <property name="accessibleType" readonly="true">
         <getter>
           <![CDATA[
             return Components.interfaces.nsIAccessibleProvider.XULRadioGroup;
           ]]>
         </getter>
       </property>
 
@@ -101,16 +123,19 @@
           var alreadySelected = false;
 
           if (val) {
             alreadySelected = val.getAttribute("selected") == "true";
             val.setAttribute("focused", focused);
             val.setAttribute("selected", "true");
             this.setAttribute("value", val.value);
           }
+          else {
+            this.removeAttribute("value");
+          }
 
           // uncheck all other group nodes
           var children = this._getRadioChildren();
           var previousItem = null;
           for (var i = 0; i < children.length; ++i) {
             if (children[i] != val) {
               if (children[i].getAttribute("selected") == "true")
                 previousItem = children[i];
@@ -170,17 +195,17 @@
         ]]>
         </setter>
       </property>
       
       <method name="checkAdjacentElement">
         <parameter name="aNextFlag"/>
         <body>
         <![CDATA[
-          var currentElement = this.focusedItem;
+          var currentElement = this.focusedItem || this.selectedItem;
           var i;
           var children = this._getRadioChildren();
           for (i = 0; i < children.length; ++i ) {
             if (children[i] == currentElement) 
               break;
           }
           var index = i;
 
@@ -208,31 +233,31 @@
             // XXX check for display/visibility props too
 
             this.selectedItem = children[i];
             children[i].doCommand();
           }
         ]]>
         </body>
       </method>
-      <field name="mRadioChildren">null</field>
+      <field name="_radioChildren">null</field>
       <method name="_getRadioChildren">
         <body>
         <![CDATA[
-          if (this.mRadioChildren)
-            return this.mRadioChildren;
+          if (this._radioChildren)
+            return this._radioChildren;
 
           // Don't store the collected child nodes immediately,
           // collecting the child nodes could trigger constructors
           // which would blow away our list.
           var radioChildren = [];
           var iterator = this.ownerDocument.createTreeWalker(this, NodeFilter.SHOW_ELEMENT, this._filterRadioGroup, true);
           while (iterator.nextNode())
             radioChildren.push(iterator.currentNode);
-          return this.mRadioChildren = radioChildren;
+          return this._radioChildren = radioChildren;
         ]]>
         </body>
       </method>
       <method name="_filterRadioGroup">
         <parameter name="node"/>
         <body>
         <![CDATA[
           switch (node.localName) {
@@ -267,17 +292,17 @@
         <parameter name="value"/>
         <body>
         <![CDATA[
           var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
           var radio = document.createElementNS(XULNS, "radio");
           radio.setAttribute("label", label);
           radio.setAttribute("value", value);
           this.appendChild(radio);
-          this.mRadioChildren = null;
+          this._radioChildren = null;
           return radio;
         ]]>
         </body>
       </method>
       
       <method name="insertItemAt">
         <parameter name="index"/>
         <parameter name="label"/>
@@ -288,30 +313,30 @@
           var radio = document.createElementNS(XULNS, "radio");
           radio.setAttribute("label", label);
           radio.setAttribute("value", value);
           var before = this.getItemAtIndex(index);
           if (before)
             before.parentNode.insertBefore(radio, before);
           else
             this.appendChild(radio);
-          this.mRadioChildren = null;
+          this._radioChildren = null;
           return radio;
         ]]>
         </body>
       </method>
 
       <method name="removeItemAt">
         <parameter name="index"/>
         <body>
         <![CDATA[
           var remove = this.getItemAtIndex(index);
           if (remove) {
             remove.parentNode.removeChild(remove);
-            this.mRadioChildren = null;
+            this._radioChildren = null;
           }
           return remove;
         ]]>
         </body>
       </method>
     </implementation>
     
     <handlers>
@@ -394,17 +419,19 @@
         <xul:label class="radio-label" xbl:inherits="xbl:text=label,accesskey,crop" flex="1"/>
       </xul:hbox>
     </content>
 
     <implementation implements="nsIDOMXULSelectControlItemElement, nsIDOMXULLabeledControlElement, nsIAccessibleProvider">
       <constructor>
         <![CDATA[
           // Just clear out the parent's cached list of radio children
-          this.radioGroup.mRadioChildren = null;
+          var control = this.control;
+          if (control)
+            control._radioChildren = null;
         ]]>
       </constructor>
       <destructor>
         <![CDATA[
           var radioList = this.radioGroup.mRadioChildren;
           if (!radioList)
             return;
           for (var i = 0; i < radioList.length; ++i) {
@@ -424,17 +451,18 @@
       </property>
       <property name="selected" readonly="true">
         <getter>
           <![CDATA[
             return this.hasAttribute('selected');
           ]]>
         </getter>
       </property>
-      <property name="radioGroup">
+      <property name="radioGroup" readonly="true" onget="return this.control"/>
+      <property name="control" readonly="true">
         <getter>
         <![CDATA[
           var parent = this.parentNode;
           while (parent) {
             if (parent.localName == "radiogroup")
               return parent;
             parent = parent.parentNode;
           }
@@ -442,29 +470,29 @@
         ]]>
         </getter>
       </property>
     </implementation>
     <handlers>
       <handler event="click" button="0">
         <![CDATA[
           if (!this.disabled)
-            this.radioGroup.selectedItem = this;
+            this.control.selectedItem = this;
          ]]>
       </handler>
 
       <handler event="mousedown" button="0">
         <![CDATA[
           if (!this.disabled)
-            this.radioGroup.focusedItem = this;
+            this.control.focusedItem = this;
          ]]>
       </handler>
       <handler event="focus">
         <![CDATA[
           if (!this.disabled) {
-            this.radioGroup.focusedItem = this;
-            this.radioGroup.focus();
+            this.control.focusedItem = this;
+            this.control.focus();
           }
          ]]>
       </handler>
     </handlers>
   </binding>
 </bindings>
--- a/xpfe/global/jar.mn
+++ b/xpfe/global/jar.mn
@@ -46,17 +46,17 @@ toolkit.jar:
         content/global/bindings/general.xml         (resources/content/bindings/general.xml)
         content/global/bindings/groupbox.xml        (resources/content/bindings/groupbox.xml)
         content/global/bindings/listbox.xml         (resources/content/bindings/listbox.xml)
         content/global/bindings/menu.xml            (resources/content/bindings/menu.xml)
         content/global/bindings/menulist.xml        (resources/content/bindings/menulist.xml)
         content/global/bindings/numberbox.xml       (/toolkit/content/widgets/numberbox.xml)
         content/global/bindings/popup.xml           (resources/content/bindings/popup.xml)
         content/global/bindings/progressmeter.xml   (resources/content/bindings/progressmeter.xml)
-        content/global/bindings/radio.xml           (resources/content/bindings/radio.xml)
+        content/global/bindings/radio.xml           (/toolkit/content/widgets/radio.xml)
         content/global/bindings/scrollbar.xml       (resources/content/bindings/scrollbar.xml)
         content/global/bindings/nativescrollbar.xml (resources/content/bindings/nativescrollbar.xml)
         content/global/bindings/scale.xml           (/toolkit/content/widgets/scale.xml)
         content/global/bindings/scrollbox.xml       (resources/content/bindings/scrollbox.xml)
         content/global/bindings/splitter.xml        (resources/content/bindings/splitter.xml)
         content/global/bindings/spinbuttons.xml     (/toolkit/content/widgets/spinbuttons.xml)
         content/global/bindings/stringbundle.xml    (resources/content/bindings/stringbundle.xml)
         content/global/bindings/tabbox.xml          (resources/content/bindings/tabbox.xml)