Bug 793108 - Add removeFocus() for MozKeyboard. r=sicking
authorShih-Chiang Chien <schien@mozilla.com>
Wed, 17 Oct 2012 19:18:14 +0800
changeset 110988 08fa42148eabf61eb052cd33e942c939d6ac8695
parent 110987 ab8ef7a28e2e31ef70820f7a0319e555b13fd0dd
child 110989 f0fd262da49b01ae16feceebb15dc352b5f9e7e7
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewerssicking
bugs793108
milestone19.0a1
Bug 793108 - Add removeFocus() for MozKeyboard. r=sicking
b2g/chrome/content/forms.js
b2g/components/MozKeyboard.js
b2g/components/b2g.idl
--- a/b2g/chrome/content/forms.js
+++ b/b2g/chrome/content/forms.js
@@ -27,32 +27,36 @@ let HTMLOptionElement = Ci.nsIDOMHTMLOpt
 let FormAssistant = {
   init: function fa_init() {
     addEventListener("focus", this, true, false);
     addEventListener("blur", this, true, false);
     addEventListener("keypress", this, true, false);
     addEventListener("resize", this, true, false);
     addMessageListener("Forms:Select:Choice", this);
     addMessageListener("Forms:Input:Value", this);
+    addMessageListener("Forms:Select:Blur", this);
     Services.obs.addObserver(this, "ime-enabled-state-changed", false);
     Services.obs.addObserver(this, "xpcom-shutdown", false);
   },
 
   isKeyboardOpened: false,
   focusedElement : null,
   selectionStart: 0,
   selectionEnd: 0,
 
   setFocusedElement: function fa_setFocusedElement(element) {
     if (element === this.focusedElement)
       return;
 
     if (this.focusedElement) {
       this.focusedElement.removeEventListener('mousedown', this);
       this.focusedElement.removeEventListener('mouseup', this);
+      if (!element) {
+        this.focusedElement.blur();
+      }
     }
 
     if (element) {
       element.addEventListener('mousedown', this);
       element.addEventListener('mouseup', this);
     }
 
     this.focusedElement = element;
@@ -181,16 +185,21 @@ let FormAssistant = {
 
         // only fire onchange event if any selected option is changed
         if (valueChanged) {
           let event = content.document.createEvent('HTMLEvents');
           event.initEvent('change', true, true);
           target.dispatchEvent(event);
         }
         break;
+
+      case "Forms:Select:Blur": {
+        this.setFocusedElement(null);
+        break;
+      }
     }
   },
 
   observe: function fa_observe(subject, topic, data) {
     switch (topic) {
       case "ime-enabled-state-changed":
         let isOpen = this.isKeyboardOpened;
         let shouldOpen = parseInt(data);
--- a/b2g/components/MozKeyboard.js
+++ b/b2g/components/MozKeyboard.js
@@ -75,16 +75,20 @@ MozKeyboard.prototype = {
   },
 
   setSelectedOptions: function mozKeyboardSetSelectedOptions(indexes) {
     this._messageManager.sendAsyncMessage("Forms:Select:Choice", {
       "indexes": indexes || []
     });
   },
 
+  removeFocus: function mozKeyboardRemoveFocus() {
+    this._messageManager.sendAsyncMessage("Forms:Select:Blur", {});
+  },
+
   set onfocuschange(val) {
     this._focusHandler = val;
   },
 
   get onfocuschange() {
     return this._focusHandler;
   },
 
--- a/b2g/components/b2g.idl
+++ b/b2g/components/b2g.idl
@@ -32,16 +32,18 @@ interface nsIB2GKeyboard : nsISupports
 
   // Set the value on the currently focused element. This has to be used
   // for special situations where the value had to be chosen amongst a
   // list (type=month) or a widget (type=date, time, etc.).
   // If the value passed in parameter isn't valid (in the term of HTML5
   // Forms Validation), the value will simply be ignored by the element. 
   void setValue(in jsval value);
 
+  void removeFocus();
+
   attribute nsIDOMEventListener onfocuschange;
 };
 
 [scriptable, uuid(acb93ff8-aa6d-4bc8-bedd-2a6a3b802a74)]
 interface nsIRecoveryService : nsISupports
 {
   /**
    * Possible values of fotaStatus.result. These should stay in sync with