Skip to content

Commit

Permalink
Bug 1841505: postpone setting the popover invoker in the "show popove…
Browse files Browse the repository at this point in the history
…r" algo. r=emilio

See
<whatwg/html#9383 (comment)>.

Differential Revision: https://phabricator.services.mozilla.com/D182709

UltraBlame original commit: 0b5333b2ef93c5e4153ac198b577c6f54c5ad538
  • Loading branch information
marco-c committed Jul 16, 2023
1 parent a394e48 commit 06fab17
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
7 changes: 2 additions & 5 deletions dom/base/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4276,7 +4276,7 @@ bool Element::IsPopoverOpen() const {
return htmlElement && htmlElement->PopoverOpen();
}

Element* Element::GetTopmostPopoverAncestor() const {
Element* Element::GetTopmostPopoverAncestor(const Element* aInvoker) const {
const Element* newPopover = this;

nsTHashMap<nsPtrHashKey<const Element>, size_t> popoverPositions;
Expand Down Expand Up @@ -4308,10 +4308,7 @@ Element* Element::GetTopmostPopoverAncestor() const {
};

checkAncestor(newPopover->GetFlattenedTreeParentElement());


RefPtr<Element> invoker = newPopover->GetPopoverData()->GetInvoker();
checkAncestor(invoker);
checkAncestor(aInvoker);

return topmostPopoverAncestor;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/base/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ class Element : public FragmentOrElement {



mozilla::dom::Element* GetTopmostPopoverAncestor() const;
Element* GetTopmostPopoverAncestor(const Element* aInvoker) const;

ElementAnimationData* GetAnimationData() const {
if (!MayHaveAnimations()) {
Expand Down
19 changes: 11 additions & 8 deletions dom/html/nsGenericHTMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3330,16 +3330,14 @@ void nsGenericHTMLElement::RunPopoverToggleEventTask(
void nsGenericHTMLElement::ShowPopover(ErrorResult& aRv) {
return ShowPopoverInternal(nullptr, aRv);
}
void nsGenericHTMLElement::ShowPopoverInternal(
nsGenericHTMLFormControlElementWithState* aInvoker, ErrorResult& aRv) {
if (PopoverData* data = GetPopoverData()) {
data->SetInvoker(aInvoker);
}

void nsGenericHTMLElement::ShowPopoverInternal(Element* aInvoker,
ErrorResult& aRv) {
if (!CheckPopoverValidity(PopoverVisibilityState::Hidden, nullptr, aRv)) {
return;
}
RefPtr<Document> document = OwnerDoc();

MOZ_ASSERT(!GetPopoverData() || !GetPopoverData()->GetInvoker());
MOZ_ASSERT(!OwnerDoc()->TopLayerContains(*this));

bool wasShowingOrHiding = GetPopoverData()->IsShowingOrHiding();
Expand All @@ -3363,7 +3361,7 @@ void nsGenericHTMLElement::ShowPopoverInternal(
nsWeakPtr originallyFocusedElement;
if (IsAutoPopover()) {
auto originalState = GetPopoverAttributeState();
RefPtr<nsINode> ancestor = GetTopmostPopoverAncestor();
RefPtr<nsINode> ancestor = GetTopmostPopoverAncestor(aInvoker);
if (!ancestor) {
ancestor = document;
}
Expand Down Expand Up @@ -3396,7 +3394,12 @@ void nsGenericHTMLElement::ShowPopoverInternal(
document->AddPopoverToTopLayer(*this);

PopoverPseudoStateUpdate(true, true);
GetPopoverData()->SetPopoverVisibilityState(PopoverVisibilityState::Showing);

{
auto* popoverData = GetPopoverData();
popoverData->SetPopoverVisibilityState(PopoverVisibilityState::Showing);
popoverData->SetInvoker(aInvoker);
}


FocusPopover();
Expand Down
4 changes: 2 additions & 2 deletions dom/html/nsGenericHTMLElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase {
mozilla::dom::PopoverToggleEventTask* aTask,
mozilla::dom::PopoverVisibilityState aOldState);
MOZ_CAN_RUN_SCRIPT void ShowPopover(ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT void ShowPopoverInternal(
nsGenericHTMLFormControlElementWithState* aInvoker, ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT void ShowPopoverInternal(Element* aInvoker,
ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT_BOUNDARY void HidePopoverWithoutRunningScript();
MOZ_CAN_RUN_SCRIPT void HidePopoverInternal(bool aFocusPreviousElement,
bool aFireEvents,
Expand Down

0 comments on commit 06fab17

Please sign in to comment.