Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit e789f9a

Browse files
committed
1 parent b7646d1 commit e789f9a

File tree

2 files changed

+25
-70
lines changed

2 files changed

+25
-70
lines changed

dom/html/nsGenericHTMLElement.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -668,45 +668,42 @@ constexpr PopoverAttributeState ToPopoverAttributeState(
668668
} // namespace
669669

670670
void nsGenericHTMLElement::AfterSetPopoverAttr() {
671-
const nsAttrValue* newValue = GetParsedAttr(nsGkAtoms::popover);
672-
673-
const PopoverAttributeState newState = [&newValue]() {
674-
if (newValue) {
675-
MOZ_ASSERT(newValue->Type() == nsAttrValue::eEnum);
671+
auto mapPopoverState = [](const nsAttrValue* value) -> PopoverAttributeState {
672+
if (value) {
673+
MOZ_ASSERT(value->Type() == nsAttrValue::eEnum);
676674
const auto popoverAttributeKeyword =
677-
static_cast<PopoverAttributeKeyword>(newValue->GetEnumValue());
675+
static_cast<PopoverAttributeKeyword>(value->GetEnumValue());
678676
return ToPopoverAttributeState(popoverAttributeKeyword);
679677
}
680678

681679
// The missing value default is the no popover state, see
682680
// <https://html.spec.whatwg.org/multipage/popover.html#attr-popover>.
683681
return PopoverAttributeState::None;
684-
}();
682+
};
683+
684+
PopoverAttributeState newState =
685+
mapPopoverState(GetParsedAttr(nsGkAtoms::popover));
685686

686687
const PopoverAttributeState oldState = GetPopoverAttributeState();
687688

688689
if (newState != oldState) {
689-
EnsurePopoverData().SetPopoverAttributeState(newState);
690-
691-
HidePopoverInternal(/* aFocusPreviousElement = */ true,
692-
/* aFireEvents = */ true, IgnoreErrors());
693-
694-
// In case `HidePopoverInternal` changed the state, keep the corresponding
695-
// changes and don't overwrite anything here.
696-
if (newState == GetPopoverAttributeState()) {
697-
if (newState == PopoverAttributeState::None) {
698-
// `HidePopoverInternal` above didn't remove the element from the top
699-
// layer, because in that call, the element's popover attribute state
700-
// was already `None`. Revisit this, when the spec is corrected
701-
// (bug 1835811).
702-
OwnerDoc()->RemovePopoverFromTopLayer(*this);
703-
704-
ClearPopoverData();
705-
RemoveStates(ElementState::POPOVER_OPEN);
706-
} else {
707-
// TODO: what if `HidePopoverInternal` called `ShowPopup()`?
708-
PopoverPseudoStateUpdate(false, true);
709-
}
690+
PopoverPseudoStateUpdate(false, true);
691+
692+
if (IsPopoverOpen()) {
693+
HidePopoverInternal(/* aFocusPreviousElement = */ true,
694+
/* aFireEvents = */ true, IgnoreErrors());
695+
// Event handlers could have removed the popover attribute, or changed
696+
// its value.
697+
newState = mapPopoverState(GetParsedAttr(nsGkAtoms::popover));
698+
}
699+
700+
if (newState == PopoverAttributeState::None) {
701+
OwnerDoc()->RemovePopoverFromTopLayer(*this);
702+
ClearPopoverData();
703+
RemoveStates(ElementState::POPOVER_OPEN);
704+
} else {
705+
// TODO: what if `HidePopoverInternal` called `ShowPopup()`?
706+
EnsurePopoverData().SetPopoverAttributeState(newState);
710707
}
711708
}
712709
}

testing/web-platform/meta/html/semantics/popovers/popover-attribute-basic.html.ini

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,12 @@
1414
[Changing a popover from auto to undefined (via attr), and then auto during 'beforetoggle' works]
1515
expected: FAIL
1616

17-
[Changing a popover from auto to undefined (via attr), and then manual during 'beforetoggle' works]
18-
expected: FAIL
19-
20-
[Changing a popover from auto to undefined (via attr), and then invalid during 'beforetoggle' works]
21-
expected: FAIL
22-
23-
[Changing a popover from auto to undefined (via attr), and then null during 'beforetoggle' works]
24-
expected: FAIL
25-
2617
[Changing a popover from manual to auto (via attr), and then auto during 'beforetoggle' works]
2718
expected: FAIL
2819

2920
[Changing a popover from manual to undefined (via attr), and then auto during 'beforetoggle' works]
3021
expected: FAIL
3122

32-
[Changing a popover from manual to undefined (via attr), and then manual during 'beforetoggle' works]
33-
expected: FAIL
34-
35-
[Changing a popover from manual to undefined (via attr), and then invalid during 'beforetoggle' works]
36-
expected: FAIL
37-
38-
[Changing a popover from manual to undefined (via attr), and then null during 'beforetoggle' works]
39-
expected: FAIL
40-
4123
[Changing a popover from auto to manual (via idl), and then auto during 'beforetoggle' works]
4224
expected: FAIL
4325

@@ -58,27 +40,3 @@
5840

5941
[Changing a popover from manual to undefined (via idl), and then auto during 'beforetoggle' works]
6042
expected: FAIL
61-
62-
[Changing a popover from auto to null (via idl), and then manual during 'beforetoggle' works]
63-
expected: FAIL
64-
65-
[Changing a popover from auto to null (via idl), and then invalid during 'beforetoggle' works]
66-
expected: FAIL
67-
68-
[Changing a popover from auto to undefined (via idl), and then manual during 'beforetoggle' works]
69-
expected: FAIL
70-
71-
[Changing a popover from auto to undefined (via idl), and then invalid during 'beforetoggle' works]
72-
expected: FAIL
73-
74-
[Changing a popover from manual to null (via idl), and then manual during 'beforetoggle' works]
75-
expected: FAIL
76-
77-
[Changing a popover from manual to null (via idl), and then invalid during 'beforetoggle' works]
78-
expected: FAIL
79-
80-
[Changing a popover from manual to undefined (via idl), and then manual during 'beforetoggle' works]
81-
expected: FAIL
82-
83-
[Changing a popover from manual to undefined (via idl), and then invalid during 'beforetoggle' works]
84-
expected: FAIL

0 commit comments

Comments
 (0)