Bug 629661 - Find in Page does not reset after it is closed (followup) [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Wed, 09 Feb 2011 00:28:52 +0100
changeset 2749 9edc4db92535e35a9a9221cf6bc97aa615db2548
parent 2748 953124a5dc824a1f26c50f55c77ff1394d7e9ca4
child 2750 fc6cc4152c42403e02a6ae82cef9c74257196b16
push id2306
push uservnicolas@mozilla.com
push dateTue, 08 Feb 2011 23:30:33 +0000
reviewersmfinkle
bugs629661
Bug 629661 - Find in Page does not reset after it is closed (followup) [r=mfinkle]
chrome/content/bindings.xml
chrome/content/common-ui.js
--- a/chrome/content/bindings.xml
+++ b/chrome/content/bindings.xml
@@ -1650,23 +1650,51 @@
           let box = this.inputField.parentNode;
           box.showContextMenu(this, false);
         ]]>
       </handler>
     </handlers>
   </binding>
 
   <binding id="search-textbox" extends="chrome://global/content/bindings/textbox.xml#search-textbox">
+    <implementation>
+      <field name="_searchClear">
+        <![CDATA[
+          document.getAnonymousElementByAttribute(this, "class", "textbox-search-clear");
+        ]]>
+      </field>
+    </implementation>
+
     <handlers>
       <handler event="TapLong" phase="capturing">
         <![CDATA[
           let box = this.inputField.parentNode;
           box.showContextMenu(this, false);
         ]]>
       </handler>
+
+      <handler event="text" phase="bubbling"><![CDATA[
+        // Listen for composition update, some VKB that does suggestions does not
+        // update directly the content of the field but in this case we want to
+        // search as soon as something is entered in the field
+        let evt = document.createEvent("Event");
+        evt.initEvent("input", true, false);
+        this.dispatchEvent(evt);
+      ]]></handler>
+
+      <handler event="click" phase="bubbling"><![CDATA[
+        // bug 629661. To reset the autosuggestions mechanism of Android, the
+        // textfield need to reset the the IME
+        if (event.originalTarget == this._searchClear) {
+          setTimeout(function(self) {
+            self.inputField.readOnly = true;
+            self.inputField.readOnly = false;
+          }, 0, this);
+        }
+      ]]></handler>
     </handlers>
   </binding>
 
   <binding id="numberbox" extends="chrome://global/content/bindings/numberbox.xml#numberbox">
     <handlers>
       <handler event="TapLong" phase="capturing">
         <![CDATA[
           let box = this.inputField.parentNode;
--- a/chrome/content/common-ui.js
+++ b/chrome/content/common-ui.js
@@ -474,21 +474,16 @@ var FindHelperUI = {
 
     this._cmdPrevious = document.getElementById(this.commands.previous);
     this._cmdNext = document.getElementById(this.commands.next);
 
     // Listen for form assistant messages from content
     messageManager.addMessageListener("FindAssist:Show", this);
     messageManager.addMessageListener("FindAssist:Hide", this);
 
-    // Listen for composition update, some VKB that does suggestions does not
-    // update directly the content of the field but in this case we want to
-    // search as soon as something is entered in the field
-    this._textbox.addEventListener("text", this, false);
-
     // Listen for events where form assistant should be closed
     document.getElementById("tabs").addEventListener("TabSelect", this, true);
     Elements.browsers.addEventListener("URLChanged", this, true);
   },
 
   receiveMessage: function findHelperReceiveMessage(aMessage) {
     let json = aMessage.json;
     switch(aMessage.name) {
@@ -510,25 +505,16 @@ var FindHelperUI = {
       case "TabSelect":
         this.hide();
         break;
 
       case "URLChanged":
         if (aEvent.detail && aEvent.target == getBrowser())
           this.hide();
         break;
-
-      case "text":
-        if (!this._open)
-          return;
-
-        let evt = document.createEvent("Event");
-        evt.initEvent("input", true, false);
-        this._textbox.dispatchEvent(evt);
-        break;
     }
   },
 
   show: function findHelperShow() {
     this._container.show(this);
     this.search(this._textbox.value);
     this._textbox.select();
     this._textbox.focus();
@@ -559,18 +545,20 @@ var FindHelperUI = {
   goToNext: function findHelperGoToNext() {
     Browser.selectedBrowser.messageManager.sendAsyncMessage("FindAssist:Next", { });
   },
 
   search: function findHelperSearch(aValue) {
     this.updateCommands(aValue);
 
     // Don't bother searching if the value is empty
-    if (aValue == "")
+    if (aValue == "") {
+      this.status = null;
       return;
+    }
 
     Browser.selectedBrowser.messageManager.sendAsyncMessage("FindAssist:Find", { searchString: aValue });
   },
 
   updateCommands: function findHelperUpdateCommands(aValue) {
     let disabled = (this._status == Ci.nsITypeAheadFind.FIND_NOTFOUND) || (aValue == "");
     this._cmdPrevious.setAttribute("disabled", disabled);
     this._cmdNext.setAttribute("disabled", disabled);