Bug 1377802 - Check if bookmarking UI is visible before anchoring bookmarking popup. r=mak
This also avoids flushing when bounds checking the identity popup for visibility.
MozReview-Commit-ID: EBUR7RIB0w6
--- 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) {