From 707aba1b0b799aad3abcb3af5968c4a5e1025208 Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Mon, 10 Aug 2020 09:47:38 +0000 Subject: [PATCH] Bug 1644337, add an isAnchored property to popups, as popups can be anchored to a rectangle as well as a node. This prevented the arrow from appearing in panels, r=smaug Differential Revision: https://phabricator.services.mozilla.com/D86099 --- dom/webidl/XULPopupElement.webidl | 6 ++++++ dom/xul/XULPopupElement.cpp | 9 +++++++++ dom/xul/XULPopupElement.h | 2 ++ toolkit/content/widgets/panel.js | 9 ++------- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/dom/webidl/XULPopupElement.webidl b/dom/webidl/XULPopupElement.webidl index 9396844ee33d..7c479f6030e5 100644 --- a/dom/webidl/XULPopupElement.webidl +++ b/dom/webidl/XULPopupElement.webidl @@ -142,6 +142,12 @@ interface XULPopupElement : XULElement */ readonly attribute Node? triggerNode; + /** + * True if the popup is anchored to a point or rectangle. False if it + * appears at a fixed screen coordinate. + */ + readonly attribute boolean isAnchored; + /** * Retrieve the anchor that was specified to openPopup or for menupopups in a * menu, the parent menu. diff --git a/dom/xul/XULPopupElement.cpp b/dom/xul/XULPopupElement.cpp index e4ac24e24ce0..5bdf66f39f66 100644 --- a/dom/xul/XULPopupElement.cpp +++ b/dom/xul/XULPopupElement.cpp @@ -188,6 +188,15 @@ nsINode* XULPopupElement::GetTriggerNode() const { return nsMenuPopupFrame::GetTriggerContent(menuPopupFrame); } +bool XULPopupElement::IsAnchored() const { + nsMenuPopupFrame* menuPopupFrame = do_QueryFrame(GetPrimaryFrame()); + if (!menuPopupFrame) { + return false; + } + + return menuPopupFrame->IsAnchored(); +} + // FIXME(emilio): should probably be renamed to GetAnchorElement? Element* XULPopupElement::GetAnchorNode() const { nsMenuPopupFrame* menuPopupFrame = do_QueryFrame(GetPrimaryFrame()); diff --git a/dom/xul/XULPopupElement.h b/dom/xul/XULPopupElement.h index 0ce18a063781..b7703a471e96 100644 --- a/dom/xul/XULPopupElement.h +++ b/dom/xul/XULPopupElement.h @@ -72,6 +72,8 @@ class XULPopupElement : public nsXULElement { nsINode* GetTriggerNode() const; + bool IsAnchored() const; + Element* GetAnchorNode() const; already_AddRefed GetOuterScreenRect(); diff --git a/toolkit/content/widgets/panel.js b/toolkit/content/widgets/panel.js index f462a2081aef..44d56bde7c7a 100644 --- a/toolkit/content/widgets/panel.js +++ b/toolkit/content/widgets/panel.js @@ -96,12 +96,7 @@ } adjustArrowPosition() { - if (!this.isArrowPanel) { - return; - } - - var anchor = this.anchorNode; - if (!anchor) { + if (!this.isArrowPanel || !this.isAnchored) { return; } @@ -159,7 +154,7 @@ on_popupshowing(event) { if (this.isArrowPanel && event.target == this) { var arrow = this.shadowRoot.querySelector(".panel-arrow"); - arrow.hidden = this.anchorNode == null; + arrow.hidden = !this.isAnchored; this.shadowRoot .querySelector(".panel-arrowbox") .style.removeProperty("transform");