Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[popover] Check for modal flag instead of open attribute
https://bugs.webkit.org/show_bug.cgi?id=257412

Reviewed by Tim Nguyen.

Check for modal flag instead of open attribute in checkPopoverValidity check:
whatwg/html#9344

* LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-top-layer-combinations.html:
* Source/WebCore/html/HTMLDialogElement.cpp:
(WebCore::HTMLDialogElement::show):
(WebCore::HTMLDialogElement::close):
* Source/WebCore/html/HTMLElement.cpp:
(WebCore::checkPopoverValidity):

Canonical link: https://commits.webkit.org/264876@main
  • Loading branch information
rwlbuis authored and nt1m committed Jun 5, 2023
1 parent 847e191 commit 62bb3c7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
Expand Up @@ -54,8 +54,9 @@
if (ex.hasAttribute('open')) {
assert_true(isDialog(ex));
assert_true(isElementVisible(ex),'Open dialog should be visible by default');
assert_throws_dom("InvalidStateError",() => ex.showPopover(),'Calling showPopover on an already-showing element should throw InvalidStateError');
ex.showPopover(); // Should not throw
ex.removeAttribute('open');
ex.hidePopover();
assert_false(isElementVisible(ex),'Removing the open attribute should hide the dialog');
} else {
ex.showPopover(); // Should not throw
Expand All @@ -72,7 +73,9 @@
if (isDialog(ex)) {
tested_something=true;
assert_throws_dom("InvalidStateError",() => ex.showModal(),'Calling showModal() on an already-showing Popover should throw InvalidStateError');
assert_throws_dom("InvalidStateError",() => ex.show(),'Calling show() on an already-showing Popover should throw InvalidStateError');
ex.show(); // Should not throw
ex.close();
ex.showPopover();
}
if (isFullscreen(ex)) {
tested_something=true;
Expand All @@ -94,14 +97,16 @@
if (isDialog(ex)) {
ex.show();
assert_true(ex.hasAttribute('open'));
assert_throws_dom("InvalidStateError",() => ex.showPopover(),'Calling showPopover() on an already-showing non-modal dialog should throw InvalidStateError');
ex.showPopover(); // Should not throw
ex.close();
assert_false(ex.hasAttribute('open'));
ex.hidePopover();
ex.showModal();
assert_true(ex.hasAttribute('open'));
assert_throws_dom("InvalidStateError",() => ex.showPopover(),'Calling showPopover() on an already-showing modal dialog should throw InvalidStateError');
ex.close();
assert_false(ex.hasAttribute('open'));
ex.hidePopover();
} else if (isFullscreen(ex)) {
let requestSucceeded = false;
await blessTopLayer(visible);
Expand Down
9 changes: 3 additions & 6 deletions Source/WebCore/html/HTMLDialogElement.cpp
Expand Up @@ -59,9 +59,6 @@ ExceptionOr<void> HTMLDialogElement::show()
return Exception { InvalidStateError, "Cannot call show() on an open modal dialog."_s };
}

if (isPopoverShowing())
return Exception { InvalidStateError, "Element is already an open popover."_s };

setBooleanAttribute(openAttr, true);

m_previouslyFocusedElement = document().focusedElement();
Expand Down Expand Up @@ -114,14 +111,14 @@ void HTMLDialogElement::close(const String& result)

setBooleanAttribute(openAttr, false);

if (isModal())
removeFromTopLayer();

setIsModal(false);

if (!result.isNull())
m_returnValue = result;

if (isInTopLayer())
removeFromTopLayer();

if (RefPtr element = std::exchange(m_previouslyFocusedElement, nullptr).get()) {
FocusOptions options;
options.preventScroll = true;
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/html/HTMLElement.cpp
Expand Up @@ -1251,8 +1251,8 @@ static ExceptionOr<bool> checkPopoverValidity(HTMLElement& element, PopoverVisib
if (expectedDocument && element.document() != *expectedDocument)
return Exception { InvalidStateError, "Invalid when the document changes while showing or hiding a popover element"_s };

if (is<HTMLDialogElement>(element) && element.hasAttributeWithoutSynchronization(HTMLNames::openAttr))
return Exception { InvalidStateError, "Element is an open <dialog> element"_s };
if (is<HTMLDialogElement>(element) && downcast<HTMLDialogElement>(element).isModal())
return Exception { InvalidStateError, "Element is a modal <dialog> element"_s };

#if ENABLE(FULLSCREEN_API)
if (element.hasFullscreenFlag())
Expand Down

0 comments on commit 62bb3c7

Please sign in to comment.