Skip to content
Permalink
Browse files

Implement IsPointInPath

  • Loading branch information
dzbarsky committed Dec 6, 2015
1 parent 2af23dc commit 789a90a82f7d0c89bf2b1065acbf218626a66a41
Showing with 71 additions and 128 deletions.
  1. +11 −0 components/canvas/canvas_paint_task.rs
  2. +7 −0 components/canvas_traits/lib.rs
  3. +14 −1 components/script/dom/canvasrenderingcontext2d.rs
  4. +4 −5 components/script/dom/webidls/CanvasRenderingContext2D.webidl
  5. +11 −11 components/servo/Cargo.lock
  6. +12 −12 ports/cef/Cargo.lock
  7. +11 −11 ports/gonk/Cargo.lock
  8. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.arc.html.ini
  9. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.basic.1.html.ini
  10. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.basic.2.html.ini
  11. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.bezier.html.ini
  12. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.bigarc.html.ini
  13. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.edge.html.ini
  14. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.empty.html.ini
  15. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.nonfinite.html.ini
  16. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.outside.html.ini
  17. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.subpath.html.ini
  18. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.transform.1.html.ini
  19. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.transform.3.html.ini
  20. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.unclosed.html.ini
  21. +0 −5 tests/wpt/metadata/2dcontext/path-objects/2d.path.isPointInPath.winding.html.ini
  22. +1 −0 tests/wpt/metadata/XMLHttpRequest/send-content-type-string.htm.ini
  23. +0 −18 tests/wpt/metadata/html/dom/interfaces.html.ini
@@ -136,6 +136,9 @@ impl<'a> CanvasPaintTask<'a> {
Canvas2dMsg::Fill => painter.fill(),
Canvas2dMsg::Stroke => painter.stroke(),
Canvas2dMsg::Clip => painter.clip(),
Canvas2dMsg::IsPointInPath(x, y, fill_rule, chan) => {
painter.is_point_in_path(x, y, fill_rule, chan)
},
Canvas2dMsg::DrawImage(imagedata, image_size, dest_rect, source_rect,
smoothing_enabled) => {
painter.draw_image(imagedata, image_size, dest_rect, source_rect, smoothing_enabled)
@@ -318,6 +321,14 @@ impl<'a> CanvasPaintTask<'a> {
self.drawtarget.push_clip(&self.path_builder.finish());
}

fn is_point_in_path(&mut self, x: f64, y: f64,
_fill_rule: FillRule, chan: IpcSender<bool>) {
let path = self.path_builder.finish();
let result = path.contains_point(x, y, &self.state.transform);
self.path_builder = path.copy_to_builder();
chan.send(result).unwrap();
}

fn draw_image(&self, image_data: Vec<u8>, image_size: Size2D<f64>,
dest_rect: Rect<f64>, source_rect: Rect<f64>, smoothing_enabled: bool) {
// We round up the floating pixel values to draw the pixels
@@ -42,6 +42,12 @@ use std::str::FromStr;
use std::sync::mpsc::Sender;
use util::mem::HeapSizeOf;

#[derive(Clone, Deserialize, Serialize)]
pub enum FillRule {
Nonzero,
Evenodd,
}

#[derive(Clone, Deserialize, Serialize)]
pub enum CanvasMsg {
Canvas2d(Canvas2dMsg),
@@ -93,6 +99,7 @@ pub enum Canvas2dMsg {
Fill,
FillRect(Rect<f32>),
GetImageData(Rect<i32>, Size2D<f64>, IpcSender<Vec<u8>>),
IsPointInPath(f64, f64, FillRule, IpcSender<bool>),
LineTo(Point2D<f32>),
MoveTo(Point2D<f32>),
PutImageData(Vec<u8>, Point2D<f64>, Size2D<f64>, Rect<f64>),
@@ -5,7 +5,7 @@
use canvas::canvas_paint_task::RectToi32;
use canvas_traits::{Canvas2dMsg, CanvasCommonMsg, CanvasMsg};
use canvas_traits::{CompositionOrBlending, LineCapStyle, LineJoinStyle};
use canvas_traits::{FillOrStrokeStyle, LinearGradientStyle, RadialGradientStyle, RepetitionStyle};
use canvas_traits::{FillOrStrokeStyle, FillRule, LinearGradientStyle, RadialGradientStyle, RepetitionStyle};
use cssparser::Color as CSSColor;
use cssparser::{Parser, RGBA};
use dom::bindings::cell::DOMRefCell;
@@ -695,6 +695,19 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
self.ipc_renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::Clip)).unwrap();
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-ispointinpath
fn IsPointInPath(&self, x: f64, y: f64, fill_rule: CanvasFillRule) -> bool {
let fill_rule = match fill_rule {
CanvasFillRule::Nonzero => FillRule::Nonzero,
CanvasFillRule::Evenodd => FillRule::Evenodd,
};
let (sender, receiver) = ipc::channel::<bool>().unwrap();
self.ipc_renderer
.send(CanvasMsg::Canvas2d(Canvas2dMsg::IsPointInPath(x, y, fill_rule, sender)))
.unwrap();
receiver.recv().unwrap()
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
fn DrawImage(&self,
image: HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D,
@@ -94,13 +94,12 @@ interface CanvasRenderingContext2D {
void clip(optional CanvasFillRule fillRule = "nonzero");
//void clip(Path2D path, optional CanvasFillRule fillRule = "nonzero");
//void resetClip();
//boolean isPointInPath(unrestricted double x, unrestricted double y,
boolean isPointInPath(unrestricted double x, unrestricted double y,
optional CanvasFillRule fillRule = "nonzero");
//boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y,
// optional CanvasFillRule fillRule = "nonzero");
//boolean isPointInPath(Path2D path, unrestricted double x, unrestricted
// double y, optional CanvasFillRule fillRule = "nonzero");
//boolean isPointInStroke(unrestricted double x, unrestricted double y);
// boolean isPointInStroke(Path2D path, unrestricted double x,
// unrestricted double y);
//boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);

// text (see also the CanvasDrawingStyles interface)
//void fillText(DOMString text, unrestricted double x, unrestricted double y,

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 789a90a

Please sign in to comment.
You can’t perform that action at this time.