Title: [284116] trunk
Revision
284116
Author
[email protected]
Date
2021-10-13 11:33:34 -0700 (Wed, 13 Oct 2021)

Log Message

Implement <dialog> focusing steps
https://bugs.webkit.org/show_bug.cgi?id=227537

Reviewed by Darin Adler.

https://html.spec.whatwg.org/multipage/interactive-elements.html#dialog-focusing-steps

LayoutTests/imported/w3c:

* web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-expected.txt:
* web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-just-once-expected.txt:
* web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-multiple-times-expected.txt:
* web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-input-expected.txt:
* web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-select-expected.txt:
* web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-focusing-steps-prevent-autofocus-expected.txt:
* web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-showModal-expected.txt:
* web-platform-tests/html/semantics/interactive-elements/the-dialog-element/focus-after-close-expected.txt:
* web-platform-tests/html/semantics/interactive-elements/the-dialog-element/show-modal-focusing-steps-expected.txt:

Source/WebCore:

* dom/Document.h:
(WebCore::Document::flushAutofocusCandidates):
(WebCore::Document::clearAutofocusCandidates):
* html/HTMLDialogElement.cpp:
(WebCore::HTMLDialogElement::show):
(WebCore::HTMLDialogElement::showModal):
(WebCore::HTMLDialogElement::close):
(WebCore::HTMLDialogElement::runFocusingSteps):
* html/HTMLDialogElement.h:

LayoutTests:

* platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-select-expected.txt: Added (test_driver.send_keys not working on iOS)

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (284115 => 284116)


--- trunk/LayoutTests/ChangeLog	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/LayoutTests/ChangeLog	2021-10-13 18:33:34 UTC (rev 284116)
@@ -1,3 +1,14 @@
+2021-10-13  Tim Nguyen  <[email protected]>
+
+        Implement <dialog> focusing steps
+        https://bugs.webkit.org/show_bug.cgi?id=227537
+
+        Reviewed by Darin Adler.
+
+        https://html.spec.whatwg.org/multipage/interactive-elements.html#dialog-focusing-steps
+
+        * platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-select-expected.txt: Added (test_driver.send_keys not working on iOS)
+
 2021-10-13  Aditya Keerthi  <[email protected]>
 
         [macOS] Add support for accent-color

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (284115 => 284116)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-13 18:33:34 UTC (rev 284116)
@@ -1,3 +1,22 @@
+2021-10-13  Tim Nguyen  <[email protected]>
+
+        Implement <dialog> focusing steps
+        https://bugs.webkit.org/show_bug.cgi?id=227537
+
+        Reviewed by Darin Adler.
+
+        https://html.spec.whatwg.org/multipage/interactive-elements.html#dialog-focusing-steps
+
+        * web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-expected.txt:
+        * web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-just-once-expected.txt:
+        * web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-multiple-times-expected.txt:
+        * web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-input-expected.txt:
+        * web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-select-expected.txt:
+        * web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-focusing-steps-prevent-autofocus-expected.txt:
+        * web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-showModal-expected.txt:
+        * web-platform-tests/html/semantics/interactive-elements/the-dialog-element/focus-after-close-expected.txt:
+        * web-platform-tests/html/semantics/interactive-elements/the-dialog-element/show-modal-focusing-steps-expected.txt:
+
 2021-10-13  Aditya Keerthi  <[email protected]>
 
         [macOS] Add support for accent-color

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-expected.txt (284115 => 284116)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-expected.txt	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-expected.txt	2021-10-13 18:33:34 UTC (rev 284116)
@@ -1,6 +1,4 @@
 
 
+PASS autofocus when a modal dialog is opened
 
