Skip to content

Commit 2be3d9a

Browse files
darktearsemilio
authored andcommitted
[css-viewport] Add the segments property (#9237).
This property exposes in JavaScript what is already exposed to CSS via env() variables. TAG review w3ctag/design-reviews#689. CSSWG Approval: #9237#issuecomment-2160730855 Fixes #9237.
1 parent 9053832 commit 2be3d9a

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

css-viewport-1/Overview.bs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,52 @@ The <dfn export>unscaled</dfn> value of a CSS length relative to an element is t
526526
The {{Window/devicePixelRatio}} of a frame is multiplied by the [=effective zoom=] inherited by its parent frame.
527527
</h3>
528528

529+
<h2 id=extensions-to-the-window-interface>Extensions to the {{Window}} Interface</h2>
530+
531+
<pre class=idl>
532+
partial interface Window {
533+
[SameObject, Replaceable] readonly attribute Viewport viewport;
534+
};
535+
</pre>
536+
537+
<h2 id=viewport>Viewport</h2>
538+
539+
<h3 id="the-viewport-interface">The {{Viewport}} Interface</h3>
540+
541+
<pre class=idl>
542+
[Exposed=Window]
543+
interface Viewport {
544+
readonly attribute FrozenArray&lt;DOMRect>? segments;
545+
};
546+
</pre>
547+
548+
<h2 id='segments'>
549+
The <dfn attribute for=Viewport>segments</dfn> property
550+
</h2>
551+
552+
The {{segments}} property is an array of {{DOMRect}} that represent the dimensions of each existing viewport segment.
553+
Each {{DOMRect}} contains the geometry of the segment (x, y, width, height) in CSS ''<length>/px''.
554+
555+
Additonal details about the definition of a viewport segment can be found here: [[css-env-1#viewport-segments]].
556+
557+
The {{segments}} attribute must run these steps:
558+
1. If the {{Viewport}}'s associated {{Document}} is not <a>fully active</a>, return null.
559+
2. Returns null if there is only a single viewport segment and abort these steps.
560+
3. Otherwise, return the {{Viewport}}'s [[css-env-1#viewport-segments|segments]] array.
561+
562+
<div class=non-normative>
563+
<em>This section is not normative.</em>
564+
565+
The {{segments}} property represents an immutable snapshot of the device {{segments}} when the value was queried.
566+
If the device state changes (rotation, window resize, <a spec="DEVICE-POSTURE">posture</a> change), the value previously retrieved will be invalid. Developers can listen to {{ScreenOrientation/onchange|Screen Orientation}}, {{Window/resize|Window Resize}}, or {{DevicePosture/onchange|Posture}} changes events to detect device state changes.
567+
568+
<div class="example">
569+
If a viewport of 400px by 400px is split horizontally into two side-by-side segments, the {{segments}} array will have the following content:
570+
<code highlight=javascript>[DOMRect(0, 0, 400, 200), DOMRect(0, 200, 400, 200)]</code>
571+
</div>
572+
573+
</div>
574+
529575
<h2 class="no-num" id="changes">Appendix A. Changes</h2>
530576

531577
This appendix is <em>informative</em>.

0 commit comments

Comments
 (0)