commit e0d620ec7e5b58dbb0d516859bb932a1560d3745
parent de1ed576e723a562f4982d417dcf96adbdcbf575
Author: Keith Cirkel <keithamus@users.noreply.github.com>
Date: Mon, 15 Dec 2025 20:09:11 +0000
Bug 1867743 - Part 4: Introduce PopoverOpenedInMode r=dom-core,smaug
`PopoverOpenedInMode` forces popovers to have a fixed state during their opened
lifetime, which may be different from the attribute state. They can use the
PopoverAttributeState as they can only be opened in modes that match their
attribute state.
This change introduces this new mode in the minimum ally viable way -
introducing it just for the check in HideAllPopoversUntil step 7; and the
callsites where it is set.
Differential Revision: https://phabricator.services.mozilla.com/D276370
Diffstat:
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp
@@ -211,6 +211,7 @@
#include "mozilla/dom/Performance.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/PolicyContainer.h"
+#include "mozilla/dom/PopoverData.h"
#include "mozilla/dom/PostMessageEvent.h"
#include "mozilla/dom/ProcessingInstruction.h"
#include "mozilla/dom/Promise.h"
@@ -16224,8 +16225,11 @@ void Document::HidePopover(Element& aPopover, bool aFocusPreviousElement,
}
});
+ PopoverData* popoverData = popoverHTMLEl->GetPopoverData();
+
// 7. If element's opened in popover mode is "auto" or "hint", then:
- if (popoverHTMLEl->IsAutoPopover()) {
+ if (popoverData &&
+ popoverData->GetOpenedInMode() == PopoverAttributeState::Auto) {
// 7.1. Run hide all popovers until given element, focusPreviousElement, and
// fireEvents.
HideAllPopoversUntil(*popoverHTMLEl, aFocusPreviousElement, fireEvents);
@@ -16299,6 +16303,8 @@ void Document::HidePopover(Element& aPopover, bool aFocusPreviousElement,
data->SetInvoker(nullptr);
// 12. Set element's opened in popover mode to null.
+ popoverHTMLEl->GetPopoverData()->SetOpenedInMode(PopoverAttributeState::None);
+
// 13. Set element's popover visibility state to hidden.
popoverHTMLEl->PopoverPseudoStateUpdate(false, true);
popoverHTMLEl->GetPopoverData()->SetPopoverVisibilityState(
diff --git a/dom/base/PopoverData.h b/dom/base/PopoverData.h
@@ -63,6 +63,9 @@ class PopoverData {
mState = aState;
}
+ PopoverAttributeState GetOpenedInMode() const { return mOpenedInMode; }
+ void SetOpenedInMode(PopoverAttributeState aMode) { mOpenedInMode = aMode; }
+
PopoverVisibilityState GetPopoverVisibilityState() const {
return mVisibilityState;
}
@@ -97,6 +100,7 @@ class PopoverData {
private:
PopoverVisibilityState mVisibilityState = PopoverVisibilityState::Hidden;
PopoverAttributeState mState = PopoverAttributeState::None;
+ PopoverAttributeState mOpenedInMode = PopoverAttributeState::None;
// Popover and dialog don't share mPreviouslyFocusedElement for there are
// chances to lose the previously focused element.
// See, https://github.com/whatwg/html/issues/9063
diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp
@@ -3577,6 +3577,8 @@ void nsGenericHTMLElement::ShowPopoverInternal(Element* aSource,
{
auto* popoverData = GetPopoverData();
+ // 18.5.2. Set element's opened in popover mode to "auto".
+ popoverData->SetOpenedInMode(GetPopoverAttributeState());
// 22. Set element's popover visibility state to showing.
popoverData->SetPopoverVisibilityState(PopoverVisibilityState::Showing);
// 23. Set element's popover trigger to source.