Bug 793108 - Add removeFocus() for MozKeyboard. r=sicking
authorShih-Chiang Chien <schien@mozilla.com>
Wed, 17 Oct 2012 19:18:14 +0800
changeset 110856 08fa42148eabf61eb052cd33e942c939d6ac8695
parent 110855 ab8ef7a28e2e31ef70820f7a0319e555b13fd0dd
child 110857 f0fd262da49b01ae16feceebb15dc352b5f9e7e7
push id23717
push userryanvm@gmail.com
push dateSat, 20 Oct 2012 16:43:11 +0000
treeherdermozilla-central@5d03feda2300 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs793108
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 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