Skip to content

Commit

Permalink
Implement request-close command for dialogs
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=288476

Reviewed by NOBODY (OOPS!).

Spec PR: whatwg/html#11045

This patch implements the request-close command for dialog, this maps to the requestClose() method.

* LayoutTests/TestExpectations:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/the-button-element/command-and-commandfor/on-dialog-behavior-request-close.tentative-expected.txt: Added.
* Source/WebCore/dom/Element.h:
* Source/WebCore/html/HTMLButtonElement.cpp:
(WebCore::HTMLButtonElement::commandType const):
* Source/WebCore/html/HTMLDialogElement.cpp:
(WebCore::HTMLDialogElement::isValidCommandType):
(WebCore::HTMLDialogElement::handleCommandInternal):
  • Loading branch information
lukewarlow committed Feb 25, 2025
1 parent 34fd069 commit 87cb00b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
1 change: 0 additions & 1 deletion LayoutTests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -2952,7 +2952,6 @@ http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-css-i
imported/w3c/web-platform-tests/css/css-text/text-spacing-trim [ Skip ]

# command/commandfor future: These tests cover additions to the command invokers API which aren't specced yet
imported/w3c/web-platform-tests/html/semantics/the-button-element/command-and-commandfor/on-dialog-behavior-request-close.tentative.html [ Skip ]
imported/w3c/web-platform-tests/html/semantics/the-button-element/command-and-commandfor/fullscreen-behavior.tentative.html [ Skip ]
imported/w3c/web-platform-tests/html/semantics/the-button-element/command-and-commandfor/on-audio-behavior.tentative.html [ Skip ]
imported/w3c/web-platform-tests/html/semantics/the-button-element/command-and-commandfor/on-audio-invalid-behavior.tentative.html [ Skip ]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@


PASS invoking to request-close (with command property as request-close) open dialog closes
PASS invoking to request-close with value (with command property as request-close) open dialog closes and sets returnValue
PASS invoking to request-close (with command property as request-close) open dialog with preventDefault is no-op
PASS invoking to request-close (with command property as request-close) open modal dialog with preventDefault is no-op
PASS invoking to request-close (with command property as request-close) open dialog while changing command still closes
PASS invoking to request-close (with command property as request-close) open modal dialog while changing command still closes
PASS invoking to request-close (with command attribute as request-close) open dialog closes
PASS invoking to request-close with value (with command attribute as request-close) open dialog closes and sets returnValue
PASS invoking to request-close (with command attribute as request-close) open dialog with preventDefault is no-op
PASS invoking to request-close (with command attribute as request-close) open modal dialog with preventDefault is no-op
PASS invoking to request-close (with command attribute as request-close) open dialog while changing command still closes
PASS invoking to request-close (with command attribute as request-close) open modal dialog while changing command still closes
PASS invoking to request-close (with command property as reQuEst-Close) open dialog closes
PASS invoking to request-close with value (with command property as reQuEst-Close) open dialog closes and sets returnValue
PASS invoking to request-close (with command property as reQuEst-Close) open dialog with preventDefault is no-op
PASS invoking to request-close (with command property as reQuEst-Close) open modal dialog with preventDefault is no-op
PASS invoking to request-close (with command property as reQuEst-Close) open dialog while changing command still closes
PASS invoking to request-close (with command property as reQuEst-Close) open modal dialog while changing command still closes
PASS invoking to request-close (with command attribute as reQuEst-Close) open dialog closes
PASS invoking to request-close with value (with command attribute as reQuEst-Close) open dialog closes and sets returnValue
PASS invoking to request-close (with command attribute as reQuEst-Close) open dialog with preventDefault is no-op
PASS invoking to request-close (with command attribute as reQuEst-Close) open modal dialog with preventDefault is no-op
PASS invoking to request-close (with command attribute as reQuEst-Close) open dialog while changing command still closes
PASS invoking to request-close (with command attribute as reQuEst-Close) open modal dialog while changing command still closes
PASS invoking (as request-close) already closed dialog is noop
PASS invoking (as request-close) dialog as open popover=manual is noop
PASS invoking (as request-close) dialog as open popover=auto is noop
PASS invoking (as request-close) dialog that is removed is noop
PASS invoking (as request-close) dialog from a detached invoker
PASS invoking (as request-close) detached dialog from a detached invoker

1 change: 1 addition & 0 deletions Source/WebCore/dom/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ enum class CommandType: uint8_t {

ShowModal,
Close,
RequestClose,
};

struct CheckVisibilityOptions;
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/html/HTMLButtonElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ constexpr ASCIILiteral showPopoverLiteral = "show-popover"_s;
constexpr ASCIILiteral hidePopoverLiteral = "hide-popover"_s;
constexpr ASCIILiteral showModalLiteral = "show-modal"_s;
constexpr ASCIILiteral closeLiteral = "close"_s;
constexpr ASCIILiteral requestCloseLiteral = "request-close"_s;
CommandType HTMLButtonElement::commandType() const
{
auto action = attributeWithoutSynchronization(HTMLNames::commandAttr);
Expand All @@ -175,6 +176,9 @@ CommandType HTMLButtonElement::commandType() const
if (equalLettersIgnoringASCIICase(action, closeLiteral))
return CommandType::Close;

if (equalLettersIgnoringASCIICase(action, requestCloseLiteral))
return CommandType::RequestClose;

if (action.startsWith("--"_s))
return CommandType::Custom;

Expand Down
7 changes: 6 additions & 1 deletion Source/WebCore/html/HTMLDialogElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ void HTMLDialogElement::requestClose(const String& returnValue)

bool HTMLDialogElement::isValidCommandType(const CommandType command)
{
return HTMLElement::isValidCommandType(command) || command == CommandType::ShowModal || command == CommandType::Close;
return HTMLElement::isValidCommandType(command) || command == CommandType::ShowModal || command == CommandType::Close
|| command == CommandType::RequestClose;
}

bool HTMLDialogElement::handleCommandInternal(const HTMLButtonElement& invoker, const CommandType& command)
Expand All @@ -211,6 +212,10 @@ bool HTMLDialogElement::handleCommandInternal(const HTMLButtonElement& invoker,
close(invoker.value().string());
return true;
}
if (command == CommandType::RequestClose) {
requestClose(invoker.value().string());
return true;
}
} else {
if (command == CommandType::ShowModal) {
showModal();
Expand Down

0 comments on commit 87cb00b

Please sign in to comment.