Skip to content

Commit

Permalink
Bug 1833570 - Reset the popover invoker in showPopover(). r=emilio
Browse files Browse the repository at this point in the history
As discussed in [1], we need to reset invoker in showPopover(). If not,
It's possible that a closed popover still has an invoker.

[1] whatwg/html#9152

Differential Revision: https://phabricator.services.mozilla.com/D179195
  • Loading branch information
ziransun committed Jun 6, 2023
1 parent 21c07a9 commit 48c6901
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
11 changes: 9 additions & 2 deletions dom/html/nsGenericHTMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2914,8 +2914,7 @@ void nsGenericHTMLFormControlElementWithState::HandlePopoverTargetAction() {
if (canHide && target->IsPopoverOpen()) {
target->HidePopover(IgnoreErrors());
} else if (canShow && !target->IsPopoverOpen()) {
target->GetPopoverData()->SetInvoker(this);
target->ShowPopover(IgnoreErrors());
target->ShowPopoverInternal(this, IgnoreErrors());
}
}

Expand Down Expand Up @@ -3370,6 +3369,14 @@ void nsGenericHTMLElement::RunPopoverToggleEventTask(

// https://html.spec.whatwg.org/#dom-showpopover
void nsGenericHTMLElement::ShowPopover(ErrorResult& aRv) {
return ShowPopoverInternal(nullptr, aRv);
}
void nsGenericHTMLElement::ShowPopoverInternal(
nsGenericHTMLFormControlElementWithState* aInvoker, ErrorResult& aRv) {
if (PopoverData* data = GetPopoverData()) {
data->SetInvoker(aInvoker);
}

if (!CheckPopoverValidity(PopoverVisibilityState::Hidden, nullptr, aRv)) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions dom/html/nsGenericHTMLElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,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_BOUNDARY void HidePopoverWithoutRunningScript();
MOZ_CAN_RUN_SCRIPT void HidePopoverInternal(bool aFocusPreviousElement,
bool aFireEvents,
Expand Down

This file was deleted.

0 comments on commit 48c6901

Please sign in to comment.