Bug 1826793 - Implement popover target attribute activation behavior step. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D174902
This commit is contained in:
Ziran Sun
2023-04-11 21:18:37 +00:00
parent a1a329e69b
commit c1e04912b6
4 changed files with 33 additions and 2 deletions

View File

@@ -2810,6 +2810,31 @@ void nsGenericHTMLFormControlElementWithState::SetPopoverTargetElement(
ExplicitlySetAttrElement(nsGkAtoms::popovertarget, aElement);
}
void nsGenericHTMLFormControlElementWithState::HandlePopoverTargetAction() {
RefPtr<nsGenericHTMLElement> target = GetEffectivePopoverTargetElement();
if (!target) {
return;
}
const nsAttrValue* value = GetParsedAttr(nsGkAtoms::popovertargetaction);
if (!value) {
return;
}
auto action = static_cast<PopoverTargetAction>(value->GetEnumValue());
bool canHide = action == PopoverTargetAction::Hide ||
action == PopoverTargetAction::Toggle;
bool canShow = action == PopoverTargetAction::Show ||
action == PopoverTargetAction::Toggle;
if (canHide && target->IsPopoverOpen()) {
target->HidePopover(IgnoreErrors());
} else if (canShow && !target->IsPopoverOpen()) {
// TODO: Set popover's popover invoker to node once invoker API is in.
target->ShowPopover(IgnoreErrors());
}
}
void nsGenericHTMLFormControlElementWithState::GenerateStateKey() {
// Keep the key if already computed
if (!mStateKey.IsVoid()) {