Changeset 287563 in webkit


Ignore:
Timestamp:
Jan 4, 2022 5:29:08 AM (7 months ago)
Author:
Manuel Rego Casasnovas
Message:

[selectors] :focus-visible not matching on accessKey focus after focusing something via mouse
https://bugs.webkit.org/show_bug.cgi?id=234077
<rdar://problem/86572561>

Reviewed by Antti Koivisto.

Source/WebCore:

This patch adds Element::focusForBindings() to differentitate when this is called from JavaScript.
If that's the case it pass a new FocusTrigger::Bindings value to Element::focus(),
so we can differentiate when this was called from some internal code or from JavaScript.

When Element::focus() has been called internally, we always want to show the focus ring
(thus pass FocusVisibility::Visible). However when it's called from a script
we'll set it to Visible or Invisible depending on if the previously focused element
was focused via mouse click or not (this is needed to pass
the css/selectors/focus-visible-script-focus-* tests from WPT repository).

Test: fast/selectors/focus-visible-accesskey.html

  • dom/Element.cpp:

(WebCore::Element::focus):
(WebCore::Element::focusForBindings):

  • dom/Element.h:

(WebCore::Element::focusForBindings):

  • dom/FocusOptions.h:
  • html/HTMLOrForeignElement.idl:

LayoutTests:

Writing an internal test as WPT tests for this don't work due to webkit.org/b/234139.

  • fast/selectors/focus-visible-accesskey-expected.txt: Added.
  • fast/selectors/focus-visible-accesskey.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r287559 r287563  
     12022-01-04  Manuel Rego Casasnovas  <rego@igalia.com>
     2
     3        [selectors] :focus-visible not matching on accessKey focus after focusing something via mouse
     4        https://bugs.webkit.org/show_bug.cgi?id=234077
     5        <rdar://problem/86572561>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Writing an internal test as WPT tests for this don't work due to webkit.org/b/234139.
     10
     11        * fast/selectors/focus-visible-accesskey-expected.txt: Added.
     12        * fast/selectors/focus-visible-accesskey.html: Added.
     13
    1142022-01-03  Diego Pino Garcia  <dpino@igalia.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r287558 r287563  
     12022-01-04  Manuel Rego Casasnovas  <rego@igalia.com>
     2
     3        [selectors] :focus-visible not matching on accessKey focus after focusing something via mouse
     4        https://bugs.webkit.org/show_bug.cgi?id=234077
     5        <rdar://problem/86572561>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        This patch adds Element::focusForBindings() to differentitate when this is called from JavaScript.
     10        If that's the case it pass a new FocusTrigger::Bindings value to Element::focus(),
     11        so we can differentiate when this was called from some internal code or from JavaScript.
     12
     13        When Element::focus() has been called internally, we always want to show the focus ring
     14        (thus pass FocusVisibility::Visible). However when it's called from a script
     15        we'll set it to Visible or Invisible depending on if the previously focused element
     16        was focused via mouse click or not (this is needed to pass
     17        the css/selectors/focus-visible-script-focus-* tests from WPT repository).
     18
     19        Test: fast/selectors/focus-visible-accesskey.html
     20
     21        * dom/Element.cpp:
     22        (WebCore::Element::focus):
     23        (WebCore::Element::focusForBindings):
     24        * dom/Element.h:
     25        (WebCore::Element::focusForBindings):
     26        * dom/FocusOptions.h:
     27        * html/HTMLOrForeignElement.idl:
     28
    1292022-01-03  Alan Bujtas  <zalan@apple.com>
    230
  • trunk/Source/WebCore/dom/Element.cpp

    r287540 r287563  
    30983098
    30993099        FocusOptions optionsWithVisibility = options;
    3100         if (!document->wasLastFocusByClick())
     3100        if (options.trigger == FocusTrigger::Bindings && document->wasLastFocusByClick())
     3101            optionsWithVisibility.visibility = FocusVisibility::Invisible;
     3102        else
    31013103            optionsWithVisibility.visibility = FocusVisibility::Visible;
    31023104
     
    31093111
    31103112    newTarget->findTargetAndUpdateFocusAppearance(options.selectionRestorationMode, options.preventScroll ? SelectionRevealMode::DoNotReveal : SelectionRevealMode::Reveal);
     3113}
     3114
     3115void Element::focusForBindings(FocusOptions&& options)
     3116{
     3117    options.trigger = FocusTrigger::Bindings;
     3118    focus(WTFMove(options));
    31113119}
    31123120
  • trunk/Source/WebCore/dom/Element.h

    r287461 r287563  
    427427    static AXTextStateChangeIntent defaultFocusTextStateChangeIntent() { return AXTextStateChangeIntent(AXTextStateChangeTypeSelectionMove, AXTextSelection { AXTextSelectionDirectionDiscontiguous, AXTextSelectionGranularityUnknown, true }); }
    428428    virtual void focus(const FocusOptions& = { });
     429    virtual void focusForBindings(FocusOptions&&);
    429430    void findTargetAndUpdateFocusAppearance(SelectionRestorationMode, SelectionRevealMode = SelectionRevealMode::Reveal);
    430431    virtual RefPtr<Element> focusAppearanceUpdateTarget();
  • trunk/Source/WebCore/dom/FocusOptions.h

    r276628 r287563  
    3333enum class FocusRemovalEventsMode : bool { Dispatch, DoNotDispatch };
    3434
    35 enum class FocusTrigger : bool { Other, Click };
     35enum class FocusTrigger : uint8_t { Other, Click, Bindings };
    3636
    3737enum class FocusVisibility : bool { Invisible, Visible };
  • trunk/Source/WebCore/html/HTMLOrForeignElement.idl

    r285478 r287563  
    3333    [CEReactions=NotNeeded, Reflect] attribute boolean autofocus;
    3434    [CEReactions, ImplementedAs=tabIndexForBindings] attribute long tabIndex;
    35     undefined focus(optional FocusOptions options);
     35    [ImplementedAs=focusForBindings] undefined focus(optional FocusOptions options);
    3636    undefined blur();
    3737};
Note: See TracChangeset for help on using the changeset viewer.