Backed out changeset 4cce744a9cbb (bug 1860457) for causing wpt failures. CLOSED TREE

This commit is contained in:
Sandor Molnar 2024-05-24 07:07:16 +03:00
parent a1dac0ff8f
commit 0148cb991d
8 changed files with 49 additions and 104 deletions

View file

@ -1131,20 +1131,8 @@ class Element : public FragmentOrElement {
virtual bool IsValidInvokeAction(InvokeAction aAction) const { virtual bool IsValidInvokeAction(InvokeAction aAction) const {
return aAction == InvokeAction::Auto; return aAction == InvokeAction::Auto;
} }
MOZ_CAN_RUN_SCRIPT virtual void HandleInvokeInternal(InvokeAction aAction,
/** ErrorResult& aRv) {}
* Elements can provide their own default behaviours for "Invoke" (see
* invoketarget/invokeaction attributes).
* If the action is not recognised, they can choose to ignore it and `return
* false`. If an action is recognised then they should `return true` to
* indicate to sub-classes that this has been handled and no further steps
* should be run.
*/
MOZ_CAN_RUN_SCRIPT virtual bool HandleInvokeInternal(Element* invoker,
InvokeAction aAction,
ErrorResult& aRv) {
return false;
}
private: private:
void DescribeAttribute(uint32_t index, nsAString& aOutDescription) const; void DescribeAttribute(uint32_t index, nsAString& aOutDescription) const;

View file

@ -3343,11 +3343,6 @@ Element* nsINode::GetNearestInclusiveOpenPopover() const {
Element* nsINode::GetNearestInclusiveTargetPopoverForInvoker() const { Element* nsINode::GetNearestInclusiveTargetPopoverForInvoker() const {
for (auto* el : InclusiveFlatTreeAncestorsOfType<Element>()) { for (auto* el : InclusiveFlatTreeAncestorsOfType<Element>()) {
if (auto* popover = el->GetEffectiveInvokeTargetElement()) {
if (popover->IsAutoPopover() && popover->IsPopoverOpen()) {
return popover;
}
}
if (auto* popover = el->GetEffectivePopoverTargetElement()) { if (auto* popover = el->GetEffectivePopoverTargetElement()) {
if (popover->IsAutoPopover() && popover->IsPopoverOpen()) { if (popover->IsAutoPopover() && popover->IsPopoverOpen()) {
return popover; return popover;
@ -3357,26 +3352,6 @@ Element* nsINode::GetNearestInclusiveTargetPopoverForInvoker() const {
return nullptr; return nullptr;
} }
nsGenericHTMLElement* nsINode::GetEffectiveInvokeTargetElement() const {
if (!StaticPrefs::dom_element_invokers_enabled()) {
return nullptr;
}
const auto* formControl =
nsGenericHTMLFormControlElementWithState::FromNode(this);
if (!formControl || formControl->IsDisabled() ||
!formControl->IsButtonControl()) {
return nullptr;
}
if (auto* popover = nsGenericHTMLElement::FromNodeOrNull(
formControl->GetInvokeTargetElement())) {
if (popover->GetPopoverAttributeState() != PopoverAttributeState::None) {
return popover;
}
}
return nullptr;
}
nsGenericHTMLElement* nsINode::GetEffectivePopoverTargetElement() const { nsGenericHTMLElement* nsINode::GetEffectivePopoverTargetElement() const {
if (!StaticPrefs::dom_element_popover_enabled()) { if (!StaticPrefs::dom_element_popover_enabled()) {
return nullptr; return nullptr;

View file

@ -542,8 +542,6 @@ class nsINode : public mozilla::dom::EventTarget {
*/ */
mozilla::dom::Element* GetNearestInclusiveTargetPopoverForInvoker() const; mozilla::dom::Element* GetNearestInclusiveTargetPopoverForInvoker() const;
nsGenericHTMLElement* GetEffectiveInvokeTargetElement() const;
/** /**
* https://html.spec.whatwg.org/multipage/popover.html#popover-target-element * https://html.spec.whatwg.org/multipage/popover.html#popover-target-element
*/ */

View file

@ -145,34 +145,24 @@ JSObject* HTMLDetailsElement::WrapNode(JSContext* aCx,
} }
bool HTMLDetailsElement::IsValidInvokeAction(InvokeAction aAction) const { bool HTMLDetailsElement::IsValidInvokeAction(InvokeAction aAction) const {
return nsGenericHTMLElement::IsValidInvokeAction(aAction) || return Element::IsValidInvokeAction(aAction) ||
aAction == InvokeAction::Toggle || aAction == InvokeAction::Close || aAction == InvokeAction::Toggle || aAction == InvokeAction::Close ||
aAction == InvokeAction::Open; aAction == InvokeAction::Open;
} }
bool HTMLDetailsElement::HandleInvokeInternal(Element* aInvoker, void HTMLDetailsElement::HandleInvokeInternal(InvokeAction aAction,
InvokeAction aAction,
ErrorResult& aRv) { ErrorResult& aRv) {
if (nsGenericHTMLElement::HandleInvokeInternal(aInvoker, aAction, aRv)) {
return true;
}
if (aAction == InvokeAction::Auto || aAction == InvokeAction::Toggle) { if (aAction == InvokeAction::Auto || aAction == InvokeAction::Toggle) {
ToggleOpen(); ToggleOpen();
return true;
} else if (aAction == InvokeAction::Close) { } else if (aAction == InvokeAction::Close) {
if (Open()) { if (Open()) {
SetOpen(false, IgnoreErrors()); SetOpen(false, IgnoreErrors());
} }
return true;
} else if (aAction == InvokeAction::Open) { } else if (aAction == InvokeAction::Open) {
if (!Open()) { if (!Open()) {
SetOpen(true, IgnoreErrors()); SetOpen(true, IgnoreErrors());
} }
return true;
} }
return false;
} }
} // namespace mozilla::dom } // namespace mozilla::dom

View file

@ -51,9 +51,7 @@ class HTMLDetailsElement final : public nsGenericHTMLElement {
void AsyncEventRunning(AsyncEventDispatcher* aEvent) override; void AsyncEventRunning(AsyncEventDispatcher* aEvent) override;
bool IsValidInvokeAction(InvokeAction aAction) const override; bool IsValidInvokeAction(InvokeAction aAction) const override;
MOZ_CAN_RUN_SCRIPT bool HandleInvokeInternal(Element* invoker, void HandleInvokeInternal(InvokeAction aAction, ErrorResult& aRv) override;
InvokeAction aAction,
ErrorResult& aRv) override;
protected: protected:
virtual ~HTMLDetailsElement(); virtual ~HTMLDetailsElement();

View file

@ -2988,48 +2988,7 @@ void nsGenericHTMLFormControlElementWithState::HandleInvokeTargetAction() {
return; return;
} }
invokee->HandleInvokeInternal(this, action, IgnoreErrors()); invokee->HandleInvokeInternal(action, IgnoreErrors());
}
bool nsGenericHTMLElement::IsValidInvokeAction(InvokeAction aAction) const {
return Element::IsValidInvokeAction(aAction) ||
aAction == InvokeAction::ShowPopover ||
aAction == InvokeAction::TogglePopover ||
aAction == InvokeAction::HidePopover;
}
MOZ_CAN_RUN_SCRIPT bool nsGenericHTMLElement::HandleInvokeInternal(
Element* aInvoker, InvokeAction aAction, ErrorResult& aRv) {
if (Element::HandleInvokeInternal(aInvoker, aAction, aRv)) {
return true;
}
// If the element is a `popover` then we may want to handle the
// invokeaction...
auto popoverState = GetPopoverAttributeState();
if (popoverState == PopoverAttributeState::None) {
return false;
}
const bool canShow = aAction == InvokeAction::Auto ||
aAction == InvokeAction::TogglePopover ||
aAction == InvokeAction::ShowPopover;
const bool canHide = aAction == InvokeAction::Auto ||
aAction == InvokeAction::TogglePopover ||
aAction == InvokeAction::HidePopover;
if (canShow && !IsPopoverOpen()) {
ShowPopoverInternal(aInvoker, aRv);
return true;
}
if (canHide && IsPopoverOpen()) {
HidePopoverInternal(/* aFocusPreviousElement = */ true,
/* aFireEvents = */ true, IgnoreErrors());
return true;
}
return false;
} }
void nsGenericHTMLFormControlElementWithState::GenerateStateKey() { void nsGenericHTMLFormControlElementWithState::GenerateStateKey() {

View file

@ -185,12 +185,6 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase {
void ForgetPreviouslyFocusedElementAfterHidingPopover(); void ForgetPreviouslyFocusedElementAfterHidingPopover();
MOZ_CAN_RUN_SCRIPT void FocusPreviousElementAfterHidingPopover(); MOZ_CAN_RUN_SCRIPT void FocusPreviousElementAfterHidingPopover();
bool IsValidInvokeAction(mozilla::dom::InvokeAction aAction) const override;
MOZ_CAN_RUN_SCRIPT bool HandleInvokeInternal(
Element* aInvoker, mozilla::dom::InvokeAction aAction,
ErrorResult& aRv) override;
MOZ_CAN_RUN_SCRIPT void FocusCandidate(Element*, bool aClearUpFocus); MOZ_CAN_RUN_SCRIPT void FocusCandidate(Element*, bool aClearUpFocus);
void SetNonce(const nsAString& aNonce) { void SetNonce(const nsAString& aNonce) {

View file

@ -0,0 +1,43 @@
[invoketarget-on-popover-behavior.tentative.html]
prefs: [dom.element.popover.enabled: true]
[invoking (as auto) closed popover opens]
expected: FAIL
[invoking (as togglepopover) closed popover opens]
expected: FAIL
[invoking (as showpopover) closed popover opens]
expected: FAIL
[invoking (as showpopover) open popover is noop]
expected: FAIL
[invoking (as auto) from within open popover closes]
expected: FAIL
[invoking (as togglepopover) from within open popover closes]
expected: FAIL
[changing invokeaction attribute inside invokeevent doesn't impact the invocation]
expected: FAIL
[invoking (as explicit empty) closed popover opens]
expected: FAIL
[invoking (as tOgGlEpOpOvEr) closed popover opens]
expected: FAIL
[invoking (as sHoWpOpOvEr) closed popover opens]
expected: FAIL
[invoking (as explicit empty) from within open popover closes]
expected: FAIL
[invoking (as hidepopover) from within open popover closes]
expected: FAIL
[invoking (as tOgGlEpOpOvEr) from within open popover closes]
expected: FAIL
[invoking (as hIdEpOpOvEr) from within open popover closes]
expected: FAIL