Bug 1374230 - Wrong tooltip position after resizing browser window r=mconley
authorRicky Chien <ricky060709@gmail.com>
Mon, 19 Jun 2017 17:38:57 +0800
changeset 366097 4961b6529b1a7e30daba766b3dc96614322fedfe
parent 366096 743a610d7281ab7564634df0ecdf24c0a6043eb6
child 366098 55f9e6931cbbc39bf3b66a69ab7b58d18369cc84
push id45494
push userrchien@mozilla.com
push dateTue, 27 Jun 2017 00:48:41 +0000
treeherderautoland@4961b6529b1a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1374230
milestone56.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 1374230 - Wrong tooltip position after resizing browser window r=mconley MozReview-Commit-ID: GYPjtzRTQdf
browser/components/preferences/in-content-new/findInPage.js
--- a/browser/components/preferences/in-content-new/findInPage.js
+++ b/browser/components/preferences/in-content-new/findInPage.js
@@ -13,16 +13,29 @@ var gSearchResultsPane = {
   init() {
     this.searchResultsCategory = document.getElementById("category-search-results");
 
     this.searchInput = document.getElementById("searchInput");
     this.searchInput.hidden = !Services.prefs.getBoolPref("browser.preferences.search");
     if (!this.searchInput.hidden) {
       this.searchInput.addEventListener("command", this);
       this.searchInput.addEventListener("focus", this);
+
+      // Throttling the resize event to reduce the callback frequency
+      let callbackId;
+      window.addEventListener("resize", () => {
+        if (!callbackId) {
+          callbackId = window.requestAnimationFrame(() => {
+            this.listSearchTooltips.forEach((anchorNode) => {
+              this.calculateTooltipPosition(anchorNode);
+            });
+            callbackId = null;
+          });
+        }
+      });
     }
   },
 
   handleEvent(event) {
     if (event.type === "command") {
       this.searchFunction(event);
     } else if (event.type === "focus") {
       this.initializeCategories();
@@ -393,16 +406,22 @@ var gSearchResultsPane = {
     let searchTooltip = anchorNode.ownerDocument.createElement("span");
     searchTooltip.setAttribute("class", "search-tooltip");
     searchTooltip.textContent = query;
 
     anchorNode.setAttribute("data-has-tooltip", "true");
     anchorNode.parentElement.classList.add("search-tooltip-parent");
     anchorNode.parentElement.appendChild(searchTooltip);
 
+    this.calculateTooltipPosition(anchorNode);
+  },
+
+  calculateTooltipPosition(anchorNode) {
+    let searchTooltip = anchorNode.parentElement.querySelector(":scope > .search-tooltip");
+
     // In order to get the up-to-date position of each of the nodes that we're
     // putting tooltips on, we have to flush layout intentionally, and that
     // this is the result of a XUL limitation (bug 1363730).
     let anchorRect = anchorNode.getBoundingClientRect();
     let tooltipRect = searchTooltip.getBoundingClientRect();
     let parentRect = anchorNode.parentElement.getBoundingClientRect();
 
     let offSet = (anchorRect.width / 2) - (tooltipRect.width / 2);