You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an early delta spec over [[css-position-3]].
43
45
44
-
<h2 id="painting-order">
45
-
Painting Order and Stacking Contexts</h2>
46
+
47
+
Painting Order and Stacking Contexts {#painting-order}
48
+
====================================
46
49
47
50
This chapter describes the painting order of CSS's [=box tree=].
48
51
@@ -78,24 +81,29 @@ and contains the root element. Initially, the viewport is anchored
78
81
with its top left corner at the canvas origin.
79
82
80
83
<div algorithm>
81
-
To <dfn>paint a document</dfn>,
82
-
given a document |root|
84
+
To <dfn export>paint a document</dfn>,
85
+
given a document |doc|
83
86
and an infinite canvas |canvas|:
84
87
85
-
1. [=Paint a stacking context=] given |root|'s root element
86
-
and |canvas|,
87
-
then return |canvas|.
88
+
1. [=Paint a stacking context=] given |doc|'s root element
89
+
and |canvas|.
90
+
91
+
2. For each element |el| in |doc|'s [=Document/top layer=]:
92
+
1. [=Paint a stacking context=] given |el| and |canvas|,
93
+
treating |el| as a [=stacking context=],
94
+
with the [=initial containing block=]
95
+
as its [=containing block=].
88
96
</div>
89
97
90
98
<div algorithm>
91
-
To <dfn>paint a stacking context</dfn>
99
+
To <dfn export>paint a stacking context</dfn>
92
100
given an [=element=] or [=box=] |root|,
93
101
and an infinite canvas |canvas|:
94
102
95
103
1. If |root| is an [=element=],
96
104
[=paint a stacking context=] given |root|'s [=principal box=]
97
105
and |canvas|,
98
-
then return |canvas|.
106
+
then return.
99
107
100
108
1. Assert: |root| is a [=box=],
101
109
and generates a [=stacking context=].
@@ -183,7 +191,7 @@ with its top left corner at the canvas origin.
183
191
</div>
184
192
185
193
<div algorithm>
186
-
To <dfn>paint a block's decorations</dfn>
194
+
To <dfn export>paint a block's decorations</dfn>
187
195
given a block box |root|
188
196
and a canvas |canvas|:
189
197
@@ -213,7 +221,7 @@ with its top left corner at the canvas origin.
213
221
</div>
214
222
215
223
<div algorithm>
216
-
To <dfn>paint a box in a line box</dfn>,
224
+
To <dfn export>paint a box in a line box</dfn>,
217
225
given a box |root|,
218
226
a line box |line box|,
219
227
and a canvas |canvas|:
@@ -290,7 +298,7 @@ with its top left corner at the canvas origin.
290
298
</div>
291
299
292
300
<div algorithm>
293
-
To <dfn>paint a stacking container</dfn>,
301
+
To <dfn export>paint a stacking container</dfn>,
294
302
given a [=box=] |root|
295
303
and a canvas |canvas|:
296
304
@@ -302,12 +310,182 @@ with its top left corner at the canvas origin.
302
310
</div>
303
311
304
312
UAs can draw outlines (from the 'outline' property)
305
-
either <dfn lt="in-band outline">in-band</dfn>
313
+
either <dfn export lt="in-band outline">in-band</dfn>
306
314
(painted along each element,
307
315
and thus potentially obscured/overlapping by following content)
308
-
or <dfn lt="out-of-band outline">out-of-band</dfn>
316
+
or <dfn export lt="out-of-band outline">out-of-band</dfn>
309
317
(all outlines painted at the end of the stacking context,
310
318
so nothing in the stacking context can obscure them).
311
319
It is recommended that UAs use [=out-of-band outlines=],
312
320
as making outlines easily visible
313
-
is an important accessibility feature.
321
+
is an important accessibility feature.
322
+
323
+
Top Layer {#top-layer}
324
+
=========
325
+
326
+
{{Document}}s have a <dfn export for=Document>top layer</dfn>,
327
+
an [=ordered set=] containing [=elements=] from the document.
328
+
Elements in the [=Document/top layer=]
329
+
do not lay out normally based on their position in the document;
330
+
instead they generate [=boxes=]
331
+
as if they were siblings of the root element.
332
+
[=Document/Top layer=] elements are rendered in the order they appear in the [=Document/top layer=];
333
+
the last element in the [=Document/top layer=] is rendered on top of everything else.
334
+
335
+
{{Document}}s also have a <dfn export>pending top layer removals</dfn>[=ordered set=],
336
+
containing elements that are pending removal.
337
+
(See the algorithms, below, for details on how this is used.)
338
+
339
+
Note: This special rendering behavior ensures
340
+
that elements in the [=Document/top layer=] cannot be clipped by anything in the document,
341
+
or obscured by anything except elements later in the [=Document/top layer=].
342
+
This ensures that things like [=popovers=]
343
+
can be displayed reliably,
344
+
regardless of what their ancestor elements might be doing.
345
+
346
+
Note: The [=Document/top layer=] is managed entirely by the [=user agent=];
347
+
it cannot be directly manipulated by authors.
348
+
This ensures that "nested" invocations of top-layer-using APIs,
349
+
like a popup within a popup,
350
+
will display correctly.
351
+
352
+
Note: The [=Document/top layer=] interacts with the 'overlay' property
353
+
in a somewhat unusual way.
354
+
See 'overlay' for details.
355
+
356
+
The [=Document/top layer=]
357
+
(and the [=pending top layer removals=])
358
+
should not be interacted with directly
359
+
by specification algorithms.
360
+
Instead, specifications should use the following algorithms.
361
+
362
+
<div algorithm>
363
+
To <dfn export lt="add an element to the top layer | add to the top layer">add an element to the top layer</dfn>,
364
+
given a {{Document}} |doc|
365
+
and an {{Element}} |el|:
366
+
367
+
1. If |doc|'s [=Document/top layer=][=set/contains=] |el| already:
368
+
1. If |doc|'s [=pending top layer removals=][=set/contains=] |el| as well,
369
+
[=set/remove=] |el| from both |doc|'s [=Document/top layer=]
370
+
and [=pending top layer removals=],
371
+
then [=set/append=] |el| to |doc|'s [=Document/top layer=].
372
+
Return.
373
+
374
+
<!-- In other words, eagerly process pending removals. -->
375
+
376
+
2. Otherwise, do nothing and return.
377
+
378
+
2. [=set/Append=] |el| to |doc|'s [=Document/top layer=].
379
+
380
+
3. At the UA !important [=cascade origin=],
381
+
add a rule targeting |el|
382
+
containing an ''overlay: auto'' declaration.
383
+
</div>
384
+
385
+
<div algorithm>
386
+
To <dfn export lt="request an element to be removed from the top layer | request removal from the top layer">request an element to be removed from the top layer</dfn>,
387
+
given a {{Document}} |doc|
388
+
and an {{Element}} |el|:
389
+
390
+
1. If |el| is not [=list/contained=] |doc|'s [=Document/top layer=],
391
+
or |el| <em>is</em> already [=list/contained=]
392
+
in |doc|'s [=pending top layer removals=],
393
+
return.
394
+
395
+
2. Remove the UA !important ''overlay: auto'' rule targeting |el|.
396
+
397
+
3. [=set/Append=] |el| to |doc|'s [=pending top layer removals=].
398
+
</div>
399
+
400
+
<div algorithm>
401
+
To <dfn export lt="remove an element from the top layer immediately | remove from the top layer immediately">remove an element from the top layer immediately</dfn>,
402
+
given a {{Document}} |doc|
403
+
and an {{Element}} |el|:
404
+
405
+
1. [=set/Remove=] |el| from |doc|'s [=Document/top layer=] and [=pending top layer removals=].
406
+
407
+
2. Remove the UA !important ''overlay: auto'' rule targeting |el|,
408
+
if it exists.
409
+
410
+
Note: This algorithm is only intended to be used in special cases
411
+
where removing something from the top layer immediately
412
+
(bypassing things like an 'overlay' transition)
413
+
is necessary.
414
+
Most of the time, [=requesting removal from the top layer=] is more appropriate.
415
+
</div>
416
+
417
+
<div algorithm>
418
+
To <dfn export>process top layer removals</dfn>,
419
+
given a {{Document}} |doc|:
420
+
421
+
1. For each element |el| in |doc|'s [=pending top layer removals=]:
422
+
if |el|'s computed value of 'overlay' is ''none'',
423
+
or |el| is [=not rendered=],
424
+
[=set/remove=] |el| from |doc|'s [=Document/top layer=]
425
+
and [=pending top layer removals=].
426
+
427
+
Note: This is intended to be called during the "Update Rendering" step
428
+
of HTML's rendering algorithm.
429
+
It is not intended to be called by other algorithms.
430
+
</div>
431
+
432
+
Controlling the Top Layer: the 'overlay' property {#overlay}
433
+
-------------------------------------------------
434
+
435
+
<pre class=propdef>
436
+
Name: overlay
437
+
Value: none | auto
438
+
Initial: none
439
+
Inherited: no
440
+
Animation Type: (see prose)
441
+
</pre>
442
+
443
+
The 'overlay' property determines and reflects
444
+
whether an element is in the [=Document/top layer=] or not.
445
+
Its values are:
446
+
447
+
<dl dfn-type=value dfn-for=overlay>
448
+
: <dfn>none</dfn>
449
+
:: The element is not in the [=Document/top layer=].
450
+
451
+
: <dfn>auto</dfn>
452
+
:: The element is rendered as part of the [=Document/top layer=].
453
+
Rather than generating boxes as part of its normal position in the document,
454
+
it generates boxes as a sibling of the root element.
455
+
</dl>
456
+
457
+
For animation,
458
+
''overlay/auto'' is [=interpolated=] as a discrete step
459
+
where values of p such that <code>0 < p < 1</code>
460
+
map to ''overlay/auto''
461
+
and other values of p map to the closer endpoint;
462
+
if neither value is ''overlay/auto'' then discrete animation is used.
463
+
464
+
User agents must have the following rule in their UA stylesheet:
465
+
466
+
<pre highlight=css>
467
+
* { overlay: none !important; }
468
+
</pre>
469
+
470
+
This means that the 'overlay' property <em>cannot be set by authors or users</em>--
471
+
it is entirely controlled by the user agent
472
+
(which sets elements to ''overlay: auto'',
473
+
via another UA-!important rule,
474
+
when they're in the [=Document/top layer=]).
475
+
476
+
However, authors <em>can</em> set a [=transition=] on 'overlay',
477
+
forcing it to stay ''overlay/auto'' for a period of time
478
+
(keeping the element in the [=Document/top layer=])
479
+
so an "exit animation" can be used on the element
480
+
(such as fading it out,
481
+
moving it offscreen,
482
+
scaling it down,
483
+
etc)
484
+
before it goes back to its normal, non-top-layer rendering.
485
+
486
+
User agents <em>may</em>, at their discretion,
487
+
remove a running [=transition=] on 'overlay'.
488
+
The conditions for this are intentionally undefined.
489
+
<span class=note>(This is to prevent potential abuse scenarios
490
+
where a ''transition: overlay 1e9s;'' or similar
491
+
attempts to keep an element in the [=Document/top layer=] permanently.)</span>
0 commit comments