Bug 615171 - Form assistant remains open even after loading another webpage - followup [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Thu, 02 Dec 2010 18:53:52 +0100
changeset 67076 23ba5d912ca404a8ac70d439c5d0dcccf2cba3a8
parent 67075 a4915efe430b088ee67c872427d6047721efe63a
child 67077 5b34c1f8e4f21807554cd85d5735d2b5ffb67c7b
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)
reviewersmfinkle
bugs615171
Bug 615171 - Form assistant remains open even after loading another webpage - followup [r=mfinkle]
mobile/chrome/content/browser-ui.js
mobile/chrome/content/forms.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -1816,20 +1816,20 @@ var FormHelperUI = {
     next: "cmd_formNext",
     previous: "cmd_formPrevious",
     close: "cmd_formClose"
   },
 
   get enabled() {
     return Services.prefs.getBoolPref("formhelper.enabled");
   },
-
+  
   _visibleScreenArea: null,
   get visibleScreenArea() {
-    let visibleRect = Rect.fromRect(Browser.selectedBrowser.getBoundingClientRect());
+    let visibleRect = Rect.fromRect(this._currentBrowser.getBoundingClientRect());
     let visibleScreenArea = visibleRect;
     if (this._visibleScreenArea) {
       visibleScreenArea = this._visibleScreenArea.clone();
       visibleScreenArea.x = visibleRect.x;
       visibleScreenArea.y = visibleRect.y;
       visibleScreenArea.width = visibleRect.width;
       visibleScreenArea.height = visibleRect.height - this._container.getBoundingClientRect().height;
     }
@@ -1860,17 +1860,20 @@ var FormHelperUI = {
 
     Services.obs.addObserver(this, "softkb-change", false);
   },
 
   uninit: function formHelperUninit() {
     Services.obs.removeObserver(this, "softkb-change");
   },
 
+  _currentBrowser: null,
   show: function formHelperShow(aElement, aHasPrevious, aHasNext) {
+    this._currentBrowser = Browser.selectedBrowser;
+
     // Update the next/previous commands
     this._cmdPrevious.setAttribute("disabled", !aHasPrevious);
     this._cmdNext.setAttribute("disabled", !aHasNext);
     this._open = true;
 
     let lastElement = this._currentElement || null;
     this._currentElement = {
       id: aElement.id,
@@ -1881,34 +1884,34 @@ var FormHelperUI = {
       isAutocomplete: aElement.isAutocomplete,
       list: aElement.choices
     }
 
     this._updateContainer(lastElement, this._currentElement);
     this._zoom(Rect.fromRect(aElement.rect), Rect.fromRect(aElement.caretRect));
 
     // Prevent the view to scroll automatically while typing
-    Browser.selectedBrowser.scrollSync = false;
+    this._currentBrowser.scrollSync = false;
   },
 
   hide: function formHelperHide() {
     if (!this._open)
       return;
 
     // Restore the scroll synchonisation
-    Browser.selectedBrowser.scrollSync = true;
+    this._currentBrowser.scrollSync = true;
 
     // reset current Element and Caret Rect
     this._currentElementRect = null;
     this._currentCaretRect = null;
 
     this._updateContainerForSelect(this._currentElement, null);
+
+    this._currentBrowser.messageManager.sendAsyncMessage("FormAssist:Closed", { });
     this._open = false;
-
-    Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:Closed", { });
   },
 
   handleEvent: function formHelperHandleEvent(aEvent) {
     if (!this._open)
       return;
 
     switch (aEvent.type) {
       case "TabSelect":
@@ -1977,27 +1980,27 @@ var FormHelperUI = {
 
     this._visibleScreenArea = rect;
     BrowserUI.sizeControls(rect.width, rect.height);
     if (this.open)
       this._zoom(this._currentElementRect, this._currentCaretRect);
   },
 
   goToPrevious: function formHelperGoToPrevious() {
-    Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:Previous", { });
+    this._currentBrowser.messageManager.sendAsyncMessage("FormAssist:Previous", { });
   },
 
   goToNext: function formHelperGoToNext() {
-    Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:Next", { });
+    this._currentBrowser.messageManager.sendAsyncMessage("FormAssist:Next", { });
   },
 
   doAutoComplete: function formHelperDoAutoComplete(aElement) {
     // Suggestions are only in <label>s. Ignore the rest.
     if (aElement instanceof Ci.nsIDOMXULLabelElement)
-      Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:AutoComplete", { value: aElement.value });
+      this._currentBrowser.messageManager.sendAsyncMessage("FormAssist:AutoComplete", { value: aElement.value });
   },
 
   get _open() {
     return (this._container.getAttribute("type") == this.type);
   },
 
   set _open(aVal) {
     if (aVal == this._open)
--- a/mobile/chrome/content/forms.js
+++ b/mobile/chrome/content/forms.js
@@ -169,22 +169,16 @@ FormAssistant.prototype = {
         this.currentIndex--;
         break;
 
       case "FormAssist:Next":
         this.currentIndex++;
         break;
 
       case "Content:SetWindowSize":
-        // We don't want to react to size change if the form assistant is not
-        // active, and since this message is the only one not sent by the Form
-        // Helper UI, it needs a check to ensure the Assistant is actually used
-        if (this._open)
-          return;
-
         // If the CSS viewport change just show the current element to the new
         // position
         sendAsyncMessage("FormAssist:Show", this._getJSON());
         break;
 
       case "FormAssist:ChoiceSelect": {
         this._selectWrapper = getWrapperForElement(currentElement);
         this._selectWrapper.select(json.index, json.selected, json.clearAll);
@@ -220,16 +214,17 @@ FormAssistant.prototype = {
         event.initEvent("DOMAutoComplete", true, true);
         currentElement.dispatchEvent(event);
         break;
       }
 
       case "FormAssist:Closed":
         currentElement.blur();
         this._currentIndex = null;
+        this._open = false;
         break;
     }
   },
 
   _els: Cc["@mozilla.org/eventlistenerservice;1"].getService(Ci.nsIEventListenerService),
   _hasKeyListener: function _hasKeyListener(aElement) {
     let els = this._els;
     let listeners = els.getListenerInfoFor(aElement, {});