@@ -668,45 +668,42 @@ constexpr PopoverAttributeState ToPopoverAttributeState(
668
668
} // namespace
669
669
670
670
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);
676
674
const auto popoverAttributeKeyword =
677
- static_cast <PopoverAttributeKeyword>(newValue ->GetEnumValue ());
675
+ static_cast <PopoverAttributeKeyword>(value ->GetEnumValue ());
678
676
return ToPopoverAttributeState (popoverAttributeKeyword);
679
677
}
680
678
681
679
// The missing value default is the no popover state, see
682
680
// <https://html.spec.whatwg.org/multipage/popover.html#attr-popover>.
683
681
return PopoverAttributeState::None;
684
- }();
682
+ };
683
+
684
+ PopoverAttributeState newState =
685
+ mapPopoverState (GetParsedAttr (nsGkAtoms::popover));
685
686
686
687
const PopoverAttributeState oldState = GetPopoverAttributeState ();
687
688
688
689
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);
710
707
}
711
708
}
712
709
}
0 commit comments