Add getBoundsWithoutFlushing draft
authorRicky Chien <ricky060709@gmail.com>
Fri, 12 May 2017 20:59:34 +0800
changeset 576856 08939e30ff04a21ad27907c63ea8560a65305c08
parent 576407 b6494252195692f3061768c5192697723e758fb6
child 628338 2b98276e32cf2604959de2683f094a31e3f539af
push id58512
push userbmo:rchien@mozilla.com
push dateFri, 12 May 2017 13:00:06 +0000
milestone55.0a1
Add getBoundsWithoutFlushing MozReview-Commit-ID: F1IkJ2zZe1u
browser/components/preferences/in-content/findInPage.js
--- a/browser/components/preferences/in-content/findInPage.js
+++ b/browser/components/preferences/in-content/findInPage.js
@@ -1,14 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* import-globals-from preferences.js */
 
+const DOMUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                       .getInterface(Ci.nsIDOMWindowUtils);
+
 var gSearchResultsPane = {
   findSelection: null,
   listSearchTooltips: [],
   searchResultsCategory: null,
   searchInput: null,
 
   init() {
     let controller = this.getSelectionController();
@@ -340,28 +343,26 @@ var gSearchResultsPane = {
    * Then calculation the offsets to position the tooltip in the correct place.
    *
    * @param Node currentNode
    *    DOM Element
    * @param String query
    *    Word or words that are being searched for
    */
   createSearchTooltip(currentNode, query) {
-    // Getting position of the current node
-    let rect = currentNode.getBoundingClientRect();
-
     currentNode.parentElement.classList.add("search-tooltip-parent");
 
     let searchTooltip = document.createElement("span");
     searchTooltip.setAttribute("class", "search-tooltip");
     searchTooltip.textContent = query;
 
     currentNode.parentElement.appendChild(searchTooltip);
-    let tooltipRect = searchTooltip.getBoundingClientRect();
+    let rect = DOMUtils.getBoundsWithoutFlushing(currentNode);
+    let tooltipRect = DOMUtils.getBoundsWithoutFlushing(searchTooltip);
     let offSet = (rect.width / 2) - (tooltipRect.width / 2);
 
-    let parentRect = currentNode.parentElement.getBoundingClientRect();
+    let parentRect = DOMUtils.getBoundsWithoutFlushing(currentNode.parentElement);
     let relativeOffset = rect.left - parentRect.left;
     offSet += relativeOffset > 0 ? relativeOffset : 0;
 
     searchTooltip.style.setProperty("left", `${offSet}px`);
   }
 }