Re: [cssom] serializing <color>

On Mon, Feb 15, 2010 at 7:47 AM, Anne van Kesteren <annevk@opera.com> wrote:
> Opera uses the algorithm specified for <canvas> everywhere. This means
> #rrggbb for when alpha is 1 and otherwise rgba().
>
>
> Gecko uses different serialization algorithms. System colors and color
> keywords are preserved for e.g. the .style.color case but not for <canvas>.
> (The keywords are returned in lowercase, not in the case specified by the
> specification. I personally like this.) Also, instead of #rrggbb it uses
> rgb() for .style.color, though not for <canvas>.
>
> Gecko also uses a slightly different parser for <canvas> it seems. E.g. I
> found it accepts "red garbage" and treats that the same as "red" whereas
> .style.color will not.
>
>
> WebKit (I toyed with Chrome) seems to follow Gecko, though the <canvas> part
> was quite buggy (fillStyle accepts any string and just returns it?) and
> tests with system colors and .style.color failed.
>
>
> I played in the "Live DOM Viewer" with these bits of code by the way:
>
> <!DOCTYPE html>
> ...<script>
>  var x =document.createElement("canvas").getContext("2d")
>  x.fillStyle = "red garbage"
>  w(x.fillStyle)
> </script>
>
>
> <!DOCTYPE html>
> ...<script>
>  document.body.style.color = "#fff"
>  w(document.body.style.color)
> </script>
>
>
> Any thoughts as to what direction we want this to go in?
>
> Personally I quite prefer the way Opera handles this, though preserving
> system colors might be valuable. Not sure.

(By the way, iirc IE's behavior is just to return exactly the same
form you provided.  It meant that I had to handle a *lot* of different
cases in my color parser.)

I also prefer Opera's way of doing it.  The hex form is *much* easier
to parse when retrieving the value.  The rgb() notation requires
running a regexp over the string.  I'd still like to see an #rrggbbaa
notation show up so we can just return that all the time, though.

It might be valuable to return system color names, but not in the
default value (you want a consistent treatment in the normal value).
Perhaps another, read-only value that will be either NULL or a system
color name (or, heck, a normal color name as well).

~TJ

Received on Monday, 15 February 2010 14:00:40 UTC