- Revision
- 292987
- Author
- alanc...@apple.com
- Date
- 2022-04-18 17:49:31 -0700 (Mon, 18 Apr 2022)
Log Message
Cherry-pick r292400. rdar://problem/89382543
[macOS][selectors] :focus-visible matching on button focused via script (after clicking on a different button)
https://bugs.webkit.org/show_bug.cgi?id=236782
<rdar://problem/89382543>
Reviewed by Antti Koivisto.
LayoutTests/imported/w3c:
Add specific test for <button> element.
* web-platform-tests/css/selectors/focus-visible-script-focus-008-b-expected.txt: Added.
* web-platform-tests/css/selectors/focus-visible-script-focus-008-b.html: Added.
Source/WebCore:
Document::m_latestFocusTrigger was not being updated after clicking on a button (or other form controls)
on platforms different than GTK and WPE.
This is because HTMLFormControlElement::isMouseFocusable() returns false on such platforms.
This issue is causing problems with :focus-visible, as the button is not actually focused via mouse click,
if you move the focus via script afterwards, the new focused element always match :focus-visible.
This patch is a workaround to solve that issue, by updating m_latestFocusTrigger on Document
even if the element is not actually focused.
That way :focus-visible doesn't match if there's a script focus afterwards.
Fix :focus-visible after clicking on a button on Mac
Test: imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-008-b.html
* dom/Document.h:
(WebCore::Document::setLatestFocusTrigger):
* page/EventHandler.cpp:
(WebCore::EventHandler::dispatchMouseEvent):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@292400 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Modified Paths
Added Paths
Diff
Modified: branches/safari-613-branch/LayoutTests/imported/w3c/ChangeLog (292986 => 292987)
--- branches/safari-613-branch/LayoutTests/imported/w3c/ChangeLog 2022-04-19 00:49:26 UTC (rev 292986)
+++ branches/safari-613-branch/LayoutTests/imported/w3c/ChangeLog 2022-04-19 00:49:31 UTC (rev 292987)
@@ -1,3 +1,58 @@
+2022-04-18 Kocsen Chung <kocsen_ch...@apple.com>
+
+ Cherry-pick r292400. rdar://problem/89382543
+
+ [macOS][selectors] :focus-visible matching on button focused via script (after clicking on a different button)
+ https://bugs.webkit.org/show_bug.cgi?id=236782
+ <rdar://problem/89382543>
+
+ Reviewed by Antti Koivisto.
+
+ LayoutTests/imported/w3c:
+
+ Add specific test for <button> element.
+
+ * web-platform-tests/css/selectors/focus-visible-script-focus-008-b-expected.txt: Added.
+ * web-platform-tests/css/selectors/focus-visible-script-focus-008-b.html: Added.
+
+ Source/WebCore:
+
+ Document::m_latestFocusTrigger was not being updated after clicking on a button (or other form controls)
+ on platforms different than GTK and WPE.
+ This is because HTMLFormControlElement::isMouseFocusable() returns false on such platforms.
+
+ This issue is causing problems with :focus-visible, as the button is not actually focused via mouse click,
+ if you move the focus via script afterwards, the new focused element always match :focus-visible.
+
+ This patch is a workaround to solve that issue, by updating m_latestFocusTrigger on Document
+ even if the element is not actually focused.
+ That way :focus-visible doesn't match if there's a script focus afterwards.
+
+ Fix :focus-visible after clicking on a button on Mac
+
+ Test: imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-008-b.html
+
+ * dom/Document.h:
+ (WebCore::Document::setLatestFocusTrigger):
+ * page/EventHandler.cpp:
+ (WebCore::EventHandler::dispatchMouseEvent):
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@292400 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2022-04-05 Manuel Rego Casasnovas <r...@igalia.com>
+
+ [macOS][selectors] :focus-visible matching on button focused via script (after clicking on a different button)
+ https://bugs.webkit.org/show_bug.cgi?id=236782
+ <rdar://problem/89382543>
+
+ Reviewed by Antti Koivisto.
+
+ Add specific test for <button> element.
+
+ * web-platform-tests/css/selectors/focus-visible-script-focus-008-b-expected.txt: Added.
+ * web-platform-tests/css/selectors/focus-visible-script-focus-008-b.html: Added.
+
2022-04-07 Alan Coon <alanc...@apple.com>
Cherry-pick r292155. rdar://problem/90572543
Added: branches/safari-613-branch/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-008-b-expected.txt (0 => 292987)
--- branches/safari-613-branch/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-008-b-expected.txt (rev 0)
+++ branches/safari-613-branch/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-008-b-expected.txt 2022-04-19 00:49:31 UTC (rev 292987)
@@ -0,0 +1,10 @@
+This test checks that a script focus after a mouse click on a button that does not match :focus visible, does NOT match :focus-visible.
+
+Click on the button that says "Click me".
+If the element that says "Focused" has a red outline then the test result is FAILURE, if it has a green background then the test result is SUCCESS.
+Click me
+Focused
+
+PASS ":focus-visible" should be a valid selector
+PASS Script focus after mouse click on a button that does not match :focus-visible, does NOT match :focus-visible
+
Added: branches/safari-613-branch/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-008-b.html (0 => 292987)
--- branches/safari-613-branch/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-008-b.html (rev 0)
+++ branches/safari-613-branch/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-008-b.html 2022-04-19 00:49:31 UTC (rev 292987)
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>CSS Test (Selectors): Script focus after mouse click on a button that does not match :focus-visible, does NOT match :focus-visible</title>
+<link rel="author" title="Manuel Rego Casasnovas" href=""
+<link rel="help" href="" />
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<style>
+ #warning {
+ display: none;
+ background: red;
+ }
+
+ @supports not selector(:focus-visible) {
+ #instructions {
+ display: none;
+ }
+
+ #warning {
+ display: block;
+ }
+ }
+
+ :focus-visible {
+ outline: solid thick red;
+ }
+
+ :focus:not(:focus-visible) {
+ background-color: lime;
+ }
+</style>
+
+<p>This test checks that a script focus after a mouse click on a button that does not match <code>:focus visible</code>, does NOT match <code>:focus-visible</code>.</p>
+<ol id="instructions">
+ <li>Click on the button that says "Click me".</li>
+ <li>If the element that says "Focused" has a red outline then the test result is FAILURE, if it has a green background then the test result is SUCCESS.</li>
+</ol>
+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>
+
+<button id="initial">Click me</button>
+<div id="target" tabindex="0">Focused</div>
+
+<script>
+ setup({ explicit_done: true });
+
+ // Check that :focus-visible is supported.
+ test_valid_selector(':focus-visible');
+
+ initial.addEventListener("click", () => {
+ target.focus();
+ });
+
+ async_test(function(t) {
+ target.addEventListener("focus", t.step_func_done(function() {
+ assert_equals(getComputedStyle(target).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${target.tagName}#${target.id} should be lime`);
+ assert_not_equals(getComputedStyle(target).outlineColor, "rgb(255, 0, 0)", `outlineColor for ${target.tagName}#${target.id} should NOT be red`);
+ }));
+
+ test_driver.click(initial).then(() => done());
+ }, "Script focus after mouse click on a button that does not match :focus-visible, does NOT match :focus-visible");
+</script>
Modified: branches/safari-613-branch/Source/WebCore/ChangeLog (292986 => 292987)
--- branches/safari-613-branch/Source/WebCore/ChangeLog 2022-04-19 00:49:26 UTC (rev 292986)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog 2022-04-19 00:49:31 UTC (rev 292987)
@@ -1,5 +1,75 @@
2022-04-18 Kocsen Chung <kocsen_ch...@apple.com>
+ Cherry-pick r292400. rdar://problem/89382543
+
+ [macOS][selectors] :focus-visible matching on button focused via script (after clicking on a different button)
+ https://bugs.webkit.org/show_bug.cgi?id=236782
+ <rdar://problem/89382543>
+
+ Reviewed by Antti Koivisto.
+
+ LayoutTests/imported/w3c:
+
+ Add specific test for <button> element.
+
+ * web-platform-tests/css/selectors/focus-visible-script-focus-008-b-expected.txt: Added.
+ * web-platform-tests/css/selectors/focus-visible-script-focus-008-b.html: Added.
+
+ Source/WebCore:
+
+ Document::m_latestFocusTrigger was not being updated after clicking on a button (or other form controls)
+ on platforms different than GTK and WPE.
+ This is because HTMLFormControlElement::isMouseFocusable() returns false on such platforms.
+
+ This issue is causing problems with :focus-visible, as the button is not actually focused via mouse click,
+ if you move the focus via script afterwards, the new focused element always match :focus-visible.
+
+ This patch is a workaround to solve that issue, by updating m_latestFocusTrigger on Document
+ even if the element is not actually focused.
+ That way :focus-visible doesn't match if there's a script focus afterwards.
+
+ Fix :focus-visible after clicking on a button on Mac
+
+ Test: imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-008-b.html
+
+ * dom/Document.h:
+ (WebCore::Document::setLatestFocusTrigger):
+ * page/EventHandler.cpp:
+ (WebCore::EventHandler::dispatchMouseEvent):
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@292400 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2022-04-05 Manuel Rego Casasnovas <r...@igalia.com>
+
+ [macOS][selectors] :focus-visible matching on button focused via script (after clicking on a different button)
+ https://bugs.webkit.org/show_bug.cgi?id=236782
+ <rdar://problem/89382543>
+
+ Reviewed by Antti Koivisto.
+
+ Document::m_latestFocusTrigger was not being updated after clicking on a button (or other form controls)
+ on platforms different than GTK and WPE.
+ This is because HTMLFormControlElement::isMouseFocusable() returns false on such platforms.
+
+ This issue is causing problems with :focus-visible, as the button is not actually focused via mouse click,
+ if you move the focus via script afterwards, the new focused element always match :focus-visible.
+
+ This patch is a workaround to solve that issue, by updating m_latestFocusTrigger on Document
+ even if the element is not actually focused.
+ That way :focus-visible doesn't match if there's a script focus afterwards.
+
+ Fix :focus-visible after clicking on a button on Mac
+
+ Test: imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-008-b.html
+
+ * dom/Document.h:
+ (WebCore::Document::setLatestFocusTrigger):
+ * page/EventHandler.cpp:
+ (WebCore::EventHandler::dispatchMouseEvent):
+
+2022-04-18 Kocsen Chung <kocsen_ch...@apple.com>
+
Cherry-pick r292310. rdar://problem/91255370
Simplify / Optimize the whitespace cache implementation
Modified: branches/safari-613-branch/Source/WebCore/dom/Document.h (292986 => 292987)
--- branches/safari-613-branch/Source/WebCore/dom/Document.h 2022-04-19 00:49:26 UTC (rev 292986)
+++ branches/safari-613-branch/Source/WebCore/dom/Document.h 2022-04-19 00:49:31 UTC (rev 292987)
@@ -792,6 +792,7 @@
WEBCORE_EXPORT bool setFocusedElement(Element*, const FocusOptions& = { });
Element* focusedElement() const { return m_focusedElement.get(); }
bool wasLastFocusByClick() const { return m_latestFocusTrigger == FocusTrigger::Click; }
+ void setLatestFocusTrigger(FocusTrigger trigger) { m_latestFocusTrigger = trigger; }
UserActionElementSet& userActionElements() { return m_userActionElements; }
const UserActionElementSet& userActionElements() const { return m_userActionElements; }
Modified: branches/safari-613-branch/Source/WebCore/page/EventHandler.cpp (292986 => 292987)
--- branches/safari-613-branch/Source/WebCore/page/EventHandler.cpp 2022-04-19 00:49:26 UTC (rev 292986)
+++ branches/safari-613-branch/Source/WebCore/page/EventHandler.cpp 2022-04-19 00:49:31 UTC (rev 292987)
@@ -2789,6 +2789,15 @@
if (!element && isInsideScrollbar(platformMouseEvent.position()))
return false;
+#if (!PLATFORM(GTK) && !PLATFORM(WPE))
+ // This is a workaround related to :focus-visible (see webkit.org/b/236782).
+ // Form control elements are not mouse focusable on some platforms (see HTMLFormControlElement::isMouseFocusable())
+ // which makes us behave differently than other browsers when a button is clicked,
+ // because the button is not actually focused so we don't set the latest FocusTrigger.
+ if (m_elementUnderMouse && !m_elementUnderMouse->isMouseFocusable() && is<HTMLFormControlElement>(m_elementUnderMouse))
+ m_frame.document()->setLatestFocusTrigger(FocusTrigger::Click);
+#endif
+
// If focus shift is blocked, we eat the event.
auto* page = m_frame.page();
if (page && !CheckedRef(page->focusController())->setFocusedElement(element.get(), m_frame, { { }, { }, { }, FocusTrigger::Click, { } }))