Commit 0e303cdb authored by Alexander Surkov's avatar Alexander Surkov
Browse files

Bug 1821732 - implement the topmost clicked popover algorithm, r=emilio

parent 16e31c7f
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -3171,18 +3171,16 @@ Element* nsINode::GetParentFlexElement() {
  return nullptr;
}

Element* nsINode::GetNearestInclusiveOpenPopover() {
  for (nsINode* node = this; node; node = node->GetFlattenedTreeParentNode()) {
    if (auto* el = Element::FromNode(node)) {
Element* nsINode::GetNearestInclusiveOpenPopover() const {
  for (auto* el : InclusiveFlatTreeAncestorsOfType<Element>()) {
    if (el->IsAutoPopover() && el->IsPopoverOpen()) {
      return el;
    }
  }
  }
  return nullptr;
}

Element* nsINode::GetNearestInclusiveTargetPopoverForInvoker() {
Element* nsINode::GetNearestInclusiveTargetPopoverForInvoker() const {
  for (auto* el : InclusiveFlatTreeAncestorsOfType<
           nsGenericHTMLFormControlElementWithState>()) {
    if (auto* popover = el->GetPopoverTargetElement()) {
@@ -3194,6 +3192,20 @@ Element* nsINode::GetNearestInclusiveTargetPopoverForInvoker() {
  return nullptr;
}

Element* nsINode::GetTopmostClickedPopover() const {
  Element* clickedPopover = GetNearestInclusiveOpenPopover();
  Element* invokedPopover = GetNearestInclusiveTargetPopoverForInvoker();
  if (!clickedPopover) {
    return invokedPopover;
  }
  for (Element* el : Reversed(clickedPopover->OwnerDoc()->AutoPopoverList())) {
    if (el == clickedPopover || el == invokedPopover) {
      return el;
    }
  }
  return nullptr;
}

void nsINode::AddAnimationObserver(nsIAnimationObserver* aAnimationObserver) {
  AddMutationObserver(aAnimationObserver);
  OwnerDoc()->SetMayHaveAnimationObservers();
+7 −2
Original line number Diff line number Diff line
@@ -506,12 +506,17 @@ class nsINode : public mozilla::dom::EventTarget {
   * 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();
  mozilla::dom::Element* GetNearestInclusiveOpenPopover() const;

  /**
   * https://html.spec.whatwg.org/multipage/popover.html#nearest-inclusive-target-popover-for-invoker
   */
  mozilla::dom::Element* GetNearestInclusiveTargetPopoverForInvoker();
  mozilla::dom::Element* GetNearestInclusiveTargetPopoverForInvoker() const;

  /**
   * https://html.spec.whatwg.org/multipage/popover.html#topmost-clicked-popover
   */
  mozilla::dom::Element* GetTopmostClickedPopover() const;

  bool IsNode() const final { return true; }