auto merge of #4891 : mmatyas/servo/canvas_gradient, r=jdm

Based on [ebalint](https://github.com/ebalint)'s original patch, this commit implements the linear and radial gradients for the canvas. The PR also includes test cases.
Depends on #4623 and servo/rust-azure#136.
This commit is contained in:
bors-servo 2015-03-20 03:12:47 -06:00
commit dea36f9816
55 changed files with 290 additions and 228 deletions

View file

@ -65,7 +65,9 @@ flaky_cpu == append_style_a.html append_style_b.html
== box_sizing_sanity_check_a.html box_sizing_sanity_check_ref.html
== br.html br-ref.html
== canvas_as_block_element_a.html canvas_as_block_element_ref.html
== canvas_linear_gradient_a.html canvas_linear_gradient_ref.html
== canvas_lineto_a.html canvas_lineto_ref.html
== canvas_radial_gradient_a.html canvas_radial_gradient_ref.html
== canvas_transform_a.html canvas_transform_ref.html
== case-insensitive-font-family.html case-insensitive-font-family-ref.html
== clear_generated_content_table_a.html clear_generated_content_table_ref.html

View file

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<body>
<style>
html, body {
margin: 0;
padding: 0;
}
canvas {
background-color: green;
}
</style>
<canvas id="c" width="200" height="200">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("c");
var ctx = c.getContext("2d");
var grd = ctx.createLinearGradient(10, 0, 190, 0);
grd.addColorStop(0, "red");
grd.addColorStop(1, "yellow");
ctx.fillStyle = grd;
ctx.fillRect(10, 10, 180, 180);
</script>
</body>
</html>

View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<body>
<style>
html, body {
margin: 0;
padding: 0;
}
section, div {
width: 180px;
height: 180px;
}
section {
padding: 10px;
background-color: green;
}
div {
background: linear-gradient(to right, red, yellow);
}
</style>
<section><div></div></section>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View file

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<body>
<style>
html, body {
margin: 0;
padding: 0;
}
canvas {
background-color: green;
}
</style>
<canvas id="c" width="200" height="200">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("c");
var ctx = c.getContext("2d");
var grd = ctx.createRadialGradient(60, 60, 0, 60, 60, 150);
grd.addColorStop(0, "red");
grd.addColorStop(1, "yellow");
ctx.fillStyle = grd;
ctx.fillRect(10, 10, 180, 180);
</script>
</body>
</html>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<body>
<style>
html, body {
margin: 0;
padding: 0;
}
</style>
<img src="canvas_radial_gradient.png">
</body>
</html>

View file

@ -1,5 +0,0 @@
[2d.missingargs.html]
type: testharness
[Missing arguments cause TypeError]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.empty.html]
type: testharness
[Canvas test: 2d.gradient.empty]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.interpolate.alpha.html]
type: testharness
[Canvas test: 2d.gradient.interpolate.alpha]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.interpolate.colour.html]
type: testharness
[Canvas test: 2d.gradient.interpolate.colour]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.interpolate.multiple.html]
type: testharness
[Canvas test: 2d.gradient.interpolate.multiple]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.interpolate.outside.html]
type: testharness
[Canvas test: 2d.gradient.interpolate.outside]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.interpolate.overlap.html]
type: testharness
[Canvas test: 2d.gradient.interpolate.overlap]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.interpolate.overlap2.html]
type: testharness
[Canvas test: 2d.gradient.interpolate.overlap2]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.interpolate.solid.html]
type: testharness
[Canvas test: 2d.gradient.interpolate.solid]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.interpolate.vertical.html]
type: testharness
[Canvas test: 2d.gradient.interpolate.vertical]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.linear.transform.1.html]
type: testharness
[Linear gradient coordinates are relative to the coordinate space at the time of filling]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.linear.transform.2.html]
type: testharness
[Linear gradient coordinates are relative to the coordinate space at the time of filling]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.linear.transform.3.html]
type: testharness
[Linear gradient transforms do not experience broken caching effects]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.object.crosscanvas.html]
type: testharness
[Canvas test: 2d.gradient.object.crosscanvas]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.object.current.html]
type: testharness
[Canvas test: 2d.gradient.object.current]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.object.return.html]
type: testharness
[createLinearGradient() and createRadialGradient() returns objects implementing CanvasGradient]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.object.type.html]
type: testharness
[window.CanvasGradient exists and has the right properties]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.cone.behind.html]
type: testharness
[Canvas test: 2d.gradient.radial.cone.behind]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.cone.beside.html]
type: testharness
[Canvas test: 2d.gradient.radial.cone.beside]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.cone.bottom.html]
type: testharness
[Canvas test: 2d.gradient.radial.cone.bottom]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.cone.cylinder.html]
type: testharness
[Canvas test: 2d.gradient.radial.cone.cylinder]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.cone.front.html]
type: testharness
[Canvas test: 2d.gradient.radial.cone.front]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.cone.shape1.html]
type: testharness
[Canvas test: 2d.gradient.radial.cone.shape1]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.cone.shape2.html]
type: testharness
[Canvas test: 2d.gradient.radial.cone.shape2]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.cone.top.html]
type: testharness
[Canvas test: 2d.gradient.radial.cone.top]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.equal.html]
type: testharness
[Canvas test: 2d.gradient.radial.equal]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.inside1.html]
type: testharness
[Canvas test: 2d.gradient.radial.inside1]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.inside2.html]
type: testharness
[Canvas test: 2d.gradient.radial.inside2]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.inside3.html]
type: testharness
[Canvas test: 2d.gradient.radial.inside3]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.outside1.html]
type: testharness
[Canvas test: 2d.gradient.radial.outside1]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.outside2.html]
type: testharness
[Canvas test: 2d.gradient.radial.outside2]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.touch1.html]
type: testharness
[Canvas test: 2d.gradient.radial.touch1]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.touch2.html]
type: testharness
[Canvas test: 2d.gradient.radial.touch2]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.touch3.html]
type: testharness
[Canvas test: 2d.gradient.radial.touch3]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.transform.1.html]
type: testharness
[Radial gradient coordinates are relative to the coordinate space at the time of filling]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.transform.2.html]
type: testharness
[Radial gradient coordinates are relative to the coordinate space at the time of filling]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.gradient.radial.transform.3.html]
type: testharness
[Radial gradient transforms do not experience broken caching effects]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.shadow.gradient.transparent.1.html]
type: testharness
[Shadows are not drawn for transparent gradient fills]
expected: FAIL

