Bug 766066 - Part 2: Handle element focus and IME state separately. r=djf
authorChris Peterson <cpeterson@mozilla.com>
Wed, 19 Dec 2012 11:49:23 -0800
changeset 116585 8351e1baffcb654be7ad4d5fec92426b01e21951
parent 116584 69b6541efafcb30fc34979167903b9c7c84f6a90
child 116586 ae4a7e6f0e0b11bd4a3072366b3d200d3bef1520
push idunknown
push userunknown
push dateunknown
reviewersdjf
bugs766066
milestone20.0a1
Bug 766066 - Part 2: Handle element focus and IME state separately. r=djf
b2g/chrome/content/forms.js
--- a/b2g/chrome/content/forms.js
+++ b/b2g/chrome/content/forms.js
@@ -59,16 +59,19 @@ let FormAssistant = {
     return this._focusedElement;
   },
 
   set focusedElement(val) {
     this._focusedElement = val;
   },
 
   setFocusedElement: function fa_setFocusedElement(element) {
+    if (element instanceof HTMLOptionElement)
+      element = element.parentNode;
+
     if (element === this.focusedElement)
       return;
 
     if (this.focusedElement) {
       this.focusedElement.removeEventListener('mousedown', this);
       this.focusedElement.removeEventListener('mouseup', this);
       if (!element) {
         this.focusedElement.blur();
@@ -87,23 +90,26 @@ let FormAssistant = {
     let focusedElement = this.focusedElement;
     let target = evt.target;
 
     switch (evt.type) {
       case "focus":
         if (this.isTextInputElement(target) && this.isIMEDisabled())
           return;
 
-        if (target && this.isFocusableElement(target))
+        if (target && this.isFocusableElement(target)) {
+          this.setFocusedElement(target);
           this.showKeyboard(target);
+        }
         break;
 
       case "blur":
         if (this.focusedElement)
           this.hideKeyboard();
+        this.setFocusedElement(null);
         break;
 
       case 'mousedown':
         // We only listen for this event on the currently focused element.
         // When the mouse goes down, note the cursor/selection position
         this.selectionStart = this.focusedElement.selectionStart;
         this.selectionEnd = this.focusedElement.selectionEnd;
         break;
@@ -206,34 +212,29 @@ let FormAssistant = {
     let disabled = false;
     try {
       disabled = domWindowUtils.IMEStatus == domWindowUtils.IME_STATUS_DISABLED;
     } catch (e) {}
 
     return disabled;
   },
 
-  showKeyboard: function fa_showKeyboard(target) {
+  showKeyboard: function fa_showKeyboard() {
     if (this.isKeyboardOpened)
       return;
 
-    if (target instanceof HTMLOptionElement)
-      target = target.parentNode;
-
+    let target = this.focusedElement;
     let kbOpened = this.sendKeyboardState(target);
     if (this.isTextInputElement(target))
       this.isKeyboardOpened = kbOpened;
-
-    this.setFocusedElement(target);
   },
 
   hideKeyboard: function fa_hideKeyboard() {
     sendAsyncMessage("Forms:Input", { "type": "blur" });
     this.isKeyboardOpened = false;
-    this.setFocusedElement(null);
   },
 
   isFocusableElement: function fa_isFocusableElement(element) {
     if (element.contentEditable && element.contentEditable == "true") {
       return true;
     }
 
     if (element instanceof HTMLSelectElement ||