Skip to content

Commit c89834c

Browse files
noamrmfreed7
authored andcommitted
Move Page Visibility APIs into HTML
Defines the document.hidden and document.visibilityState APIs in the HTML Standard, while improving their definitions to be more rigorous. This is similar to 3285b98 which did the same for the visibilitychange event. Also updates the discussion of "page is in the background" to refer to the new definitions. See w3c/page-visibility#74 and w3c/page-visibility#73 for more background.
1 parent 5180d9c commit c89834c

File tree

1 file changed

+76
-10
lines changed

1 file changed

+76
-10
lines changed

source

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9276,6 +9276,7 @@ o.myself = o;</code></pre>
92769276
this specification extends significantly.</p>
92779277

92789278
<pre><code class="idl">enum <dfn enum>DocumentReadyState</dfn> { "loading", "interactive", "complete" };
9279+
enum <dfn enum>DocumentVisibilityState</dfn> { "visible", "hidden" };
92799280
typedef (<span>HTMLScriptElement</span> or <span>SVGScriptElement</span>) <dfn typedef>HTMLOrSVGScriptElement</dfn>;
92809281

92819282
[<span>LegacyOverrideBuiltIns</span>]
@@ -9320,6 +9321,8 @@ partial interface <dfn id="document" data-lt="">Document</dfn> {
93209321
boolean <span data-x="dom-document-queryCommandState">queryCommandState</span>(DOMString commandId);
93219322
boolean <span data-x="dom-document-queryCommandSupported">queryCommandSupported</span>(DOMString commandId);
93229323
DOMString <span data-x="dom-document-queryCommandValue">queryCommandValue</span>(DOMString commandId);
9324+
readonly attribute boolean <span data-x="dom-document-hidden">hidden</span>;
9325+
readonly attribute <span>DocumentVisibilityState</span> <span data-x="dom-document-visibilityState">visibilityState</span>;
93239326

93249327
// special <span>event handler IDL attributes</span> that only apply to Document objects
93259328
[<span>LegacyLenientThis</span>] attribute <span>EventHandler</span> <span data-x="handler-onreadystatechange">onreadystatechange</span>;
@@ -74111,6 +74114,61 @@ END:VCARD</pre>
7411174114

7411274115
</div>
7411374116

74117+
<h3>Page visibility</h3>
74118+
74119+
<p>A <span>top-level browsing context</span> has a <dfn>system visibility state</dfn>,
74120+
which is either "<code data-x="">hidden</code>" or "<code data-x="">visible</code>".</p>
74121+
74122+
<p class="note">The <span>system visibility state</span> is determined by the user-agent, and
74123+
represents, for example, whether the browser window is minimized, a browser tab is currently in
74124+
the background, or a system element such as a task switcher obscures the page.</p>
74125+
74126+
<p>When a user-agent determines that the <span>system visibility state</span> for
74127+
<span>top-level browsing context</span> <var>context</var> has changed to <var>newState</var>,
74128+
it must <span>queue a task</span> on the <span>user interaction task source</span> to
74129+
<span>update the visibility state</span> of all the <code>Document</code> objects in the
74130+
<span>top-level browsing context</span>'s <span>document family</span> with
74131+
<var>newState</var>.</p>
74132+
74133+
<p>A <code>Document</code> has a <dfn>visibility state</dfn>, which is either
74134+
"<code data-x="">hidden</code>" or "<code data-x="">visible</code>", initially set to
74135+
"<code data-x="">hidden</code>".</p>
74136+
74137+
<p>The <dfn attribute for="Document"><code
74138+
data-x="dom-document-visibilityState">visibilityState</code></dfn> getter steps are to return
74139+
<span>this</span>'s <span>visibility state</span>.</p>
74140+
74141+
<p>The <dfn attribute for="Document"><code data-x="dom-document-hidden">hidden</code></dfn> getter
74142+
steps are to return true if <span>this</span>'s <span>visibility state</span> is
74143+
"<code data-x="">hidden</code>", otherwise false.</p>
74144+
74145+
<p>To <dfn>update the visibility state</dfn> of <code>Document</code> <var>document</var> to
74146+
<var>visibilityState</var>:</p>
74147+
74148+
<ol>
74149+
<li><p>If <var>document</var>'s <span>visibility state</span> equals <var>visibilityState</var>,
74150+
then return.</p></li>
74151+
74152+
<li><p>Set <var>document</var>'s <span>visibility state</span> to
74153+
<var>visibilityState</var>.</p></li>
74154+
74155+
<li>
74156+
<p>Run any <dfn export>page visibility change steps</dfn> which may be defined in other
74157+
specificactions, with <span>visibility state</span> and <var>document</var>.</p>
74158+
74159+
<p class="XXX">It would be better if specification authors sent a pull request to add calls
74160+
from here into their specifications directly, instead of using the <span>page visibility change
74161+
steps</span> hook, to ensure well-defined cross-specification call order. As of the time of
74162+
this writing the following specifications are known to have <span>page visibility change
74163+
steps</span>, which will be run in an unspecified order: <cite>Device Posture API</cite>,
74164+
<cite>Screen Orientation API</cite>, and <cite>Web NFC</cite>. <ref spec=DEVICEPOSTURE> <ref
74165+
spec=SCREENORIENTATION> <ref spec=WEBNFC></p>
74166+
</li>
74167+
74168+
<li><p>Fire an event named <code data-x="event-visibilitychange">visibilitychange</code> at
74169+
<var>document</var>, with its <code data-x="dom-Event-bubbles">bubbles</code> attribute
74170+
initialized to true.</p></li>
74171+
</ol>
7411474172

7411574173

7411674174
<h3>Inert subtrees</h3>
@@ -79244,6 +79302,9 @@ popup4.close();</code></pre></div>
7924479302
<li><p>Let <var>window</var> be <var>document</var>'s <span>relevant global
7924579303
object</span>.</p></li>
7924679304

79305+
<li><p>Set <var>document</var>'s <span>visibility state</span> to <var>browsingContext</var>'s
79306+
<span>top-level browsing context</span>'s <span>system visibility state</span>.</p></li>
79307+
7924779308
<li><p>Set <var>browsingContext</var>'s <span>active window</span> to <var>window</var>.</p></li>
7924879309

7924979310
<li><p>Set <var>window</var>'s <span data-x="concept-document-window">associated
@@ -79372,8 +79433,8 @@ popup4.close();</code></pre></div>
7937279433
data-x="concept-document-permissions-policy">permissions policy</span> is
7937379434
<var>permissionsPolicy</var>, <span data-x="concept-document-coop">cross-origin opener
7937479435
policy</span> is <var>coop</var>,
79375-
<span data-x="concept-document-navigation-id">navigation id</span> is null,
79376-
and which is <span>ready for post-load tasks</span>.</p></li>
79436+
<span data-x="concept-document-navigation-id">navigation id</span> is null, and which is
79437+
<span>ready for post-load tasks</span>.</p></li>
7937779438

7937879439
<li><p>Assert: <var>document</var>'s <span data-x="concept-document-url">URL</span> and
7937979440
<var>document</var>'s <span>relevant settings object</span>'s <span
@@ -88638,9 +88699,8 @@ new PaymentRequest(&hellip;); // Allowed to use
8863888699

8863988700
<li><p>Set <var>newDocument</var>'s <span>page showing</span> flag to true.</p></li>
8864088701

88641-
<li><p>Fire an event named <code data-x="event-visibilitychange">visibilitychange</code> at
88642-
<var>newDocument</var>, with its <code data-x="dom-Event-bubbles">bubbles</code> attribute
88643-
initialized to true.</p></li>
88702+
<li><p><span>Update the visibility state</span> of <var>newDocument</var> to
88703+
"<code data-x="">hidden</code>".</p></li>
8864488704

8864588705
<li><p><span>Fire a page transition event</span> named <code
8864688706
data-x="event-pageshow">pageshow</code> at <var>newDocument</var>'s <span>relevant global
@@ -89109,9 +89169,8 @@ dictionary <dfn dictionary>PageTransitionEventInit</dfn> : <span>EventInit</span
8910989169
object</span> with <var>document</var>'s <i
8911089170
data-x="concept-document-salvageable">salvageable</i> state.</p></li>
8911189171

89112-
<li><p>Fire an event named <code data-x="event-visibilitychange">visibilitychange</code> at
89113-
<var>newDocument</var>, with its <code data-x="dom-Event-bubbles">bubbles</code> attribute
89114-
initialized to true.</p></li>
89172+
<li><p><span>Update the visibility state</span> of <var>newDocument</var> to
89173+
"<code data-x="">hidden</code>".</p></li>
8911589174
</ol>
8911689175
</li>
8911789176

@@ -93643,8 +93702,9 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
9364393702

9364493703
<p><span>Browsing context</span> <span data-x="rendering opportunity">rendering
9364593704
opportunities</span> are determined based on hardware constraints such as display refresh
93646-
rates and other factors such as page performance or whether the page is in the background.
93647-
Rendering opportunities typically occur at regular intervals.</p>
93705+
rates and other factors such as page performance or whether the document's
93706+
<span>visibility state</span> is "<code data-x="">visible</code>". Rendering opportunities
93707+
typically occur at regular intervals.</p>
9364893708

9364993709
<p class="note">This specification does not mandate any particular model for selecting
9365093710
rendering opportunities. But for example, if the browser is attempting to achieve a 60Hz
@@ -126106,6 +126166,9 @@ INSERT INTERFACES HERE
126106126166
<dt id="refsDASH">[DASH]</dt>
126107126167
<dd><cite><a href="https://www.iso.org/standard/65274.html">Dynamic adaptive streaming over HTTP (DASH)</a></cite>. ISO.</dd>
126108126168

126169+
<dt id="refsDEVICEPOSTURE">[DEVICEPOSTURE]</dt>
126170+
<dd>(Non-normative) <cite><a href="https://w3c.github.io/device-posture/">Device Posture API</a></cite>, D. Gonzalez-Zuniga, K. Christiansen. W3C.</dd>
126171+
126109126172
<dt id="refsDOM">[DOM]</dt>
126110126173
<dd><cite><a href="https://dom.spec.whatwg.org/">DOM</a></cite>, A. van Kesteren, A. Gregor, Ms2ger. WHATWG.</dd>
126111126174

@@ -126499,6 +126562,9 @@ INSERT INTERFACES HERE
126499126562
<dt id="refsWEBMCG">[WEBMCG]</dt>
126500126563
<dd><cite><a href="https://www.webmproject.org/docs/container/">WebM Container Guidelines</a></cite>. The WebM Project.</dd>
126501126564

126565+
<dt id="refsWEBNFC">[WEBNFC]</dt>
126566+
<dd>(Non-normative) <cite><a href="https://w3c.github.io/web-nfc/">Web NFC</a></cite>, F. Beaufort, K. Christiansen, Z. Kis. W3C.</dd>
126567+
126502126568
<dt id="refsWEBVTT">[WEBVTT]</dt>
126503126569
<dd><cite><a href="https://w3c.github.io/webvtt/">WebVTT</a></cite>, S. Pieters. W3C.</dd>
126504126570

0 commit comments

Comments
 (0)