-
Notifications
You must be signed in to change notification settings - Fork 707
/
Copy pathOverview.bs
429 lines (337 loc) · 18.6 KB
/
Overview.bs
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
<pre class=metadata>
Title: CSS Containment Module Level 1
Level: 1
Shortname: css-contain
Status: ED
Work Status: Revising
Group: csswg
ED: https://drafts.csswg.org/css-contain/
TR: https://www.w3.org/TR/css-contain-1/
Previous Version: https://www.w3.org/TR/2017/WD-css-contain-1-20170419/
Previous Version: https://www.w3.org/TR/2017/WD-css-contain-1-20170221/
Editor: Tab Atkins, Google, http://xanthir.com/contact/, w3cid 42199
Editor: Florian Rivoal, On behalf of Bloomberg, https://florian.rivoal.net/, w3cid 43241
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>...</aside>
<section>
<h2>Messages</h2>
<article>
Lol, check out this dog: images.example.com/jsK3jkl
</article>
<article>
I had a ham sandwich today. #goodtimes
</article>
<article>
I have political opinions that you need to hear!
</article>
…
</section>
</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>
If the element does not generate a <a>principal box</a> (as is the case with ''display: contents'' or ''display: none''),
or if the element is an <a spec="css-display-3">internal table element</a>,
size containment has no effect.
Otherwise, 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.
<a>Replaced elements</a> must be treated as having an intrinsic width and height of 0.
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>
If the element does not generate a <a>principal box</a> (as is the case with ''display: contents'' or ''display: none''),
or if the element is an <a spec="css-display-3">internal table element</a> other than ''display: table-cell'',
layout containment has no effect.
Otherwise, giving an element <dfn export>layout containment</dfn> has the following effects:
1. The element <a>becomes a formatting context root</a>.
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.
3. If the contents of the element overflow the element,
they must be treated as <a>ink overflow</a>.
4. The element acts as a containing block for absolutely positioned and fixed positioned descendants.
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 ''content/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>
If the element does not generate a <a>principal box</a> (as is the case with ''display: contents'' or ''display: none''),
or if the element is an <a spec="css-display-3">internal table element</a> other than ''display: table-cell'',
paint containment has no effect.
Otherwise, giving an element <dfn export>paint containment</dfn> has the following effects:
1. The contents of the element must be clipped to the element's content box,
including both the paint of the descendants and their geometry.
<span class=note>This is similar to ''overflow: clip'',
but has no effect or dependency on the computed value of the 'overflow' property.</span>
This does not include the creation of any mechanism
to access or indicate the presence of the clipped content;
nor does it inhibit the creation of any such mechanism through other properties,
such as 'overflow', 'resize', or 'text-overflow'.
2. The element acts as a containing block for absolutely positioned and fixed positioned descendants.
3. The element creates a <a>stacking context</a>.
4. The element <a>becomes a formatting context root</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. Unless the clipped content is made accessible via a separate mechanism
such as the 'overflow', 'resize', or 'text-overflow' properties,
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.
<h2 id="becoming-formatting-context">Becoming a formatting context root</h2>
In some some types of containement,
a box may need to <dfn export lt='become a formatting context root|becomes a formatting context root|becoming a formatting context root'>become a <a>formatting context</a> root</dfn>.
If the box already establishes a <a>formatting context</a> of any kind other than an <a>inline formatting context</a>,
this condition is satisfied.
Otherwise, it is made to establish a <a>BFC</a> by changing its <a>inner display type</a> to ''flow-root''.
This change happens at <a>used value</a> time,
and does not affect the <a>computed value</a> of the 'display' property.
Issue: What should we do about boxes that establish <a>ruby formatting contexts</a>?
See some discussion here: https://github.com/w3c/csswg-drafts/issues/1457#issuecomment-319996309
Privacy and Security Considerations {#privsec}
==============================================
This specification introduces no new privacy or security considerations.
Like any other CSS specification, it affects the rendering of the document,
but does not introduce any special ability to present content in a misleading way
that was not previously available through other CSS modules
and that isn't inherent to the act of formatting the document.
The <a href="http://www.w3.org/2001/tag/">TAG</a> has developed a <a href="https://www.w3.org/TR/security-privacy-questionnaire/">self-review questionaire</a>
to help editors and Working Groups evaluate the risks introduced by their specifications.
Answers are provided below.
<dl>
<dt>Does this specification deal with personally-identifiable information?
<dd>No.
<dt>Does this specification deal with high-value data?
<dd>No.
<dt>Does this specification introduce new state for an origin that persists across browsing sessions?
<dd>No.
<dt>Does this specification expose persistent, cross-origin state to the web?
<dd>No.
<dt>Does this specification expose any other data to an origin that it doesn’t currently have access to?
<dd>No.
<dt>Does this specification enable new script execution/loading mechanisms?
<dd>No.
<dt>Does this specification allow an origin access to a user’s location?
<dd>No.
<dt>Does this specification allow an origin access to sensors on a user’s device?
<dd>No.
<dt>Does this specification allow an origin access to aspects of a user’s local computing environment?
<dd>No.
<dt>Does this specification allow an origin access to other devices?
<dd>No.
<dt>Does this specification allow an origin some measure of control over a user agent’s native UI?
<dd>No.
<dt>Does this specification expose temporary identifiers to the web?
<dd>No.
<dt>Does this specification distinguish between behavior in first-party and third-party contexts?
<dd>No.
<dt>How should this specification work in the context of a user agent’s "incognito" mode?
<dd>No difference in behavior is needed.
<dt>Does this specification persist data to a user’s local device?
<dd>No.
<dt>Does this specification have a "Security Considerations" and "Privacy Considerations" section?
<dd>Yes, this is the section you are currently reading.
<dt>Does this specification allow downgrading default security characteristics?
<dd>No.
</dl>
<h2 class="no-num" id="changes">Appendix A. Changes</h2>
This appendix is <em>informative</em>.
<h3 id="2017-08-08-changes">Changes from the
<a href="https://www.w3.org/TR/2017/CR-css-contain-1-20170808/">Candidate Recommendation of 8 August 2017</a></h3>
<ul>
<li>Move the definition of "Becoming a formatting context" back to this specification
<li>Rename "Becoming a formatting context" to "Becoming a formatting context root".
</ul>
<h3 id="2017-04-19-changes">Changes from the
<a href="https://www.w3.org/TR/2017/WD-css-contain-1-20170419/">Working Draft of 19 April 2017</a></h3>
<ul>
<li>Clarify the interaction with display: contents
<li>Clarify how containment works on table parts
<li>Move the interaction between containment and fragmentation of overflow from this specification to CSS-OVERFLOW-4
</ul>
<h3 id="fpwd-changes">Changes from the
<a href="https://www.w3.org/TR/2017/WD-css-contain-1-20170221/">First Public Working Draft of 21 February 2017</a></h3>
<ul>
<li>Specify handling of replaced elements for size containment
<li>Layout containment makes element act as a containing block for absolutely positioned and fixed positioned descendants.
</ul>