Skip to content

Commit cc508eb

Browse files
Ms2gerannevk
authored andcommitted
Clarify the definition of addColorStop()
Also use a single <color> parse algorithm.
1 parent 99e2cdf commit cc508eb

File tree

1 file changed

+73
-60
lines changed

1 file changed

+73
-60
lines changed

source

Lines changed: 73 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,12 +3421,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
34213421
a CSS grammar"
34223422
data-x-href="https://drafts.csswg.org/css-syntax/#parse-grammar">parsed
34233423
according to a particular CSS grammar</dfn>, the relevant algorithm in the CSS Syntax
3424-
specification must be followed. <ref spec=CSSSYNTAX></p>
3425-
3426-
<p>In particular, some features require that a string be <dfn>parsed as a CSS &lt;color&gt;
3427-
value</dfn>. When parsing a CSS value, user agents are required by the CSS specifications to
3428-
apply some error handling rules. These apply to this specification also. <ref spec=CSSCOLOR>
3429-
<ref spec=CSS></p>
3424+
specification must be followed, including error handling rules. <ref spec=CSSSYNTAX></p>
34303425

34313426
<p class="example">For example, user agents are required to close all open constructs upon
34323427
finding the end of a style sheet unexpectedly. Thus, when parsing the string "<code
@@ -3436,6 +3431,31 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
34363431
parenthesis and a missing "blue" value) cannot be parsed, as closing the open construct does not
34373432
result in a viable value.</p>
34383433

3434+
<p>To <dfn id="parsed-as-a-css-color-value">parse a CSS &lt;color> value</dfn>, given a string
3435+
<var>input</var> with an optional element <var>element</var>, run these steps:</p>
3436+
3437+
<ol>
3438+
<li><p>Let <var>color</var> be the result of <span data-x="parse something according to a CSS
3439+
grammar">parsing</span> <var>input</var> as a CSS <span>&lt;color></span>. <ref
3440+
spec=CSSCOLOR></p></li>
3441+
3442+
<li><p>If <var>color</var> is failure, then return failure.</p></li>
3443+
3444+
<li>
3445+
<p>If <var>color</var> is <code>currentColor</code>, then:</p>
3446+
3447+
<ol>
3448+
<li><p>If <var>element</var> is not given, then set <var>color</var> to fully opaque
3449+
black.</p></li>
3450+
3451+
<li><p>Otherwise, set <var>color</var> to the computed value of the <span>'color'</span>
3452+
property of <var>element</var>.</p></li>
3453+
</ol>
3454+
</li>
3455+
3456+
<li><p>Return <var>color</var>.</p></li>
3457+
</ol>
3458+
34393459
<p>The following terms and features are defined in the CSS specification: <ref spec=CSS></p>
34403460

34413461
<ul class="brief">
@@ -3537,6 +3557,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
35373557
<ul class="brief">
35383558
<li><dfn data-x-href="https://drafts.csswg.org/css-color/#named-color">named color</dfn></li>
35393559
<li><dfn data-x-href="https://drafts.csswg.org/css-color/#typedef-color">&lt;color></dfn></li>
3560+
<li><dfn data-x-href="https://drafts.csswg.org/css-color/#valdef-color-currentcolor">currentColor</dfn></li>
35403561
<li>The <dfn data-x-href="https://drafts.csswg.org/css-color/#the-color-property">'color'</dfn> property</li>
35413562
</ul>
35423563

