Bug 1377802 - Check if bookmarking UI is visible before anchoring bookmarking popup. r=mak, a=jcristau
authorJohann Hofmann <jhofmann@mozilla.com>
Tue, 11 Jul 2017 23:17:07 +0200
changeset 414332 f7250aab6183d6ad2ceadc4aa297cabe63c2c574
parent 414331 fc07a77aa27cf650296f6d732ad9b1f559e2542c
child 414333 c7cdbecbfc601e3b1d4f6f6f09f9e9ef335b3f9e
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, jcristau
bugs1377802
milestone55.0
Bug 1377802 - Check if bookmarking UI is visible before anchoring bookmarking popup. r=mak, a=jcristau This also avoids flushing when bounds checking the identity popup for visibility. MozReview-Commit-ID: EBUR7RIB0w6
browser/base/content/browser-places.js
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -375,16 +375,24 @@ var StarUI = {
       this._batchBlockingDeferred = null;
     } else {
       PlacesUtils.transactionManager.endBatch(false);
     }
     this._batching = false;
   }
 };
 
+// Checks if an element is visible without flushing layout changes.
+function isVisible(element) {
+  let windowUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                          .getInterface(Ci.nsIDOMWindowUtils);
+  let bounds = windowUtils.getBoundsWithoutFlushing(element);
+  return bounds.height > 0 && bounds.width > 0;
+}
+
 var PlacesCommandHook = {
   /**
    * Adds a bookmark to the page loaded in the given browser.
    *
    * @param aBrowser
    *        a <browser> element.
    * @param [optional] aParent
    *        The folder in which to create a new bookmark if the page loaded in
@@ -443,24 +451,24 @@ var PlacesCommandHook = {
     // If it was not requested to open directly in "edit" mode, we are done.
     if (!aShowEditUI)
       return;
 
     // Try to dock the panel to:
     // 1. the bookmarks menu button
     // 2. the identity icon
     // 3. the content area
-    if (BookmarkingUI.anchor) {
+    if (BookmarkingUI.anchor && isVisible(BookmarkingUI.anchor)) {
       StarUI.showEditBookmarkPopup(itemId, BookmarkingUI.anchor,
                                    "bottomcenter topright", isNewBookmark);
       return;
     }
 
     let identityIcon = document.getElementById("identity-icon");
-    if (isElementVisible(identityIcon)) {
+    if (isVisible(identityIcon)) {
       StarUI.showEditBookmarkPopup(itemId, identityIcon,
                                    "bottomcenter topright", isNewBookmark);
     } else {
       StarUI.showEditBookmarkPopup(itemId, aBrowser, "overlap", isNewBookmark);
     }
   },
 
   // TODO: Replace bookmarkPage code with this function once legacy
@@ -518,24 +526,24 @@ var PlacesCommandHook = {
       return;
 
     let node = await PlacesUIUtils.promiseNodeLikeFromFetchInfo(info);
 
     // Try to dock the panel to:
     // 1. the bookmarks menu button
     // 2. the identity icon
     // 3. the content area
-    if (BookmarkingUI.anchor) {
+    if (BookmarkingUI.anchor && isVisible(BookmarkingUI.anchor)) {
       StarUI.showEditBookmarkPopup(node, BookmarkingUI.anchor,
                                    "bottomcenter topright", isNewBookmark);
       return;
     }
 
     let identityIcon = document.getElementById("identity-icon");
-    if (isElementVisible(identityIcon)) {
+    if (isVisible(identityIcon)) {
       StarUI.showEditBookmarkPopup(node, identityIcon,
                                    "bottomcenter topright", isNewBookmark);
     } else {
       StarUI.showEditBookmarkPopup(node, aBrowser, "overlap", isNewBookmark);
     }
   },
 
   _getPageDetails(browser) {