Title: [295179] branches/safari-613-branch
Revision
295179
Author
[email protected]
Date
2022-06-02 23:45:17 -0700 (Thu, 02 Jun 2022)

Log Message

Cherry-pick 07c0107aa7af. rdar://problem/92301472

    [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.

    Canonical link: https://commits.webkit.org/250373@main
    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293926 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-613-branch/LayoutTests/imported/w3c/ChangeLog (295178 => 295179)


--- branches/safari-613-branch/LayoutTests/imported/w3c/ChangeLog	2022-06-03 06:45:13 UTC (rev 295178)
+++ branches/safari-613-branch/LayoutTests/imported/w3c/ChangeLog	2022-06-03 06:45:17 UTC (rev 295179)
@@ -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-16  Alan Coon  <[email protected]>
 
         Cherry-pick r294012. rdar://problem/92425915

Added: branches/safari-613-branch/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020-expected.txt (0 => 295179)


--- branches/safari-613-branch/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020-expected.txt	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020-expected.txt	2022-06-03 06:45:17 UTC (rev 295179)
@@ -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: branches/safari-613-branch/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020.html (0 => 295179)


--- branches/safari-613-branch/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-script-focus-020.html	2022-06-03 06:45:17 UTC (rev 295179)
@@ -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: branches/safari-613-branch/Source/WebCore/ChangeLog (295178 => 295179)


--- branches/safari-613-branch/Source/WebCore/ChangeLog	2022-06-03 06:45:13 UTC (rev 295178)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog	2022-06-03 06:45:17 UTC (rev 295179)
@@ -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-25  Alan Coon  <[email protected]>
 
         Cherry-pick a173819be243. rdar://problem/87980543

Modified: branches/safari-613-branch/Source/WebCore/dom/Document.cpp (295178 => 295179)


--- branches/safari-613-branch/Source/WebCore/dom/Document.cpp	2022-06-03 06:45:13 UTC (rev 295178)
+++ branches/safari-613-branch/Source/WebCore/dom/Document.cpp	2022-06-03 06:45:17 UTC (rev 295179)
@@ -4671,7 +4671,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