servo: Merge #8740 - Implement IsPointInPath for Canvas (from dzbarsky:ispointinpath); r=frewsxcv

Source-Repo: https://github.com/servo/servo
Source-Revision: 98972d04342602610a7465de7b0639e2b9c1dcf3
This commit is contained in:
David Zbarsky 2015-12-06 06:50:23 +05:01
Родитель 636b1c6bcb
Коммит dcbe691e75
7 изменённых файлов: 70 добавлений и 40 удалений

Просмотреть файл

@ -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,

22
servo/components/servo/Cargo.lock сгенерированный
Просмотреть файл

@ -91,8 +91,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "azure"
version = "0.2.0"
source = "git+https://github.com/servo/rust-azure#a835f8578737034d48762b379f19a92bb2882cc0"
version = "0.2.1"
source = "git+https://github.com/servo/rust-azure#b8a761c2d4bc6ee1fa62e1c34763c2f5a7650779"
dependencies = [
"core-foundation 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -153,7 +153,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "canvas"
version = "0.0.1"
dependencies = [
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"canvas_traits 0.0.1",
"cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -172,7 +172,7 @@ dependencies = [
name = "canvas_traits"
version = "0.0.1"
dependencies = [
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_traits 0.0.1",
@ -260,7 +260,7 @@ name = "compositing"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"canvas 0.0.1",
"canvas_traits 0.0.1",
"clipboard 0.1.0 (git+https://github.com/aweinstock314/rust-clipboard)",
@ -623,7 +623,7 @@ name = "gfx"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas_traits 0.0.1",
"core-foundation 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -671,7 +671,7 @@ dependencies = [
name = "gfx_traits"
version = "0.0.1"
dependencies = [
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
]
[[package]]
@ -929,7 +929,7 @@ name = "layers"
version = "0.2.0"
source = "git+https://github.com/servo/rust-layers#c4efb24deb170908a534ae916d23890f85725b17"
dependencies = [
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"cgl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -949,7 +949,7 @@ name = "layout"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas 0.0.1",
"canvas_traits 0.0.1",
@ -1127,7 +1127,7 @@ name = "msg"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas_traits 0.0.1",
"core-foundation 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1952,7 +1952,7 @@ name = "util"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",

24
servo/ports/cef/Cargo.lock сгенерированный
Просмотреть файл

@ -2,7 +2,7 @@
name = "embedding"
version = "0.0.1"
dependencies = [
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"cgl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cocoa 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"compositing 0.0.1",
@ -80,8 +80,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "azure"
version = "0.2.0"
source = "git+https://github.com/servo/rust-azure#a835f8578737034d48762b379f19a92bb2882cc0"
version = "0.2.1"
source = "git+https://github.com/servo/rust-azure#b8a761c2d4bc6ee1fa62e1c34763c2f5a7650779"
dependencies = [
"core-foundation 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -142,7 +142,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "canvas"
version = "0.0.1"
dependencies = [
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"canvas_traits 0.0.1",
"cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -161,7 +161,7 @@ dependencies = [
name = "canvas_traits"
version = "0.0.1"
dependencies = [
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_traits 0.0.1",
@ -260,7 +260,7 @@ name = "compositing"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"canvas 0.0.1",
"canvas_traits 0.0.1",
"clipboard 0.1.0 (git+https://github.com/aweinstock314/rust-clipboard)",
@ -590,7 +590,7 @@ name = "gfx"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas_traits 0.0.1",
"core-foundation 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -631,7 +631,7 @@ dependencies = [
name = "gfx_traits"
version = "0.0.1"
dependencies = [
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
]
[[package]]
@ -889,7 +889,7 @@ name = "layers"
version = "0.2.0"
source = "git+https://github.com/servo/rust-layers#c4efb24deb170908a534ae916d23890f85725b17"
dependencies = [
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"cgl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -909,7 +909,7 @@ name = "layout"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas 0.0.1",
"canvas_traits 0.0.1",
@ -1087,7 +1087,7 @@ name = "msg"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas_traits 0.0.1",
"core-foundation 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1888,7 +1888,7 @@ name = "util"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",

22
servo/ports/gonk/Cargo.lock сгенерированный
Просмотреть файл

@ -71,8 +71,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "azure"
version = "0.2.0"
source = "git+https://github.com/servo/rust-azure#a835f8578737034d48762b379f19a92bb2882cc0"
version = "0.2.1"
source = "git+https://github.com/servo/rust-azure#b8a761c2d4bc6ee1fa62e1c34763c2f5a7650779"
dependencies = [
"core-foundation 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -133,7 +133,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "canvas"
version = "0.0.1"
dependencies = [
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"canvas_traits 0.0.1",
"cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -152,7 +152,7 @@ dependencies = [
name = "canvas_traits"
version = "0.0.1"
dependencies = [
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_traits 0.0.1",
@ -240,7 +240,7 @@ name = "compositing"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"canvas 0.0.1",
"canvas_traits 0.0.1",
"clipboard 0.1.0 (git+https://github.com/aweinstock314/rust-clipboard)",
@ -588,7 +588,7 @@ name = "gfx"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas_traits 0.0.1",
"core-foundation 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -629,7 +629,7 @@ dependencies = [
name = "gfx_traits"
version = "0.0.1"
dependencies = [
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
]
[[package]]
@ -865,7 +865,7 @@ name = "layers"
version = "0.2.0"
source = "git+https://github.com/servo/rust-layers#c4efb24deb170908a534ae916d23890f85725b17"
dependencies = [
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"cgl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -885,7 +885,7 @@ name = "layout"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas 0.0.1",
"canvas_traits 0.0.1",
@ -1063,7 +1063,7 @@ name = "msg"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas_traits 0.0.1",
"core-foundation 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1862,7 +1862,7 @@ name = "util"
version = "0.0.1"
dependencies = [
"app_units 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"azure 0.2.0 (git+https://github.com/servo/rust-azure)",
"azure 0.2.1 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",