Bug 609987 - Clicking inside the text area box in portrait when the hardware keyboard is not in use may cause the text area box to be panned out of view [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Tue, 23 Nov 2010 11:52:17 +0100
changeset 67062 def0ac079806a354fd25cb7614b11c6d3412c60d
parent 67061 2f40aecdd38f7c301744cadacb10d017d8918679
child 67063 adaaa2c20d1b3e9e0b4ee22bce4d00af9abd1a78
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
bugs609987
Bug 609987 - Clicking inside the text area box in portrait when the hardware keyboard is not in use may cause the text area box to be panned out of view [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
@@ -1806,20 +1806,16 @@ var FindHelperUI = {
 var FormHelperUI = {
   type: "form",
   commands: {
     next: "cmd_formNext",
     previous: "cmd_formPrevious",
     close: "cmd_formClose"
   },
 
-  //for resize/rotate case
-  _currentCaretRect: null,
-  _currentElementRect: null,
-
   get enabled() {
     return Services.prefs.getBoolPref("formhelper.enabled");
   },
 
   _visibleScreenArea: null,
   get visibleScreenArea() {
     let visibleRect = Rect.fromRect(Browser.selectedBrowser.getBoundingClientRect());
     let visibleScreenArea = visibleRect;
@@ -1839,22 +1835,22 @@ var FormHelperUI = {
     this._cmdPrevious = document.getElementById(this.commands.previous);
     this._cmdNext = document.getElementById(this.commands.next);
     this._visibleScreenArea = new Rect(0, 0, 0, 0);
 
     // Listen for form assistant messages from content
     messageManager.addMessageListener("FormAssist:Show", this);
     messageManager.addMessageListener("FormAssist:Hide", this);
     messageManager.addMessageListener("FormAssist:Update", this);
-    messageManager.addMessageListener("FormAssist:Resize", this);
     messageManager.addMessageListener("FormAssist:AutoComplete", this);
 
-    // Listen for events where form assistant should be closed
+    // Listen for events where form assistant should be closed or updated
     document.getElementById("tabs").addEventListener("TabSelect", this, true);
     Elements.browsers.addEventListener("URLChanged", this, true);
+    window.addEventListener("resize", this, true);
 
     // Listen for modal dialog to show/hide the UI
     messageManager.addMessageListener("DOMWillOpenModalDialog", this);
     messageManager.addMessageListener("DOMModalDialogClosed", this);
 
     Services.obs.addObserver(this, "softkb-change", false);
   },
 
@@ -1899,18 +1895,29 @@ var FormHelperUI = {
 
     this._updateContainerForSelect(this._currentElement, null);
     this._open = false;
 
     Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:Closed", { });
   },
 
   handleEvent: function formHelperHandleEvent(aEvent) {
-    if (aEvent.type == "TabSelect" || aEvent.type == "URLChanged")
-      this.hide();
+    switch (aEvent.type) {
+      case "TabSelect":
+      case "URLChanged":
+        this.hide();
+        break;
+
+      case "resize":
+        setTimeout(function(self) {
+          SelectHelperUI.resize();
+          self._container.contentHasChanged();
+        }, 0, this);
+        break;
+    }
   },
 
   receiveMessage: function formHelperReceiveMessage(aMessage) {
     let json = aMessage.json;
     switch (aMessage.name) {
       case "FormAssist:Show":
         // if the user has manually disabled the Form Assistant UI we still
         // want to show a UI for <select /> element but not managed by
@@ -1923,22 +1930,16 @@ var FormHelperUI = {
         this.hide();
         break;
 
       case "FormAssist:AutoComplete":
         this._updateAutocompleteFor(json.current);
         this._container.contentHasChanged();
         break;
 
-      case "FormAssist:Resize":
-        SelectHelperUI.resize();
-        this._zoom(this._currentElementRect, this._currentCaretRect);
-        this._container.contentHasChanged();
-        break;
-
        case "FormAssist:Update":
         Browser.hideSidebars();
         Browser.hideTitlebar();
         this._zoom(null, Rect.fromRect(json.caretRect));
         break;
 
       case "DOMWillOpenModalDialog":
         if (this._open && aMessage.target == Browser.selectedBrowser) {
@@ -1951,16 +1952,19 @@ var FormHelperUI = {
         if (this._open && aMessage.target == Browser.selectedBrowser) {
           this._container.style.display = "-moz-box";
           this._container._spacer.hidden = false;
         }
         break;
     }
   },
 
+  // for VKB that does not resize the window
+  _currentCaretRect: null,
+  _currentElementRect: null,
   observe: function formHelperObserve(aSubject, aTopic, aData) {
     let rect = Rect.fromRect(JSON.parse(aData));
     rect.height = rect.bottom - rect.top;
     rect.width  = rect.right - rect.left;
 
     this._visibleScreenArea = rect;
     BrowserUI.sizeControls(rect.width, rect.height);
     if (this.open)
--- a/mobile/chrome/content/forms.js
+++ b/mobile/chrome/content/forms.js
@@ -60,19 +60,19 @@ let XULMenuListElement = Ci.nsIDOMXULMen
  */
 function FormAssistant() {
   addMessageListener("FormAssist:Closed", this);
   addMessageListener("FormAssist:Previous", this);
   addMessageListener("FormAssist:Next", this);
   addMessageListener("FormAssist:ChoiceSelect", this);
   addMessageListener("FormAssist:ChoiceChange", this);
   addMessageListener("FormAssist:AutoComplete", this);
+  addMessageListener("Content:SetWindowSize", this);
 
   addEventListener("keyup", this, false);
-  addEventListener("resize", this, false);
   addEventListener("focus", this, true);
 
   this._enabled = Services.prefs.getBoolPref("formhelper.enabled");
 };
 
 FormAssistant.prototype = {
   _selectWrapper: null,
   _currentIndex: -1,
@@ -168,16 +168,22 @@ FormAssistant.prototype = {
       case "FormAssist:Previous":
         this.currentIndex--;
         break;
 
       case "FormAssist:Next":
         this.currentIndex++;
         break;
 
+      case "Content:SetWindowSize":
+        // 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);
         break;
       }
 
       case "FormAssist:ChoiceChange": {
         // ChoiceChange happened once we have move to an other element so we 
@@ -217,19 +223,16 @@ FormAssistant.prototype = {
   },
 
   focusSync: false,
   handleEvent: function formHelperHandleEvent(aEvent) {
     if (!this._enabled || (!this.currentElement && (aEvent.type != "focus" || !this.focusSync)))
       return;
 
     switch (aEvent.type) {
-      case "resize":
-        sendAsyncMessage("FormAssist:Resize");
-        break;
       case "focus":
         let focusedElement = gFocusManager.getFocusedElementForWindow(content, true, {});
 
         // If a body element is editable and the body is the child of an
         // iframe we can assume this is an advanced HTML editor, so let's 
         // redirect the form helper selection to the iframe element
         if (focusedElement) {
           let editableElement = this._getTopLevelEditable(focusedElement);
@@ -255,16 +258,17 @@ FormAssistant.prototype = {
           }
           return;
         }
 
         let focusedIndex = this._getIndexForElement(focusedElement);
         if (focusedIndex != -1 && this.currentIndex != focusedIndex)
           this.currentIndex = focusedIndex;
         break;
+
       case "keyup":
         let currentElement = this.currentElement;
         switch (aEvent.keyCode) {
           case aEvent.DOM_VK_DOWN:
             if (currentElement instanceof HTMLInputElement && !this._isAutocomplete(currentElement)) {
               if (this._hasKeyListener(currentElement))
                 return;
             }