Skip to content

Commit

Permalink
Implement new popover inside invoker behaviour
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=283494

Reviewed by NOBODY (OOPS!).

This patch matches the new spec behaviour for when a popover is inside its invoker.

See whatwg/html#10770

* LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-nested-in-button-expected.txt:
* Source/WebCore/html/HTMLButtonElement.cpp:
(WebCore::HTMLButtonElement::defaultEventHandler):
* Source/WebCore/html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::handlePopoverTargetAction const):
* Source/WebCore/html/HTMLFormControlElement.h:
* Source/WebCore/html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::defaultEventHandler):
  • Loading branch information
lukewarlow committed Dec 7, 2024
1 parent d53ea6f commit 22aa592
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Button Button

FAIL clicking a popover nested inside a button should not re-invoke the popover assert_true: Should still be open expected true got false
PASS clicking a popover nested inside a button should not re-invoke the popover
PASS corner case: invoker that is also a popover
FAIL invoker inside popover still works, even with weird nesting assert_true: descendant doesn't close popover expected true got false
PASS invoker inside popover still works, even with weird nesting

2 changes: 1 addition & 1 deletion Source/WebCore/html/HTMLButtonElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void HTMLButtonElement::defaultEventHandler(Event& event)
}

if (!(protectedForm && m_type == SUBMIT))
handlePopoverTargetAction();
handlePopoverTargetAction(event.target());

}

Expand Down
21 changes: 13 additions & 8 deletions Source/WebCore/html/HTMLFormControlElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,24 +395,29 @@ void HTMLFormControlElement::setPopoverTargetAction(const AtomString& value)
}

// https://html.spec.whatwg.org/#popover-target-attribute-activation-behavior
void HTMLFormControlElement::handlePopoverTargetAction() const
void HTMLFormControlElement::handlePopoverTargetAction(const EventTarget* eventTarget) const
{
RefPtr target = popoverTargetElement();
if (!target)
RefPtr popover = popoverTargetElement();
if (!popover)
return;

ASSERT(target->popoverData());
ASSERT(popover->popoverData());

if (RefPtr eventTargetNode = dynamicDowncast<Node>(eventTarget)) {
if (popover->containsIncludingShadowDOM(eventTargetNode.get()) && popover->isDescendantOrShadowDescendantOf(this))
return;
}

auto action = popoverTargetAction();
bool canHide = action == hideAtom() || action == toggleAtom();
bool shouldHide = canHide && target->popoverData()->visibilityState() == PopoverVisibilityState::Showing;
bool shouldHide = canHide && popover->popoverData()->visibilityState() == PopoverVisibilityState::Showing;
bool canShow = action == showAtom() || action == toggleAtom();
bool shouldShow = canShow && target->popoverData()->visibilityState() == PopoverVisibilityState::Hidden;
bool shouldShow = canShow && popover->popoverData()->visibilityState() == PopoverVisibilityState::Hidden;

if (shouldHide)
target->hidePopover();
popover->hidePopover();
else if (shouldShow)
target->showPopover(this);
popover->showPopover(this);
}

RefPtr<Element> HTMLFormControlElement::commandForElement() const
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/HTMLFormControlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class HTMLFormControlElement : public HTMLElement, public ValidatedFormListedEle

void dispatchBlurEvent(RefPtr<Element>&& newFocusedElement) override;

void handlePopoverTargetAction() const;
void handlePopoverTargetAction(const EventTarget*) const;

CommandType commandType() const;
void handleCommand();
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ void HTMLInputElement::defaultEventHandler(Event& event)
if (commandForElement())
handleCommand();
else
handlePopoverTargetAction();
handlePopoverTargetAction(event.target());
if (event.defaultHandled())
return;
}
Expand Down

0 comments on commit 22aa592

Please sign in to comment.