forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.bs
More file actions
314 lines (253 loc) · 13.6 KB
/
Overview.bs
File metadata and controls
314 lines (253 loc) · 13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<h1>CSS Containment Module Level 3</h1>
<pre class=metadata>
Level: 3
Shortname: css-containment
Status: ED
Work Status: Exploring
Group: csswg
ED: https://drafts.csswg.org/css-containment/
Editor: Tab Atkins, Google, http://xanthir.com/contact/
Abstract: This CSS module describes the 'contain' property, which indicates that the element's subtree is independent of the rest of the page. This enables heavy optimizations by user agents when used well.
Ignored Terms: scrollWidth, scrollHeight, clientWidth, clientHeight, formatting context
Link Defaults: css-lists-3 (property) counter-increment, css-content-3 (property) string-set
</pre>
<h2 id='intro'>
Introduction</h2>
Efficiently rendering a website relies on the User Agent being able to detect what parts of the page are being displayed,
which parts might affect the currently-displayed section,
and what can be ignored.
There are various heuristics that can be used to guess when a given sub-tree is independent of the rest of the page in some manner,
but they're fragile,
so innocuous changes to a page may inadvertently make it flunk the heuristics and fall into a slow mode.
There are also many things that would be good to isolate which are difficult or impossible to detect in a heuristic manner.
To alleviate these problems
and allow strong, predictable isolation of a subtree from the rest of the page,
this specification defines a 'contain' property.
<h2 id='contain-property'>
Strong Containment: the 'contain' property</h2>
<pre class='propdef'>
Name: contain
Value: none | strict | content | [ size || layout || style || paint ]
Initial: none
Inherited: no
Applies to: all elements
Media: all
Computed value: specified value
</pre>
The 'contain' property allows an author to indicate that an element and its contents are,
as much as possible,
<em>independent</em> of the rest of the document tree.
This allows user agents to utilize much stronger optimizations when rendering a page using 'contain' properly,
and allows authors to be confident that their page won't accidentally fall into a slow code path
due to an innocuous change.
<dl dfn-type=value dfn-for=contain>
<dt><dfn>none</dfn>
<dd>
This value indicates that the property has no effect.
The element renders as normal,
with no containment effects applied.
<dt><dfn>strict</dfn>
<dd>
This value turns on all forms of <a>containment</a> for the element.
In other words, it behaves the same as ''contain: size layout style paint;'',
so that its contents are guaranteed to have no effect on the rest of the page outside the element's bounds.
<dt><dfn>content</dfn>
<dd>
This value turns on all forms of <a>containment</a> <em>except</em> <a>size containment</a> for the element.
In other words, it behaves the same as ''contain: layout style paint;''.
Note: ''contain: content'' is reasonably "safe" to apply widely;
its effects are fairly minor in practice,
and most content won't run afoul of its restrictions.
However, because it doesn't apply <a>size containment</a>,
the element can still respond to the size of its contents,
which can cause layout-invalidation to percolate further up the tree than desired.
Use ''contain: strict'' when possible,
to gain as much containment as you can.
<dt><dfn>size</dfn>
<dd>
The value turns on <a>size containment</a> for the element.
This ensures that the containing element can be laid out
without needing to examine its descendants.
<dt><dfn>layout</dfn>
<dd>
This value turns on <a>layout containment</a> for the element.
This ensures that the containing element is <em>totally opaque</em> for layout purposes;
nothing outside can affect its internal layout,
and vice versa.
<dt><dfn>style</dfn>
<dd>
This value turns on <a>style containment</a> for the element.
This ensures that,
for properties which can have effects on more than just an element and its descendants,
those effects don't escape the containing element.
<dt><dfn>paint</dfn>
<dd>
This value turns on <a>paint containment</a> for the element.
This ensures that the descendants of the containing element don't display outside its bounds,
so if an element is off-screen or otherwise not visible,
its descendants are also guaranteed to be not visible.
</dl>
<div class='example'>
'contain' is useful when used widely on a page,
particularly when a page contains a lot of "widgets" which are all independent.
For example, assume a micropost social network had markup something like this:
<pre class='lang-css'>
<body>
<aside class='sidebar'>...</aside>
<article class='messages'>
<section class='message'>
Lol, check out this dog: images.example.com/jsK3jkl
</section>
<section class='message'>
I had a ham sandwich today. #goodtimes
</section>
<section class='message'>
I have political opinions that you need to hear!
</section>
…
</article>
</body>
</pre>
There are probably a <em>lot</em> of messages displayed on the site,
but each is independent and won't affect anything else on the site.
As such, each can be marked with ''contain: content'' to communicate this to the user agent,
so it can optimize the page and skip a lot of computation for messages that are off-screen.
If the size of each message is known ahead of time,
''contain: strict'' can be applied to communicate further restrictions.
</div>
<h2 id='containment-types'>
Types of Containment</h2>
There are several varieties of <dfn export>containment</dfn> that an element can be subject to,
restricting the effects that its descendants can have on the rest of the page in various ways.
<a>Containment</a> enables much more powerful optimizations by user agents,
and helps authors compose their page out of functional units,
as it limits how widely an effect a given change can have on a document.
<h3 id='containment-size'>
Size Containment</h3>
Giving an element <dfn export>size containment</dfn> has the following effect:
1. When laying out the containing element,
it must be treated as having no contents.
After layout of the element is complete,
its contents must then be laid out into the containing element's resolved size.
By itself, <a>size containment</a> does not offer much optimization opportunity.
Its primary benefit on its own is that tools which want to lay out the containing element's contents
based on the containing element's size
(such as a JS library implementing the "container query" concept)
can do so without fear of "infinite loops",
where having a child's size respond to the size of the containing element
causes the containing element's size to change as well,
possibly triggering <em>further</em> changes in how the child sizes itself
and possibly thus more changes to the containing element's size,
ad infinitum.
When paired with <a>layout containment</a>, though,
possible optimizations that can be enabled include (but are not limited to):
1. When the style or contents of a descendant of the containing element is changed,
calculating what part of the DOM tree is "dirtied" and might need to be re-laid out
can stop at the containing element.
2. When laying out the page,
if the containing element is off-screen or obscured,
the layout of its contents can be delayed or done at a lower priority.
<h3 id='containment-layout'>
Layout Containment</h3>
Giving an element <dfn export>layout containment</dfn> has the following effects:
1. The element must be a <a>formatting context</a>.
Issue: This needs to specify how it becomes a formatting
context (and which type it becomes).
2. If a <a>fragmentation context</a> participates in <a>layout containment</a>,
the first element with <a>layout containment</a>
affecting the <a>fragmentation context</a>
must “trap” the remainder of the <a>fragmented flow</a>.
<a>Fragmentation</a> must not continue past the <a>layout containment</a> boundary,
and the last <a>fragmentation container</a>
within the first <a>layout containment</a> boundary
is treated as if it is the last <a>fragmentation container</a>
in its <a>fragmentation context</a>.
If subsequent <a>fragmentation containers</a> in the <a>fragmentation context</a>
are only generated when more content remains in the <a>fragmented flow</a>,
then they are not generated.
If they would exist regardless,
they remain part of the <a>fragmentation context</a>,
but do not receive any content from the <a>fragmented flow</a>.
Specifically:
- <a>CSS Regions</a> following the one which traps the content
are still considered part of the <a>region chain</a>
as returned by the {{NamedFlow/getRegions()}} method
of the {{NamedFlow}} interface.
- the {{Region/regionOverset}} attribute of the {{Region}} interface
of the region which traps the content
is set to ''overset'' if the content doesn't fit,
even if it is not the last region in the region chain.
- If the computed value of the 'continue' property
on an element with <a>layout containment</a>
would otherwise have been ''continue/auto'' or ''continue/fragments'',
it must instead compute to ''continue/overflow''.
3. If the contents of the element overflow the element,
they must not project any "geometry" beyond the element's normal bounds.
In particular, any overflow must not be capable of causing the element's ancestors to overflow;
as far as the ancestors are concerned,
the element is perfectly confined to its normal width×height bounds.
Possible optimizations that can be enabled by <a>layout containment</a> include (but are not limited to):
1. When laying out the page,
the contents of separate containing elements
can be laid out in parallel,
as they're guaranteed not to affect each other.
2. When laying out the page,
if the containing element is off-screen or obscured
and the layout of the visible parts of the screen do not depend on the size of the containing element
(for example, if the containing element is near the end of a block container,
and you're viewing the beginning of the block container),
the layout of the containing elements' contents can be delayed or done at a lower priority.
(When paired with <a>size containment</a>,
this optimization can be applied more liberally.)
<h3 id='containment-style'>
Style Containment</h3>
Giving an element <dfn export>style containment</dfn> has the following effects:
1. The following properties must have no effect on descendants of the element:
* 'break-*' (and the related aliases)
* 'bookmark-*'
* 'string-set'
2. The 'counter-increment', 'counter-set', 'flow-from', 'flow-into', and 'content' (for the purpose of ''open-quote''/etc values) properties must be <a>scoped</a> to the element's sub-tree.
A <dfn export local-lt="scoped">scoped property</dfn> has its effects scoped to a particular element or subtree.
It must act as if the scoping element was the root of the document
for the purpose of evaluating the property's effects:
any uses of the property outside the scoping element must have no effect on the uses of the property on or in the scoping element,
and vice versa.
If scoped to a sub-tree, it's the same,
except the scoping element itself is counted as "outside" the tree,
like the rest of the document.
For example, if 'counter-increment' is scoped to an element,
the first use of it within the subtree acts as if the named counter were set to 0 at the scoping element,
regardless of whether the counter had been used outside the scoping element.
Any increments made within the subtree have no effect on counters of the same name outside the scoping element.
Possible optimizations that can be enabled by <a>style containment</a> include (but are not limited to):
1. Whenever a property is changed on a descendant of the containing element,
calculating what part of the DOM tree is "dirtied" and might need to have its style recalculated
can stop at the containing element.
<h3 id='containment-paint'>
Paint Containment</h3>
Giving an element <dfn export>paint containment</dfn> has the following effects:
1. If the computed value of overflow-x or overflow-y would otherwise have been ''overflow/visible'',
it must instead compute to ''overflow/clip''. [[!CSS-OVERFLOW-3]]
<span class=note>This means that regardless of the specified value of 'overflow',
the contents of the element is clipped to the element's content box,
including both the paint of the descendants and their geometry</span>
2. The element must act as a containing block for absolutely positioned and fixed positioned descendants.
3. The element must be a <a>stacking context</a>.
4. The element must be a <a>formatting context</a>.
Possible optimizations that can be enabled by <a>paint containment</a> include (but are not limited to):
1. If the containing element is off-screen or obscured,
the UA can directly skip trying to paint its contents,
as they're guaranteed to be off-screen/obscured as well.
2. If the containing element's overflow has been changed to ''overflow/clip''
(because it was originally ''overflow/visible''),
the UA can reserve "canvas" space for the element exactly the element's size.
(In similar, scrollable, situations, like ''overflow: hidden'',
it's possible to scroll to the currently-clipped content,
so UAs often predictively overpaint somewhat
so there's something to see as soon as the scroll happens,
rather than a frame later.)
3. Because they are guaranteed to be stacking contexts,
scrolling elements can be painted into a single GPU layer.
Privacy and Security Considerations {#privsec}
==============================================
This specification introduces no new privacy or security considerations.