Re: Clarification on CanvasGradient Behaviour

On Wed, 3 Mar 2010, Jatinder Mann wrote:
> 
> As we continue to review the HTML5 Canvas 2D Context Specification [1] 
> we came across an issue that needs clarification in Section 5 Colors and 
> styles.
> 
> What is the expected behaviour when a CanvasGradient object is modified 
> after it gets assigned? Does the drawing use the parameters of the 
> gradient at the time of assignment or at the time of drawing?
> 
> In the following example, will the stops added in lines 6 and 7 appear 
> in the gradient drawn in line 9? Can the spec clarify this point?
> 
> 0 var gradient = ctx.createLinearGradient(0,0,0,150);
> 1 gradient.addColorStop(0, 'blue');
> 2 gradient.addColorStop(.5, 'white');
>  
> 3 //assign gradient to fill style
> 4 ctx.fillStyle = gradient;
>  
> 5 //add additional stops after assignment
> 6 gradient.addColorStop(.5, 'red');
> 7 gradient.addColorStop(1, 'white');
> 
> 8 // draw shapes
> 9 ctx.fillRect(10,10,130,130);

To answer your questions, yes and yes respectively.


On Wed, 3 Mar 2010, Philip Taylor wrote:
> 
> It looks like the latest versions of Firefox, Opera, Safari and 
> Konqueror agree that the gradient is drawn based on the stops that are 
> present at the time of drawing (which is the behaviour the test 
> expects). Only Chrome disagrees and uses the stops at the time of 
> assignment.
> 
> I don't see anything in the spec that is explicit about this, so I agree 
> it would be nice to clarify it.

I don't see any way to interpret the spec literally that leads to the 
Chrome behaviour, to be honest. But I've added clarififcations on the 
matter.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Friday, 12 March 2010 01:01:52 UTC