Bug 1867811 - Expose EXPANDED state for element with popovertarget. r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D196541
This commit is contained in:
Ziran Sun
2023-12-19 17:30:56 +00:00
parent 24a78c4744
commit 2a15361c10
5 changed files with 78 additions and 2 deletions

View File

@@ -93,6 +93,10 @@
#include "mozilla/dom/ElementBinding.h"
#include "mozilla/dom/ElementInternals.h"
#ifdef ACCESSIBILITY
# include "nsAccessibilityService.h"
#endif
using namespace mozilla;
using namespace mozilla::dom;
@@ -2853,14 +2857,28 @@ void nsGenericHTMLFormControlElementWithState::HandlePopoverTargetAction() {
bool canHide = action == PopoverTargetAction::Hide ||
action == PopoverTargetAction::Toggle;
bool shouldHide = canHide && target->IsPopoverOpen();
bool canShow = action == PopoverTargetAction::Show ||
action == PopoverTargetAction::Toggle;
bool shouldShow = canShow && !target->IsPopoverOpen();
if (canHide && target->IsPopoverOpen()) {
if (shouldHide) {
target->HidePopover(IgnoreErrors());
} else if (canShow && !target->IsPopoverOpen()) {
} else if (shouldShow) {
target->ShowPopoverInternal(this, IgnoreErrors());
}
#ifdef ACCESSIBILITY
// Notify the accessibility service about the change.
if (shouldHide || shouldShow) {
if (RefPtr<Document> doc = GetComposedDoc()) {
if (PresShell* presShell = doc->GetPresShell()) {
if (nsAccessibilityService* accService = GetAccService()) {
accService->PopovertargetMaybeChanged(presShell, this);
}
}
}
}
#endif
}
void nsGenericHTMLFormControlElementWithState::GetInvokeAction(