Bug 539102 - Entering '(' or '&' moves formfill to elements [r=stuart]
authorMark Finkle <mfinkle@mozilla.com>
Sat, 16 Jan 2010 00:41:48 -0500
changeset 65983 267b55795aa7d02598e6659ddc1bdcbf29b73767
parent 65982 b9ea9d195738cfa7dffc4bc0783f62068cd4bf54
child 65984 a7e92bf9dcb2931ca0832f45b6e9831f18118775
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstuart
bugs539102
Bug 539102 - Entering '(' or '&' moves formfill to elements [r=stuart]
mobile/chrome/content/browser-ui.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -149,17 +149,17 @@ var BrowserUI = {
     let link = aEvent.originalTarget;
     if (!link || !link.href)
       return;
 
     if (/\bicon\b/i(link.rel)) {
       var ownerDoc = link.ownerDocument;
       if (!ownerDoc) // no document, no icon
         return;
-      
+
       let tab = Browser.getTabForDocument(ownerDoc);
       tab.setIcon(link.href);
       // If the link changes after pageloading, update it right away.
       // otherwise we wait until the pageload finishes
       if ((tab.browser == Browser.selectedBrowser) && !tab.isLoading())
         this._updateIcon(tab.browser.mIconURL);
     }
     else if (/\bsearch\b/i(link.rel)) {
@@ -212,21 +212,21 @@ var BrowserUI = {
   },
 
   lockToolbar: function lockToolbar() {
     this._toolbarLocked++;
     document.getElementById("toolbar-moveable-container").top = "0";
     if (this._toolbarLocked == 1)
       Browser.forceChromeReflow();
   },
-  
+
   unlockToolbar: function unlockToolbar() {
     if (!this._toolbarLocked)
       return;
-    
+
     this._toolbarLocked--;
     if (!this._toolbarLocked)
       document.getElementById("toolbar-moveable-container").top = "";
   },
 
   _setURI: function _setURI(aCaption) {
     if (this.isAutoCompleteOpen())
       this._edit.defaultValue = aCaption;
@@ -292,17 +292,17 @@ var BrowserUI = {
     if (!this._dialogs.length) {
       document.getElementById("toolbar-main").removeAttribute("dialog");
       Elements.contentShowing.removeAttribute("disabled");
     }
   },
 
   pushPopup: function pushPopup(aPanel, aElements) {
     this._hidePopup();
-    this._popup =  { "panel": aPanel, 
+    this._popup =  { "panel": aPanel,
                      "elements": (aElements instanceof Array) ? aElements : [aElements] };
     this._dispatchPopupChanged();
   },
 
   popPopup: function popPopup() {
     this._popup = null;
     this._dispatchPopupChanged();
   },
@@ -317,17 +317,17 @@ var BrowserUI = {
 
   _hidePopup: function _hidePopup() {
     if (!this._popup)
       return;
     let panel = this._popup.panel;
     if (panel.hide)
       panel.hide();
   },
-  
+
   _isEventInsidePopup: function _isEventInsidePopup(aEvent) {
     if (!this._popup)
       return false;
     let elements = this._popup.elements;
     let targetNode = aEvent ? aEvent.target : null;
     while (targetNode && elements.indexOf(targetNode) == -1)
       targetNode = targetNode.parentNode;
     return targetNode ? true : false;
@@ -344,25 +344,25 @@ var BrowserUI = {
 
   get toolbarH() {
     if (!this._toolbarH) {
       let toolbar = document.getElementById("toolbar-main");
       this._toolbarH = toolbar.boxObject.height;
     }
     return this._toolbarH;
   },
-  
+
   get sidebarW() {
     if (!this._sidebarW) {
       let sidebar = document.getElementById("browser-controls");
       this._sidebarW = sidebar.boxObject.width;
     }
     return this._sidebarW;
   },
-  
+
   get starButton() {
     delete this.starButton;
     return this.starButton = document.getElementById("tool-star");
   },
 
   sizeControls : function(windowW, windowH) {
     // tabs
     document.getElementById("tabs").resize();
@@ -396,17 +396,17 @@ var BrowserUI = {
 
     let browsers = document.getElementById("browsers");
     browsers.addEventListener("DOMWindowClose", this, true);
 
     // XXX these really want to listen to only the current browser
     browsers.addEventListener("DOMTitleChanged", this, true);
     browsers.addEventListener("DOMLinkAdded", this, true);
     browsers.addEventListener("DOMWillOpenModalDialog", this, true);
-    
+
     // listening mousedown for automatically dismiss some popups (e.g. larry)
     window.addEventListener("mousedown", this, true);
 
     // listening escape to dismiss dialog on VK_ESCAPE
     window.addEventListener("keypress", this, true);
 
     // Push the panel initialization out of the startup path
     // (Using a timeout because we have no good way to delay-init [Bug 535366])
@@ -521,17 +521,17 @@ var BrowserUI = {
   showAutoComplete : function showAutoComplete() {
     if (this.isAutoCompleteOpen())
       return;
 
     BrowserSearch.updateSearchButtons();
 
     this._edit.showHistoryPopup();
   },
-  
+
   closeAutoComplete: function closeAutoComplete(aResetInput) {
     if (aResetInput)
       this._edit.popup.close();
     else
       this._edit.popup.closePopup();
   },
 
   isAutoCompleteOpen: function isAutoCompleteOpen() {
@@ -563,17 +563,17 @@ var BrowserUI = {
       this.starButton.removeAttribute("starred");
   },
 
   newTab : function newTab(aURI) {
     aURI = aURI || "about:blank";
     let tab = Browser.addTab(aURI, true);
 
     this.hidePanel();
-    
+
     if (aURI == "about:blank") {
       // Display awesomebar UI
       this.showToolbar(true);
       this.showAutoComplete();
     }
     else {
       // Give the new page lots of room
       Browser.hideSidebars();
@@ -638,29 +638,29 @@ var BrowserUI = {
   },
 
   switchTask: function switchTask() {
     try {
       let phone = Cc["@mozilla.org/phone/support;1"].createInstance(Ci.nsIPhoneSupport);
       phone.switchTask();
     } catch(e) { }
   },
-  
+
 #ifdef WINCE
   updateDefaultBrowser: function updateDefaultBrowser(aSet) {
     try {
       let phone = Cc["@mozilla.org/phone/support;1"].getService(Ci.nsIPhoneSupport);
       if (aSet)
         phone.setDefaultBrowser();
       else
         phone.restoreDefaultBrowser();
     } catch(e) { }
   },
 #endif
-  
+
   handleEvent: function (aEvent) {
     switch (aEvent.type) {
       // Browser events
       case "DOMWillOpenModalDialog":
         this._domWillOpenModalDialog(aEvent);
         break;
       case "DOMTitleChanged":
         this._titleChanged(aEvent.target);
@@ -860,17 +860,17 @@ var NewTabPopup = {
       clearTimeout(this._timeout);
       this._timeout = 0;
     }
 
     this._tabs = [];
     this.box.hidden = true;
     BrowserUI.popPopup();
   },
-  
+
   show: function(aTab) {
     BrowserUI.pushPopup(this, this.box);
 
     this._tabs.push(aTab);
     this._updateLabel();
 
     this.box.top = aTab.getBoundingClientRect().top + (aTab.getBoundingClientRect().height / 3);
     this.box.hidden = false;
@@ -900,17 +900,17 @@ var BookmarkPopup = {
   hide : function hide() {
     if (this._bookmarkPopupTimeout != -1) {
       clearTimeout(this._bookmarkPopupTimeout);
       this._bookmarkPopupTimeout = -1;
     }
     this.box.hidden = true;
     BrowserUI.popPopup();
   },
-  
+
   show : function show(aAutoClose) {
     const margin = 10;
 
     this.box.hidden = false;
 
     let [,,,controlsW] = Browser.computeSidebarVisibility();
     this.box.left = window.innerWidth - (this.box.getBoundingClientRect().width + controlsW + margin);
     this.box.top  = BrowserUI.starButton.getBoundingClientRect().top + margin;
@@ -920,17 +920,17 @@ var BookmarkPopup = {
         self._bookmarkPopupTimeout = -1;
         self.hide();
       }, 2000, this);
     }
 
     // include starButton here, so that click-to-dismiss works as expected
     BrowserUI.pushPopup(this, [this.box, BrowserUI.starButton]);
   },
-  
+
   toggle : function toggle(aAutoClose) {
     if (this.box.hidden)
       this.show(aAutoClose);
     else
       this.hide();
   }
 }
 
@@ -973,17 +973,17 @@ var BookmarkHelper = {
     let self = this;
     Browser.forceChromeReflow();
     self._editor.startEditing();
   },
 
   save: function BH_save() {
     this._editor.stopEditing(true);
   },
-  
+
   hide: function BH_hide() {
     BrowserUI.updateStar();
 
     // Note: the _editor will have already saved the data, if needed, by the time
     // this method is called, since this method is called via the "close" event.
     this._editor.parentNode.removeChild(this._editor);
     this._editor = null;
 
@@ -1012,24 +1012,24 @@ var BookmarkList = {
     this._panel.height = window.innerHeight;
     this._panel.hidden = false;
     BrowserUI.pushDialog(this);
 
     this._bookmarks = document.getElementById("bookmark-items");
     this._bookmarks.addEventListener("BookmarkRemove", this, true);
     this._bookmarks.manageUI = false;
     this._bookmarks.openFolder();
-    
+
     this._manageButton = document.getElementById("tool-bookmarks-manage");
     this._manageButton.disabled = (this._bookmarks.items.length == 0);
   },
 
   close: function() {
     BrowserUI.updateStar();
-    
+
     this._bookmarks.close();
 
     if (this._bookmarks.manageUI)
       this.toggleManage();
     this._bookmarks.blur();
     this._bookmarks.removeEventListener("BookmarkRemove", this, true);
 
     this._panel.hidden = true;
@@ -1099,17 +1099,17 @@ var FormHelper = {
 
     document.getElementById("form-helper-previous").disabled = this._getPrevious() ? false : true;
     document.getElementById("form-helper-next").disabled = this._getNext() ? false : true;
   },
 
   _updateSelect: function(aPreviousElement, aNewElement) {
     let previousIsSelect = this._isValidSelectElement(aPreviousElement);
     let currentIsSelect = this._isValidSelectElement(aNewElement);
-    
+
     if (currentIsSelect && !previousIsSelect) {
       this._selectContainer.height = window.innerHeight / 1.8;
 
       let rootNode = this._container;
       rootNode.insertBefore(this._selectContainer, rootNode.lastChild);
 
       SelectHelper.show(aNewElement);
     }
@@ -1129,23 +1129,23 @@ var FormHelper = {
     if (aElement.disabled)
       return false;
 
     if (aElement.getAttribute("role") == "button" && aElement.hasAttribute("tabindex"))
       return this._isElementVisible(aElement);
 
     if (this._isValidSelectElement(aElement) || aElement instanceof HTMLTextAreaElement)
       return this._isElementVisible(aElement);
-    
+
     if (aElement instanceof HTMLInputElement) {
       let ignoreInputElements = ["checkbox", "radio", "hidden", "reset", "button"];
       let isValidElement = (ignoreInputElements.indexOf(aElement.type) == -1);
       if (!isValidElement)
         return false;
- 
+
       return this._isElementVisible(aElement);
     }
 
     return false;
   },
 
   _isValidSelectElement: function(aElement) {
     return (aElement instanceof HTMLSelectElement) || (aElement instanceof Ci.nsIDOMXULMenuListElement);
@@ -1171,17 +1171,17 @@ var FormHelper = {
       for (let j =0; j < nodes.length; j++) {
         let node = nodes[j];
         if (this._isValidElement(node))
           elements.push(node);
       }
     }
 
     function orderByTabIndex(a, b) {
-      // for an explanation on tabbing navigation see 
+      // for an explanation on tabbing navigation see
       // http://www.w3.org/TR/html401/interact/forms.html#h-17.11.1
       // In resume tab index navigation order is 1, 2, 3, ..., 32767, 0
       if (a.tabIndex == 0 || b.tabIndex == 0)
         return b.tabIndex;
 
       return a.tabIndex > b.tabIndex;
     }
     return elements.sort(orderByTabIndex);
@@ -1220,17 +1220,17 @@ var FormHelper = {
 
   setCurrentElement: function(aElement) {
     if (!aElement)
       return;
 
     let previousElement = this._currentElement;
     this._currentElement = aElement;
     this._update(previousElement, aElement);
-    
+
     let containerHeight = this._container.getBoundingClientRect().height;
     this._helperSpacer.setAttribute("height", containerHeight);
 
     this.zoom(aElement);
     gFocusManager.setFocus(aElement, Ci.nsIFocusManager.FLAG_NOSCROLL);
   },
 
   goToPrevious: function formHelperGoToPrevious() {
@@ -1268,33 +1268,32 @@ var FormHelper = {
     this._updateSelect(this._currentElement, null);
 
     this._helperSpacer.hidden = true;
     // give the form spacer area back to the content
     let bv = Browser._browserView;
     Browser.forceChromeReflow();
     Browser.contentScrollboxScroller.scrollBy(0, 0);
     bv.onAfterVisibleMove();
-    
+
     bv.ignorePageScroll(false);
 
     window.removeEventListener("keypress", this, true);
     this._container.hidden = true;
     this._currentElement = null;
     this._open = false;
   },
 
   handleEvent: function formHelperHandleEvent(aEvent) {
     let isChromeFocused = gFocusManager.getFocusedElementForWindow(window, false, {}) == gFocusManager.focusedElement;
     if (isChromeFocused || aEvent.type != "keypress")
       return;
 
     let currentElement = this.getCurrentElement();
-    let keyCode = aEvent.keyCode || aEvent.charCode;
-    switch (keyCode) {
+    switch (aEvent.keyCode) {
       case aEvent.DOM_VK_DOWN:
         if (currentElement instanceof HTMLTextAreaElement) {
           let existSelection = currentElement.selectionEnd - currentElement.selectionStart;
           let isEnd = (currentElement.textLength == currentElement.selectionEnd);
           if (!isEnd || existSelection)
             return;
         }
 
@@ -1332,74 +1331,74 @@ var FormHelper = {
     if (!aElement)
       return false;
 
     // Some forms elements are valid in the sense that we want the Form
     // Assistant to stop on it, but we don't want it to display when
     // the user clicks on it
     let formExceptions = ["submit", "image", "file"];
     if (aElement instanceof HTMLInputElement && formExceptions.indexOf(aElement.type) != -1)
-      return false;    
+      return false;
 
     return this._isValidElement(aElement);
   }
 };
 
 function SelectWrapper(aControl) {
   this._control = aControl;
 }
 
 SelectWrapper.prototype = {
   get selectedIndex() { return this._control.selectedIndex; },
   get multiple() { return this._control.multiple; },
   get options() { return this._control.options; },
   get children() { return this._control.children; },
-  
+
   getText: function(aChild) { return aChild.text; },
   isOption: function(aChild) { return aChild instanceof HTMLOptionElement; },
   isGroup: function(aChild) { return aChild instanceof HTMLOptGroupElement; },
   select: function(aIndex, aSelected, aClearAll) {
     let selectElement = this._control.QueryInterface(Ci.nsISelectElement);
     selectElement.setOptionsSelectedByIndex(aIndex, aIndex, aSelected, aClearAll, false, true);
   },
   focus: function() { this._control.focus(); },
   fireOnChange: function() {
     let control = this._control;
     let evt = document.createEvent("Events");
     evt.initEvent("change", true, true, window, 0,
                   false, false,
                   false, false, null);
-    control.dispatchEvent(evt); 
+    control.dispatchEvent(evt);
   }
 };
 
 function MenulistWrapper(aControl) {
   this._control = aControl;
 }
 
 MenulistWrapper.prototype = {
   get selectedIndex() { return this._control.selectedIndex; },
   get multiple() { return false; },
   get options() { return this._control.menupopup.children; },
   get children() { return this._control.menupopup.children; },
-  
+
   getText: function(aChild) { return aChild.label; },
   isOption: function(aChild) { return aChild instanceof Ci.nsIDOMXULSelectControlItemElement; },
   isGroup: function(aChild) { return false },
   select: function(aIndex, aSelected, aClearAll) {
     this._control.selectedIndex = aIndex;
   },
   focus: function() { this._control.focus(); },
   fireOnChange: function() {
     let control = this._control;
     let evt = document.createEvent("XULCommandEvent");
     evt.initCommandEvent("command", true, true, window, 0,
                          false, false,
                          false, false, null);
-    control.dispatchEvent(evt); 
+    control.dispatchEvent(evt);
   }
 };
 
 var SelectHelper = {
   _panel: null,
   _list: null,
   _control: null,
   _selectedIndexes: [],
@@ -1524,31 +1523,31 @@ var SelectHelper = {
       for (let i = 0; i < currentSelectedIndexes.length; i++) {
         if (currentSelectedIndexes[i] != this._selectedIndexes[i]) {
           isIdentical = false;
           break;
         }
       }
     }
 
-    if (!isIdentical) 
+    if (!isIdentical)
       this._control.fireOnChange();
   },
 
   reset: function() {
     this._updateControl();
     let empty = this._list.cloneNode(false);
     this._list.parentNode.replaceChild(empty, this._list);
     this._list = empty;
   },
 
   close: function() {
     this._list.removeEventListener("click", this, false);
     this._panel.hidden = true;
-    
+
     this.reset();
   },
 
   handleEvent: function(aEvent) {
     switch (aEvent.type) {
       case "click":
         let item = aEvent.target;
         if (item && item.hasOwnProperty("optionIndex")) {