Skip to content

Commit 07a5b3e

Browse files
authored
Introduce the system focus concept
This is reflected by document.hasFocus(), and blur/focus events. Fixes #5049. Fixes #2716. Related to #5493.
1 parent f5628b9 commit 07a5b3e

File tree

1 file changed

+53
-26
lines changed

1 file changed

+53
-26
lines changed

source

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68323,14 +68323,14 @@ Demos:
6832368323
<span>pseudo-class</span>, an <dfn>element has the focus</dfn> when:</p>
6832468324

6832568325
<ul>
68326-
<li><p>its <span>top-level browsing context</span> has the system focus;</p></li>
6832768326
<li><p>it is not itself a <span>browsing context container</span>; and</p></li>
6832868327
<li>
6832968328
<p>at least one of the following is true:</p>
6833068329
<ul>
68331-
<li><p>it is one of the elements listed in the <span>focus chain</span> of the <span
68332-
data-x="currently focused area of a top-level browsing context">currently focused area of
68333-
the top-level browsing context</span>, or</p></li>
68330+
<li><p>it is one of the elements listed in the <span data-x="current focus chain of a
68331+
top-level browsing context">current focus chain of the top-level browsing context</span>,
68332+
or</p></li>
68333+
6833468334
<li><p>its <span data-x="concept-element-shadow-root">shadow root</span>
6833568335
<var>shadowRoot</var> is not null and <var>shadowRoot</var> is the <span>root</span> of at
6833668336
least one element that <span data-x="element has the focus">has the focus</span>.</p></li>
@@ -72550,8 +72550,14 @@ END:VCARD</pre>
7255072550

7255172551
<h4>Data model</h4>
7255272552

72553-
<p>The term <dfn>focusable area</dfn> is used to refer to regions of the interface that can become
72554-
the target of keyboard input. Focusable areas can be elements, parts of elements, or other regions
72553+
<p>A <span>top-level browsing context</span> has <dfn data-x="tlbc system focus">system
72554+
focus</dfn> when it can receive keyboard input channeled from the operating system.</p>
72555+
72556+
<p class="note">System focus is lost when a browser window loses focus, but might also be lost to
72557+
other system widgets in the browser window such as a URL bar.</p>
72558+
72559+
<p>The term <dfn>focusable area</dfn> is used to refer to regions of the interface that can further become
72560+
the target of such keyboard input. Focusable areas can be elements, parts of elements, or other regions
7255572561
managed by the user agent.</p>
7255672562

7255772563
<p>Each <span>focusable area</span> has a <dfn>DOM anchor</dfn>, which is a <code>Node</code> object
@@ -72694,9 +72700,12 @@ END:VCARD</pre>
7269472700
in this specification.</p>
7269572701

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

7269972705
<ol>
72706+
<li><p>If <var>topLevelBC</var> does not have <span data-x="tlbc system focus">system
72707+
focus</span>, then return null.</p></li>
72708+
7270072709
<li><p>Let <var>candidate</var> be <var>topLevelBC</var>'s <span>active document</span>.</p></li>
7270172710

7270272711
<li><p>While <var>candidate</var>'s <span data-x="focused area of the document">focused
@@ -72712,11 +72721,16 @@ END:VCARD</pre>
7271272721
<li><p>Return <var>candidate</var>.</p></li>
7271372722
</ol>
7271472723

72724+
<p>The <dfn>current focus chain of a top-level browsing context</dfn> <var>topLevelBC</var> at any
72725+
particular time is the <span>focus chain</span> of the <span data-x="currently focused area of a
72726+
top-level browsing context">currently focused area</span> of <var>topLevelBC</var>, if
72727+
<var>topLevelBC</var> is non-null, or an empty list otherwise.</p>
72728+
7271572729
<p>An element that is the <span>DOM anchor</span> of a <span>focusable area</span> is said to <dfn
72716-
data-x="gains focus">gain focus</dfn> when that <span>focusable area</span> becomes the <span>currently
72717-
focused area of a top-level browsing context</span>. When an element is the <span>DOM anchor</span> of a
72718-
<span>focusable area</span> of the <span>currently focused area of a top-level browsing context</span>,
72719-
it is <dfn>focused</dfn>.</p>
72730+
data-x="gains focus">gain focus</dfn> when that <span>focusable area</span> becomes the
72731+
<span>currently focused area of a top-level browsing context</span>. When an element is the
72732+
<span>DOM anchor</span> of a <span>focusable area</span> of the <span>currently focused area of a
72733+
top-level browsing context</span>, it is <dfn>focused</dfn>.</p>
7272072734

