Bug 732265 - (1/2) Some light refactoring of SelectHelper code [r=margaret]
authorMatt Brubeck <mbrubeck@mozilla.com>
Thu, 01 Mar 2012 17:34:37 -0800
changeset 88123 0f085bd21bc75eb6453c6101086e1fe80c21d61d
parent 88122 9613e21afa3425f13a8ff343f3ea581f9d1c17dc
child 88124 51e8195da28db2d910b4874721484f54a428c9cd
push id22171
push usermak77@bonardo.net
push dateFri, 02 Mar 2012 13:56:30 +0000
treeherderautoland@343ec916dfd5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs732265
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 732265 - (1/2) Some light refactoring of SelectHelper code [r=margaret]
mobile/android/chrome/content/SelectHelper.js
--- a/mobile/android/chrome/content/SelectHelper.js
+++ b/mobile/android/chrome/content/SelectHelper.js
@@ -37,18 +37,19 @@ var SelectHelper = {
 
     if (!(selected instanceof Array)) {
       let temp = [];
       for (let i = 0; i < aList.listitems.length; i++) {
         temp[i] = (i == selected);
       }
       selected = temp;
     }
-    this.forOptions(aElement, function(aNode, aIndex) {
-      aNode.selected = selected[aIndex];
+    let i = 0;
+    this.forOptions(aElement, function(aNode) {
+      aNode.selected = selected[i++];
     });
     this.fireOnChange(aElement);
   },
 
   _isSelectElement: function(aElement) {
     return (aElement instanceof HTMLSelectElement);
   },
 
@@ -61,56 +62,60 @@ var SelectHelper = {
     };
 
     if (aElement.multiple) {
       result.buttons = [
         { label: Strings.browser.GetStringFromName("selectHelper.closeMultipleSelectDialog") },
       ];
     }
 
-    this.forOptions(aElement, function(aNode, aIndex, aIsGroup, aInGroup) {
+    let index = 0;
+    this.forOptions(aElement, function(aNode, aOptions) {
       let item = {
         label: aNode.text || aNode.label,
-        isGroup: aIsGroup,
-        inGroup: aInGroup,
+        isGroup: aOptions.isGroup,
+        inGroup: aOptions.inGroup,
         disabled: aNode.disabled,
-        id: aIndex
+        id: index
       }
-      if (aInGroup)
+      if (aOptions.inGroup)
         item.disabled = item.disabled || aNode.parentNode.disabled;
 
-      result.listitems[aIndex] = item;
-      result.selected[aIndex] = aNode.selected;
+      result.listitems[index] = item;
+      result.selected[index] = aNode.selected;
+      index++;
     });
     return result;
   },
 
   forOptions: function(aElement, aFunction) {
-    let optionIndex = 0;
     let children = aElement.children;
     let numChildren = children.length;
     // if there are no children in this select, we add a dummy row so that at least something appears
     if (numChildren == 0)
-      aFunction.call(this, {label:""}, optionIndex);
+      aFunction.call(this, { label: "" }, { isGroup: false, inGroup: false });
     for (let i = 0; i < numChildren; i++) {
       let child = children[i];
       if (child instanceof HTMLOptionElement) {
         // This is a regular choice under no group.
-        aFunction.call(this, child, optionIndex, false, false);
-        optionIndex++;
+        aFunction.call(this, child, {
+          isGroup: false, inGroup: false
+        });
       } else if (child instanceof HTMLOptGroupElement) {
-        aFunction.call(this, child, optionIndex, true, false);
-        optionIndex++;
+        aFunction.call(this, child, {
+          isGroup: true, inGroup: false
+        });
 
         let subchildren = child.children;
         let numSubchildren = subchildren.length;
         for (let j = 0; j < numSubchildren; j++) {
           let subchild = subchildren[j];
-          aFunction.call(this, subchild, optionIndex, false, true);
-          optionIndex++;
+          aFunction.call(this, subchild, {
+            isGroup: false, inGroup: true
+          });
         }
       }
     }
   },
 
   fireOnChange: function(aElement) {
     let evt = aElement.ownerDocument.createEvent("Events");
     evt.initEvent("change", true, true, aElement.defaultView, 0,