Bug 766066 - Part 3: Open keyboard when user taps input element, not when panning. r=djf
authorChris Peterson <cpeterson@mozilla.com>
Wed, 19 Dec 2012 11:49:25 -0800
changeset 116586 ae4a7e6f0e0b11bd4a3072366b3d200d3bef1520
parent 116585 8351e1baffcb654be7ad4d5fec92426b01e21951
child 116587 73f36736a1aeb82d61be4b66088ddfe0f5a99796
push idunknown
push userunknown
push dateunknown
reviewersdjf
bugs766066
milestone20.0a1
Bug 766066 - Part 3: Open keyboard when user taps input element, not when panning. r=djf
b2g/chrome/content/forms.js
--- a/b2g/chrome/content/forms.js
+++ b/b2g/chrome/content/forms.js
@@ -66,43 +66,46 @@ let FormAssistant = {
   setFocusedElement: function fa_setFocusedElement(element) {
     if (element instanceof HTMLOptionElement)
       element = element.parentNode;
 
     if (element === this.focusedElement)
       return;
 
     if (this.focusedElement) {
+      this.focusedElement.removeEventListener('click', this);
       this.focusedElement.removeEventListener('mousedown', this);
       this.focusedElement.removeEventListener('mouseup', this);
       if (!element) {
         this.focusedElement.blur();
       }
     }
 
     if (element) {
+      element.addEventListener('click', this);
       element.addEventListener('mousedown', this);
       element.addEventListener('mouseup', this);
     }
 
     this.focusedElement = element;
   },
 
   handleEvent: function fa_handleEvent(evt) {
     let focusedElement = this.focusedElement;
     let target = evt.target;
 
     switch (evt.type) {
       case "focus":
         if (this.isTextInputElement(target) && this.isIMEDisabled())
           return;
 
+        // We got input focus, but don't open the virtual keyboard unless we
+        // get a 'click' event, i.e. the user is tapping the input element.
         if (target && this.isFocusableElement(target)) {
           this.setFocusedElement(target);
-          this.showKeyboard(target);
         }
         break;
 
       case "blur":
         if (this.focusedElement)
           this.hideKeyboard();
         this.setFocusedElement(null);
         break;
@@ -120,16 +123,24 @@ let FormAssistant = {
         // selection changed) since the mouse went down. If it has, we
         // need to tell the keyboard about it
         if (this.focusedElement.selectionStart !== this.selectionStart ||
             this.focusedElement.selectionEnd !== this.selectionEnd) {
           this.sendKeyboardState(this.focusedElement);
         }
         break;
 
+      case 'click':
+        // We only listen for click events on the currently focused element.
+        // Gecko fires a click event if the user "taps" an input element
+        // without dragging. This is how we differentiate tap gestures to set
+        // input focus (and open the keyboard) from simply panning the page.
+        this.showKeyboard();
+        break;
+
       case "resize":
         if (!this.isKeyboardOpened)
           return;
 
         if (this.scrollIntoViewTimeout) {
           content.clearTimeout(this.scrollIntoViewTimeout);
           this.scrollIntoViewTimeout = null;
         }