Bug 785663 - Wait for keyboard to stop resizing before scrolling text input into view. r=djf a=blocking-basecamp+
authorChris Peterson <cpeterson@mozilla.com>
Fri, 09 Nov 2012 09:39:23 -0800
changeset 113036 3de447b1c39655778504203e2b3e8547b726d199
parent 113035 bcb591d32bd65872c8ed7fe46fdbc4a3d6467f89
child 113037 e12e84a82fa34d7da870b700c04ea7bc09a08c18
push id17901
push usercpeterson@mozilla.com
push dateTue, 13 Nov 2012 00:27:46 +0000
treeherdermozilla-inbound@3de447b1c396 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdjf, blocking-basecamp
bugs785663
milestone19.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 785663 - Wait for keyboard to stop resizing before scrolling text input into view. r=djf a=blocking-basecamp+
b2g/chrome/content/forms.js
--- a/b2g/chrome/content/forms.js
+++ b/b2g/chrome/content/forms.js
@@ -19,16 +19,17 @@ XPCOMUtils.defineLazyServiceGetter(Servi
                                    "nsIFocusManager");
 
 XPCOMUtils.defineLazyGetter(this, "domWindowUtils", function () {
   return content.QueryInterface(Ci.nsIInterfaceRequestor)
                 .getInterface(Ci.nsIDOMWindowUtils);
 });
 
 const FOCUS_CHANGE_DELAY = 20;
+const RESIZE_SCROLL_DELAY = 20;
 
 let HTMLInputElement = Ci.nsIDOMHTMLInputElement;
 let HTMLTextAreaElement = Ci.nsIDOMHTMLTextAreaElement;
 let HTMLSelectElement = Ci.nsIDOMHTMLSelectElement;
 let HTMLOptGroupElement = Ci.nsIDOMHTMLOptGroupElement;
 let HTMLOptionElement = Ci.nsIDOMHTMLOptionElement;
 
 let FormAssistant = {
@@ -45,17 +46,18 @@ let FormAssistant = {
 
   ignoredInputTypes: new Set([
     'button', 'file', 'checkbox', 'radio', 'reset', 'submit', 'image'
   ]),
 
   isKeyboardOpened: false,
   selectionStart: 0,
   selectionEnd: 0,
-
+  blurTimeout: null,
+  scrollIntoViewTimeout: null,
   _focusedElement: null,
 
   get focusedElement() {
     if (this._focusedElement && Cu.isDeadWrapper(this._focusedElement))
       this._focusedElement = null;
 
     return this._focusedElement;
   },
@@ -128,18 +130,30 @@ let FormAssistant = {
           this.tryShowIme(this.focusedElement);
         }
         break;
 
       case "resize":
         if (!this.isKeyboardOpened)
           return;
 
+        if (this.scrollIntoViewTimeout) {
+          content.clearTimeout(this.scrollIntoViewTimeout);
+          this.scrollIntoViewTimeout = null;
+        }
+
+        // We may receive multiple resize events in quick succession, so wait
+        // a bit before scrolling the input element into view.
         if (this.focusedElement) {
-          this.focusedElement.scrollIntoView(false);
+          this.scrollIntoViewTimeout = content.setTimeout(function () {
+            this.scrollIntoViewTimeout = null;
+            if (this.focusedElement) {
+              this.focusedElement.scrollIntoView(false);
+            }
+          }.bind(this), RESIZE_SCROLL_DELAY);
         }
         break;
     }
   },
 
   receiveMessage: function fa_receiveMessage(msg) {
     let target = this.focusedElement;
     if (!target) {