Skip to content

Commit 60f8416

Browse files
lukewarlowmnutt
authored andcommitted
Implement new popover inside invoker behaviour
https://bugs.webkit.org/show_bug.cgi?id=283494 Reviewed by Tim Nguyen. 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): Canonical link: https://commits.webkit.org/287522@main
1 parent aaf0660 commit 60f8416

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Button Button
22

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

Source/WebCore/html/HTMLButtonElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void HTMLButtonElement::defaultEventHandler(Event& event)
172172
}
173173

174174
if (!(protectedForm && m_type == SUBMIT))
175-
handlePopoverTargetAction();
175+
handlePopoverTargetAction(event.target());
176176

177177
}
178178

Source/WebCore/html/HTMLFormControlElement.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,24 +395,29 @@ void HTMLFormControlElement::setPopoverTargetAction(const AtomString& value)
395395
}
396396

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

404-
ASSERT(target->popoverData());
404+
ASSERT(popover->popoverData());
405+
406+
if (RefPtr eventTargetNode = dynamicDowncast<Node>(eventTarget)) {
407+
if (popover->containsIncludingShadowDOM(eventTargetNode.get()) && popover->isDescendantOrShadowDescendantOf(this))
408+
return;
409+
}
405410

406411
auto action = popoverTargetAction();
407412
bool canHide = action == hideAtom() || action == toggleAtom();
408-
bool shouldHide = canHide && target->popoverData()->visibilityState() == PopoverVisibilityState::Showing;
413+
bool shouldHide = canHide && popover->popoverData()->visibilityState() == PopoverVisibilityState::Showing;
409414
bool canShow = action == showAtom() || action == toggleAtom();
410-
bool shouldShow = canShow && target->popoverData()->visibilityState() == PopoverVisibilityState::Hidden;
415+
bool shouldShow = canShow && popover->popoverData()->visibilityState() == PopoverVisibilityState::Hidden;
411416

412417
if (shouldHide)
413-
target->hidePopover();
418+
popover->hidePopover();
414419
else if (shouldShow)
415-
target->showPopover(this);
420+
popover->showPopover(this);
416421
}
417422

418423
RefPtr<Element> HTMLFormControlElement::commandForElement() const

Source/WebCore/html/HTMLFormControlElement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class HTMLFormControlElement : public HTMLElement, public ValidatedFormListedEle
130130

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

133-
void handlePopoverTargetAction() const;
133+
void handlePopoverTargetAction(const EventTarget*) const;
134134

135135
CommandType commandType() const;
136136
void handleCommand();

Source/WebCore/html/HTMLInputElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ void HTMLInputElement::defaultEventHandler(Event& event)
13621362
if (commandForElement())
13631363
handleCommand();
13641364
else
1365-
handlePopoverTargetAction();
1365+
handlePopoverTargetAction(event.target());
13661366
if (event.defaultHandled())
13671367
return;
13681368
}

0 commit comments

Comments
 (0)