Skip to content

Commit 1ff4b29

Browse files
noamrdomenic
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 6b24119 commit 1ff4b29

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
@@ -9274,6 +9274,7 @@ o.myself = o;</code></pre>
92749274
this specification extends significantly.</p>
92759275

92769276
<pre><code class="idl">enum <dfn enum>DocumentReadyState</dfn> { "loading", "interactive", "complete" };
9277+
enum <dfn enum>DocumentVisibilityState</dfn> { "visible", "hidden" };
92779278
typedef (<span>HTMLScriptElement</span> or <span>SVGScriptElement</span>) <dfn typedef>HTMLOrSVGScriptElement</dfn>;
92789279

92799280
[<span>LegacyOverrideBuiltIns</span>]
@@ -9318,6 +9319,8 @@ partial interface <dfn id="document" data-lt="">Document</dfn> {
93189319
boolean <span data-x="dom-document-queryCommandState">queryCommandState</span>(DOMString commandId);
93199320
boolean <span data-x="dom-document-queryCommandSupported">queryCommandSupported</span>(DOMString commandId);
93209321
DOMString <span data-x="dom-document-queryCommandValue">queryCommandValue</span>(DOMString commandId);
9322+
readonly attribute boolean <span data-x="dom-document-hidden">hidden</span>;
9323+
readonly attribute <span>DocumentVisibilityState</span> <span data-x="dom-document-visibilityState">visibilityState</span>;
93219324

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

7410974112
</div>
7411074113

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

7411274170

7411374171
<h3>Inert subtrees</h3>
@@ -79241,6 +79299,9 @@ popup4.close();</code></pre></div>
7924179299
<li><p>Let <var>window</var> be <var>document</var>'s <span>relevant global
7924279300
object</span>.</p></li>
7924379301

79302+
<li><p>Set <var>document</var>'s <span>visibility state</span> to <var>browsingContext</var>'s
79303+
<span>top-level browsing context</span>'s <span>system visibility state</span>.</p></li>
79304+
7924479305
<li><p>Set <var>browsingContext</var>'s <span>active window</span> to <var>window</var>.</p></li>
7924579306

7924679307
<li><p>Set <var>window</var>'s <span data-x="concept-document-window">associated
@@ -79369,8 +79430,8 @@ popup4.close();</code></pre></div>
7936979430
data-x="concept-document-permissions-policy">permissions policy</span> is
7937079431
<var>permissionsPolicy</var>, <span data-x="concept-document-coop">cross-origin opener
7937179432
policy</span> is <var>coop</var>,
79372-
<span data-x="concept-document-navigation-id">navigation id</span> is null,
79373-
and which is <span>ready for post-load tasks</span>.</p></li>
79433+
<span data-x="concept-document-navigation-id">navigation id</span> is null, and which is
79434+
<span>ready for post-load tasks</span>.</p></li>
7937479435

7937579436
<li><p>Assert: <var>document</var>'s <span data-x="concept-document-url">URL</span> and
7937679437
<var>document</var>'s <span>relevant settings object</span>'s <span
@@ -88635,9 +88696,8 @@ new PaymentRequest(&hellip;); // Allowed to use
8863588696

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

88638-
<li><p>Fire an event named <code data-x="event-visibilitychange">visibilitychange</code> at
88639-
<var>newDocument</var>, with its <code data-x="dom-Event-bubbles">bubbles</code> attribute
88640-
initialized to true.</p></li>
88699+
<li><p><span>Update the visibility state</span> of <var>newDocument</var> to
88700+
"<code data-x="">hidden</code>".</p></li>
8864188701

8864288702
<li><p><span>Fire a page transition event</span> named <code
8864388703
data-x="event-pageshow">pageshow</code> at <var>newDocument</var>'s <span>relevant global
@@ -89106,9 +89166,8 @@ dictionary <dfn dictionary>PageTransitionEventInit</dfn> : <span>EventInit</span
8910689166
object</span> with <var>document</var>'s <i
8910789167
data-x="concept-document-salvageable">salvageable</i> state.</p></li>
8910889168

89109-
<li><p>Fire an event named <code data-x="event-visibilitychange">visibilitychange</code> at
89110-
<var>newDocument</var>, with its <code data-x="dom-Event-bubbles">bubbles</code> attribute
89111-
initialized to true.</p></li>
89169+
<li><p><span>Update the visibility state</span> of <var>newDocument</var> to
89170+
"<code data-x="">hidden</code>".</p></li>
8911289171
</ol>
8911389172
</li>
8911489173

@@ -93640,8 +93699,9 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
9364093699

9364193700
<p><span>Browsing context</span> <span data-x="rendering opportunity">rendering
9364293701
opportunities</span> are determined based on hardware constraints such as display refresh
93643-
rates and other factors such as page performance or whether the page is in the background.
93644-
Rendering opportunities typically occur at regular intervals.</p>
93702+
rates and other factors such as page performance or whether the document's
93703+
<span>visibility state</span> is "<code data-x="">visible</code>". Rendering opportunities
93704+
typically occur at regular intervals.</p>
9364593705

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

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

@@ -126488,6 +126551,9 @@ INSERT INTERFACES HERE
126488126551
<dt id="refsWEBMCG">[WEBMCG]</dt>
126489126552
<dd><cite><a href="https://www.webmproject.org/docs/container/">WebM Container Guidelines</a></cite>. The WebM Project.</dd>
126490126553

126554+
<dt id="refsWEBNFC">[WEBNFC]</dt>
126555+
<dd>(Non-normative) <cite><a href="https://w3c.github.io/web-nfc/">Web NFC</a></cite>, F. Beaufort, K. Christiansen, Z. Kis. W3C.</dd>
126556+
126491126557
<dt id="refsWEBVTT">[WEBVTT]</dt>
126492126558
<dd><cite><a href="https://w3c.github.io/webvtt/">WebVTT</a></cite>, S. Pieters. W3C.</dd>
126493126559

0 commit comments

Comments
 (0)