Skip to content

Commit 29eaa5c

Browse files
authored
[cssom-view-1] Introduce VisualViewport API #6339 (#7316)
* Introduce VisualViewport into cssom-view-1
1 parent 24cec31 commit 29eaa5c

File tree

1 file changed

+119
-10
lines changed

1 file changed

+119
-10
lines changed

cssom-view-1/Overview.bs

+119-10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Can I Use URL: https://www.w3.org/TR/cssom-view-1/
2828

2929
<pre class='link-defaults'>
3030
spec:css-ui-4; type:property; text:pointer-events
31+
spec:css2; type:dfn; text:canvas
3132
spec:css2; type:dfn; text:viewport
3233
spec:html; type:dfn;
3334
text: inert
@@ -265,6 +266,22 @@ The <dfn>ending edges</dfn> of a particular set of edges of a box or element are
265266
<dd>The top and right edges.
266267
</dl>
267268

269+
The <dfn>visual viewport</dfn> is a kind of <a>viewport</a> whose <a>scrolling area</a> is another <a>viewport</a>,
270+
called the <dfn>layout viewport</dfn>.
271+
272+
In addition to scrolling, the <a>visual viewport</a> may also apply a scale transform to its <a>layout viewport</a>.
273+
This transform is applied to the <a>canvas</a> of the <a>layout viewport</a> and does not affect its internal coordinate space.
274+
275+
Note: The scale transform of the visual viewport is often referred to as "pinch-zoom". Conceptually, this transform
276+
changes the size of the CSS <a>reference pixel</a> but changes the size of the layout viewport proportionally so that it
277+
does not cause reflow of the page's contents.
278+
279+
The magnitude of the scale transform is known as the <a>visual viewport</a>'s <dfn>scale factor</dfn>.
280+
281+
The {{VisualViewport}} object has an <dfn for=visualviewport>associated document</dfn>, which is a {{Document}} object.
282+
It is the <a for="/">associated document</a> of the owner {{Window}} of {{VisualViewport}}. The <a>layout viewport</a>
283+
is the owner {{Window}}'s <a>viewport</a>.
284+
268285
For the purpose of the requirements in this specification,
269286
elements that have a computed value of the 'display' property
270287
that is ''table-column'' or ''table-column-group''
@@ -293,9 +310,12 @@ Note: This does not apply to e.g. {{matchMedia()}} as the units are explicitly g
293310

294311
<h3 id=zooming>Zooming</h3>
295312

296-
There are two kinds of zoom, <dfn>page zoom</dfn> which affects the size of the initial viewport<!-- XXX ref -->, and <dfn>pinch zoom</dfn> which acts like
313+
There are two kinds of zoom, <dfn>page zoom</dfn> which affects the size of the initial viewport<!-- XXX ref -->, and the visual viewport <a>scale factor</a> which acts like
297314
a magnifying glass and does not affect the initial viewport<!-- XXX ref --> or actual viewport<!-- XXX ref -->. [[!CSS-DEVICE-ADAPT]]
298315

316+
Note: The "scale factor" is often referred to as "pinch-zoom"; however, it can be affected through means other than
317+
pinch-zooming. e.g. The user agent may zooms in on a focused input element to make it legible.
318+
299319

300320
<h3 id=web-exposed-screen-information>Web-exposed screen information</h3>
301321

