Skip to content

Commit

Permalink
Yet more fixes to focus delegation
Browse files Browse the repository at this point in the history
Fixes #8156. Fixes #8157.

See also previous work in #7361, #7284, and #7079.
  • Loading branch information
domenic authored Oct 22, 2022
1 parent b9a961d commit 4d6609f
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -76857,51 +76857,59 @@ partial interface <span id="NavigatorUserActivation-partial">Navigator</span> {
<dd><p>Return null.</p></dd>
</dl>

<p>The <dfn>focus delegate</dfn> for a <var>focus target</var>, given an optional string
<var>focus trigger</var> (default "<code data-x="">other</code>"), is given by the following
<p>The <dfn>focus delegate</dfn> for a <var>focusTarget</var>, given an optional string
<var>focusTrigger</var> (default "<code data-x="">other</code>"), is given by the following
steps:</p>

<ol>
<li><p>Let <var>autofocus delegate</var> be the <span>autofocus delegate</span> for <var>focus
target</var> given <var>focus trigger</var>.</p></li>

<li><p>If <var>autofocus delegate</var> is not null, then return <var>autofocus
delegate</var>.</p></li>

<li><p>If <var>focus target</var> is a <span>shadow host</span> and its <span
<li><p>If <var>focusTarget</var> is a <span>shadow host</span> and its <span
data-x="concept-element-shadow-root">shadow root</span>'s <span>delegates focus</span> is false,
then return null.</p></li>

<li><p>Let <var>parent</var> be <var>focus target</var>.</p></li>
<li><p>Let <var>whereToLook</var> be <var>focusTarget</var>.</p></li>

<li><p>If <var>whereToLook</var> is a <span>shadow host</span>, then set <var>whereToLook</var>
to <var>whereToLook</var>'s <span data-x="concept-element-shadow-root">shadow
root</span>.</p></li>

<li><p>Let <var>autofocusDelegate</var> be the <span>autofocus delegate</span> for
<var>whereToLook</var> given <var>focusTrigger</var>.</p></li>

<li><p>If <var>parent</var> is a <span>shadow host</span>, then set <var>parent</var> to
<var>parent</var>'s <span data-x="concept-element-shadow-root">shadow root</span>.</p></li>
<li><p>If <var>autofocusDelegate</var> is not null, then return
<var>autofocusDelegate</var>.</p></li>

<li>
<p><span data-x="list iterate">For each</span> <var>child</var> of <var>parent</var>'s <span
data-x="concept-tree-child">children</span>:</p>
<p><span data-x="list iterate">For each</span> <var>descendant</var> of
<var>whereToLook</var>'s <span data-x="descendant">descendants</span>, in <span>tree
order</span>:</p>

<ol>
<li><p>If <var>descendant</var> is a <span>focusable area</span>, then return
<var>descendant</var>.</p></li>

<li>
<p>Let <var>focusable area</var> be <var>child</var>, if <var>child</var> is a
<span>focusable area</span>; otherwise let <var>focusable area</var> be the result of <span
data-x="get the focusable area">getting the focusable area</span> for <var>child</var> given
<var>focus trigger</var>.</p>
<p>Let <var>focusableArea</var> be the result of <span data-x="get the focusable
area">getting the focusable area</span> for <var>descendant</var> given
<var>focusTrigger</var>.</p>

<p class="note">This step can end up recursing, i.e., the <span>get the focusable area</span>
steps might return the <span>focus delegate</span> of <var>child</var>.</p>
steps might return the <span>focus delegate</span> of <var>descendant</var>.</p>
</li>

<li><p>If <var>focusable area</var> is not null, then return <var>focusable
area</var>.</p></li>
<li><p>If <var>focusableArea</var> is not null, then return <var>focusableArea</var>.</p></li>
</ol>

<p class="note">It's important that we are <em>not</em> looking at the <span
data-x="shadow-including descendant">shadow-including descendants</span> here, but instead only
at the <span data-x="descendant">descendants</span>. <span data-x="shadow host">Shadow
hosts</span> are instead handled by the recursive case mentioned above.</p>
</li>

<li><p>Return null.</p></li>
</ol>

<p class="note">The above algorithm essentially returns the first suitable <span>focusable
area</span> where the path between its <span>DOM anchor</span> and <var>focus target</var>
area</span> where the path between its <span>DOM anchor</span> and <var>focusTarget</var>
delegates focus at any shadow tree boundaries.</p>

<p>The <dfn>autofocus delegate</dfn> for a <var>focus target</var> given a <var>focus
Expand Down

0 comments on commit 4d6609f

Please sign in to comment.