7272172735
<div w-nodev>
7272272736

@@ -73229,10 +73243,9 @@ END:VCARD</pre>
7322973243
<li><p>If <var>new focus target</var> is the <span>currently focused area of a
7323073244
top-level browsing context</span>, then return.</p></li>
7323173245

73232-
<li><p>Let <var>old chain</var> be the <span>focus chain</span> of the <span
73233-
data-x="currently focused area of a top-level browsing context">currently focused area of the
73234-
top-level browsing context</span> in which <var>new focus target</var> finds
73235-
itself.</p></li>
73246+
<li><p>Let <var>old chain</var> be the <span data-x="current focus chain of a top-level browsing
73247+
context">current focus chain of the top-level browsing context</span> in which <var>new focus
73248+
target</var> finds itself.</p></li>
7323673249

7323773250
<li><p>Let <var>new chain</var> be the <span>focus chain</span> of <var>new
7323873251
focus target</var>.</p></li>
@@ -73262,21 +73275,27 @@ END:VCARD</pre>
7326273275
target</var> be that <span>currently focused area of a top-level browsing context</span>.</p>
7326373276
</li>
7326473277

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

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

73285+
<li><p>If <var>old focus target</var> is not a <span>focusable area</span>, then return.</p></li>
73286+
73287+
<li><p>Let <var>topDocument</var> be <var>old chain</var>'s last entry.</p></li>
73288+
7327173289
<li>
73272-
<p>If <var>old focus target</var> is a <span>focusable area</span>, then let <var>new
73273-
focus target</var> be its <code>Document</code>'s <span>viewport</span>.</p>
73290+
<p>If <var>topDocument</var>'s <span data-x="concept-document-bc">browsing context</span> has
73291+
<span data-x="tlbc system focus">system focus</span>, then run the <span>focusing steps</span>
73292+
for <var>topDocument</var>'s <span>viewport</span>.</p>
7327473293

73275-
<p>Otherwise, let <var>new focus target</var> be null.</p>
73294+
<p>Otherwise, apply any relevant platform-specific conventions for removing <span data-x="tlbc
73295+
system focus">system focus</span> from <var>topDocument</var>'s <span
73296+
data-x="concept-document-bc">browsing context</span>, and run the <span>focus update
73297+
steps</span> with <var>old chain</var>, an empty list, and null respectively.</p>
7327673298
</li>
73277-
73278-
<li><p>If <var>new focus target</var> is not null, then run the <span>focusing
73279-
steps</span> for <var>new focus target</var>.</p></li>
7328073299
</ol>
7328173300

7328273301
<p>When the <span>currently focused area of a top-level browsing context</span> is somehow
@@ -73364,9 +73383,9 @@ END:VCARD</pre>
7336473383
</ol>
7336573384
</li>
7336673385

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

7337173390
<li>
7337273391
<p>For each entry <var>entry</var> in <var>new chain</var>, in reverse
@@ -73426,6 +73445,10 @@ END:VCARD</pre>
7342673445
top-level browsing context">currently focused area of the top-level browsing
7342773446
context</span>.</p></li>
7342873447

73448+
<li><p>Assert: <var>target area</var> is not null, since key events are only routed to <span
73449+
data-x="top-level browsing context">top-level browsing contexts</span> that have <span
73450+
data-x="tlbc system focus">system focus</span>.</p></li>
73451+
7342973452
<li><p>If <var>target area</var> is a <span>focusable area</span>, let <var>target
7343073453
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
7343173454
<var>target area</var>.</p></li>
@@ -73467,6 +73490,10 @@ END:VCARD</pre>
7346773490
are as follows:</p>
7346873491

7346973492
<ol>
73493+
<li><p>If <var>target</var>'s <span data-x="concept-document-bc">browsing context</span>'s
73494+
<span>top-level browsing context</span> does have not have <span data-x="tlbc system
73495+
focus">system focus</span>, then return false.</p></li>
73496+
7347073497
<li><p>Let <var>candidate</var> be <var>target</var>'s <span>top-level browsing context</span>'s
7347173498
<span>active document</span>.</p></li>
7347273499

0 commit comments

Comments
 (0)