@@ -391,6 +411,7 @@ dictionary ScrollToOptions : ScrollOptions {
391411
partial interface Window {
392412
[NewObject] MediaQueryList matchMedia(CSSOMString query);
393413
[SameObject, Replaceable] readonly attribute Screen screen;
414+
[SameObject, Replaceable] readonly attribute VisualViewport? visualViewport;
394415

395416
// browsing context
396417
undefined moveTo(long x, long y);
@@ -432,7 +453,7 @@ When the <dfn method for=Window caniuse=matchmedia>matchMedia(<var>query</var>)<
432453
<var>query</var>.
433454
<li>Return a new {{MediaQueryList}} object,
434455
with [=this=]'s
435-
<a>associated <code>Document</code></a>
456+
<a for="/">associated <code>Document</code></a>
436457
as the <a for=MediaQueryList>document</a>,
437458
with <var>parsed media query list</var> as its associated [=MediaQueryList/media query list=].
438459
</ol>
@@ -443,6 +464,14 @@ associated with the {{Window}} object.
443464
Note: Accessing {{Window/screen}} through a {{WindowProxy}} object might yield different
444465
results when the {{Document}} is navigated.
445466

467+
If the <a for="/">associated document</a> is <a>fully active</a>, the <dfn attribute for=Window>visualViewport</dfn>
468+
attribute must return the {{VisualViewport}} object associated with the {{Window}} object's <a for="/">associated
469+
document</a>. Otherwise, it must return null.
470+
471+
Note: the VisualViewport object is only returned and useful for a window whose Document is currently being presented. If
472+
a reference is retained to a VisualViewport whose associated Document is not being currently presented, the values in
473+
that VisualViewport must not reveal any information about the browsing context.
474+
446475
The <dfn method for=Window>moveTo(<var>x</var>, <var>y</var>)</dfn> method must follow these steps:
447476

448477
1. Optionally, return.
@@ -585,7 +614,7 @@ attribute must return zero. <!--fingerprint-->
585614
The <dfn attribute for=Window caniuse=devicepixelratio>devicePixelRatio</dfn> attribute must return the result of the following <dfn export>determine the device pixel ratio</dfn> algorithm:
586615

587616
1. If there is no output device, return 1 and abort these steps.
588-
1. Let <var>CSS pixel size</var> be the size of a <a lt=px value>CSS pixel</a> at the current <a>page zoom</a> scale factor and at a <a>pinch zoom</a> scale factor of 1.0.
617+
1. Let <var>CSS pixel size</var> be the size of a <a lt=px value>CSS pixel</a> at the current <a>page zoom</a> and using a <a>scale factor</a> of 1.0.
589618
1. Let <var>device pixel size</var> be the vertical size of a device pixel of the output device.
590619
1. Return the result of dividing <var>CSS pixel size</var> by <var>device pixel size</var>.
591620

@@ -1645,6 +1674,76 @@ method must run the following steps:
16451674
<li><p class=issue>...
16461675
</ol>
16471676

1677+
<h2 id=visualViewport>VisualViewport</h2>
1678+
1679+
<h3 id="the-visualviewport-interface">The {{VisualViewport}} Interface</h3>
1680+
1681+
<pre class=idl>
1682+
[Exposed=Window]
1683+
interface VisualViewport : EventTarget {
1684+
readonly attribute double offsetLeft;
1685+
readonly attribute double offsetTop;
1686+
1687+
readonly attribute double pageLeft;
1688+
readonly attribute double pageTop;
1689+
1690+
readonly attribute double width;
1691+
readonly attribute double height;
1692+
1693+
readonly attribute double scale;
1694+
1695+
attribute EventHandler onresize;
1696+
attribute EventHandler onscroll;
1697+
};
1698+
</pre>
1699+
1700+
The <dfn attribute for=VisualViewport>offsetLeft</dfn> attribute must run these steps:
1701+
1. If the <a>visual viewport</a>'s <a for=visualviewport>associated document</a> is not <a>fully active</a>, return 0.
1702+
1. Otherwise, return the offset of the left edge of the <a>visual viewport</a> from the left edge
1703+
of the <a>layout viewport</a>.
1704+
1705+
The <dfn attribute for=VisualViewport>offsetTop</dfn> attribute must run these steps:
1706+
1. If the <a>visual viewport</a>'s <a for=visualviewport>associated document</a> is not <a>fully active</a>, return 0.
1707+
1. Otherwise, return the offset of the top edge of the <a>visual viewport</a> from the top edge
1708+
of the <a>layout viewport</a>.
1709+
1710+
The <dfn attribute for=VisualViewport>pageLeft</dfn> attribute must run these steps:
1711+
1. If the <a>visual viewport</a>'s <a for=visualviewport>associated document</a> is not <a>fully active</a>, return 0.
1712+
1. Otherwise, return the offset of the left edge of the <a>visual viewport</a> from the left edge
1713+
of the <a>initial containing block</a> of the <a>layout viewport</a>'s <a for="/">document</a>.
1714+
1715+
The <dfn attribute for=VisualViewport>pageTop</dfn> attribute must run these steps:
1716+
1. If the <a>visual viewport</a>'s <a for=visualviewport>associated document</a> is not <a>fully active</a>, return 0.
1717+
1. Otherwise, return the offset of the top edge of the <a>visual viewport</a> from the top edge
1718+
of the <a>initial containing block</a> of the <a>layout viewport</a>'s <a for="/">document</a>.
1719+
1720+
The <dfn attribute for=VisualViewport>width</dfn> attribute must run these steps:
1721+
1. If the <a>visual viewport</a>'s <a for=visualviewport>associated document</a> is not <a>fully active</a>, return 0.
1722+
1. Otherwise, return the width of the <a>visual viewport</a> excluding the width of any rendered vertical <a>classic
1723+
scrollbar</a> that is fixed to the visual viewport.
1724+
1725+
Note: Since this value is returned in CSS pixels, the value will decrease in magnitude if either <a>page zoom</a> or the
1726+
<a>scale factor</a> is increased.
1727+
1728+
Note: A scrollbar that is fixed to the visual viewport is one that does not change size or location as the visual
1729+
viewport is zoomed and panned. Because this value is in CSS pixels, when excluding the scrollbar width the UA must
1730+
account for how large the scrollbar is as measured in CSS pixels. That is, the amount excluded decreases when zooming in
1731+
and increases when zooming out.
1732+
1733+
The <dfn attribute for=VisualViewport>height</dfn> attribute must run these steps:
1734+
1. If the <a>visual viewport</a>'s <a for=visualviewport>associated document</a> is not <a>fully active</a>, return 0.
1735+
1. Otherwise, return the height of the <a>visual viewport</a> excluding the height of any rendered horizontal <a>classic
1736+
scrollbar</a> that is fixed to the visual viewport.
1737+
1738+
The <dfn attribute for=VisualViewport>scale</dfn> attribute must run these steps:
1739+
1. If the <a>visual viewport</a>'s <a for=visualviewport>associated document</a> is not <a>fully active</a>, return 0
1740+
and abort these steps.
1741+
1. If there is no output device, return 1 and abort these steps.
1742+
1. Otherwise, return the <a>visual viewport</a>'s <a>scale factor</a>.
1743+
1744+
<dfn attribute for=VisualViewport>onresize</dfn> is the <a>event handler IDL attribute</a> for the <a event>resize</a> event.
1745+
1746+
<dfn attribute for=VisualViewport>onscroll</dfn> is the <a>event handler IDL attribute</a> for the <a event>scroll</a> event.
16481747

16491748
<h2 id=events>Events</h2>
16501749

@@ -1656,11 +1755,14 @@ When asked to <dfn export for=Document>run the resize steps</dfn> for a {{Docume
16561755

16571756
1. If <var>doc</var>'s <a>viewport</a> has had its width or height changed
16581757
(e.g. as a result of the user resizing the browser window,
1659-
or changing the <span>page zoom</span> scale factor,
1758+
or changing <span>page zoom</span>,
16601759
or an <code>iframe</code> element's dimensions are changed)
16611760
since the last time these steps were run,
16621761
<a>fire an event</a> named <a event>resize</a>
16631762
at the {{Window}} object associated with <var>doc</var>.
1763+
1. If the {{VisualViewport}} associated with <var>doc</var> has had its <a attribute for=VisualViewport>scale</a>,
1764+
<a attribute for=VisualViewport>width</a>, or <a attribute for=VisualViewport>height</a> properties changed since
1765+
the last time these steps were run, <a>fire an event</a> named <a event>resize</a> at the {{VisualViewport}}.
16641766

16651767

16661768
<h3 id=scrolling-events>Scrolling</h3>
@@ -1686,7 +1788,8 @@ When asked to <dfn export for=Document>run the scroll steps</dfn> for a {{Docume
16861788
1. For each item <var>target</var> in <var>doc</var>'s <a>pending scroll event targets</a>,
16871789
in the order they were added to the list, run these substeps:
16881790

1689-
1. If <var>target</var> is a {{Document}}, <a>fire an event</a> named <a event>scroll</a> that bubbles at <var>target</var>.
1791+
1. If <var>target</var> is a {{Document}}, <a>fire an event</a> named <a event>scroll</a> that bubbles at <var>target</var> and fire an event
1792+
named <a event>scroll</a> at the {{VisualViewport}} that is associated with with <var>target</var>.
16901793
1. Otherwise, <a>fire an event</a> named <a event>scroll</a> at <var>target</var>.
16911794
1. Empty <var>doc</var>'s <a>pending scroll event targets</a>.
16921795

@@ -1717,13 +1820,15 @@ Otherwise, scrolling is done on an element and let <var>doc</var> be the element
17171820
<tr>
17181821
<td><dfn event for=Window>resize</dfn>
17191822
<td>{{Event}}
1720-
<td>{{Window}}
1721-
<td>Fired at the {{Window}} when the <a>viewport</a> is resized.
1823+
<td>{{Window}}, {{VisualViewport}}
1824+
<td>Fired at the {{Window}} when the <a>viewport</a> is resized. Fired at {{VisualViewport}} when the <a>visual viewport</a> is resized
1825+
or the <a>layout viewport</a> is scaled.
17221826
<tr>
17231827
<td><dfn event for="Document, Element">scroll</dfn>
17241828
<td>{{Event}}
1725-
<td>{{Document}}, elements
1726-
<td>Fired at the {{Document}} or element when the <a>viewport</a> or element is scrolled, respectively.
1829+
<td>{{Document}}, elements, {{VisualViewport}}
1830+
<td>Fired at the {{Document}} or element when the <a>viewport</a> or element is scrolled, respectively. Fired at the {{VisualViewport}}
1831+
when the <a>visual viewport</a> is scrolled.
17271832
<tr>
17281833
<td><dfn event for="Document, Element">scrollend</dfn>
17291834
<td>{{Event}}
@@ -1747,6 +1852,10 @@ Changes {#changes}
17471852
This section documents some of the changes between publications of this specification. This section is not exhaustive. Bug fixes and editorial changes are
17481853
generally not listed.
17491854

1855+
<h3 id='changes-from-2022-07-07' class=no-num>Changes From 07 July 2022</h3>
1856+
* Introduced the {{VisualViewport}} API and related concepts
1857+
* Pinch zoom is now renamed to <a>scale factor</a>
1858+
17501859
<h3 id='changes-from-2022-06-22' class=no-num>Changes From 22 June 2022</h3>
17511860
* Adam Argyle moved the 'scrollend' event from <a href="https://wicg.github.io/overscroll-scrollend-events/">WICG 'overscroll-scrollend-events'</a> to [[CSSOM-VIEW-1]]
17521861

@@ -1785,7 +1894,7 @@ generally not listed.
17851894
<h3 id='changes-from-2011-08-04' class=no-num>Changes From 4 August 2011 To 17 December 2013</h3>
17861895

17871896
* The specification now handles right-to-left and vertical writing modes.
1788-
* The specification is now aware of <a>page zoom</a> and <a>pinch zoom</a>.
1897+
* The specification is now aware of <a>page zoom</a> and pinch zoom.
17891898
* The 'scroll-behavior' CSS property is introduced and scrolling APIs are extended with a mechanism to control smooth scrolling.
17901899
* The {{Window/moveTo()}}, {{Window/moveBy()}}, {{Window/resizeTo()}} and {{Window/resizeBy()}} methods are now defined.
17911900
* {{Window/innerWidth}} et al now use the WebIDL type {{double}} instead of {{long}}.

0 commit comments

Comments
 (0)