@@ -14050,12 +14071,14 @@ interface <dfn>HTMLMetaElement</dfn> : <span>HTMLElement</span> {
1405014071
whitespace">stripping leading and trailing ASCII whitespace</span> from the value of
1405114072
<var>element</var>'s <code data-x="attr-meta-content">content</code> attribute.</p></li>
1405214073

14053-
<li><p>If <var>value</var> can be <span>parsed as a CSS &lt;color&gt; value</span>, return
14054-
the parsed color.</p></li>
14074+
<li><p>Let <var>color</var> be the result of <span data-x="parse a CSS &lt;color>
14075+
value">parsing</span> <var>value</var>.</p></li>
14076+
14077+
<li><p>If <var>color</var> is not failure, then return <var>color</var>.</p></li>
1405514078
</ol>
1405614079
</li>
1405714080

14058-
<li><p>If this step is reached, the page has no theme color.</p></li>
14081+
<li><p>Return nothing (the page has no theme color).</p></li>
1405914082
</ol>
1406014083

1406114084
<p>If any <code>meta</code> elements are <span data-x="node is inserted into a
@@ -60088,33 +60111,6 @@ context.fillRect(100,0,50,50); // only this square remains</pre>
6008860111
<p>The <dfn><code data-x="dom-context-2d-canvas">canvas</code></dfn> attribute must return the
6008960112
value it was initialized to when the object was created.</p>
6009060113

60091-
<hr>
60092-
60093-
<p id="canvasrenderingcontext2d-currentcolor">Whenever the CSS value <code
60094-
data-x="">currentColor</code> is used as a color in the <code>CanvasRenderingContext2D</code>
60095-
API, the <span>computed value</span> of the <code data-x="">currentColor</code> keyword is
60096-
the <span>computed value</span> of the <span>'color'</span> property on the <code>canvas</code>
60097-
element at the time that the color is specified (e.g. when the appropriate attribute is set, or
60098-
when the method is called; not when the color is rendered or otherwise used). If the computed
60099-
value of the <span>'color'</span> property is undefined for a particular case (e.g. because the element is
60100-
not in a document), then the <span>computed value</span> of the <span>'color'</span> property
60101-
for the purposes of determining the computed value of the <code data-x="">currentColor</code>
60102-
keyword is fully opaque black. <ref spec=CSSCOLOR></p>
60103-
60104-
<p>In the case of <code data-x="dom-canvasgradient-addColorStop">addColorStop()</code> on
60105-
<code>CanvasGradient</code>, the "<span>computed value</span> of the <span>'color'</span>
60106-
property" for the purposes of determining the <span>computed value</span> of the <code
60107-
data-x="">currentColor</code> keyword is always fully opaque black (there is no associated
60108-
element). <ref spec=CSSCOLOR></p>
60109-
60110-
<p class="note">This is because <code>CanvasGradient</code> objects are
60111-
<code>canvas</code>-neutral &mdash; a <code>CanvasGradient</code> object created by one
60112-
<code>canvas</code> can be used by another, and there is therefore no way to know which is the
60113-
"element in question" at the time that the color is specified.</p>
60114-
60115-
<p class="note">Similar concerns exist with font-related properties; the rules for those are
60116-
described in detail in the relevant section below.</p>
60117-
6011860114
</div>
6011960115

6012060116
<hr>
@@ -62370,18 +62366,14 @@ try {
6237062366
or style to use for the lines around the shapes.</p>
6237162367

6237262368
<p>Both attributes can be either strings, <code>CanvasGradient</code>s, or
62373-
<code>CanvasPattern</code>s. On setting, strings must be <span data-x="parsed as a CSS
62374-
&lt;color&gt; value">parsed as CSS &lt;color&gt; values</span> and the color assigned, and
62375-
<code>CanvasGradient</code> and <code>CanvasPattern</code> objects must be assigned themselves. <ref spec=CSSCOLOR> If the value is a string but cannot be <span>parsed as a CSS
62376-
&lt;color&gt; value</span>, then it must be ignored, and the attribute must retain its previous
62377-
value.
62378-
<!--ADD-TOPIC:Security-->
62379-
If the new value is a <code>CanvasPattern</code> object that is marked as <span
62369+
<code>CanvasPattern</code>s. On setting, strings must be <span data-x="parse a CSS &lt;color>
62370+
value">parsed</span> with this <code>canvas</code> element and the color assigned, and
62371+
<code>CanvasGradient</code> and <code>CanvasPattern</code> objects must be assigned themselves. If
62372+
parsing the value results in failure, then it must be ignored, and the attribute must retain its
62373+
previous value. If the new value is a <code>CanvasPattern</code> object that is marked as <span
6238062374
data-x="concept-canvas-pattern-not-origin-clean">not origin-clean</span>, then the
6238162375
<code>CanvasRenderingContext2D</code>'s <span
62382-
data-x="concept-canvas-origin-clean">origin-clean</span> flag must be set to false.
62383-
<!--REMOVE-TOPIC:Security-->
62384-
</p>
62376+
data-x="concept-canvas-origin-clean">origin-clean</span> flag must be set to false.</p>
6238562377

6238662378
<p>When set to a <code>CanvasPattern</code> or <code>CanvasGradient</code> object, the assignment
6238762379
is <span>live</span>, meaning that changes made to the object after the assignment do affect
@@ -62480,17 +62472,37 @@ try {
6248062472
<div w-nodev>
6248162473

6248262474
<p>The <dfn><code data-x="dom-canvasgradient-addColorStop">addColorStop(<var>offset</var>,
62483-
<var>color</var>)</code></dfn> method on the <code>CanvasGradient</code> interface adds a new stop
62484-
to a gradient. If the <var>offset</var> is less than 0 or greater than 1 then an
62485-
<span>"<code>IndexSizeError</code>"</span> <code>DOMException</code> must be thrown. If the
62486-
<var>color</var> cannot be <span>parsed as a CSS &lt;color&gt; value</span>, then a
62487-
<span>"<code>SyntaxError</code>"</span> <code>DOMException</code> must be thrown. Otherwise, the
62488-
gradient must have a new stop placed, at offset <var>offset</var> relative to the whole gradient,
62489-
and with the color obtained by <span data-x="parsed as a CSS &lt;color&gt; value">parsing
62490-
<var>color</var> as a CSS &lt;color&gt; value</span>. If multiple stops are added at the same
62491-
offset on a gradient, then they must be placed in the order added, with the first one closest to
62492-
the start of the gradient, and each subsequent one infinitesimally further along towards the end
62493-
point (in effect causing all but the first and last stop added at each point to be ignored).</p>
62475+
<var>color</var>)</code></dfn> method on the <code>CanvasGradient</code>, when invoked, must run
62476+
these steps:</p>
62477+
62478+
<ol>
62479+
<li><p>If the <var>offset</var> is less than 0 or greater than 1, then throw an
62480+
<span>"<code>IndexSizeError</code>"</span> <code>DOMException</code>.</p></li>
62481+
62482+
<li>
62483+
<p>Let <var>parsed color</var> be the result of <span data-x="parse a CSS &lt;color>
62484+
value">parsing</span> <var>color</var>.</p>
62485+
62486+
<p class="note">No element is passed to the parser because <code>CanvasGradient</code> objects
62487+
are <code>canvas</code>-neutral &mdash; a <code>CanvasGradient</code> object created by one
62488+
<code>canvas</code> can be used by another, and there is therefore no way to know which is the
62489+
"element in question" at the time that the color is specified.</p>
62490+
</li>
62491+
62492+
<li><p>If <var>parsed color</var> is failure, throw a <span>"<code>SyntaxError</code>"</span>
62493+
<code>DOMException</code>.</p></li>
62494+
62495+
<li>
62496+
<p>Place a new stop on the gradient, at offset <var>offset</var> relative to the whole gradient,
62497+
and with the color <var>parsed color</var>.</p>
62498+
62499+
<p>If multiple stops are added at the same offset on a gradient, then they must be placed in the
62500+
order added, with the first one closest to the start of the gradient, and each subsequent one
62501+
infinitesimally further along towards the end point (in effect causing all but the first and
62502+
last stop added at each point to be ignored).</p>
62503+
</li>
62504+
</ol>
62505+
6249462506

6249562507
<p>The <dfn><code data-x="dom-context-2d-createLinearGradient">createLinearGradient(<var>x0</var>,
6249662508
<var>y0</var>, <var>x1</var>, <var>y1</var>)</code></dfn> method takes four arguments that
@@ -64348,9 +64360,10 @@ function AddCloud(data, x, y) { ... }</pre>
6434864360
<p>On getting, the <span data-x="serialization of a color">serialization of the color</span>
6434964361
must be returned.</p>
6435064362

64351-
<p>On setting, the new value must be <span>parsed as a CSS &lt;color&gt; value</span> and the
64352-
color assigned. If the value cannot be <span>parsed as a CSS &lt;color&gt; value</span> then it
64353-
must be ignored, and the attribute must retain its previous value. <ref spec=CSSCOLOR></p>
64363+
<p>On setting, the new value must be <span data-x="parse a CSS &lt;color> value">parsed</span>
64364+
with this <code>canvas</code> element and the color assigned. If parsing the value results in
64365+
failure then it must be ignored, and the attribute must retain its previous value. <ref
64366+
spec=CSSCOLOR></p>
6435464367

6435564368
<p>The <dfn><code data-x="dom-context-2d-shadowOffsetX">shadowOffsetX</code></dfn> and <dfn><code
6435664369
data-x="dom-context-2d-shadowOffsetY">shadowOffsetY</code></dfn> attributes specify the distance

0 commit comments

Comments
 (0)