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
The paint stage of CSS is responsible for painting the background, content and highlight of an element based on that element's geometry (as generated by the layout stage) and computed style.
17
+
18
+
This specification describes an API which allows developers to paint a part of an element in response to geometry / computed style changes.
19
+
20
+
Issue: Currently this spec doesn't provide any mechanism for setting clip, opacity, filter, etc. on either the context, background of an element. This would be nice to have.
21
+
22
+
Paint Invalidation {#paint-invalidation}
23
+
==================================
24
+
25
+
At any point in time the output of a paint callback for an element may be either <dfn>paint-valid</dfn> or <dfn>paint-invalid</dfn>.
26
+
27
+
Issue: Describe output in a nicer way. This could be pixels, or a display list type object.
28
+
29
+
If the output is <a>paint-invalid</a> and the output should not be used for rendering, and can be safely disposed.
30
+
31
+
Invoking the paint callback will cause the output to become <a>paint-valid</a>.
32
+
33
+
The output of a paint callback will become <a>paint-invalid</a> when:
34
+
* The geometry of an element/fragment (as determined by layout) changes.
35
+
* The computed style of a property that the paint callback has registered a dependency on has changed.
36
+
37
+
Output which is <a>paint-valid</a> does not provide a guarantee that the paint callback is not invoked. Browsers may choose to invoke all callbacks every frame for simplicity.
38
+
Thus to ensure cross-browser compatibility paint callbacks should be idempotent.
39
+
40
+
Output which is <a>paint-invalid</a> are not necessarily invoked on the current frame.
41
+
For example if the element is outside the current viewport, the browser may choose to only invoke the callback when it appears in the viewport.
42
+
43
+
Issue: This describes everything in terms of element which is incorrect. Callbacks should be at the fragment level.
44
+
45
+
Issue: Describe what happens if a callback doesn't hit a frame timing boundary. I.e. just renders a transparent image instead?
46
+
47
+
Issue: Should paint callbacks support partial area invalidation?
48
+
For example if the paint callback just invalidates 1/4 of the actual element, should we provide an API to just update that area?
49
+
This may be expensive for memory/computation for display list based implementations.
:: The list of CSS properties (custom or native) which are provided to the custom paint callback. In addition when any of these properties changes, an element will become <a>paint-invalid</a>.
:: Unregisters a paint callback based on the ID given by <a>registerPaint()</a>.
126
+
127
+
: <dfn argument for=PaintCallback>context</dfn>
128
+
:: The paint callback is passed a new <a href=''>CanvasRenderingContext2d</a> each time it is invoked. Implicitly this means that there is no stored data, or state on the rendering context.
129
+
For example you can't setup a clip on the context, and expect the same clip to be applied next time the function is called.
130
+
131
+
Several methods will be modified from the current CanvasRenderingContext2d. For example:
132
+
* The <a href=''>canvas</a> accessor will throw a <a href=''>InvalidAccessError</a> as the context doesn't have a parent <a href=''>HTMLCanvasElement</a>.
133
+
* <a href=''>getImageData()</a> and similar pixel data accessors will be no-ops.
134
+
* <a href=''>addHitRegion()</a>, <a href=''>removeHitRegion()</a>, <a href=''>clearHitRegions()</a> will be no-ops.
135
+
* <a href=''>drawFocusIfNeeded()</a> will be a no-op.
136
+
137
+
Note: The litmus test used for deciding above was: methods should become no-ops if they can, otherwise throw an error if they'd require an IDL change.
138
+
139
+
Issue: We should probably create a new interface for CanvasRenderingContext2d and use IDL mixins (like CanvasPathMethods) to share common interfaces.
140
+
141
+
: <dfn argument for=PaintCallback>geometry</dfn>
142
+
:: The geometry information for the callback.
143
+
144
+
Issue: Decide what is needed here (in level 1). Obviously we need the width/height of the fragment.
145
+
If we are going down the fragment route do we need continuation data? I.e. what edge is shared etc.
146
+
Do we need children position data?
147
+
Should make sure we don't rabbit hole too much on this, provide what we think is useful for v1, iterate in v2.
Issue: Should this just replace the <<image>> type instead? I don't think so as it'll mean that we can custom paint the cursor. Which I don't think we want.
167
+
168
+
The <<paint()>> function will lookup to see if there has been a paint callback registered with the same name.
169
+
If it has the output of the paint callback should appear in the appropriate place.
170
+
If there is no paint callback registered, the function output should be replaced with a transparent image, as if nothing was there.
171
+
172
+
Issue: Word-smith this better.
173
+
174
+
<pre class='prod'>
175
+
<dfn>paint()</dfn> = paint( <<ident>> )
176
+
</pre>
177
+
178
+
Issue: Change 'background-image', 'border-image' and 'content' to accept <<image-or-paint>> or <<paint()>>.
0 commit comments