WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-227537-20210720113257.patch (text/plain), 21.21 KB, created by
Tim Nguyen (:ntim)
on 2021-07-20 02:32:59 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Tim Nguyen (:ntim)
Created:
2021-07-20 02:32:59 PDT
Size:
21.21 KB
patch
obsolete
>Subversion Revision: 280058 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 7207ca6cfd71174eba71d58519934f0718ab06f0..d23a769e87cb8b8a96ac296c0bffbf42142ab719 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,29 @@ >+2021-07-19 Tim Nguyen <ntim@apple.com> >+ >+ Implement <dialog> focusing steps >+ https://bugs.webkit.org/show_bug.cgi?id=227537 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ https://html.spec.whatwg.org/multipage/interactive-elements.html#dialog-focusing-steps >+ >+ * dom/Document.h: >+ (WebCore::Document::isAutofocusProcessed const): >+ (WebCore::Document::setAutofocusProcessed): >+ * html/HTMLDialogElement.cpp: >+ (WebCore::HTMLDialogElement::show): >+ (WebCore::HTMLDialogElement::showModal): >+ (WebCore::HTMLDialogElement::close): >+ (WebCore::HTMLDialogElement::runFocusingSteps): >+ * html/HTMLDialogElement.h: >+ * html/HTMLFormControlElement.cpp: >+ (WebCore::HTMLFormControlElement::HTMLFormControlElement): >+ (WebCore::shouldAutofocus): >+ (WebCore::HTMLFormControlElement::didAttachRenderers): >+ * html/HTMLFormControlElement.h: >+ (WebCore::HTMLFormControlElement::hasAutofocused): Deleted. >+ (WebCore::HTMLFormControlElement::setAutofocused): Deleted. >+ > 2021-07-19 Sihui Liu <sihui_liu@apple.com> > > Implement IDBTransaction.commit() >diff --git a/Source/WebCore/dom/Document.h b/Source/WebCore/dom/Document.h >index 973144cfb765c3e113839ffe0f860b49e83341b7..2c166393d6f26ea21b484e84b961f5232debd276 100644 >--- a/Source/WebCore/dom/Document.h >+++ b/Source/WebCore/dom/Document.h >@@ -1623,6 +1623,9 @@ public: > > String debugDescription() const; > >+ bool isAutofocusProcessed() const { return m_autofocusProcessed; } >+ void setAutofocusProcessed() { m_autofocusProcessed = true; } >+ > protected: > enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 }; > WEBCORE_EXPORT Document(Frame*, const Settings&, const URL&, DocumentClassFlags = DefaultDocumentClass, unsigned constructionFlags = 0); >@@ -2067,6 +2070,9 @@ private: > bool m_hasElementUsingStyleBasedEditability { false }; > bool m_focusNavigationStartingNodeIsRemoved { false }; > >+ // https://html.spec.whatwg.org/multipage/interaction.html#autofocus-processed-flag >+ bool m_autofocusProcessed { false }; >+ > bool m_printing { false }; > bool m_paginatedForScreen { false }; > >diff --git a/Source/WebCore/html/HTMLDialogElement.cpp b/Source/WebCore/html/HTMLDialogElement.cpp >index 2a3ba5581e2d9b6ed341c680d8124167c4cc59b8..ddf597079348aa7bd63fb760c1cebae2c2330a08 100644 >--- a/Source/WebCore/html/HTMLDialogElement.cpp >+++ b/Source/WebCore/html/HTMLDialogElement.cpp >@@ -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 @@ void HTMLDialogElement::show() > return; > > setBooleanAttribute(openAttr, true); >+ >+ m_previouslyFocusedElement = makeWeakPtr(document().focusedElement()); >+ >+ runFocusingSteps(); > } > > ExceptionOr<void> HTMLDialogElement::showModal() >@@ -68,7 +74,9 @@ ExceptionOr<void> HTMLDialogElement::showModal() > // FIXME: Only add dialog to top layer if it's not already in it. (webkit.org/b/227907) > document().addToTopLayer(*this); > >- // FIXME: Add steps 8 & 9 from spec. (webkit.org/b/227537) >+ m_previouslyFocusedElement = makeWeakPtr(document().focusedElement()); >+ >+ runFocusingSteps(); > > return { }; > } >@@ -88,11 +96,52 @@ void HTMLDialogElement::close(const String& result) > // FIXME: Only remove dialog from top layer if it's inside it. (webkit.org/b/227907) > document().removeFromTopLayer(*this); > >- // FIXME: Add step 6 from spec. (webkit.org/b/227537) >+ if (m_previouslyFocusedElement) { >+ FocusOptions options; >+ options.preventScroll = true; >+ m_previouslyFocusedElement->focus(options); >+ } > > document().eventLoop().queueTask(TaskSource::UserInteraction, [protectedThis = GCReachableRef { *this }] { > protectedThis->dispatchEvent(Event::create(eventNames().closeEvent, Event::CanBubble::No, Event::IsCancelable::No)); > }); > } > >+void HTMLDialogElement::runFocusingSteps() >+{ >+ // FIXME: Add step 1 from spec. (webkit.org/b/110952) >+ >+ Element* control = nullptr; >+ for (Element* element = ElementTraversal::firstWithin(*this); element; element = ElementTraversal::next(*element)) { >+ if (!element->isFocusable()) >+ continue; >+ >+ // Let control be the first descendant element of subject, in tree order, that is not inert and has the autofocus attribute specified. >+ if (element->hasAttribute(autofocusAttr)) { >+ control = element; >+ break; >+ } >+ >+ // If there isn't one, then let control be the first non-inert descendant element of subject, in tree order. >+ if (!control) >+ control = element; >+ } >+ >+ // If there isn't one of those either, then let control be subject. >+ if (!control) >+ control = this; >+ >+ // 3. Run the focusing steps for control. >+ control->focus(); >+ >+ // 4. Let topDocument be the active document of control's node document's browsing context's top-level browsing context. >+ // 5. If control's node document's origin is not the same as the origin of topDocument, then return. >+ if (!control->document().securityOrigin().isSameOriginAs(control->document().topOrigin())) >+ return; >+ >+ // 6. Empty topDocument's autofocus candidates. >+ // 7. Set topDocument's autofocus processed flag to true. >+ control->document().topDocument().setAutofocusProcessed(); >+} >+ > } >diff --git a/Source/WebCore/html/HTMLDialogElement.h b/Source/WebCore/html/HTMLDialogElement.h >index 9859a1d3bc6b8ff68c41a4ff68c5f0f396bc7a64..9e3a18b68de9cb4d37067d49469828b73b7345a9 100644 >--- a/Source/WebCore/html/HTMLDialogElement.h >+++ b/Source/WebCore/html/HTMLDialogElement.h >@@ -45,11 +45,15 @@ public: > > bool isModal() const { return m_isModal; }; > >+ // https://html.spec.whatwg.org/multipage/interactive-elements.html#dialog-focusing-steps >+ void runFocusingSteps(); >+ > private: > HTMLDialogElement(const QualifiedName&, Document&); > > String m_returnValue; > bool m_isModal { false }; >+ WeakPtr<Element> m_previouslyFocusedElement; > }; > > } // namespace WebCore >diff --git a/Source/WebCore/html/HTMLFormControlElement.cpp b/Source/WebCore/html/HTMLFormControlElement.cpp >index 04f78ed71031ff333c2896c19108e3dd95efe3c5..21759ceaf8cd90eb0820620751075e31aae0c848 100644 >--- a/Source/WebCore/html/HTMLFormControlElement.cpp >+++ b/Source/WebCore/html/HTMLFormControlElement.cpp >@@ -72,7 +72,6 @@ HTMLFormControlElement::HTMLFormControlElement(const QualifiedName& tagName, Doc > , m_willValidate(true) > , m_isValid(true) > , m_wasChangedSinceLastFormControlChangeEvent(false) >- , m_hasAutofocused(false) > { > setHasCustomStyleResolveCallbacks(); > } >@@ -221,7 +220,7 @@ static bool shouldAutofocus(HTMLFormControlElement* element) > return false; > } > >- if (element->hasAutofocused()) >+ if (document.topDocument().isAutofocusProcessed()) > return false; > > // FIXME: Should this set of hasTagName checks be replaced by a >@@ -249,17 +248,17 @@ void HTMLFormControlElement::didAttachRenderers() > renderer()->updateFromElement(); > > if (shouldAutofocus(this)) { >- setAutofocused(); >- > RefPtr<HTMLFormControlElement> element = this; > auto frameView = makeRefPtr(document().view()); > if (frameView && frameView->layoutContext().isInLayout()) { > frameView->queuePostLayoutCallback([element] { > element->focus({ SelectionRestorationMode::PlaceCaretAtStart }); >+ element->document().topDocument().setAutofocusProcessed(); > }); > } else { > Style::queuePostResolutionCallback([element] { > element->focus({ SelectionRestorationMode::PlaceCaretAtStart }); >+ element->document().topDocument().setAutofocusProcessed(); > }); > } > } >diff --git a/Source/WebCore/html/HTMLFormControlElement.h b/Source/WebCore/html/HTMLFormControlElement.h >index cdfa5bd324de0b9b4b63c5d7968ae84ef17dcd31..a37609454842aaf94d507f46d956796ba41e83b9 100644 >--- a/Source/WebCore/html/HTMLFormControlElement.h >+++ b/Source/WebCore/html/HTMLFormControlElement.h >@@ -116,9 +116,6 @@ public: > bool isReadOnly() const { return m_isReadOnly; } > bool isDisabledOrReadOnly() const { return isDisabledFormControl() || m_isReadOnly; } > >- bool hasAutofocused() { return m_hasAutofocused; } >- void setAutofocused() { m_hasAutofocused = true; } >- > WEBCORE_EXPORT String autocomplete() const; > WEBCORE_EXPORT void setAutocomplete(const String&); > >@@ -215,8 +212,6 @@ private: > unsigned m_isValid : 1; > > unsigned m_wasChangedSinceLastFormControlChangeEvent : 1; >- >- unsigned m_hasAutofocused : 1; > }; > > class DelayedUpdateValidityScope { >diff --git a/LayoutTests/imported/w3c/ChangeLog b/LayoutTests/imported/w3c/ChangeLog >index b5b847a56113766657ad7d85dfa7f3d150a05ccb..86c305bfdea39a6f5f3bd576f7545504a7efec6f 100644 >--- a/LayoutTests/imported/w3c/ChangeLog >+++ b/LayoutTests/imported/w3c/ChangeLog >@@ -1,3 +1,22 @@ >+2021-07-19 Tim Nguyen <ntim@apple.com> >+ >+ Implement <dialog> focusing steps >+ https://bugs.webkit.org/show_bug.cgi?id=227537 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ https://html.spec.whatwg.org/multipage/interactive-elements.html#dialog-focusing-steps >+ >+ * web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-empty-expected.txt: >+ * web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-nonexistent-expected.txt: >+ * web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-top-expected.txt: >+ * 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-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: >+ > 2021-07-19 Sihui Liu <sihui_liu@apple.com> > > Implement IDBTransaction.commit() >diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-empty-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-empty-expected.txt >index a452d53edba63587d9c2ebdc6f6a50d53fe4efe5..d41929f9b7df7b18d602dad4608befe0715fca22 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-empty-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-empty-expected.txt >@@ -1,5 +1,5 @@ > > >-FAIL Autofocus elements in iframed documents with empty fragments should work. assert_not_equals: got disallowed value Element node <input autofocus=""></input> >+PASS Autofocus elements in iframed documents with empty fragments should work. > PASS Autofocus elements in top-level browsing context's documents with empty fragments should work. > >diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-nonexistent-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-nonexistent-expected.txt >index 2b1e57d6282956918d2721555d04d5802ab7df6d..8dd6b4c770ce9aa5cc29bfc85cce42d5dcee8781 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-nonexistent-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-nonexistent-expected.txt >@@ -1,5 +1,5 @@ > > >-FAIL Autofocus elements in iframed documents with non-existent fragments should work. assert_not_equals: got disallowed value Element node <input autofocus=""></input> >+PASS Autofocus elements in iframed documents with non-existent fragments should work. > PASS Autofocus elements in top-level browsing context's documents with non-existent fragments should work. > >diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-top-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-top-expected.txt >index 0374109a30c624dbd94d87913b4e338ee91993ef..8ba50a51a3dad570d49277499972d594d5dfeb98 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-top-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-top-expected.txt >@@ -1,5 +1,5 @@ > > >-FAIL Autofocus elements in iframed documents with "top" fragments should work. assert_not_equals: got disallowed value Element node <input autofocus=""></input> >+PASS Autofocus elements in iframed documents with "top" fragments should work. > PASS Autofocus elements in top-level browsing context's documents with "top" fragments should work. > >diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-expected.txt >index 60433e29cb0eb1e5db04cdea514d5e2539845fc1..1a24de008095d58f631583d1808545e4ffddf3b5 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-expected.txt >@@ -1,6 +1,4 @@ > > >- >- >-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> >+PASS autofocus when a modal dialog is opened > >diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-just-once-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-just-once-expected.txt >index 33fc6d94a537a06dafbc98c03e66fb3631e350d4..18163eb9732908f96c5a3072742e8d7e75aa7281 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-just-once-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-just-once-expected.txt >@@ -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. > >diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-multiple-times-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-multiple-times-expected.txt >index 045107a83c824cab0375a351a0aff0be14b66609..e506090f6f763fc75687c3acbc0e8eac4eee0b62 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-multiple-times-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-autofocus-multiple-times-expected.txt >@@ -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 > >diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-focusing-steps-prevent-autofocus-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-focusing-steps-prevent-autofocus-expected.txt >index ca7c317c4b71f1ee992a3c0b07bf5604496a9e19..cb65cc141d25ef7442ff179e9c872667d28c8a25 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-focusing-steps-prevent-autofocus-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-focusing-steps-prevent-autofocus-expected.txt >@@ -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. > >diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-showModal-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-showModal-expected.txt >index 839091e922b229f31b3c816821dad5ca027949d3..ed3c530158a7302110fd7f257dd4a60f4ec85830 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-showModal-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-showModal-expected.txt >@@ -1,17 +1,13 @@ > >-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> >+FAIL opening dialog without focusable children assert_equals: expected Element node <body><div id="log"></div> > <button id="b0">OK</button> >-<d... >+<d... but got Element node <button id="b5">OK</button> >+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 >diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/focus-after-close-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/focus-after-close-expected.txt >index e4645058483e00af8f4b0e04fb014328f7a80b86..5fc50deb7891123a2469372d3d77b9f37f3d0c67 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/focus-after-close-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/focus-after-close-expected.txt >@@ -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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 227537
:
433800
|
433841
|
433863
|
440840
|
440845
|
440893
|
440934
|
441113