[Pkg-mozext-commits] [requestpolicy] 227/257: [imp] menu position: check visibility of toolbarbutton
David Prévot
taffit at moszumanska.debian.org
Thu Jan 28 03:20:16 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit d35dc9ec82464ebfd6f03f4a25467e51c3aaedd3
Author: Martin Kimmerle <dev at 256k.de>
Date: Sun Dec 20 16:42:46 2015 +0100
[imp] menu position: check visibility of toolbarbutton
If the toolbar button is hidden in some submenu, e.g. the
Australis menu, then the menu popup should be aligned to
the browsing content.
Fixes #690
---
src/content/lib/utils/dom.jsm | 23 ++++++++++++
src/content/main/window-manager-toolbarbutton.js | 2 +-
src/content/ui/overlay.js | 47 +++++++++++++++++++-----
src/content/ui/xul-trees.js | 2 +-
4 files changed, 63 insertions(+), 11 deletions(-)
diff --git a/src/content/lib/utils/dom.jsm b/src/content/lib/utils/dom.jsm
index 97b4112..3a77c0e 100644
--- a/src/content/lib/utils/dom.jsm
+++ b/src/content/lib/utils/dom.jsm
@@ -49,5 +49,28 @@ var DOMUtils = (function() {
}
};
+ function isThisElementVisible(aElement) {
+ let rects = aElement.getClientRects();
+ if (rects.length === 0) {
+ return false;
+ }
+ let rect = rects[0];
+ return rect.width > 0 && rect.height > 0;
+ }
+
+ /**
+ * Check if the element and all of its parent elements is visible.
+ *
+ * @param {Element} aElement
+ * @return {boolean}
+ */
+ self.isElementVisible = function(aElement) {
+ if (!isThisElementVisible(aElement)) {
+ return false;
+ }
+ let parent = aElement.parentElement;
+ return parent !== null ? self.isElementVisible(parent) : true;
+ };
+
return self;
}());
diff --git a/src/content/main/window-manager-toolbarbutton.js b/src/content/main/window-manager-toolbarbutton.js
index 570fd15..8a13ee7 100644
--- a/src/content/main/window-manager-toolbarbutton.js
+++ b/src/content/main/window-manager-toolbarbutton.js
@@ -84,7 +84,7 @@ rpWindowManager = (function(self) {
onCommand: function(aEvent) {
// Bad smell
let win = aEvent.target.ownerDocument.defaultView;
- win.rpcontinued.overlay.openToolbarPopup(aEvent.target);
+ win.rpcontinued.overlay.openMenu();
}
});
}
diff --git a/src/content/ui/overlay.js b/src/content/ui/overlay.js
index e9a5f74..b20811d 100644
--- a/src/content/ui/overlay.js
+++ b/src/content/ui/overlay.js
@@ -47,6 +47,7 @@ window.rpcontinued.overlay = (function() {
let {StringUtils} = importModule("lib/utils/strings");
let {WindowUtils} = importModule("lib/utils/windows");
let {Utils} = importModule("lib/utils");
+ let {DOMUtils} = importModule("lib/utils/dom");
let {C} = importModule("lib/utils/constants");
let rpcontinued = window.rpcontinued;
@@ -1072,18 +1073,21 @@ window.rpcontinued.overlay = (function() {
gBrowser.selectedTab = gBrowser.addTab(uri);
};
- self.openMenuByHotkey = function() {
- // Ideally we'd put the popup in its normal place based on the rp toolbar
- // button but let's not count on that being visible. So, we'll be safe and
- // anchor it within the content element. However, there's no good way to
- // right-align a popup. So, we can either let it be left aligned or we can
- // figure out where we think the top-left corner should be. And that's what
- // we do.
+ /**
+ * Open the menu at the browsing content.
+ *
+ * The menu is aligned to the top right.
+ */
+ self.openMenuAtContent = function() {
+ // There's no good way to right-align a popup. So, we can either
+ // let it be left aligned or we can figure out where we think the
+ // top-left corner should be. And that's what we do.
// The first time the width will be 0. The default value is determined by
// logging it or you can probably figure it out from the CSS which doesn't
// directly specify the width of the entire popup.
//Logger.dump('popup width: ' + popup.clientWidth);
- var popupWidth = popupElement.clientWidth ? 730 : popupElement.clientWidth;
+ var popupWidth = popupElement.clientWidth === 0 ? 730 :
+ popupElement.clientWidth;
var anchor = $id("content");
var contentWidth = anchor.clientWidth;
// Take a few pixels off so it doesn't cover the browser chrome's border.
@@ -1091,12 +1095,37 @@ window.rpcontinued.overlay = (function() {
popupElement.openPopup(anchor, "overlap", xOffset);
};
- self.openToolbarPopup = function(anchor) {
+ self.openMenuAtToolbarButton = function() {
+ let anchor = $id("rpcontinuedToolbarButton");
// rpcontinued.overlay._toolbox.insertBefore(rpcontinued.overlay.popupElement,
// null);
popupElement.openPopup(anchor, "after_start", 0, 0, true, true);
};
+ /**
+ * Open RequestPolicy's menu.
+ *
+ * If the toolbar button is visible, it will be placed there. Otherwise
+ * it will be placed near the browsing content.
+ */
+ self.openMenu = function() {
+ // `setTimeout` is needed in certain cases where the toolbar button
+ // is actually hidden. For example, it can reside in the Australis
+ // menu. By delaying "openMenu" the menu will be closed in the
+ // meantime, and the toolbar button will be detected as invisible.
+ window.setTimeout(function() {
+ if (self.isToolbarButtonVisible()) {
+ self.openMenuAtToolbarButton();
+ } else {
+ self.openMenuAtContent();
+ }
+ }, 0);
+ };
+
+ self.isToolbarButtonVisible = function() {
+ return DOMUtils.isElementVisible($id("rpcontinuedToolbarButton"));
+ };
+
function openLinkInNewTab(url, relatedToCurrent) {
window.openUILinkIn(url, "tab", {relatedToCurrent: !!relatedToCurrent});
popupElement.hidePopup();
diff --git a/src/content/ui/xul-trees.js b/src/content/ui/xul-trees.js
index 9f58d80..2325c30 100644
--- a/src/content/ui/xul-trees.js
+++ b/src/content/ui/xul-trees.js
@@ -92,7 +92,7 @@ exports.mainTree = [
tag: "key",
attributes: {key: "r",
modifiers: "accel alt"},
- events: {command: ["overlay", "openMenuByHotkey"]}
+ events: {command: ["overlay", "openMenu"]}
}
]
},
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git
More information about the Pkg-mozext-commits
mailing list