-
-FAIL autofocus when a modal dialog is opened assert_equals: expected Element node <button id="autofocus-button" autofocus=""></button> but got Element node <button id="outer-button" autofocus=""></button>
-

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-just-once-expected.txt (284115 => 284116)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-just-once-expected.txt	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-just-once-expected.txt	2021-10-13 18:33:34 UTC (rev 284116)
@@ -1,8 +1,4 @@
 
 
-FAIL An autofocus element in a dialog element should not try to get focus twice. assert_equals: dialog.show() should set focus on a descendant element with an autofocus attribute. expected Element node <input autofocus=""></input> but got Element node <body>
-<dialog open="">
-<input>
-<input autofocus="">
-</di...
+PASS An autofocus element in a dialog element should not try to get focus twice.
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-multiple-times-expected.txt (284115 => 284116)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-multiple-times-expected.txt	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-multiple-times-expected.txt	2021-10-13 18:33:34 UTC (rev 284116)
@@ -1,4 +1,4 @@
 
 
-FAIL autofocus is run every time a dialog is opened assert_equals: expected Element node <input id="input2" autofocus=""></input> but got Element node <button id="outer-button" autofocus=""></button>
+PASS autofocus is run every time a dialog is opened
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-input-expected.txt (284115 => 284116)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-input-expected.txt	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-input-expected.txt	2021-10-13 18:33:34 UTC (rev 284116)
@@ -1,7 +1,5 @@
-CONSOLE MESSAGE: Error: assert_true: input element should be focused expected true got false
 Test dialog modal is closed by escape key with input focused
 
 
+PASS Test dialog modal is closed by escape key with input focused
 
-FAIL Test dialog modal is closed by escape key with input focused Error: assert_true: input element should be focused expected true got false
-

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-select-expected.txt (284115 => 284116)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-select-expected.txt	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-select-expected.txt	2021-10-13 18:33:34 UTC (rev 284116)
@@ -1,7 +1,5 @@
-CONSOLE MESSAGE: Error: assert_true: select element should be focused expected true got false
 Test dialog modal is closed by escape key with select focused
 
 
+PASS Test dialog modal is closed by escape key with select focused
 
-FAIL Test dialog modal is closed by escape key with select focused Error: assert_true: select element should be focused expected true got false
-

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-focusing-steps-prevent-autofocus-expected.txt (284115 => 284116)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-focusing-steps-prevent-autofocus-expected.txt	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-focusing-steps-prevent-autofocus-expected.txt	2021-10-13 18:33:34 UTC (rev 284116)
@@ -1,7 +1,4 @@
 
 
-FAIL After showing a dialog, non-dialog autofocus processing won't work. assert_equals: Non-dialog autofocus processing should be skipped. expected Element node <body>
-<input autofocus=""><dialog></dialog>
-<script>
-// ... but got Element node <input autofocus=""></input>
+PASS After showing a dialog, non-dialog autofocus processing won't work.
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-showModal-expected.txt (284115 => 284116)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-showModal-expected.txt	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-showModal-expected.txt	2021-10-13 18:33:34 UTC (rev 284116)
@@ -1,17 +1,11 @@
 
-FAIL dialog element: showModal() assert_equals: expected Element node <button id="b1">OK</button> but got Element node <body><div id="log"></div>
-<button id="b0">OK</button>
-<d...
+PASS dialog element: showModal()
 PASS showModal() on a <dialog> that already has an open attribute throws an InvalidStateError exception
 PASS showModal() on a <dialog> after initial showModal() and removing the open attribute
 PASS showModal() on a <dialog> not in a Document throws an InvalidStateError exception
 PASS when opening multiple dialogs, only the newest one is non-inert
 PASS opening dialog without focusable children
-FAIL opening dialog with multiple focusable children assert_equals: expected Element node <input id="i71" value="foobar"></input> but got Element node <body><div id="log"></div>
-<button id="b0">OK</button>
-<d...
-FAIL opening dialog with multiple focusable children, one having the autofocus attribute assert_equals: expected Element node <input id="i82" value="foobar" autofocus=""></input> but got Element node <body><div id="log"></div>
-<button id="b0">OK</button>
-<d...
+PASS opening dialog with multiple focusable children
+PASS opening dialog with multiple focusable children, one having the autofocus attribute
 PASS when opening multiple dialogs, the most recently opened is rendered on top
 OK

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/focus-after-close-expected.txt (284115 => 284116)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/focus-after-close-expected.txt	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/focus-after-close-expected.txt	2021-10-13 18:33:34 UTC (rev 284116)
@@ -2,10 +2,7 @@
 
 
 PASS Focus should be moved to the previously focused element(Simple dialog usage)
