Bug 994063 - Properly disable the quick-find bar only if an editable element is focused, or if the document is in design mode; r=mikedeboer
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 13 Oct 2015 15:41:19 -0400
changeset 268037 c1cf9458c72a5f1f6ba326054e48d31a458d4da7
parent 268036 69af7cab1bc04f8bcb5b815ba158790f4a3fb928
child 268038 c07248ffb45460b9afd12d75910146878165b2db
push id66685
push usereakhgari@mozilla.com
push dateFri, 16 Oct 2015 16:43:35 +0000
treeherdermozilla-inbound@c1cf9458c72a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs994063
milestone44.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 994063 - Properly disable the quick-find bar only if an editable element is focused, or if the document is in design mode; r=mikedeboer
toolkit/content/tests/browser/browser.ini
toolkit/content/tests/browser/browser_quickfind_editable.js
toolkit/modules/BrowserUtils.jsm
--- a/toolkit/content/tests/browser/browser.ini
+++ b/toolkit/content/tests/browser/browser.ini
@@ -42,8 +42,10 @@ support-files =
 [browser_mediaPlayback_mute.js]
 support-files =
   file_mediaPlayback2.html
   file_mediaPlaybackFrame2.html
 skip-if = buildapp == 'mulet' || buildapp == 'b2g'
 [browser_mute.js]
 [browser_mute2.js]
 skip-if = buildapp == 'mulet' || buildapp == 'b2g'
+[browser_quickfind_editable.js]
+skip-if = e10s # synthesizeKey() doesn't work in e10s mode
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/browser/browser_quickfind_editable.js
@@ -0,0 +1,47 @@
+const PAGE = "data:text/html,<div contenteditable>foo</div><input><textarea></textarea>";
+const DESIGNMODE_PAGE = "data:text/html,<body onload='document.designMode=\"on\";'>";
+const HOTKEYS = ["/", "'"];
+
+function* test_hotkeys(browser, expected) {
+  let findbar = gBrowser.getFindBar();
+  for (let key of HOTKEYS) {
+    is(findbar.hidden, true, "findbar is hidden");
+    EventUtils.synthesizeKey(key, {}, browser.contentWindow);
+    is(findbar.hidden, expected, "findbar should" + (expected ? "" : " not") + " be hidden");
+    if (!expected) {
+      yield closeFindbarAndWait(findbar);
+    }
+  }
+}
+
+function* focus_element(browser, query) {
+  yield ContentTask.spawn(browser, query, function* focus(query) {
+    let element = content.document.querySelector(query);
+    element.focus();
+  });
+}
+
+add_task(function* test_hotkey_on_editable_element() {
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: PAGE
+  }, function* do_tests(browser) {
+    yield test_hotkeys(browser, false);
+    const ELEMENTS = ["div", "input", "textarea"];
+    for (let elem of ELEMENTS) {
+      yield focus_element(browser, elem);
+      yield test_hotkeys(browser, true);
+      yield focus_element(browser, ":root");
+      yield test_hotkeys(browser, false);
+    }
+  });
+});
+
+add_task(function* test_hotkey_on_designMode_document() {
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: DESIGNMODE_PAGE
+  }, function* do_tests(browser) {
+    yield test_hotkeys(browser, true);
+  });
+});
--- a/toolkit/modules/BrowserUtils.jsm
+++ b/toolkit/modules/BrowserUtils.jsm
@@ -255,17 +255,17 @@ this.BrowserUtils = {
    *        The window that is focused
    *
    */
   shouldFastFind: function(elt, win) {
     if (elt) {
       if (elt instanceof win.HTMLInputElement && elt.mozIsTextField(false))
         return false;
 
-      if (elt.isContentEditable)
+      if (elt.isContentEditable || win.document.designMode == "on")
         return false;
 
       if (elt instanceof win.HTMLTextAreaElement ||
           elt instanceof win.HTMLSelectElement ||
           elt instanceof win.HTMLObjectElement ||
           elt instanceof win.HTMLEmbedElement)
         return false;
     }
@@ -279,30 +279,16 @@ this.BrowserUtils = {
       return false;
 
     // disable FAYT in documents that ask for it to be disabled.
     if ((loc.protocol == "about:" || loc.protocol == "chrome:") &&
         (win && win.document.documentElement &&
          win.document.documentElement.getAttribute("disablefastfind") == "true"))
       return false;
 
-    if (win) {
-      try {
-        let editingSession = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-          .getInterface(Components.interfaces.nsIWebNavigation)
-          .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-          .getInterface(Components.interfaces.nsIEditingSession);
-        if (editingSession.windowIsEditable(win))
-          return false;
-      }
-      catch (e) {
-        Cu.reportError(e);
-        // If someone built with composer disabled, we can't get an editing session.
-      }
-    }
     return true;
   },
 
   getSelectionDetails: function(topWindow, aCharLen) {
     // selections of more than 150 characters aren't useful
     const kMaxSelectionLen = 150;
     const charLen = Math.min(aCharLen || kMaxSelectionLen, kMaxSelectionLen);