Changeset 274365 in webkit


Ignore:
Timestamp:
Mar 12, 2021 11:03:26 AM (16 months ago)
Author:
Manuel Rego Casasnovas
Message:

[selectors] :focus-visible matches body after keyboard event
https://bugs.webkit.org/show_bug.cgi?id=223113

Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

  • web-platform-tests/css/selectors/focus-visible-001.html: Modify the test to verify

that only the element matches :focus-visible (and not the body).

  • web-platform-tests/css/selectors/focus-visible-019-expected.txt: Added.
  • web-platform-tests/css/selectors/focus-visible-019.html: Added new test to check script focus in keyboard event,

and that again only the element matches :focus-visible (and not the body).

Source/WebCore:

Fix the bug with some changes in EventHandler::internalKeyEvent().
When you use TAB (or other key) the |element| variable in this method is the document body,
however that element is not focused (element->focused() is false).
Before this patch we were marking the element as matchin :focus-visible,
however we shouldn't do that if the element is not focused (added a condition to avoid doing that).

Apart from that this patch also fixes a related issue, if a keyboard event handler is changing focus via script
there's a part of this method that takes care of updating the |element| variable.
In that case we have to remove :focus-visible flag from the previous element, and add it to the new one.

Test: imported/w3c/web-platform-tests/css/selectors/focus-visible-001.html
Test: imported/w3c/web-platform-tests/css/selectors/focus-visible-019.html

  • page/EventHandler.cpp:

(WebCore::EventHandler::internalKeyEvent):

LayoutTests:

  • platform/ios/TestExpectations: Skip new test for iOS.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r274359 r274365  
     12021-03-12  Manuel Rego Casasnovas  <rego@igalia.com>
     2
     3        [selectors] :focus-visible matches body after keyboard event
     4        https://bugs.webkit.org/show_bug.cgi?id=223113
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * platform/ios/TestExpectations: Skip new test for iOS.
     9
    1102021-03-12  Robert Jenner  <jenner@apple.com>
    211
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r274355 r274365  
     12021-03-12  Manuel Rego Casasnovas  <rego@igalia.com>
     2
     3        [selectors] :focus-visible matches body after keyboard event
     4        https://bugs.webkit.org/show_bug.cgi?id=223113
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * web-platform-tests/css/selectors/focus-visible-001.html: Modify the test to verify
     9        that only the element matches :focus-visible (and not the body).
     10        * web-platform-tests/css/selectors/focus-visible-019-expected.txt: Added.
     11        * web-platform-tests/css/selectors/focus-visible-019.html: Added new test to check script focus in keyboard event,
     12        and that again only the element matches :focus-visible (and not the body).
     13
    1142021-03-12  Antoine Quint  <graouts@webkit.org>
    215
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-001.html

    r271395 r274365  
    4040  <script>
    4141    async_test(function(t) {
    42       el.addEventListener("focus", t.step_func(function() {
     42      el.addEventListener("focus", t.step_func_done(function() {
    4343        assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${el.tagName}#${el.id} should be green`);
    4444        assert_not_equals(getComputedStyle(el).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${el.tagName}#${el.id} should NOT be red`);
    45         t.done();
     45
     46        let focusVisiblePseudoAll = document.querySelectorAll(':focus-visible');
     47        assert_equals(focusVisiblePseudoAll.length, 1, "Only 1 element matches ':focus-visible'");
     48        let focusVisiblePseudo = document.querySelector(':focus-visible');
     49        assert_equals(el, focusVisiblePseudo, "${el.tagName}#${el.id} matches ':focus-visible'");
    4650      }));
    4751      const tab_key = '\ue004';
  • trunk/LayoutTests/platform/ios/TestExpectations

    r274244 r274365  
    33963396webkit.org/b/209734 imported/w3c/web-platform-tests/css/selectors/focus-visible-012.html [ Skip ]
    33973397webkit.org/b/209734 imported/w3c/web-platform-tests/css/selectors/focus-visible-013.html [ Skip ]
     3398webkit.org/b/209734 imported/w3c/web-platform-tests/css/selectors/focus-visible-019.html [ Skip ]
    33983399webkit.org/b/209734 imported/w3c/web-platform-tests/css/selectors/hover-002.html [ Skip ]
    33993400
  • trunk/Source/WebCore/ChangeLog

    r274362 r274365  
     12021-03-12  Manuel Rego Casasnovas  <rego@igalia.com>
     2
     3        [selectors] :focus-visible matches body after keyboard event
     4        https://bugs.webkit.org/show_bug.cgi?id=223113
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Fix the bug with some changes in EventHandler::internalKeyEvent().
     9        When you use TAB (or other key) the |element| variable in this method is the document body,
     10        however that element is not focused (element->focused() is false).
     11        Before this patch we were marking the element as matchin :focus-visible,
     12        however we shouldn't do that if the element is not focused (added a condition to avoid doing that).
     13
     14        Apart from that this patch also fixes a related issue, if a keyboard event handler is changing focus via script
     15        there's a part of this method that takes care of updating the |element| variable.
     16        In that case we have to remove :focus-visible flag from the previous element, and add it to the new one.
     17
     18        Test: imported/w3c/web-platform-tests/css/selectors/focus-visible-001.html
     19        Test: imported/w3c/web-platform-tests/css/selectors/focus-visible-019.html
     20
     21        * page/EventHandler.cpp:
     22        (WebCore::EventHandler::internalKeyEvent):
     23
    1242021-03-12  Alex Christensen  <achristensen@webkit.org>
    225
  • trunk/Source/WebCore/page/EventHandler.cpp

    r274352 r274365  
    35343534    keydown->setTarget(element);
    35353535
    3536     // If the user interacts with the page via the keyboard, the currently focused element should match :focus-visible.
    3537     // Just typing a modifier key is not considered user interaction with the page, but Shift + a (or Caps Lock + a) is considered an interaction.
    3538     if (keydown->modifierKeys().isEmpty() || ((keydown->shiftKey() || keydown->capsLockKey()) && !initialKeyEvent.text().isEmpty()))
    3539         element->setHasFocusVisible(true);
     3536    auto shouldMatchFocusVisible = [initialKeyEvent, keydown](const Element& element) {
     3537        if (!element.focused())
     3538            return false;
     3539
     3540        // If the user interacts with the page via the keyboard, the currently focused element should match :focus-visible.
     3541        // Just typing a modifier key is not considered user interaction with the page, but Shift + a (or Caps Lock + a) is considered an interaction.
     3542        return keydown->modifierKeys().isEmpty() || ((keydown->shiftKey() || keydown->capsLockKey()) && !initialKeyEvent.text().isEmpty());
     3543    };
     3544    element->setHasFocusVisible(shouldMatchFocusVisible(*element));
    35403545
    35413546    if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) {
     
    35843589    // But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original element.
    35853590    if (!keydownResult) {
     3591        element->setHasFocusVisible(false);
    35863592        element = eventTargetElementForDocument(m_frame.document());
    35873593        if (!element)
    35883594            return false;
     3595        element->setHasFocusVisible(shouldMatchFocusVisible(*element));
    35893596    }
    35903597
Note: See TracChangeset for help on using the changeset viewer.