Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have document.hasFocus() and blur/focus events reveal system-level focus #6172

Merged
merged 11 commits into from
Dec 11, 2020
79 changes: 53 additions & 26 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -68318,14 +68318,14 @@ Demos:
<span>pseudo-class</span>, an <dfn>element has the focus</dfn> when:</p>

<ul>
<li><p>its <span>top-level browsing context</span> has the system focus;</p></li>
<li><p>it is not itself a <span>browsing context container</span>; and</p></li>
<li>
<p>at least one of the following is true:</p>
<ul>
<li><p>it is one of the elements listed in the <span>focus chain</span> of the <span
data-x="currently focused area of a top-level browsing context">currently focused area of
the top-level browsing context</span>, or</p></li>
<li><p>it is one of the elements listed in the <span data-x="current focus chain of a
top-level browsing context">current focus chain of the top-level browsing context</span>,
or</p></li>

<li><p>its <span data-x="concept-element-shadow-root">shadow root</span>
<var>shadowRoot</var> is not null and <var>shadowRoot</var> is the <span>root</span> of at
least one element that <span data-x="element has the focus">has the focus</span>.</p></li>
Expand Down Expand Up @@ -72545,8 +72545,14 @@ END:VCARD</pre>

<h4>Data model</h4>

<p>The term <dfn>focusable area</dfn> is used to refer to regions of the interface that can become
the target of keyboard input. Focusable areas can be elements, parts of elements, or other regions
<p>A <span>top-level browsing context</span> has <dfn data-x="tlbc system focus">system
focus</dfn> when it can receive keyboard input channeled from the operating system.</p>

<p class="note">System focus is lost when a browser window loses focus, but might also be lost to
other system widgets in the browser window such as a URL bar.</p>

<p>The term <dfn>focusable area</dfn> is used to refer to regions of the interface that can further become
the target of such keyboard input. Focusable areas can be elements, parts of elements, or other regions
managed by the user agent.</p>

<p>Each <span>focusable area</span> has a <dfn>DOM anchor</dfn>, which is a <code>Node</code> object
jan-ivar marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -72689,9 +72695,12 @@ END:VCARD</pre>
in this specification.</p>

<p>The <dfn>currently focused area of a top-level browsing context</dfn> <var>topLevelBC</var> at
any particular time is the <span>focusable area</span> returned by this algorithm:</p>
any particular time is the <span>focusable area</span>-or-null returned by this algorithm:</p>

<ol>
<li><p>If <var>topLevelBC</var> does not have <span data-x="tlbc system focus">system
focus</span>, then return null.</p></li>

<li><p>Let <var>candidate</var> be <var>topLevelBC</var>'s <span>active document</span>.</p></li>

<li><p>While <var>candidate</var>'s <span data-x="focused area of the document">focused
Expand All @@ -72707,11 +72716,16 @@ END:VCARD</pre>
<li><p>Return <var>candidate</var>.</p></li>
</ol>

<p>The <dfn>current focus chain of a top-level browsing context</dfn> <var>topLevelBC</var> at any
particular time is the <span>focus chain</span> of the <span data-x="currently focused area of a
top-level browsing context">currently focused area</span> of <var>topLevelBC</var>, if
<var>topLevelBC</var> is non-null, or an empty list otherwise.</p>

<p>An element that is the <span>DOM anchor</span> of a <span>focusable area</span> is said to <dfn
data-x="gains focus">gain focus</dfn> when that <span>focusable area</span> becomes the <span>currently
focused area of a top-level browsing context</span>. When an element is the <span>DOM anchor</span> of a
<span>focusable area</span> of the <span>currently focused area of a top-level browsing context</span>,
it is <dfn>focused</dfn>.</p>
data-x="gains focus">gain focus</dfn> when that <span>focusable area</span> becomes the
<span>currently focused area of a top-level browsing context</span>. When an element is the
<span>DOM anchor</span> of a <span>focusable area</span> of the <span>currently focused area of a
top-level browsing context</span>, it is <dfn>focused</dfn>.</p>

<div w-nodev>

Expand Down Expand Up @@ -73224,10 +73238,9 @@ END:VCARD</pre>
<li><p>If <var>new focus target</var> is the <span>currently focused area of a
top-level browsing context</span>, then return.</p></li>

