aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMátyás Mustoha <mmatyas@inf.u-szeged.hu>2015-04-01 17:15:32 +0200
committerMátyás Mustoha <mmatyas@inf.u-szeged.hu>2015-04-07 16:10:29 +0200
commit6da2ce9b1b93ce2063188c0b296f9047547b9296 (patch)
tree967c697f9f74a7cbecf90b0278f3cd209f6becc5
parent07520de97047916f0d15c7a63b3de20eac50f010 (diff)
downloadservo-6da2ce9b1b93ce2063188c0b296f9047547b9296.tar.gz
servo-6da2ce9b1b93ce2063188c0b296f9047547b9296.zip
Canvas: added lineWidth support.
-rw-r--r--components/canvas/canvas_paint_task.rs6
-rw-r--r--components/script/dom/canvasrenderingcontext2d.rs15
-rw-r--r--components/script/dom/webidls/CanvasRenderingContext2D.webidl21
-rw-r--r--tests/wpt/metadata/2dcontext/drawing-rectangles-to-the-canvas/2d.strokeRect.basic.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/drawing-rectangles-to-the-canvas/2d.strokeRect.globalalpha.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/drawing-rectangles-to-the-canvas/2d.strokeRect.globalcomposite.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/line-styles/2d.line.join.bevel.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/line-styles/2d.line.union.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/line-styles/2d.line.width.basic.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/line-styles/2d.line.width.invalid.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/line-styles/2d.line.width.valid.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.scale.2.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.selfintersect.2.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.shape.2.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.shape.4.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.twopie.2.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.twopie.3.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.twopie.4.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.arcTo.coincide.1.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.arcTo.shape.start.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.bezierCurveTo.ensuresubpath.2.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.bezierCurveTo.shape.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.quadraticCurveTo.ensuresubpath.2.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.quadraticCurveTo.shape.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.stroke.overlap.html.ini5
-rw-r--r--tests/wpt/metadata/2dcontext/path-objects/2d.path.stroke.union.html.ini5
-rw-r--r--tests/wpt/metadata/html/dom/interfaces.html.ini6
27 files changed, 52 insertions, 111 deletions
diff --git a/components/canvas/canvas_paint_task.rs b/components/canvas/canvas_paint_task.rs
index 403e4b2a3c7..bb0793df948 100644
--- a/components/canvas/canvas_paint_task.rs
+++ b/components/canvas/canvas_paint_task.rs
@@ -38,6 +38,7 @@ pub enum CanvasMsg {
ArcTo(Point2D<f32>, Point2D<f32>, f32),
SetFillStyle(FillOrStrokeStyle),
SetStrokeStyle(FillOrStrokeStyle),
+ SetLineWidth(f32),
SetTransform(Matrix2D<f32>),
Recreate(Size2D<i32>),
SendPixelContents(Sender<Vec<u8>>),
@@ -237,6 +238,7 @@ impl<'a> CanvasPaintTask<'a> {
}
CanvasMsg::SetFillStyle(style) => painter.set_fill_style(style),
CanvasMsg::SetStrokeStyle(style) => painter.set_stroke_style(style),
+ CanvasMsg::SetLineWidth(width) => painter.set_line_width(width),
CanvasMsg::SetTransform(ref matrix) => painter.set_transform(matrix),
CanvasMsg::Recreate(size) => painter.recreate(size),
CanvasMsg::SendPixelContents(chan) => painter.send_pixel_contents(chan),
@@ -412,6 +414,10 @@ impl<'a> CanvasPaintTask<'a> {
self.stroke_style = style.to_azure_pattern(&self.drawtarget)
}
+ fn set_line_width(&mut self, width: f32) {
+ self.stroke_opts.line_width = width;
+ }
+
fn set_transform(&mut self, transform: &Matrix2D<f32>) {
self.transform = *transform;
self.drawtarget.set_transform(transform)
diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs
index fc8573923d0..96bd12b3958 100644
--- a/components/script/dom/canvasrenderingcontext2d.rs
+++ b/components/script/dom/canvasrenderingcontext2d.rs
@@ -41,6 +41,7 @@ pub struct CanvasRenderingContext2D {
canvas: JS<HTMLCanvasElement>,
image_smoothing_enabled: Cell<bool>,
stroke_color: Cell<RGBA>,
+ line_width: Cell<f64>,
fill_color: Cell<RGBA>,
transform: Cell<Matrix2D<f32>>,
}
@@ -61,6 +62,7 @@ impl CanvasRenderingContext2D {
canvas: JS::from_rooted(canvas),
image_smoothing_enabled: Cell::new(true),
stroke_color: Cell::new(black),
+ line_width: Cell::new(1.0),
fill_color: Cell::new(black),
transform: Cell::new(Matrix2D::identity()),
}
@@ -649,6 +651,19 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
Ok(CanvasGradient::new(self.global.root().r(),
CanvasGradientStyle::Radial(RadialGradientStyle::new(x0, y0, r0, x1, y1, r1, Vec::new()))))
}
+
+ fn LineWidth(self) -> f64 {
+ self.line_width.get()
+ }
+
+ fn SetLineWidth(self, width: f64) {
+ if !width.is_finite() || width <= 0.0 {
+ return;
+ }
+
+ self.line_width.set(width);
+ self.renderer.send(CanvasMsg::SetLineWidth(width as f32)).unwrap()
+ }
}
#[unsafe_destructor]
diff --git a/components/script/dom/webidls/CanvasRenderingContext2D.webidl b/components/script/dom/webidls/CanvasRenderingContext2D.webidl
index 511a26ae66b..ba088067dc9 100644
--- a/components/script/dom/webidls/CanvasRenderingContext2D.webidl
+++ b/components/script/dom/webidls/CanvasRenderingContext2D.webidl
@@ -131,6 +131,26 @@ interface CanvasRenderingContext2D {
};
[NoInterfaceObject]
+interface CanvasDrawingStyles {
+ // line caps/joins
+ attribute unrestricted double lineWidth; // (default 1)
+ //attribute DOMString lineCap; // "butt", "round", "square" (default "butt")
+ //attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter")
+ //attribute unrestricted double miterLimit; // (default 10)
+
+ // dashed lines
+ //void setLineDash(sequence<unrestricted double> segments); // default empty
+ //sequence<unrestricted double> getLineDash();
+ //attribute unrestricted double lineDashOffset;
+
+ // text
+ //attribute DOMString font; // (default 10px sans-serif)
+ //attribute DOMString textAlign; // "start", "end", "left", "right", "center" (default: "start")
+ //attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" (default: "alphabetic")
+ //attribute DOMString direction; // "ltr", "rtl", "inherit" (default: "inherit")
+};
+
+[NoInterfaceObject]
interface CanvasPathMethods {
// shared path API methods
void closePath();
@@ -159,5 +179,6 @@ interface CanvasPathMethods {
};
+CanvasRenderingContext2D implements CanvasDrawingStyles;
CanvasRenderingContext2D implements CanvasPathMethods;
diff --git a/tests/wpt/metadata/2dcontext/drawing-rectangles-to-the-canvas/2d.strokeRect.basic.html.ini b/tests/wpt/metadata/2dcontext/drawing-rectangles-to-the-canvas/2d.strokeRect.basic.html.ini
deleted file mode 100644
index 844a6ba3474..00000000000
--- a/tests/wpt/metadata/2dcontext/drawing-rectangles-to-the-canvas/2d.strokeRect.basic.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.strokeRect.basic.html]
- type: testharness
- [strokeRect works]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/drawing-rectangles-to-the-canvas/2d.strokeRect.globalalpha.html.ini b/tests/wpt/metadata/2dcontext/drawing-rectangles-to-the-canvas/2d.strokeRect.globalalpha.html.ini
new file mode 100644
index 00000000000..6d4c4fe583d
--- /dev/null
+++ b/tests/wpt/metadata/2dcontext/drawing-rectangles-to-the-canvas/2d.strokeRect.globalalpha.html.ini
@@ -0,0 +1,5 @@
+[2d.strokeRect.globalalpha.html]
+ type: testharness
+ [strokeRect is affected by globalAlpha]
+ expected: FAIL
+
diff --git a/tests/wpt/metadata/2dcontext/drawing-rectangles-to-the-canvas/2d.strokeRect.globalcomposite.html.ini b/tests/wpt/metadata/2dcontext/drawing-rectangles-to-the-canvas/2d.strokeRect.globalcomposite.html.ini
new file mode 100644
index 00000000000..4fce54347a4
--- /dev/null
+++ b/tests/wpt/metadata/2dcontext/drawing-rectangles-to-the-canvas/2d.strokeRect.globalcomposite.html.ini
@@ -0,0 +1,5 @@
+[2d.strokeRect.globalcomposite.html]
+ type: testharness
+ [strokeRect is not affected by globalCompositeOperation]
+ expected: FAIL
+
diff --git a/tests/wpt/metadata/2dcontext/line-styles/2d.line.join.bevel.html.ini b/tests/wpt/metadata/2dcontext/line-styles/2d.line.join.bevel.html.ini
deleted file mode 100644
index 4f618507159..00000000000
--- a/tests/wpt/metadata/2dcontext/line-styles/2d.line.join.bevel.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.line.join.bevel.html]
- type: testharness
- [lineJoin \'bevel\' is rendered correctly]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/line-styles/2d.line.union.html.ini b/tests/wpt/metadata/2dcontext/line-styles/2d.line.union.html.ini
deleted file mode 100644
index d3819b5f9cd..00000000000
--- a/tests/wpt/metadata/2dcontext/line-styles/2d.line.union.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.line.union.html]
- type: testharness
- [Canvas test: 2d.line.union]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/line-styles/2d.line.width.basic.html.ini b/tests/wpt/metadata/2dcontext/line-styles/2d.line.width.basic.html.ini
deleted file mode 100644
index d81daf9d6a1..00000000000
--- a/tests/wpt/metadata/2dcontext/line-styles/2d.line.width.basic.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.line.width.basic.html]
- type: testharness
- [lineWidth determines the width of line strokes]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/line-styles/2d.line.width.invalid.html.ini b/tests/wpt/metadata/2dcontext/line-styles/2d.line.width.invalid.html.ini
deleted file mode 100644
index e3b85032ad3..00000000000
--- a/tests/wpt/metadata/2dcontext/line-styles/2d.line.width.invalid.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.line.width.invalid.html]
- type: testharness
- [Setting lineWidth to invalid values is ignored]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/line-styles/2d.line.width.valid.html.ini b/tests/wpt/metadata/2dcontext/line-styles/2d.line.width.valid.html.ini
deleted file mode 100644
index b2c4e676ccb..00000000000
--- a/tests/wpt/metadata/2dcontext/line-styles/2d.line.width.valid.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.line.width.valid.html]
- type: testharness
- [Setting lineWidth to valid values works]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.scale.2.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.scale.2.html.ini
deleted file mode 100644
index 457a90e47be..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.scale.2.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.arc.scale.2.html]
- type: testharness
- [Highly scaled arcs are the right shape]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.selfintersect.2.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.selfintersect.2.html.ini
deleted file mode 100644
index f0aa0f59ab3..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.selfintersect.2.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.arc.selfintersect.2.html]
- type: testharness
- [arc() with lineWidth > 2*radius is drawn sensibly]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.shape.2.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.shape.2.html.ini
deleted file mode 100644
index eca2267ee9e..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.shape.2.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.arc.shape.2.html]
- type: testharness
- [arc() from 0 to pi draws stuff in the right half]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.shape.4.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.shape.4.html.ini
deleted file mode 100644
index a9441c8ff7b..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.shape.4.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.arc.shape.4.html]
- type: testharness
- [arc() from 0 to -pi/2 draws stuff in the right quadrant]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.twopie.2.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.twopie.2.html.ini
deleted file mode 100644
index deed1c408ec..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.twopie.2.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.arc.twopie.2.html]
- type: testharness
- [arc() draws a full circle when end = start + 2pi-e and clockwise]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.twopie.3.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.twopie.3.html.ini
deleted file mode 100644
index eb1a8875b19..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.twopie.3.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.arc.twopie.3.html]
- type: testharness
- [arc() draws a full circle when end = start + 2pi+e and anticlockwise]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.twopie.4.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.twopie.4.html.ini
deleted file mode 100644
index 9b60546068c..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arc.twopie.4.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.arc.twopie.4.html]
- type: testharness
- [arc() draws nothing when end = start + 2pi+e and clockwise]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arcTo.coincide.1.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.arcTo.coincide.1.html.ini
deleted file mode 100644
index 48de25791b4..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arcTo.coincide.1.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.arcTo.coincide.1.html]
- type: testharness
- [arcTo() has no effect if P0 = P1]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arcTo.shape.start.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.arcTo.shape.start.html.ini
deleted file mode 100644
index 69a3f30735b..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.arcTo.shape.start.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.arcTo.shape.start.html]
- type: testharness
- [arcTo() draws a straight line from P0 to P1]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.bezierCurveTo.ensuresubpath.2.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.bezierCurveTo.ensuresubpath.2.html.ini
deleted file mode 100644
index 706725605f5..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.bezierCurveTo.ensuresubpath.2.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.bezierCurveTo.ensuresubpath.2.html]
- type: testharness
- [If there is no subpath, the first control point is added]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.bezierCurveTo.shape.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.bezierCurveTo.shape.html.ini
deleted file mode 100644
index 90b2a0bee97..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.bezierCurveTo.shape.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.bezierCurveTo.shape.html]
- type: testharness
- [Canvas test: 2d.path.bezierCurveTo.shape]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.quadraticCurveTo.ensuresubpath.2.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.quadraticCurveTo.ensuresubpath.2.html.ini
deleted file mode 100644
index 393a15509f0..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.quadraticCurveTo.ensuresubpath.2.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.quadraticCurveTo.ensuresubpath.2.html]
- type: testharness
- [If there is no subpath, the first control point is added]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.quadraticCurveTo.shape.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.quadraticCurveTo.shape.html.ini
deleted file mode 100644
index 46cd3f28585..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.quadraticCurveTo.shape.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.quadraticCurveTo.shape.html]
- type: testharness
- [Canvas test: 2d.path.quadraticCurveTo.shape]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.stroke.overlap.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.stroke.overlap.html.ini
deleted file mode 100644
index cc7b9903abe..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.stroke.overlap.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.stroke.overlap.html]
- type: testharness
- [Stroked subpaths are combined before being drawn]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/2dcontext/path-objects/2d.path.stroke.union.html.ini b/tests/wpt/metadata/2dcontext/path-objects/2d.path.stroke.union.html.ini
deleted file mode 100644
index b539c394b03..00000000000
--- a/tests/wpt/metadata/2dcontext/path-objects/2d.path.stroke.union.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[2d.path.stroke.union.html]
- type: testharness
- [Strokes in opposite directions are unioned, not subtracted]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini
index 6bb217f0051..d3bf2fe08f1 100644
--- a/tests/wpt/metadata/html/dom/interfaces.html.ini
+++ b/tests/wpt/metadata/html/dom/interfaces.html.ini
@@ -7026,9 +7026,6 @@
[CanvasRenderingContext2D interface: operation putImageData(ImageData,double,double)]
expected: FAIL
- [CanvasRenderingContext2D interface: attribute lineWidth]
- expected: FAIL
-
[CanvasRenderingContext2D interface: attribute lineCap]
expected: FAIL
@@ -7242,9 +7239,6 @@
[CanvasRenderingContext2D interface: calling removeHitRegion(DOMString) 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 "lineWidth" with the proper type (59)]
- expected: FAIL
-
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "lineCap" with the proper type (60)]
expected: FAIL