<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>237273</bug_id>
          
          <creation_ts>2022-02-28 06:20:53 -0800</creation_ts>
          <short_desc>Implement focus fixup rule</short_desc>
          <delta_ts>2023-02-09 09:46:54 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Tim Nguyen (:ntim)">ntim</reporter>
          <assigned_to name="Ryosuke Niwa">rniwa</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>emilio</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1846620</commentid>
    <comment_count>0</comment_count>
    <who name="Tim Nguyen (:ntim)">ntim</who>
    <bug_when>2022-02-28 06:20:53 -0800</bug_when>
    <thetext>https://html.spec.whatwg.org/multipage/interaction.html#focus-fixup-rule

Focus fixup rule: When the designated focused area of the document is removed from that Document in some way (e.g. it stops being a focusable area, it is removed from the DOM, it becomes inert, etc.), designate the Document&apos;s viewport to be the new focused area of the document.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1846623</commentid>
    <comment_count>1</comment_count>
    <who name="Tim Nguyen (:ntim)">ntim</who>
    <bug_when>2022-02-28 06:38:28 -0800</bug_when>
    <thetext>Adding this seems to work:

```
        if (auto* activeElement = document.activeElement()) {
            if (!activeElement-&gt;isFocusable())
                document.setFocusedElement(nullptr);
        }
```

I put it in the RenderingUpdateStep::FlushAutofocusCandidates block, but that&apos;s probably not the right place (not sure which one is?).

One thing that&apos;s broken is interaction with shadow DOM: shadow-dom/focus/focus-pseudo-on-shadow-host-1.html fails. This is precisely because activeElement-&gt;isFocusable() doesn&apos;t take in account contents of the shadow DOM, and wrongly clears focus in this case. Though I expect that&apos;s not too hard to fix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1846624</commentid>
    <comment_count>2</comment_count>
    <who name="Tim Nguyen (:ntim)">ntim</who>
    <bug_when>2022-02-28 06:40:04 -0800</bug_when>
    <thetext>imported/w3c/web-platform-tests/inert/dynamic-inert-on-focused-element.tentative.html tests this functionality.

I&apos;m actually a bit surprised there aren&apos;t more tests (e.g. moving out of a focusable area, disabled attribute, etc.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1848718</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-03-07 06:21:13 -0800</bug_when>
    <thetext>&lt;rdar://problem/89902824&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1890952</commentid>
    <comment_count>4</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2022-08-12 11:28:55 -0700</bug_when>
    <thetext>Safari TP 151 is still failing these tests:

https://wpt.fyi/results/inert/dynamic-inert-on-focused-element.html?label=master&amp;label=experimental&amp;aligned&amp;view=subtest&amp;q=dynamic-inert-on-focused-element</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1909964</commentid>
    <comment_count>5</comment_count>
    <who name="Tim Nguyen (:ntim)">ntim</who>
    <bug_when>2022-11-02 18:51:55 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/6069</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1932125</commentid>
    <comment_count>6</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2023-02-08 13:35:55 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/9835</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1932369</commentid>
    <comment_count>7</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-02-09 09:46:51 -0800</bug_when>
    <thetext>Committed 260067@main (71bc5343fd7b): &lt;https://commits.webkit.org/260067@main&gt;

Reviewed commits have been landed. Closing PR #9835 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>