Bug 225147

Summary: [selectors] :focus-visible and contenteditable
Product: WebKit Reporter: Manuel Rego Casasnovas <rego>
Component: CSSAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: rniwa, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 185859    
Attachments:
Description Flags
Example none

Description Manuel Rego Casasnovas 2021-04-28 03:11:03 PDT
This comes from a comment in a different bug:
https://bugs.webkit.org/show_bug.cgi?id=225075#c13

There we were talking about the condition in Element::shouldAlwaysHaveFocusVisibleWhenFocused().
And we were wondering if we should use isRootEditableElement() instead of isContentEditable().

I'm attaching an example like this:
    <style>
      :focus { border: solid thick magenta; }
      :focus-visible { background: cyan; } 
    </style>
    <div id="wrapper" contenteditable>
      <div>Inner DIV</div>
      <div id="target" tabindex="0">Inner DIV with tabindex</div>
      <div>Another inner DIV</div>
    </div>

Here the first time you click in DIV#target, the whole DIV#wrapper is focused. And the whole DIV#wrapper matches :focus-visible.
This time both isRootEditableElement() and isContentEditable() are true, because we're focusing DIV#wrapper.
The 2nd time we click in DIV#target, only DIV#target is focused, and only DIV#target matches :focus-visible.
Now isRootEditableElement() is false and isContentEditable() is true.

If we change the code to use isRootEditableElement(), then wewon't match :focus-visible in DIV#target in the 2nd click. So we'll be editing that element without matching :focus-visible which seems wrong.

Maybe the example should be different, or I'm missing some other combination.

Please Ryosuke share your thoughts. Thanks!
Comment 1 Manuel Rego Casasnovas 2021-04-28 03:28:48 PDT
Created attachment 427250 [details]
Example
Comment 2 Radar WebKit Bug Importer 2021-05-05 03:12:14 PDT
<rdar://problem/77549465>