View file

@ -6978,12 +6978,6 @@
[CanvasRenderingContext2D interface: attribute imageSmoothingEnabled]
expected: FAIL
[CanvasRenderingContext2D interface: operation createLinearGradient(double,double,double,double)]
expected: FAIL
[CanvasRenderingContext2D interface: operation createRadialGradient(double,double,double,double,double,double)]
expected: FAIL
[CanvasRenderingContext2D interface: operation createPattern(CanvasImageSource,DOMString)]
expected: FAIL
@ -7170,18 +7164,6 @@
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "fillStyle" with the proper type (17)]
expected: FAIL
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "createLinearGradient" with the proper type (18)]
expected: FAIL
[CanvasRenderingContext2D interface: calling createLinearGradient(double,double,double,double) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
expected: FAIL
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "createRadialGradient" with the proper type (19)]
expected: FAIL
[CanvasRenderingContext2D interface: calling createRadialGradient(double,double,double,double,double,double) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
expected: FAIL
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "createPattern" with the proper type (20)]
expected: FAIL
@ -7401,9 +7383,6 @@
[CanvasGradient interface object length]
expected: FAIL
[CanvasGradient interface: operation addColorStop(double,DOMString)]
expected: FAIL
[CanvasPattern interface object length]
expected: FAIL

View file

@ -1,5 +0,0 @@
[initial.reset.gradient.html]
type: testharness
[Resetting the canvas state does not invalidate any existing gradients]
expected: FAIL