-FAIL Focus should be moved to the previously focused element(Complex dialog usage) assert_equals: expected Element node <input></input> but got Element node <body>
-
-<dialog>
-    <button id="button1">This is a butto...
+PASS Focus should be moved to the previously focused element(Complex dialog usage)
 PASS Focus should be moved to the body if the previously focused element is removed
 PASS Focus should be moved to the shadow DOM host if the previouly focused element is a shadow DOM node
 FAIL Focus should not scroll if the previously focused element is outside the viewport assert_true: expected true got false

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/show-modal-focusing-steps-expected.txt (284115 => 284116)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/show-modal-focusing-steps-expected.txt	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/show-modal-focusing-steps-expected.txt	2021-10-13 18:33:34 UTC (rev 284116)
@@ -1,6 +1,4 @@
 
 
-FAIL focus when a modal dialog is opened assert_equals: expected Element node <body>
-<button id="outer-button" autofocus=""></button>
-<... but got Element node <button id="outer-button" autofocus=""></button>
+PASS focus when a modal dialog is opened
 

Added: trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-select-expected.txt (0 => 284116)


--- trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-select-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-with-select-expected.txt	2021-10-13 18:33:34 UTC (rev 284116)
@@ -0,0 +1,8 @@
+Test dialog modal is closed by escape key with select focused
+
+
+
+Harness Error (TIMEOUT), message = null
+
+NOTRUN Test dialog modal is closed by escape key with select focused
+

Modified: trunk/Source/WebCore/ChangeLog (284115 => 284116)


--- trunk/Source/WebCore/ChangeLog	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/Source/WebCore/ChangeLog	2021-10-13 18:33:34 UTC (rev 284116)
@@ -1,3 +1,22 @@
+2021-10-13  Tim Nguyen  <[email protected]>
+
+        Implement <dialog> focusing steps
+        https://bugs.webkit.org/show_bug.cgi?id=227537
+
+        Reviewed by Darin Adler.
+
+        https://html.spec.whatwg.org/multipage/interactive-elements.html#dialog-focusing-steps
+
+        * dom/Document.h:
+        (WebCore::Document::flushAutofocusCandidates):
+        (WebCore::Document::clearAutofocusCandidates):
+        * html/HTMLDialogElement.cpp:
+        (WebCore::HTMLDialogElement::show):
+        (WebCore::HTMLDialogElement::showModal):
+        (WebCore::HTMLDialogElement::close):
+        (WebCore::HTMLDialogElement::runFocusingSteps):
+        * html/HTMLDialogElement.h:
+
 2021-10-13  Aditya Keerthi  <[email protected]>
 
         [macOS] Add support for accent-color

Modified: trunk/Source/WebCore/dom/Document.cpp (284115 => 284116)


--- trunk/Source/WebCore/dom/Document.cpp	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/Source/WebCore/dom/Document.cpp	2021-10-13 18:33:34 UTC (rev 284116)
@@ -4506,7 +4506,7 @@
         // FIXME: Need to ignore if the inclusive ancestor documents has a target element.
         // FIXME: Use the result of getting the focusable area for element if element is not focusable.
         if (element->isFocusable()) {
-            m_autofocusCandidates.clear();
+            clearAutofocusCandidates();
             setAutofocusProcessed();
             element->runFocusingStepsForAutofocus();
             return;

Modified: trunk/Source/WebCore/dom/Document.h (284115 => 284116)


--- trunk/Source/WebCore/dom/Document.h	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/Source/WebCore/dom/Document.h	2021-10-13 18:33:34 UTC (rev 284116)
@@ -799,7 +799,9 @@
 
     bool isAutofocusProcessed() const { return m_isAutofocusProcessed; }
     void setAutofocusProcessed() { m_isAutofocusProcessed = true; }
+
     void appendAutofocusCandidate(Element&);
+    void clearAutofocusCandidates() { m_autofocusCandidates.clear(); }
     void flushAutofocusCandidates();
 
     void hoveredElementDidDetach(Element&);

Modified: trunk/Source/WebCore/html/HTMLDialogElement.cpp (284115 => 284116)


--- trunk/Source/WebCore/html/HTMLDialogElement.cpp	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/Source/WebCore/html/HTMLDialogElement.cpp	2021-10-13 18:33:34 UTC (rev 284116)
@@ -25,8 +25,10 @@
 
 #include "config.h"
 #include "HTMLDialogElement.h"
+#include "ElementTraversal.h"
 #include "EventLoop.h"
 #include "EventNames.h"
+#include "FocusOptions.h"
 
 #include "HTMLNames.h"
 #include <wtf/IsoMallocInlines.h>
@@ -49,6 +51,10 @@
         return;
 
     setBooleanAttribute(openAttr, true);
+
+    m_previouslyFocusedElement = document().focusedElement();
+
+    runFocusingSteps();
 }
 
 ExceptionOr<void> HTMLDialogElement::showModal()
