Bug 14442

Summary: Adding a stop with value 1.0 to a gradient that has already been used has no effect
Product: WebKit Reporter: Adam Roben (:aroben) <aroben>
Component: Layout and RenderingAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal    
Priority: P2    
Version: 523.x (Safari 3)   
Hardware: All   
OS: All   
Attachments:
Description Flags
testcase
none
Firefox vs. Safari rendering
none
First attempt
darin: review-
New attempt aroben: review+

Description Adam Roben (:aroben) 2007-06-27 22:14:59 PDT
Adding a stop with value 1.0 to a gradient that has already been used has no effect. This is because CanvasGradient::findStop (http://trac.webkit.org/projects/webkit/browser/trunk/WebCore/html/CanvasGradient.cpp#L164) adds stops with values 0.0 and 1.0 to the gradient if they aren't already present. A stop added with a value of 1.0 after findStep has been called will have no effect because it will be sorted after the one findStop added.
Comment 1 Adam Roben (:aroben) 2007-06-27 22:15:20 PDT
Created attachment 15283 [details]
testcase
Comment 2 Adam Roben (:aroben) 2007-06-27 22:15:44 PDT
Created attachment 15284 [details]
Firefox vs. Safari rendering
Comment 3 Rob Buis 2007-07-04 13:43:36 PDT
Created attachment 15390 [details]
First attempt

This one should work, though I had to do it quickly so it needs good reviewing.
Cheers, 

Rob.
Comment 4 Darin Adler 2007-07-05 00:14:55 PDT
Comment on attachment 15390 [details]
First attempt

Seems like a good idea.

But I don't think this is right yes. I don't think that findStop will return -1 for values that are less than the first stop; we need a test case that covers that.

Also, I don't think the special cases in CanvasGradient::getColor for <= 0 and >= 1 will work properly, since they assume that <= 0 and >= 1 are the first and last stop. In fact, I suspect that was already broken since the sorting is done inside findStop, and there's no guarantee it's called in those cases.
Comment 5 Rob Buis 2007-07-05 01:03:14 PDT
Created attachment 15394 [details]
New attempt

The spec says:

"Before the first stop, the color must be the color of the first stop. After the last stop, the color must be the color of the last stop."

It seems like we did that wrong, FF seems to confirm it. This patch corrects that and fixes the regression.
Cheers,

Rob.
Comment 6 Adam Roben (:aroben) 2007-07-06 01:52:08 PDT
Comment on attachment 15394 [details]
New attempt

Add an ASSERT(m_stopsSorted) to the beginning of CanvasGradient::findStop

otherwise, r=me
Comment 7 Rob Buis 2007-07-06 02:02:24 PDT
Landed in r24048.