[whatwg] Question about gradient stops in canvas and parsing as CSS colors

Boris Zbarsky bzbarsky at MIT.EDU
Wed Sep 22 07:47:02 PDT 2010


Consider this code:

   gradient.addColorStop("1.0","rgba(  0,   0,  0,  0");

where |gradient| is a canvas radial gradient.  Note the lack of ')' at 
the end of the rgba string there.

What's the correct behavior?  The spec says:

   If the color cannot be parsed as a CSS color, then a SYNTAX_ERR
   exception must be raised.

However an actual CSS parser parsing that string as a color would infer 
the closing ')' per CSS 2.1 section 4.2 the item about "unexpected EOF". 
  Note that this is a tokenization-level requirement, as far as I can 
tell, so this happens before the syntax rules for productions like 
<color> are applied.

Observed behavior in UAs is:

* Webkit simply doesn't implement CSS 2.1 section 4.2 correctly

* Opera throws an exception from the addColorStop call above, but shows
   lime text if loading this:
     data:text/html,<span style="color: rgb(0, 255, 0">Lime</span>

* Gecko shows lime text in the HTML testcase and treats the color stop
   above as valid rgba(0, 0, 0, 0).

Clearly I happen to think Gecko's behavior is the sane one here, but 
there's a clear interoperability problem either way.  Certainly Opera 
and Gecko interpreted the spec differently.

-Boris



More information about the whatwg mailing list