diff --git a/dom/base/nsINode.cpp b/dom/base/nsINode.cpp index 6cc088c98ec5..d99da4763b32 100644 --- a/dom/base/nsINode.cpp +++ b/dom/base/nsINode.cpp @@ -3182,6 +3182,18 @@ Element* nsINode::GetNearestInclusiveOpenPopover() { return nullptr; } +Element* nsINode::GetNearestInclusiveTargetPopoverForInvoker() { + for (auto* el : InclusiveFlatTreeAncestorsOfType< + nsGenericHTMLFormControlElementWithState>()) { + if (auto* popover = el->GetPopoverTargetElement()) { + if (popover->IsAutoPopover() && popover->IsPopoverOpen()) { + return popover; + } + } + } + return nullptr; +} + void nsINode::AddAnimationObserver(nsIAnimationObserver* aAnimationObserver) { AddMutationObserver(aAnimationObserver); OwnerDoc()->SetMayHaveAnimationObservers(); diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h index 9fed05bc73e0..8dc9c17189ba 100644 --- a/dom/base/nsINode.h +++ b/dom/base/nsINode.h @@ -502,12 +502,17 @@ class nsINode : public mozilla::dom::EventTarget { MOZ_CAN_RUN_SCRIPT mozilla::dom::Element* GetParentFlexElement(); - /* + /** * Returns the nearest inclusive open popover for a given node, see * https://html.spec.whatwg.org/multipage/popover.html#nearest-inclusive-open-popover */ mozilla::dom::Element* GetNearestInclusiveOpenPopover(); + /** + * https://html.spec.whatwg.org/multipage/popover.html#nearest-inclusive-target-popover-for-invoker + */ + mozilla::dom::Element* GetNearestInclusiveTargetPopoverForInvoker(); + bool IsNode() const final { return true; } NS_IMPL_FROMEVENTTARGET_HELPER(nsINode, IsNode()) @@ -518,6 +523,9 @@ class nsINode : public mozilla::dom::EventTarget { bool IsElement() const { return GetBoolFlag(NodeIsElement); } virtual bool IsTextControlElement() const { return false; } + virtual bool IsGenericHTMLFormControlElementWithState() const { + return false; + } // Returns non-null if this element subclasses `LinkStyle`. virtual const mozilla::dom::LinkStyle* AsLinkStyle() const { return nullptr; } diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h index da4245806e69..a041144cdf30 100644 --- a/dom/html/nsGenericHTMLElement.h +++ b/dom/html/nsGenericHTMLElement.h @@ -1224,6 +1224,10 @@ class nsGenericHTMLFormControlElementWithState already_AddRefed&& aNodeInfo, mozilla::dom::FromParser aFromParser, FormControlType); + bool IsGenericHTMLFormControlElementWithState() const final { return true; } + NS_IMPL_FROMNODE_HELPER(nsGenericHTMLFormControlElementWithState, + IsGenericHTMLFormControlElementWithState()) + // nsIContent bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, const nsAString& aValue,