@@ -68,8 +74,10 @@
     if (!isInTopLayer())
         addToTopLayer();
 
-    // FIXME: Add steps 8 & 9 from spec. (webkit.org/b/227537)
+    m_previouslyFocusedElement = document().focusedElement();
 
+    runFocusingSteps();
+
     return { };
 }
 
@@ -88,7 +96,11 @@
     if (isInTopLayer())
         removeFromTopLayer();
 
-    // FIXME: Add step 6 from spec. (webkit.org/b/227537)
+    if (RefPtr element = std::exchange(m_previouslyFocusedElement, nullptr).get(); element && element->isConnected()) {
+        FocusOptions options;
+        options.preventScroll = true;
+        element->focus(options);
+    }
 
     document().eventLoop().queueTask(TaskSource::UserInteraction, [protectedThis = GCReachableRef { *this }] {
         protectedThis->dispatchEvent(Event::create(eventNames().closeEvent, Event::CanBubble::No, Event::IsCancelable::No));
@@ -105,6 +117,43 @@
     });
 }
 
+// https://html.spec.whatwg.org/multipage/interactive-elements.html#dialog-focusing-steps
+void HTMLDialogElement::runFocusingSteps()
+{
+    if (renderer() && renderer()->style().effectiveInert())
+        return;
+
+    RefPtr<Element> control;
+    for (auto& element : descendantsOfType<Element>(*this)) {
+        if (!element.isFocusable())
+            continue;
+
+        if (element.hasAttribute(autofocusAttr)) {
+            control = &element;
+            break;
+        }
+
+        // FIXME: Potentially remove this and adjust related WPTs after https://github.com/whatwg/html/pull/4184.
+        if (!control)
+            control = &element;
+    }
+
+    if (!control)
+        control = this;
+
+    if (control->isFocusable())
+        control->runFocusingStepsForAutofocus();
+    else
+        document().setFocusedElement(nullptr);
+
+    if (!control->document().isSameOriginAsTopDocument())
+        return;
+
+    Ref topDocument = control->document().topDocument();
+    topDocument->clearAutofocusCandidates();
+    topDocument->setAutofocusProcessed();
+}
+
 void HTMLDialogElement::removedFromAncestor(RemovalType removalType, ContainerNode& oldParentOfRemovedTree)
 {
     HTMLElement::removedFromAncestor(removalType, oldParentOfRemovedTree);

Modified: trunk/Source/WebCore/html/HTMLDialogElement.h (284115 => 284116)


--- trunk/Source/WebCore/html/HTMLDialogElement.h	2021-10-13 18:05:21 UTC (rev 284115)
+++ trunk/Source/WebCore/html/HTMLDialogElement.h	2021-10-13 18:33:34 UTC (rev 284116)
@@ -47,6 +47,8 @@
 
     void queueCancelTask();
 
+    void runFocusingSteps();
+
 private:
     HTMLDialogElement(const QualifiedName&, Document&);
 
@@ -54,6 +56,7 @@
 
     String m_returnValue;
     bool m_isModal { false };
+    WeakPtr<Element> m_previouslyFocusedElement;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to