Bug 1365105 - Clear all find highlights, in the PDF Viewer, when the findbar is closed. r=bdahl,paolo
authorJonas Jenwald <jonas.jenwald@gmail.com>
Thu, 25 Oct 2018 15:52:02 +0200
changeset 491282 e55f02b20a9ced3c912ab4642c32a77e4337c11b
parent 491281 e8b53fa4ae7e8047eabaab6b2da701c209a74cba
child 491283 16d26c24fa86c7f5c4e6f2634ace2b06181fd294
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersbdahl, paolo
bugs1365105
milestone65.0a1
Bug 1365105 - Clear all find highlights, in the PDF Viewer, when the findbar is closed. r=bdahl,paolo In order to support this, a new "findbarclose" event (mirroring the pre-existing "findbaropen" one) was added to the `MozFindbar.close` method in the findbar.js file.
browser/base/content/test/general/browser_findbarClose.js
browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm
toolkit/content/widgets/findbar.js
--- a/browser/base/content/test/general/browser_findbarClose.js
+++ b/browser/base/content/test/general/browser_findbarClose.js
@@ -22,12 +22,15 @@ add_task(async function findbar_test() {
     let awaitLoad = ContentTaskUtils.waitForEvent(iframe, "load", false);
     iframe.src = "https://example.org/";
     await awaitLoad;
   });
 
   ok(!gFindBar.hidden, "the Find bar isn't hidden after the location of a " +
      "subdocument changes");
 
+  let findBarClosePromise = promiseWaitForEvent(gBrowser, "findbarclose");
   gFindBar.close();
+  await findBarClosePromise;
+
   gBrowser.removeTab(newTab);
 });
 
--- a/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm
+++ b/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm
@@ -187,50 +187,56 @@ var PdfjsChromeUtils = {
     };
     if (result.total > result.limit) {
       result.total = -1;
     }
     return result;
   },
 
   handleEvent(aEvent) {
+    const type = aEvent.type;
     // Handle the tab find initialized event specially:
-    if (aEvent.type == "TabFindInitialized") {
+    if (type == "TabFindInitialized") {
       let browser = aEvent.target.linkedBrowser;
       this._hookupEventListeners(browser);
-      aEvent.target.removeEventListener(aEvent.type, this);
+      aEvent.target.removeEventListener(type, this);
       return;
     }
 
     // To avoid forwarding the message as a CPOW, create a structured cloneable
     // version of the event for both performance, and ease of usage, reasons.
-    let type = aEvent.type;
-    let detail = {
-      query: aEvent.detail.query,
-      caseSensitive: aEvent.detail.caseSensitive,
-      entireWord: aEvent.detail.entireWord,
-      highlightAll: aEvent.detail.highlightAll,
-      findPrevious: aEvent.detail.findPrevious,
-    };
+    let detail = null;
+    if (type !== "findbarclose") {
+      detail = {
+        query: aEvent.detail.query,
+        caseSensitive: aEvent.detail.caseSensitive,
+        entireWord: aEvent.detail.entireWord,
+        highlightAll: aEvent.detail.highlightAll,
+        findPrevious: aEvent.detail.findPrevious,
+      };
+    }
 
     let browser = aEvent.currentTarget.browser;
     if (!this._browsers.has(browser)) {
       throw new Error("FindEventManager was not bound " +
                       "for the current browser.");
     }
     // Only forward the events if the current browser is a registered browser.
     let mm = browser.messageManager;
     mm.sendAsyncMessage("PDFJS:Child:handleEvent", { type, detail });
     aEvent.preventDefault();
   },
 
-  _types: ["find",
-           "findagain",
-           "findhighlightallchange",
-           "findcasesensitivitychange"],
+  _types: [
+    "find",
+    "findagain",
+    "findhighlightallchange",
+    "findcasesensitivitychange",
+    "findbarclose",
+  ],
 
   _addEventListener(aMsg) {
     let browser = aMsg.target;
     if (this._browsers.has(browser)) {
       throw new Error("FindEventManager was bound 2nd time " +
                       "without unbinding it first.");
     }
 
--- a/toolkit/content/widgets/findbar.js
+++ b/toolkit/content/widgets/findbar.js
@@ -663,16 +663,20 @@ class MozFindbar extends XULElement {
   close(aNoAnim) {
     if (this.hidden)
       return;
 
     if (aNoAnim)
       this.setAttribute("noanim", true);
     this.hidden = true;
 
+    let event = document.createEvent("Events");
+    event.initEvent("findbarclose", true, false);
+    this.dispatchEvent(event);
+
     // 'focusContent()' iterates over all listeners in the chrome
     // process, so we need to call it from here.
     this.browser.finder.focusContent();
     this.browser.finder.onFindbarClose();
 
     this._cancelTimers();
     this._updateBrowserWithState();