Title: [293926] trunk
Revision
293926
Author
[email protected]
Date
2022-05-06 15:06:52 -0700 (Fri, 06 May 2022)

Log Message

[selectors] Double script focus after mouse click shouldn't match :focus-visible
https://bugs.webkit.org/show_bug.cgi?id=239472
<rdar://problem/92301472>

Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

* web-platform-tests/css/selectors/focus-visible-script-focus-020-expected.txt: Added.
* web-platform-tests/css/selectors/focus-visible-script-focus-020.html: Added.

Source/WebCore:

When you do the second script focus, we were setting
m_latestFocusTrigger to FocusTrigger::Bindings, that makes us lose the
information about the previous element that was focused via mouse
click and start matching :focus-visible on that case.

Test: imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020.html

* dom/Document.cpp:
(WebCore::Document::setFocusedElement): We avoid setting
m_latestFocusTrigger if we come from script focus. That way we know if
the previous focused element was focused via mouse click after several
script focus.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (293925 => 293926)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-05-06 21:54:27 UTC (rev 293925)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-05-06 22:06:52 UTC (rev 293926)
@@ -1,3 +1,14 @@
+2022-05-06  Manuel Rego Casasnovas  <[email protected]>
+
+        [selectors] Double script focus after mouse click shouldn't match :focus-visible
+        https://bugs.webkit.org/show_bug.cgi?id=239472
+        <rdar://problem/92301472>
+
+        Reviewed by Antti Koivisto.
+
+        * web-platform-tests/css/selectors/focus-visible-script-focus-020-expected.txt: Added.
+        * web-platform-tests/css/selectors/focus-visible-script-focus-020.html: Added.
+
 2022-05-05  Ben Nham  <[email protected]>
         
         Add support for Notification objects with custom data

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020-expected.txt (0 => 293926)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020-expected.txt	2022-05-06 22:06:52 UTC (rev 293926)
@@ -0,0 +1,10 @@
+This test checks that a double script focus after a mouse click on a focusable element that does not match :focus visible, does NOT match :focus-visible.
+
+Click on the element 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 Double script focus after mouse click on a focusable element that does not match :focus-visible, does NOT match :focus-visible
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020.html (0 => 293926)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020.html	2022-05-06 22:06:52 UTC (rev 293926)
@@ -0,0 +1,70 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>CSS Test (Selectors): Double script focus after mouse click on a focusable element 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 double script focus after a mouse click on a focusable element that does not match <code>:focus visible</code>, does NOT match <code>:focus-visible</code>.</p>
+<ol id="instructions">
+  <li>Click on the element 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>
+
+<div id="initial" tabindex="0">Click me</div>
+<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();
+    target.blur();
+    target.focus();
+  });
+
+  async_test(function(t) {
+    let count = 0;
+    target.addEventListener("focus", t.step_func(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`);
+      if (count > 0)
+        t.done();
+      count++;
+    }));
+
+    test_driver.click(initial).then(() => done());
+  }, "Double script focus after mouse click on a focusable element that does not match :focus-visible, does NOT match :focus-visible");
+</script>

Modified: trunk/Source/WebCore/ChangeLog (293925 => 293926)


--- trunk/Source/WebCore/ChangeLog	2022-05-06 21:54:27 UTC (rev 293925)
+++ trunk/Source/WebCore/ChangeLog	2022-05-06 22:06:52 UTC (rev 293926)
@@ -1,3 +1,24 @@
+2022-05-06  Manuel Rego Casasnovas  <[email protected]>
+
+        [selectors] Double script focus after mouse click shouldn't match :focus-visible
+        https://bugs.webkit.org/show_bug.cgi?id=239472
+        <rdar://problem/92301472>
+
+        Reviewed by Antti Koivisto.
+
+        When you do the second script focus, we were setting
+        m_latestFocusTrigger to FocusTrigger::Bindings, that makes us lose the
+        information about the previous element that was focused via mouse
+        click and start matching :focus-visible on that case.
+
+        Test: imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::setFocusedElement): We avoid setting
+        m_latestFocusTrigger if we come from script focus. That way we know if
+        the previous focused element was focused via mouse click after several
+        script focus.
+
 2022-05-06  Brent Fulgham  <[email protected]>
 
         Remove abandoned WKPreference for SelectionPaintingWithoutSelectionGaps

Modified: trunk/Source/WebCore/dom/Document.cpp (293925 => 293926)


--- trunk/Source/WebCore/dom/Document.cpp	2022-05-06 21:54:27 UTC (rev 293925)
+++ trunk/Source/WebCore/dom/Document.cpp	2022-05-06 22:06:52 UTC (rev 293926)
@@ -4739,7 +4739,8 @@
         m_focusedElement = newFocusedElement;
         setFocusNavigationStartingNode(m_focusedElement.get());
         m_focusedElement->setFocus(true, options.visibility);
-        m_latestFocusTrigger = options.trigger;
+        if (options.trigger != FocusTrigger::Bindings)
+            m_latestFocusTrigger = options.trigger;
 
         // The setFocus call triggers a blur and a focus event. Event handlers could cause the focused element to be cleared.
         if (m_focusedElement != newFocusedElement) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to