W3C home > Mailing lists > Public > public-canvas-api@w3.org > January to March 2010

Re: Clarification on CanvasGradient Behaviour

From: Ian Hickson <ian@hixie.ch>
Date: Fri, 12 Mar 2010 01:01:21 +0000 (UTC)
To: Jatinder Mann <jmann@microsoft.com>, Philip Taylor <pjt47@cam.ac.uk>
Cc: "public-canvas-api@w3.org" <public-canvas-api@w3.org>
Message-ID: <Pine.LNX.4.64.1003120055200.21376@ps20323.dreamhostps.com>
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

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:31:49 UTC