<li><p>Let <var>old chain</var> be the <span>focus chain</span> of the <span
data-x="currently focused area of a top-level browsing context">currently focused area of the
top-level browsing context</span> in which <var>new focus target</var> finds
itself.</p></li>
<li><p>Let <var>old chain</var> be the <span data-x="current focus chain of a top-level browsing
context">current focus chain of the top-level browsing context</span> in which <var>new focus
target</var> finds itself.</p></li>

<li><p>Let <var>new chain</var> be the <span>focus chain</span> of <var>new
focus target</var>.</p></li>
Expand Down Expand Up @@ -73257,21 +73270,27 @@ END:VCARD</pre>
target</var> be that <span>currently focused area of a top-level browsing context</span>.</p>
</li>

<li><p>Let <var>old chain</var> be the <span>focus chain</span> of the <span>currently
focused area of a top-level browsing context</span>.</p></li>
<li><p>Let <var>old chain</var> be the <span data-x="current focus chain of a top-level browsing
context">current focus chain of the top-level browsing context</span> in which <var>old focus
target</var> finds itself.</p></li>

<li><p>If <var>old focus target</var> is not one of the entries in <var>old
chain</var>, then return.</p></li>

<li><p>If <var>old focus target</var> is not a <span>focusable area</span>, then return.</p></li>

<li><p>Let <var>topDocument</var> be <var>old chain</var>'s last entry.</p></li>

<li>
<p>If <var>old focus target</var> is a <span>focusable area</span>, then let <var>new
focus target</var> be its <code>Document</code>'s <span>viewport</span>.</p>
<p>If <var>topDocument</var>'s <span data-x="concept-document-bc">browsing context</span> has
<span data-x="tlbc system focus">system focus</span>, then run the <span>focusing steps</span>
for <var>topDocument</var>'s <span>viewport</span>.</p>

<p>Otherwise, let <var>new focus target</var> be null.</p>
<p>Otherwise, apply any relevant platform-specific conventions for removing <span data-x="tlbc
system focus">system focus</span> from <var>topDocument</var>'s <span
data-x="concept-document-bc">browsing context</span>, and run the <span>focus update
steps</span> with <var>old chain</var>, an empty list, and null respectively.</p>
</li>

<li><p>If <var>new focus target</var> is not null, then run the <span>focusing
steps</span> for <var>new focus target</var>.</p></li>
</ol>

<p>When the <span>currently focused area of a top-level browsing context</span> is somehow
Expand Down Expand Up @@ -73359,9 +73378,9 @@ END:VCARD</pre>
</ol>
</li>

<li><p>Apply any relevant platform-specific conventions for focusing <var>new focus
target</var>. (For example, some platforms select the contents of a text control when that
control is focused.)</p></li>
<li><p>Apply any relevant platform-specific conventions for focusing <var>new focus target</var>.
(For example, some platforms select the contents of a text control when that control is
focused.)</p></li>

<li>
<p>For each entry <var>entry</var> in <var>new chain</var>, in reverse
Expand Down Expand Up @@ -73421,6 +73440,10 @@ END:VCARD</pre>
top-level browsing context">currently focused area of the top-level browsing
context</span>.</p></li>

<li><p>Assert: <var>target area</var> is not null, since key events are only routed to <span
data-x="top-level browsing context">top-level browsing contexts</span> that have <span
data-x="tlbc system focus">system focus</span>.</p></li>

<li><p>If <var>target area</var> is a <span>focusable area</span>, let <var>target
node</var> be <var>target area</var>'s <span>DOM anchor</span>. Otherwise, <var>target area</var> is a <code>dialog</code>; let <var>target node</var> be
<var>target area</var>.</p></li>
Expand Down Expand Up @@ -73462,6 +73485,10 @@ END:VCARD</pre>
are as follows:</p>

<ol>
<li><p>If <var>target</var>'s <span data-x="concept-document-bc">browsing context</span>'s
<span>top-level browsing context</span> does have not have <span data-x="tlbc system
focus">system focus</span>, then return false.</p></li>

<li><p>Let <var>candidate</var> be <var>target</var>'s <span>top-level browsing context</span>'s
<span>active document</span>.</p></li>

Expand Down