Bug 717147 part.3 Findbar shouldn't do incremental search during composition r=gavin
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 13 Jan 2012 15:19:22 +0900
changeset 84402 78e58e679fca654cfc28fa12127803b824e62487
parent 84401 1a71337e5cf7b1443455ab68a9da65c747a1acd5
child 84403 2877e53c2d70d2c0e3ae57e95e9a4a1eaebb72d4
push id21848
push usermak77@bonardo.net
push dateSat, 14 Jan 2012 09:02:20 +0000
treeherdermozilla-central@27a7f197c6fc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs717147
milestone12.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 717147 part.3 Findbar shouldn't do incremental search during composition r=gavin
toolkit/content/tests/chrome/findbar_window.xul
toolkit/content/widgets/findbar.xml
--- a/toolkit/content/tests/chrome/findbar_window.xul
+++ b/toolkit/content/tests/chrome/findbar_window.xul
@@ -113,16 +113,19 @@
       // setTimeout to the test runs after painting suppression ends
       setTimeout(onPageShow, 0);
     }
 
     function onPageShow() {
       testNormalFind();
       gFindBar.close();
       ok(gFindBar.hidden, "Failed to close findbar after testNormalFind");
+      testNormalFindWithComposition();
+      gFindBar.close();
+      ok(gFindBar.hidden, "findbar should be hidden after testNormalFindWithComposition");
       testAutoCaseSensitivityUI();
       testQuickFindText();
       gFindBar.close();
       ok(gFindBar.hidden, "Failed to close findbar after testQuickFindText");
       testFindbarSelection();
       testDrop();
       testQuickFindLink();
       testStatusText();
@@ -221,16 +224,70 @@
         matchCaseCheckbox.click();
         enterStringIntoFindField("t");
         ok(gBrowser.contentWindow.getSelection() != searchStr,
            "testNormalFind: Case-sensitivy is broken '" + searchStr + "'");
         matchCaseCheckbox.click();
       }
     }
 
+    function testNormalFindWithComposition() {
+      document.getElementById("cmd_find").doCommand();
+
+      ok(!gFindBar.hidden, "testNormalFindWithComposition: findbar should be open");
+      ok(document.commandDispatcher.focusedElement == gFindBar._findField.inputField,
+         "testNormalFindWithComposition: find field should be focused");
+
+      var matchCaseCheckbox = gFindBar.getElement("find-case-sensitive");
+      var clicked = false;
+      if (!matchCaseCheckbox.hidden & matchCaseCheckbox.checked) {
+        matchCaseCheckbox.click();
+        clicked = true;
+      }
+
+      gFindBar._findField.inputField.focus();
+
+      var searchStr = "text";
+
+      synthesizeComposition({ type: "compositionstart" });
+      synthesizeComposition({ type: "compositionupdate", data: searchStr });
+      synthesizeText(
+        { "composition":
+          { "string": searchStr,
+            "clauses":
+            [
+              { "length": searchStr.length, "attr": COMPOSITION_ATTR_RAWINPUT }
+            ]
+          },
+          "caret": { "start": searchStr.length, "length": 0 }
+        });
+
+      ok(gBrowser.contentWindow.getSelection().toString().toLowerCase() != searchStr,
+         "testNormalFindWithComposition: text shouldn't be found during composition");
+
+      synthesizeText(
+        { "composition":
+          { "string": searchStr,
+            "clauses":
+            [
+              { "length": 0, "attr": 0 }
+            ]
+          },
+          "caret": { "start": searchStr.length, "length": 0 }
+        });
+      synthesizeComposition({ type: "compositionend", data: searchStr });
+
+      ok(gBrowser.contentWindow.getSelection().toString().toLowerCase() == searchStr,
+         "testNormalFindWithComposition: text should be found after committing composition");
+
+      if (clicked) {
+        matchCaseCheckbox.click();
+      }
+    }
+
     function testAutoCaseSensitivityUI() {
       var matchCaseCheckbox = gFindBar.getElement("find-case-sensitive");
       var matchCaseLabel = gFindBar.getElement("match-case-status");
       document.getElementById("cmd_find").doCommand();
       ok(!matchCaseCheckbox.hidden, "match case box is hidden in manual mode");
       ok(matchCaseLabel.hidden, "match case label is visible in manual mode");
 
       var prefsvc = Cc["@mozilla.org/preferences-service;1"].
--- a/toolkit/content/widgets/findbar.xml
+++ b/toolkit/content/widgets/findbar.xml
@@ -108,16 +108,24 @@
               document.commandDispatcher.advanceFocus();
           }
         ]]></body>
       </method>
     </implementation>
 
     <handlers>
       <handler event="input"><![CDATA[
+        // We should do nothing during composition.  E.g., composing string
+        // before converting may matches a forward word of expected word.
+        // After that, even if user converts the composition string to the
+        // expected word, it may find second or later searching word in the
+        // document.
+        if (this.findbar._isIMEComposing) {
+          return;
+        }
         this.findbar._find(this.value);
       ]]></handler>
 
       <handler event="keypress"><![CDATA[
         var win = this.findbar._currentWindow ||
                   this.findbar.browser.contentWindow;
 
         var shouldHandle = !event.altKey && !event.ctrlKey &&