Skip to content

Commit

Permalink
Implement Ellipse Canvas 2D API
Browse files Browse the repository at this point in the history
* Update rust-azure to 0.21.0
* Mark the following test case as fail:
  tests/wpt/mozilla/tests/mozilla/css-paint-api/background-image-tiled.html
* Make the ellipse test case pass.

BUG: #17598
  • Loading branch information
Joone Hur committed Sep 1, 2017
1 parent ac7cf53 commit 57e283a
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions components/canvas/canvas_paint_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ impl<'a> CanvasPaintThread<'a> {
Canvas2dMsg::ArcTo(ref cp1, ref cp2, radius) => {
painter.arc_to(cp1, cp2, radius)
}
Canvas2dMsg::Ellipse(ref center, radius_x, radius_y, rotation, start, end, ccw) => {
painter.ellipse(center, radius_x, radius_y, rotation, start, end, ccw)
}
Canvas2dMsg::RestoreContext => painter.restore_context_state(),
Canvas2dMsg::SaveContext => painter.save_context_state(),
Canvas2dMsg::SetFillStyle(style) => painter.set_fill_style(style),
Expand Down Expand Up @@ -501,6 +504,17 @@ impl<'a> CanvasPaintThread<'a> {
}
}

fn ellipse(&mut self,
center: &Point2D<AzFloat>,
radius_x: AzFloat,
radius_y: AzFloat,
rotation_angle: AzFloat,
start_angle: AzFloat,
end_angle: AzFloat,
ccw: bool) {
self.path_builder.ellipse(*center, radius_x, radius_y, rotation_angle, start_angle, end_angle, ccw);
}

fn set_fill_style(&mut self, style: FillOrStrokeStyle) {
if let Some(pattern) = style.to_azure_pattern(&self.drawtarget) {
self.state.fill_style = pattern
Expand Down
1 change: 1 addition & 0 deletions components/canvas_traits/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub enum Canvas2dMsg {
ClearRect(Rect<f32>),
Clip,
ClosePath,
Ellipse(Point2D<f32>, f32, f32, f32, f32, f32, bool),
Fill,
FillText(String, f64, f64, Option<f64>),
FillRect(Rect<f32>),
Expand Down
20 changes: 20 additions & 0 deletions components/script/dom/canvasrenderingcontext2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,26 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
Ok(())
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-ellipse
fn Ellipse(&self, x: f64, y: f64, rx: f64, ry: f64, rotation: f64, start: f64, end: f64, ccw: bool) -> ErrorResult {
if !([x, y, rx, ry, rotation, start, end].iter().all(|x| x.is_finite())) {
return Ok(());
}
if rx < 0.0 || ry < 0.0 {
return Err(Error::IndexSize);
}

let msg = CanvasMsg::Canvas2d(Canvas2dMsg::Ellipse(Point2D::new(x as f32, y as f32),
rx as f32,
ry as f32,
rotation as f32,
start as f32,
end as f32,
ccw));
self.ipc_renderer.send(msg).unwrap();
Ok(())
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled
fn ImageSmoothingEnabled(&self) -> bool {
let state = self.state.borrow();
Expand Down
5 changes: 5 additions & 0 deletions components/script/dom/paintrenderingcontext2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ impl PaintRenderingContext2DMethods for PaintRenderingContext2D {
self.context.ArcTo(cp1x, cp1y, cp2x, cp2y, r)
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-ellipse
fn Ellipse(&self, x: f64, y: f64, rx: f64, ry: f64, rotation: f64, start: f64, end: f64, ccw: bool) -> ErrorResult {
self.context.Ellipse(x, y, rx, ry, rotation, start, end, ccw)
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled
fn ImageSmoothingEnabled(&self) -> bool {
self.context.ImageSmoothingEnabled()
Expand Down
5 changes: 5 additions & 0 deletions components/script/dom/webidls/CanvasRenderingContext2D.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,9 @@ interface CanvasPath {
// [LenientFloat] void ellipse(double x, double y, double radiusX, double radiusY,
// double rotation, double startAngle, double endAngle,
// boolean anticlockwise);

[Throws]
void ellipse(unrestricted double x, unrestricted double y, unrestricted double radius_x,
unrestricted double radius_y, unrestricted double rotation, unrestricted double startAngle,
unrestricted double endAngle, optional boolean anticlockwise = false);
};
12 changes: 0 additions & 12 deletions tests/wpt/metadata/html/dom/interfaces.html.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3927,9 +3927,6 @@
[CanvasRenderingContext2D interface: attribute direction]
expected: FAIL

[CanvasRenderingContext2D interface: operation ellipse(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,boolean)]
expected: FAIL

[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "width" with the proper type (1)]
expected: FAIL

Expand Down Expand Up @@ -4050,12 +4047,6 @@
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "direction" with the proper type (69)]
expected: FAIL

[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "ellipse" with the proper type (79)]
expected: FAIL

[CanvasRenderingContext2D interface: calling ellipse(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,boolean) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
expected: FAIL

[CanvasPattern interface: operation setTransform(SVGMatrix)]
expected: FAIL

Expand Down Expand Up @@ -9591,9 +9582,6 @@
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "direction" with the proper type (68)]
expected: FAIL
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "ellipse" with the proper type (78)]
expected: FAIL
[CanvasPattern interface: operation setTransform(DOMMatrixInit)]
expected: FAIL
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[background-image-tiled.html]
type: reftest
expected: FAIL

0 comments on commit 57e283a

Please sign in to comment.