mirror of
https://github.com/servo/servo.git
synced 2025-06-08 08:33:26 +00:00
script: Implement enough 2D canvas support to render basic SVGs such as the tiger.
This commit is contained in:
parent
287f390c4a
commit
55a0ee6ec7
28 changed files with 419 additions and 181 deletions
|
@ -10,6 +10,9 @@ path = "lib.rs"
|
||||||
[dependencies.azure]
|
[dependencies.azure]
|
||||||
git = "https://github.com/servo/rust-azure"
|
git = "https://github.com/servo/rust-azure"
|
||||||
|
|
||||||
|
[dependencies.cssparser]
|
||||||
|
git = "https://github.com/servo/rust-cssparser"
|
||||||
|
|
||||||
[dependencies.geom]
|
[dependencies.geom]
|
||||||
git = "https://github.com/servo/rust-geom"
|
git = "https://github.com/servo/rust-geom"
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use azure::azure_hl::{DrawTarget, SurfaceFormat, BackendType, StrokeOptions, DrawOptions};
|
use azure::azure::AzFloat;
|
||||||
use azure::azure_hl::{ColorPattern, PatternRef, JoinStyle, CapStyle, DrawSurfaceOptions, Filter};
|
use azure::azure_hl::{DrawTarget, SurfaceFormat, BackendType, StrokeOptions, DrawOptions, Pattern};
|
||||||
use azure::AzFloat;
|
use azure::azure_hl::{ColorPattern, PathBuilder, JoinStyle, CapStyle, DrawSurfaceOptions, Filter};
|
||||||
|
use geom::matrix2d::Matrix2D;
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
|
@ -12,6 +13,7 @@ use gfx::color;
|
||||||
use util::task::spawn_named;
|
use util::task::spawn_named;
|
||||||
use util::vec::byte_swap;
|
use util::vec::byte_swap;
|
||||||
|
|
||||||
|
use cssparser::RGBA;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
use std::sync::mpsc::{channel, Sender};
|
use std::sync::mpsc::{channel, Sender};
|
||||||
|
@ -21,6 +23,14 @@ pub enum CanvasMsg {
|
||||||
FillRect(Rect<f32>),
|
FillRect(Rect<f32>),
|
||||||
ClearRect(Rect<f32>),
|
ClearRect(Rect<f32>),
|
||||||
StrokeRect(Rect<f32>),
|
StrokeRect(Rect<f32>),
|
||||||
|
BeginPath,
|
||||||
|
ClosePath,
|
||||||
|
Fill,
|
||||||
|
MoveTo(Point2D<f32>),
|
||||||
|
BezierCurveTo(Point2D<f32>, Point2D<f32>, Point2D<f32>),
|
||||||
|
SetFillStyle(FillOrStrokeStyle),
|
||||||
|
SetStrokeStyle(FillOrStrokeStyle),
|
||||||
|
SetTransform(Matrix2D<f32>),
|
||||||
Recreate(Size2D<i32>),
|
Recreate(Size2D<i32>),
|
||||||
SendPixelContents(Sender<Vec<u8>>),
|
SendPixelContents(Sender<Vec<u8>>),
|
||||||
GetImageData(Rect<i32>, Size2D<i32>, Sender<Vec<u8>>),
|
GetImageData(Rect<i32>, Size2D<i32>, Sender<Vec<u8>>),
|
||||||
|
@ -30,18 +40,26 @@ pub enum CanvasMsg {
|
||||||
|
|
||||||
pub struct CanvasPaintTask<'a> {
|
pub struct CanvasPaintTask<'a> {
|
||||||
drawtarget: DrawTarget,
|
drawtarget: DrawTarget,
|
||||||
fill_color: ColorPattern,
|
fill_style: Pattern,
|
||||||
stroke_color: ColorPattern,
|
stroke_style: Pattern,
|
||||||
stroke_opts: StrokeOptions<'a>,
|
stroke_opts: StrokeOptions<'a>,
|
||||||
|
/// TODO(pcwalton): Support multiple paths.
|
||||||
|
path_builder: PathBuilder,
|
||||||
|
/// The current 2D transform matrix.
|
||||||
|
transform: Matrix2D<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CanvasPaintTask<'a> {
|
impl<'a> CanvasPaintTask<'a> {
|
||||||
fn new(size: Size2D<i32>) -> CanvasPaintTask<'a> {
|
fn new(size: Size2D<i32>) -> CanvasPaintTask<'a> {
|
||||||
|
let draw_target = CanvasPaintTask::create(size);
|
||||||
|
let path_builder = draw_target.create_path_builder();
|
||||||
CanvasPaintTask {
|
CanvasPaintTask {
|
||||||
drawtarget: CanvasPaintTask::create(size),
|
drawtarget: draw_target,
|
||||||
fill_color: ColorPattern::new(color::black()),
|
fill_style: Pattern::Color(ColorPattern::new(color::black())),
|
||||||
stroke_color: ColorPattern::new(color::black()),
|
stroke_style: Pattern::Color(ColorPattern::new(color::black())),
|
||||||
stroke_opts: StrokeOptions::new(1.0, JoinStyle::MiterOrBevel, CapStyle::Butt, 1.0, &[]),
|
stroke_opts: StrokeOptions::new(1.0, JoinStyle::MiterOrBevel, CapStyle::Butt, 1.0, &[]),
|
||||||
|
path_builder: path_builder,
|
||||||
|
transform: Matrix2D::identity(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +73,16 @@ impl<'a> CanvasPaintTask<'a> {
|
||||||
CanvasMsg::FillRect(ref rect) => painter.fill_rect(rect),
|
CanvasMsg::FillRect(ref rect) => painter.fill_rect(rect),
|
||||||
CanvasMsg::StrokeRect(ref rect) => painter.stroke_rect(rect),
|
CanvasMsg::StrokeRect(ref rect) => painter.stroke_rect(rect),
|
||||||
CanvasMsg::ClearRect(ref rect) => painter.clear_rect(rect),
|
CanvasMsg::ClearRect(ref rect) => painter.clear_rect(rect),
|
||||||
|
CanvasMsg::BeginPath => painter.begin_path(),
|
||||||
|
CanvasMsg::ClosePath => painter.close_path(),
|
||||||
|
CanvasMsg::Fill => painter.fill(),
|
||||||
|
CanvasMsg::MoveTo(ref point) => painter.move_to(point),
|
||||||
|
CanvasMsg::BezierCurveTo(ref cp1, ref cp2, ref pt) => {
|
||||||
|
painter.bezier_curve_to(cp1, cp2, pt)
|
||||||
|
}
|
||||||
|
CanvasMsg::SetFillStyle(style) => painter.set_fill_style(style),
|
||||||
|
CanvasMsg::SetStrokeStyle(style) => painter.set_stroke_style(style),
|
||||||
|
CanvasMsg::SetTransform(ref matrix) => painter.set_transform(matrix),
|
||||||
CanvasMsg::Recreate(size) => painter.recreate(size),
|
CanvasMsg::Recreate(size) => painter.recreate(size),
|
||||||
CanvasMsg::SendPixelContents(chan) => painter.send_pixel_contents(chan),
|
CanvasMsg::SendPixelContents(chan) => painter.send_pixel_contents(chan),
|
||||||
CanvasMsg::GetImageData(dest_rect, canvas_size, chan) => painter.get_image_data(dest_rect, canvas_size, chan),
|
CanvasMsg::GetImageData(dest_rect, canvas_size, chan) => painter.get_image_data(dest_rect, canvas_size, chan),
|
||||||
|
@ -69,7 +97,7 @@ impl<'a> CanvasPaintTask<'a> {
|
||||||
|
|
||||||
fn fill_rect(&self, rect: &Rect<f32>) {
|
fn fill_rect(&self, rect: &Rect<f32>) {
|
||||||
let drawopts = DrawOptions::new(1.0, 0);
|
let drawopts = DrawOptions::new(1.0, 0);
|
||||||
self.drawtarget.fill_rect(rect, PatternRef::Color(&self.fill_color), Some(&drawopts));
|
self.drawtarget.fill_rect(rect, self.fill_style.to_pattern_ref(), Some(&drawopts));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_rect(&self, rect: &Rect<f32>) {
|
fn clear_rect(&self, rect: &Rect<f32>) {
|
||||||
|
@ -78,7 +106,58 @@ impl<'a> CanvasPaintTask<'a> {
|
||||||
|
|
||||||
fn stroke_rect(&self, rect: &Rect<f32>) {
|
fn stroke_rect(&self, rect: &Rect<f32>) {
|
||||||
let drawopts = DrawOptions::new(1.0, 0);
|
let drawopts = DrawOptions::new(1.0, 0);
|
||||||
self.drawtarget.stroke_rect(rect, &self.stroke_color, &self.stroke_opts, &drawopts);
|
match self.stroke_style {
|
||||||
|
Pattern::Color(ref color) => {
|
||||||
|
self.drawtarget.stroke_rect(rect, color, &self.stroke_opts, &drawopts)
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// TODO(pcwalton)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn begin_path(&mut self) {
|
||||||
|
self.path_builder = self.drawtarget.create_path_builder()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn close_path(&self) {
|
||||||
|
self.path_builder.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fill(&self) {
|
||||||
|
let draw_options = DrawOptions::new(1.0, 0);
|
||||||
|
match self.fill_style {
|
||||||
|
Pattern::Color(ref color) => {
|
||||||
|
self.drawtarget.fill(&self.path_builder.finish(), color, &draw_options);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// TODO(pcwalton)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_to(&self, point: &Point2D<AzFloat>) {
|
||||||
|
self.path_builder.move_to(*point)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bezier_curve_to(&self,
|
||||||
|
cp1: &Point2D<AzFloat>,
|
||||||
|
cp2: &Point2D<AzFloat>,
|
||||||
|
endpoint: &Point2D<AzFloat>) {
|
||||||
|
self.path_builder.bezier_curve_to(cp1, cp2, endpoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_fill_style(&mut self, style: FillOrStrokeStyle) {
|
||||||
|
self.fill_style = style.to_azure_pattern()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_stroke_style(&mut self, style: FillOrStrokeStyle) {
|
||||||
|
self.stroke_style = style.to_azure_pattern()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_transform(&mut self, transform: &Matrix2D<f32>) {
|
||||||
|
self.transform = *transform;
|
||||||
|
self.drawtarget.set_transform(transform)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create(size: Size2D<i32>) -> DrawTarget {
|
fn create(size: Size2D<i32>) -> DrawTarget {
|
||||||
|
@ -192,3 +271,22 @@ impl<'a> CanvasPaintTask<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum FillOrStrokeStyle {
|
||||||
|
Color(RGBA),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FillOrStrokeStyle {
|
||||||
|
fn to_azure_pattern(&self) -> Pattern {
|
||||||
|
match *self {
|
||||||
|
FillOrStrokeStyle::Color(ref color) => {
|
||||||
|
Pattern::Color(ColorPattern::new(color::new(color.red,
|
||||||
|
color.green,
|
||||||
|
color.blue,
|
||||||
|
color.alpha)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#![allow(missing_copy_implementations)]
|
#![allow(missing_copy_implementations)]
|
||||||
|
|
||||||
extern crate azure;
|
extern crate azure;
|
||||||
|
extern crate cssparser;
|
||||||
extern crate geom;
|
extern crate geom;
|
||||||
extern crate gfx;
|
extern crate gfx;
|
||||||
extern crate util;
|
extern crate util;
|
||||||
|
|
|
@ -35,6 +35,7 @@ use dom::bindings::utils::{Reflectable, Reflector, WindowProxyHandler};
|
||||||
use script_task::ScriptChan;
|
use script_task::ScriptChan;
|
||||||
|
|
||||||
use cssparser::RGBA;
|
use cssparser::RGBA;
|
||||||
|
use geom::matrix2d::Matrix2D;
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use html5ever::tree_builder::QuirksMode;
|
use html5ever::tree_builder::QuirksMode;
|
||||||
use hyper::header::Headers;
|
use hyper::header::Headers;
|
||||||
|
@ -225,6 +226,7 @@ no_jsmanaged_fields!(WindowProxyHandler);
|
||||||
no_jsmanaged_fields!(UntrustedNodeAddress);
|
no_jsmanaged_fields!(UntrustedNodeAddress);
|
||||||
no_jsmanaged_fields!(LengthOrPercentageOrAuto);
|
no_jsmanaged_fields!(LengthOrPercentageOrAuto);
|
||||||
no_jsmanaged_fields!(RGBA);
|
no_jsmanaged_fields!(RGBA);
|
||||||
|
no_jsmanaged_fields!(Matrix2D<T>);
|
||||||
|
|
||||||
impl JSTraceable for Box<ScriptChan+Send> {
|
impl JSTraceable for Box<ScriptChan+Send> {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
11
components/script/dom/canvasgradient.rs
Normal file
11
components/script/dom/canvasgradient.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::utils::Reflector;
|
||||||
|
|
||||||
|
#[dom_struct]
|
||||||
|
pub struct CanvasGradient {
|
||||||
|
reflector_: Reflector,
|
||||||
|
}
|
||||||
|
|
12
components/script/dom/canvaspattern.rs
Normal file
12
components/script/dom/canvaspattern.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::utils::Reflector;
|
||||||
|
|
||||||
|
#[dom_struct]
|
||||||
|
pub struct CanvasPattern {
|
||||||
|
reflector_: Reflector,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,9 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding;
|
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding;
|
||||||
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods;
|
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods;
|
||||||
|
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasWindingRule;
|
||||||
use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods;
|
use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods;
|
||||||
|
use dom::bindings::codegen::UnionTypes::StringOrCanvasGradientOrCanvasPattern;
|
||||||
use dom::bindings::error::Error::IndexSize;
|
use dom::bindings::error::Error::IndexSize;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::{GlobalRef, GlobalField};
|
use dom::bindings::global::{GlobalRef, GlobalField};
|
||||||
|
@ -13,13 +15,16 @@ use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||||
use dom::htmlcanvaselement::{HTMLCanvasElement, HTMLCanvasElementHelpers};
|
use dom::htmlcanvaselement::{HTMLCanvasElement, HTMLCanvasElementHelpers};
|
||||||
use dom::imagedata::{ImageData, ImageDataHelpers};
|
use dom::imagedata::{ImageData, ImageDataHelpers};
|
||||||
|
|
||||||
|
use cssparser::Color as CSSColor;
|
||||||
|
use cssparser::{Parser, RGBA, ToCss};
|
||||||
|
use geom::matrix2d::Matrix2D;
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
|
|
||||||
use canvas::canvas_paint_task::{CanvasMsg, CanvasPaintTask};
|
use canvas::canvas_paint_task::{CanvasMsg, CanvasPaintTask, FillOrStrokeStyle};
|
||||||
use canvas::canvas_paint_task::CanvasMsg::{ClearRect, Close, FillRect, Recreate, StrokeRect, GetImageData, PutImageData};
|
|
||||||
|
|
||||||
|
use std::cell::Cell;
|
||||||
use std::num::{Float, ToPrimitive};
|
use std::num::{Float, ToPrimitive};
|
||||||
use std::sync::mpsc::{channel, Sender};
|
use std::sync::mpsc::{channel, Sender};
|
||||||
|
|
||||||
|
@ -29,25 +34,43 @@ pub struct CanvasRenderingContext2D {
|
||||||
global: GlobalField,
|
global: GlobalField,
|
||||||
renderer: Sender<CanvasMsg>,
|
renderer: Sender<CanvasMsg>,
|
||||||
canvas: JS<HTMLCanvasElement>,
|
canvas: JS<HTMLCanvasElement>,
|
||||||
|
stroke_color: Cell<RGBA>,
|
||||||
|
fill_color: Cell<RGBA>,
|
||||||
|
transform: Cell<Matrix2D<f32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CanvasRenderingContext2D {
|
impl CanvasRenderingContext2D {
|
||||||
fn new_inherited(global: GlobalRef, canvas: JSRef<HTMLCanvasElement>, size: Size2D<i32>) -> CanvasRenderingContext2D {
|
fn new_inherited(global: GlobalRef, canvas: JSRef<HTMLCanvasElement>, size: Size2D<i32>)
|
||||||
|
-> CanvasRenderingContext2D {
|
||||||
|
let black = RGBA {
|
||||||
|
red: 0.0,
|
||||||
|
green: 0.0,
|
||||||
|
blue: 0.0,
|
||||||
|
alpha: 1.0,
|
||||||
|
};
|
||||||
CanvasRenderingContext2D {
|
CanvasRenderingContext2D {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
global: GlobalField::from_rooted(&global),
|
global: GlobalField::from_rooted(&global),
|
||||||
renderer: CanvasPaintTask::start(size),
|
renderer: CanvasPaintTask::start(size),
|
||||||
canvas: JS::from_rooted(canvas),
|
canvas: JS::from_rooted(canvas),
|
||||||
|
stroke_color: Cell::new(black),
|
||||||
|
fill_color: Cell::new(black),
|
||||||
|
transform: Cell::new(Matrix2D::identity()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(global: GlobalRef, canvas: JSRef<HTMLCanvasElement>, size: Size2D<i32>) -> Temporary<CanvasRenderingContext2D> {
|
pub fn new(global: GlobalRef, canvas: JSRef<HTMLCanvasElement>, size: Size2D<i32>)
|
||||||
|
-> Temporary<CanvasRenderingContext2D> {
|
||||||
reflect_dom_object(box CanvasRenderingContext2D::new_inherited(global, canvas, size),
|
reflect_dom_object(box CanvasRenderingContext2D::new_inherited(global, canvas, size),
|
||||||
global, CanvasRenderingContext2DBinding::Wrap)
|
global, CanvasRenderingContext2DBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn recreate(&self, size: Size2D<i32>) {
|
pub fn recreate(&self, size: Size2D<i32>) {
|
||||||
self.renderer.send(Recreate(size)).unwrap();
|
self.renderer.send(CanvasMsg::Recreate(size)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_transform(&self) {
|
||||||
|
self.renderer.send(CanvasMsg::SetTransform(self.transform.get())).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,19 +89,125 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
|
||||||
Temporary::new(self.canvas)
|
Temporary::new(self.canvas)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn Scale(self, x: f64, y: f64) {
|
||||||
|
self.transform.set(self.transform.get().scale(x as f32, y as f32));
|
||||||
|
self.update_transform()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn Translate(self, x: f64, y: f64) {
|
||||||
|
self.transform.set(self.transform.get().translate(x as f32, y as f32));
|
||||||
|
self.update_transform()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn Transform(self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
|
||||||
|
self.transform.set(self.transform.get().mul(&Matrix2D::new(a as f32,
|
||||||
|
b as f32,
|
||||||
|
c as f32,
|
||||||
|
d as f32,
|
||||||
|
e as f32,
|
||||||
|
f as f32)));
|
||||||
|
self.update_transform()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn SetTransform(self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
|
||||||
|
self.transform.set(Matrix2D::new(a as f32,
|
||||||
|
b as f32,
|
||||||
|
c as f32,
|
||||||
|
d as f32,
|
||||||
|
e as f32,
|
||||||
|
f as f32));
|
||||||
|
self.update_transform()
|
||||||
|
}
|
||||||
|
|
||||||
fn FillRect(self, x: f64, y: f64, width: f64, height: f64) {
|
fn FillRect(self, x: f64, y: f64, width: f64, height: f64) {
|
||||||
let rect = Rect(Point2D(x as f32, y as f32), Size2D(width as f32, height as f32));
|
let rect = Rect(Point2D(x as f32, y as f32), Size2D(width as f32, height as f32));
|
||||||
self.renderer.send(FillRect(rect)).unwrap();
|
self.renderer.send(CanvasMsg::FillRect(rect)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ClearRect(self, x: f64, y: f64, width: f64, height: f64) {
|
fn ClearRect(self, x: f64, y: f64, width: f64, height: f64) {
|
||||||
let rect = Rect(Point2D(x as f32, y as f32), Size2D(width as f32, height as f32));
|
let rect = Rect(Point2D(x as f32, y as f32), Size2D(width as f32, height as f32));
|
||||||
self.renderer.send(ClearRect(rect)).unwrap();
|
self.renderer.send(CanvasMsg::ClearRect(rect)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn StrokeRect(self, x: f64, y: f64, width: f64, height: f64) {
|
fn StrokeRect(self, x: f64, y: f64, width: f64, height: f64) {
|
||||||
let rect = Rect(Point2D(x as f32, y as f32), Size2D(width as f32, height as f32));
|
let rect = Rect(Point2D(x as f32, y as f32), Size2D(width as f32, height as f32));
|
||||||
self.renderer.send(StrokeRect(rect)).unwrap();
|
self.renderer.send(CanvasMsg::StrokeRect(rect)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn BeginPath(self) {
|
||||||
|
self.renderer.send(CanvasMsg::BeginPath).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ClosePath(self) {
|
||||||
|
self.renderer.send(CanvasMsg::ClosePath).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn Fill(self, _: CanvasWindingRule) {
|
||||||
|
self.renderer.send(CanvasMsg::Fill).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn MoveTo(self, x: f64, y: f64) {
|
||||||
|
self.renderer.send(CanvasMsg::MoveTo(Point2D(x as f32, y as f32))).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn BezierCurveTo(self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, x: f64, y: f64) {
|
||||||
|
self.renderer.send(CanvasMsg::BezierCurveTo(Point2D(cp1x as f32, cp1y as f32),
|
||||||
|
Point2D(cp2x as f32, cp2y as f32),
|
||||||
|
Point2D(x as f32, y as f32))).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn StrokeStyle(self) -> StringOrCanvasGradientOrCanvasPattern {
|
||||||
|
// FIXME(pcwalton, #4761): This is not spec-compliant. See:
|
||||||
|
//
|
||||||
|
// https://html.spec.whatwg.org/multipage/scripting.html#serialisation-of-a-colour
|
||||||
|
let mut result = String::new();
|
||||||
|
self.stroke_color.get().to_css(&mut result).unwrap();
|
||||||
|
StringOrCanvasGradientOrCanvasPattern::eString(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn SetStrokeStyle(self, value: StringOrCanvasGradientOrCanvasPattern) {
|
||||||
|
match value {
|
||||||
|
StringOrCanvasGradientOrCanvasPattern::eString(string) => {
|
||||||
|
match parse_color(string.as_slice()) {
|
||||||
|
Ok(rgba) => {
|
||||||
|
self.stroke_color.set(rgba);
|
||||||
|
self.renderer
|
||||||
|
.send(CanvasMsg::SetStrokeStyle(FillOrStrokeStyle::Color(rgba)))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// TODO(pcwalton)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn FillStyle(self) -> StringOrCanvasGradientOrCanvasPattern {
|
||||||
|
// FIXME(pcwalton, #4761): This is not spec-compliant. See:
|
||||||
|
//
|
||||||
|
// https://html.spec.whatwg.org/multipage/scripting.html#serialisation-of-a-colour
|
||||||
|
let mut result = String::new();
|
||||||
|
self.stroke_color.get().to_css(&mut result).unwrap();
|
||||||
|
StringOrCanvasGradientOrCanvasPattern::eString(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn SetFillStyle(self, value: StringOrCanvasGradientOrCanvasPattern) {
|
||||||
|
match value {
|
||||||
|
StringOrCanvasGradientOrCanvasPattern::eString(string) => {
|
||||||
|
match parse_color(string.as_slice()) {
|
||||||
|
Ok(rgba) => {
|
||||||
|
self.fill_color.set(rgba);
|
||||||
|
self.renderer
|
||||||
|
.send(CanvasMsg::SetFillStyle(FillOrStrokeStyle::Color(rgba)))
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn CreateImageData(self, sw: f64, sh: f64) -> Fallible<Temporary<ImageData>> {
|
fn CreateImageData(self, sw: f64, sh: f64) -> Fallible<Temporary<ImageData>> {
|
||||||
|
@ -101,7 +230,7 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
|
||||||
let (sender, receiver) = channel::<Vec<u8>>();
|
let (sender, receiver) = channel::<Vec<u8>>();
|
||||||
let dest_rect = Rect(Point2D(sx.to_i32().unwrap(), sy.to_i32().unwrap()), Size2D(sw.to_i32().unwrap(), sh.to_i32().unwrap()));
|
let dest_rect = Rect(Point2D(sx.to_i32().unwrap(), sy.to_i32().unwrap()), Size2D(sw.to_i32().unwrap(), sh.to_i32().unwrap()));
|
||||||
let canvas_size = self.canvas.root().r().get_size();
|
let canvas_size = self.canvas.root().r().get_size();
|
||||||
self.renderer.send(GetImageData(dest_rect, canvas_size, sender)).unwrap();
|
self.renderer.send(CanvasMsg::GetImageData(dest_rect, canvas_size, sender)).unwrap();
|
||||||
let data = receiver.recv().unwrap();
|
let data = receiver.recv().unwrap();
|
||||||
Ok(ImageData::new(self.global.root().r(), sw.abs().to_u32().unwrap(), sh.abs().to_u32().unwrap(), Some(data)))
|
Ok(ImageData::new(self.global.root().r(), sw.abs().to_u32().unwrap(), sh.abs().to_u32().unwrap(), Some(data)))
|
||||||
}
|
}
|
||||||
|
@ -111,7 +240,7 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
|
||||||
let image_data_rect = Rect(Point2D(dx.to_i32().unwrap(), dy.to_i32().unwrap()), imagedata.get_size());
|
let image_data_rect = Rect(Point2D(dx.to_i32().unwrap(), dy.to_i32().unwrap()), imagedata.get_size());
|
||||||
let dirty_rect = None;
|
let dirty_rect = None;
|
||||||
let canvas_size = self.canvas.root().r().get_size();
|
let canvas_size = self.canvas.root().r().get_size();
|
||||||
self.renderer.send(PutImageData(data, image_data_rect, dirty_rect, canvas_size)).unwrap()
|
self.renderer.send(CanvasMsg::PutImageData(data, image_data_rect, dirty_rect, canvas_size)).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn PutImageData_(self, imagedata: JSRef<ImageData>, dx: f64, dy: f64,
|
fn PutImageData_(self, imagedata: JSRef<ImageData>, dx: f64, dy: f64,
|
||||||
|
@ -124,13 +253,21 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
|
||||||
Size2D(dirtyWidth.to_i32().unwrap(),
|
Size2D(dirtyWidth.to_i32().unwrap(),
|
||||||
dirtyHeight.to_i32().unwrap())));
|
dirtyHeight.to_i32().unwrap())));
|
||||||
let canvas_size = self.canvas.root().r().get_size();
|
let canvas_size = self.canvas.root().r().get_size();
|
||||||
self.renderer.send(PutImageData(data, image_data_rect, dirty_rect, canvas_size)).unwrap()
|
self.renderer.send(CanvasMsg::PutImageData(data, image_data_rect, dirty_rect, canvas_size)).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe_destructor]
|
#[unsafe_destructor]
|
||||||
impl Drop for CanvasRenderingContext2D {
|
impl Drop for CanvasRenderingContext2D {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.renderer.send(Close).unwrap();
|
self.renderer.send(CanvasMsg::Close).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn parse_color(string: &str) -> Result<RGBA,()> {
|
||||||
|
match CSSColor::parse(&mut Parser::new(string.as_slice())) {
|
||||||
|
Ok(CSSColor::RGBA(rgba)) => Ok(rgba),
|
||||||
|
_ => Err(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,6 +195,8 @@ pub mod activation;
|
||||||
pub mod attr;
|
pub mod attr;
|
||||||
pub mod blob;
|
pub mod blob;
|
||||||
pub mod browsercontext;
|
pub mod browsercontext;
|
||||||
|
pub mod canvasgradient;
|
||||||
|
pub mod canvaspattern;
|
||||||
pub mod canvasrenderingcontext2d;
|
pub mod canvasrenderingcontext2d;
|
||||||
pub mod characterdata;
|
pub mod characterdata;
|
||||||
pub mod cssstyledeclaration;
|
pub mod cssstyledeclaration;
|
||||||
|
|
12
components/script/dom/webidls/CanvasGradient.webidl
Normal file
12
components/script/dom/webidls/CanvasGradient.webidl
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
interface CanvasGradient {
|
||||||
|
// opaque object
|
||||||
|
// addColorStop should take a double
|
||||||
|
//void addColorStop(float offset, DOMString color);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
9
components/script/dom/webidls/CanvasPattern.webidl
Normal file
9
components/script/dom/webidls/CanvasPattern.webidl
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
interface CanvasPattern {
|
||||||
|
//void setTransform(SVGMatrix matrix);
|
||||||
|
};
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
enum CanvasWindingRule { "nonzero", "evenodd" };
|
||||||
|
|
||||||
// http://www.whatwg.org/html/#2dcontext
|
// http://www.whatwg.org/html/#2dcontext
|
||||||
//[Constructor(optional unsigned long width, unsigned long height), Exposed=Window,Worker]
|
//[Constructor(optional unsigned long width, unsigned long height), Exposed=Window,Worker]
|
||||||
interface CanvasRenderingContext2D {
|
interface CanvasRenderingContext2D {
|
||||||
|
@ -23,11 +25,21 @@ interface CanvasRenderingContext2D {
|
||||||
|
|
||||||
// transformations (default transform is the identity matrix)
|
// transformations (default transform is the identity matrix)
|
||||||
// attribute SVGMatrix currentTransform;
|
// attribute SVGMatrix currentTransform;
|
||||||
//void scale(unrestricted double x, unrestricted double y);
|
void scale(/*unrestricted*/ double x, /*unrestricted*/ double y);
|
||||||
//void rotate(unrestricted double angle);
|
//void rotate(unrestricted double angle);
|
||||||
//void translate(unrestricted double x, unrestricted double y);
|
void translate(/*unrestricted*/ double x, /*unrestricted*/ double y);
|
||||||
//void transform(unrestricted double a, unrestricted double b, unrestricted double c, unrestricted double d, unrestricted double e, unrestricted double f);
|
void transform(/*unrestricted*/ double a,
|
||||||
//void setTransform(unrestricted double a, unrestricted double b, unrestricted double c, unrestricted double d, unrestricted double e, unrestricted double f);
|
/*unrestricted*/ double b,
|
||||||
|
/*unrestricted*/ double c,
|
||||||
|
/*unrestricted*/ double d,
|
||||||
|
/*unrestricted*/ double e,
|
||||||
|
/*unrestricted*/ double f);
|
||||||
|
void setTransform(/*unrestricted*/ double a,
|
||||||
|
/*unrestricted*/ double b,
|
||||||
|
/*unrestricted*/ double c,
|
||||||
|
/*unrestricted*/ double d,
|
||||||
|
/*unrestricted*/ double e,
|
||||||
|
/*unrestricted*/ double f);
|
||||||
//void resetTransform();
|
//void resetTransform();
|
||||||
|
|
||||||
// compositing
|
// compositing
|
||||||
|
@ -38,8 +50,8 @@ interface CanvasRenderingContext2D {
|
||||||
// attribute boolean imageSmoothingEnabled; // (default true)
|
// attribute boolean imageSmoothingEnabled; // (default true)
|
||||||
|
|
||||||
// colours and styles (see also the CanvasDrawingStyles interface)
|
// colours and styles (see also the CanvasDrawingStyles interface)
|
||||||
// attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (default black)
|
attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (default black)
|
||||||
// attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (default black)
|
attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (default black)
|
||||||
//CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1);
|
//CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1);
|
||||||
//CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1);
|
//CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1);
|
||||||
//CanvasPattern createPattern(CanvasImageSource image, [TreatNullAs=EmptyString] DOMString repetition);
|
//CanvasPattern createPattern(CanvasImageSource image, [TreatNullAs=EmptyString] DOMString repetition);
|
||||||
|
@ -62,9 +74,9 @@ interface CanvasRenderingContext2D {
|
||||||
void strokeRect(double x, double y, double w, double h);
|
void strokeRect(double x, double y, double w, double h);
|
||||||
|
|
||||||
// path API (see also CanvasPathMethods)
|
// path API (see also CanvasPathMethods)
|
||||||
//void beginPath();
|
void beginPath();
|
||||||
//void fill(optional CanvasFillRule fillRule = "nonzero");
|
void fill(optional CanvasWindingRule fillRule = "nonzero");
|
||||||
//void fill(Path2D path, optional CanvasFillRule fillRule = "nonzero");
|
//void fill(Path2D path, optional CanvasWindingRule fillRule = "nonzero");
|
||||||
//void stroke();
|
//void stroke();
|
||||||
//void stroke(Path2D path);
|
//void stroke(Path2D path);
|
||||||
//void drawSystemFocusRing(Element element);
|
//void drawSystemFocusRing(Element element);
|
||||||
|
@ -73,11 +85,11 @@ interface CanvasRenderingContext2D {
|
||||||
//boolean drawCustomFocusRing(Path2D path, Element element);
|
//boolean drawCustomFocusRing(Path2D path, Element element);
|
||||||
//void scrollPathIntoView();
|
//void scrollPathIntoView();
|
||||||
//void scrollPathIntoView(Path2D path);
|
//void scrollPathIntoView(Path2D path);
|
||||||
//void clip(optional CanvasFillRule fillRule = "nonzero");
|
//void clip(optional CanvasWindingRule fillRule = "nonzero");
|
||||||
//void clip(Path2D path, optional CanvasFillRule fillRule = "nonzero");
|
//void clip(Path2D path, optional CanvasWindingRule fillRule = "nonzero");
|
||||||
//void resetClip();
|
//void resetClip();
|
||||||
//boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule fillRule = "nonzero");
|
//boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasWindingRule 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 CanvasWindingRule fillRule = "nonzero");
|
||||||
//boolean isPointInStroke(unrestricted double x, unrestricted double y);
|
//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);
|
||||||
|
|
||||||
|
@ -105,3 +117,31 @@ interface CanvasRenderingContext2D {
|
||||||
void putImageData(ImageData imagedata, double dx, double dy);
|
void putImageData(ImageData imagedata, double dx, double dy);
|
||||||
void putImageData(ImageData imagedata, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight);
|
void putImageData(ImageData imagedata, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[NoInterfaceObject]
|
||||||
|
interface CanvasPathMethods {
|
||||||
|
// shared path API methods
|
||||||
|
void closePath();
|
||||||
|
void moveTo(/*unrestricted*/ double x, /*unrestricted*/ double y);
|
||||||
|
//void lineTo(double x, double y);
|
||||||
|
//void quadraticCurveTo(double cpx, double cpy, double x, double y);
|
||||||
|
|
||||||
|
void bezierCurveTo(/*unrestricted*/ double cp1x,
|
||||||
|
/*unrestricted*/ double cp1y,
|
||||||
|
/*unrestricted*/ double cp2x,
|
||||||
|
/*unrestricted*/ double cp2y,
|
||||||
|
/*unrestricted*/ double x,
|
||||||
|
/*unrestricted*/ double y);
|
||||||
|
|
||||||
|
//void arcTo(double x1, double y1, double x2, double y2, double radius);
|
||||||
|
// NOT IMPLEMENTED [LenientFloat] void arcTo(double x1, double y1, double x2, double y2, double radiusX, double radiusY, double rotation);
|
||||||
|
|
||||||
|
//void rect(double x, double y, double w, double h);
|
||||||
|
|
||||||
|
//void arc(double x, double y, double radius, double startAngle, double endAngle, optional boolean anticlockwise = false);
|
||||||
|
// NOT IMPLEMENTED [LenientFloat] void ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, boolean anticlockwise);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
CanvasRenderingContext2D implements CanvasPathMethods;
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ pub mod cors;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod dom;
|
pub mod dom;
|
||||||
|
|
||||||
pub mod parse;
|
pub mod parse;
|
||||||
|
|
||||||
pub mod layout_interface;
|
pub mod layout_interface;
|
||||||
|
|
3
components/servo/Cargo.lock
generated
3
components/servo/Cargo.lock
generated
|
@ -36,7 +36,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "azure"
|
name = "azure"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/servo/rust-azure#2c60291733afe631eba90105e9ac9c8847e89cac"
|
source = "git+https://github.com/servo/rust-azure#3fa95e4ce2c12234e75b7a68b1a2542e3804b67c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)",
|
"core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)",
|
||||||
"core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)",
|
"core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)",
|
||||||
|
@ -59,6 +59,7 @@ name = "canvas"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"azure 0.1.0 (git+https://github.com/servo/rust-azure)",
|
"azure 0.1.0 (git+https://github.com/servo/rust-azure)",
|
||||||
|
"cssparser 0.2.0 (git+https://github.com/servo/rust-cssparser)",
|
||||||
"geom 0.1.0 (git+https://github.com/servo/rust-geom)",
|
"geom 0.1.0 (git+https://github.com/servo/rust-geom)",
|
||||||
"gfx 0.0.1",
|
"gfx 0.0.1",
|
||||||
"util 0.0.1",
|
"util 0.0.1",
|
||||||
|
|
3
ports/cef/Cargo.lock
generated
3
ports/cef/Cargo.lock
generated
|
@ -39,7 +39,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "azure"
|
name = "azure"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/servo/rust-azure#2c60291733afe631eba90105e9ac9c8847e89cac"
|
source = "git+https://github.com/servo/rust-azure#3fa95e4ce2c12234e75b7a68b1a2542e3804b67c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)",
|
"core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)",
|
||||||
"core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)",
|
"core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)",
|
||||||
|
@ -62,6 +62,7 @@ name = "canvas"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"azure 0.1.0 (git+https://github.com/servo/rust-azure)",
|
"azure 0.1.0 (git+https://github.com/servo/rust-azure)",
|
||||||
|
"cssparser 0.2.0 (git+https://github.com/servo/rust-cssparser)",
|
||||||
"geom 0.1.0 (git+https://github.com/servo/rust-geom)",
|
"geom 0.1.0 (git+https://github.com/servo/rust-geom)",
|
||||||
"gfx 0.0.1",
|
"gfx 0.0.1",
|
||||||
"util 0.0.1",
|
"util 0.0.1",
|
||||||
|
|
3
ports/gonk/Cargo.lock
generated
3
ports/gonk/Cargo.lock
generated
|
@ -23,7 +23,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "azure"
|
name = "azure"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/servo/rust-azure#2c60291733afe631eba90105e9ac9c8847e89cac"
|
source = "git+https://github.com/servo/rust-azure#3fa95e4ce2c12234e75b7a68b1a2542e3804b67c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)",
|
"core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)",
|
||||||
"core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)",
|
"core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)",
|
||||||
|
@ -46,6 +46,7 @@ name = "canvas"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"azure 0.1.0 (git+https://github.com/servo/rust-azure)",
|
"azure 0.1.0 (git+https://github.com/servo/rust-azure)",
|
||||||
|
"cssparser 0.2.0 (git+https://github.com/servo/rust-cssparser)",
|
||||||
"geom 0.1.0 (git+https://github.com/servo/rust-geom)",
|
"geom 0.1.0 (git+https://github.com/servo/rust-geom)",
|
||||||
"gfx 0.0.1",
|
"gfx 0.0.1",
|
||||||
"util 0.0.1",
|
"util 0.0.1",
|
||||||
|
|
|
@ -53,7 +53,9 @@ var ecmaGlobals = [
|
||||||
var interfaceNamesInGlobalScope = [
|
var interfaceNamesInGlobalScope = [
|
||||||
"Attr",
|
"Attr",
|
||||||
"Blob",
|
"Blob",
|
||||||
|
"CanvasGradient",
|
||||||
"CanvasRenderingContext2D",
|
"CanvasRenderingContext2D",
|
||||||
|
"CanvasPattern",
|
||||||
"CharacterData",
|
"CharacterData",
|
||||||
"CSSStyleDeclaration",
|
"CSSStyleDeclaration",
|
||||||
"DOMRect",
|
"DOMRect",
|
||||||
|
|
|
@ -249,3 +249,4 @@ fragment=top != ../html/acid2.html acid2_ref.html
|
||||||
== text_overflow_basic_a.html text_overflow_basic_ref.html
|
== text_overflow_basic_a.html text_overflow_basic_ref.html
|
||||||
== text_align_complex_a.html text_align_complex_ref.html
|
== text_align_complex_a.html text_align_complex_ref.html
|
||||||
== percentage_height_root.html percentage_height_root_ref.html
|
== percentage_height_root.html percentage_height_root_ref.html
|
||||||
|
== canvas_transform_a.html canvas_transform_ref.html
|
||||||
|
|
26
tests/ref/canvas_transform_a.html
Normal file
26
tests/ref/canvas_transform_a.html
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id=c width=400 height=300></canvas>
|
||||||
|
<script>
|
||||||
|
var canvas = document.getElementById('c');
|
||||||
|
var ctx = canvas.getContext('2d');
|
||||||
|
ctx.scale(3, 3);
|
||||||
|
ctx.fillStyle = 'rgb(255, 0, 0)';
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(10, 10);
|
||||||
|
ctx.bezierCurveTo(10, 10, 20, 10, 20, 10);
|
||||||
|
ctx.bezierCurveTo(20, 10, 20, 20, 20, 20);
|
||||||
|
ctx.bezierCurveTo(20, 20, 10, 20, 10, 20);
|
||||||
|
ctx.closePath();
|
||||||
|
ctx.fill();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
21
tests/ref/canvas_transform_ref.html
Normal file
21
tests/ref/canvas_transform_ref.html
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
section {
|
||||||
|
position: absolute;
|
||||||
|
background: rgb(255, 0, 0);
|
||||||
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
top: 30px;
|
||||||
|
left: 30px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<section></section>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
|
@ -6975,21 +6975,9 @@
|
||||||
[CanvasRenderingContext2D interface: attribute currentTransform]
|
[CanvasRenderingContext2D interface: attribute currentTransform]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation scale(unrestricted double,unrestricted double)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation rotate(unrestricted double)]
|
[CanvasRenderingContext2D interface: operation rotate(unrestricted double)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation translate(unrestricted double,unrestricted double)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation transform(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation setTransform(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation resetTransform()]
|
[CanvasRenderingContext2D interface: operation resetTransform()]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -7002,12 +6990,6 @@
|
||||||
[CanvasRenderingContext2D interface: attribute imageSmoothingEnabled]
|
[CanvasRenderingContext2D interface: attribute imageSmoothingEnabled]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: attribute strokeStyle]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: attribute fillStyle]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation createLinearGradient(double,double,double,double)]
|
[CanvasRenderingContext2D interface: operation createLinearGradient(double,double,double,double)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -7029,15 +7011,9 @@
|
||||||
[CanvasRenderingContext2D interface: attribute shadowColor]
|
[CanvasRenderingContext2D interface: attribute shadowColor]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation beginPath()]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation fill(CanvasFillRule)]
|
[CanvasRenderingContext2D interface: operation fill(CanvasFillRule)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation fill(Path2D,CanvasFillRule)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation stroke()]
|
[CanvasRenderingContext2D interface: operation stroke()]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -7146,21 +7122,12 @@
|
||||||
[CanvasRenderingContext2D interface: attribute direction]
|
[CanvasRenderingContext2D interface: attribute direction]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation closePath()]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation moveTo(unrestricted double,unrestricted double)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation lineTo(unrestricted double,unrestricted double)]
|
[CanvasRenderingContext2D interface: operation lineTo(unrestricted double,unrestricted double)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation quadraticCurveTo(unrestricted double,unrestricted double,unrestricted double,unrestricted double)]
|
[CanvasRenderingContext2D interface: operation quadraticCurveTo(unrestricted double,unrestricted double,unrestricted double,unrestricted double)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation bezierCurveTo(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation arcTo(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double)]
|
[CanvasRenderingContext2D interface: operation arcTo(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -7194,36 +7161,12 @@
|
||||||
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "currentTransform" with the proper type (6)]
|
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "currentTransform" with the proper type (6)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "scale" with the proper type (7)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: calling scale(unrestricted double,unrestricted 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 "rotate" with the proper type (8)]
|
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "rotate" with the proper type (8)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: calling rotate(unrestricted double) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
|
[CanvasRenderingContext2D interface: calling rotate(unrestricted double) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "translate" with the proper type (9)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: calling translate(unrestricted double,unrestricted 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 "transform" with the proper type (10)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: calling transform(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted 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 "setTransform" with the proper type (11)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: calling setTransform(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted 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 "resetTransform" with the proper type (12)]
|
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "resetTransform" with the proper type (12)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -7272,18 +7215,6 @@
|
||||||
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "shadowColor" with the proper type (24)]
|
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "shadowColor" with the proper type (24)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "beginPath" with the proper type (28)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "fill" with the proper type (29)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: calling fill(CanvasFillRule) 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 "fill" with the proper type (30)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: calling fill(Path2D,CanvasFillRule) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
|
[CanvasRenderingContext2D interface: calling fill(Path2D,CanvasFillRule) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -7452,15 +7383,6 @@
|
||||||
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "direction" with the proper type (69)]
|
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "direction" with the proper type (69)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "closePath" with the proper type (70)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "moveTo" with the proper type (71)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: calling moveTo(unrestricted double,unrestricted 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 "lineTo" with the proper type (72)]
|
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "lineTo" with the proper type (72)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -7473,12 +7395,6 @@
|
||||||
[CanvasRenderingContext2D interface: calling quadraticCurveTo(unrestricted double,unrestricted double,unrestricted double,unrestricted double) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
|
[CanvasRenderingContext2D interface: calling quadraticCurveTo(unrestricted double,unrestricted double,unrestricted double,unrestricted double) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "bezierCurveTo" with the proper type (74)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: calling bezierCurveTo(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted 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 "arcTo" with the proper type (75)]
|
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "arcTo" with the proper type (75)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -7509,33 +7425,15 @@
|
||||||
[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]
|
[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
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasGradient interface: existence and properties of interface object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasGradient interface object length]
|
[CanvasGradient interface object length]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasGradient interface: existence and properties of interface prototype object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasGradient interface: existence and properties of interface prototype object\'s "constructor" property]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasGradient interface: operation addColorStop(double,DOMString)]
|
[CanvasGradient interface: operation addColorStop(double,DOMString)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasPattern interface: existence and properties of interface object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasPattern interface object length]
|
[CanvasPattern interface object length]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasPattern interface: existence and properties of interface prototype object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasPattern interface: existence and properties of interface prototype object\'s "constructor" property]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasPattern interface: operation setTransform(SVGMatrix)]
|
[CanvasPattern interface: operation setTransform(SVGMatrix)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.getcontext.shared.html]
|
|
||||||
type: testharness
|
|
||||||
[getContext(\'2d\') returns objects which share canvas state]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.type.extend.html]
|
|
||||||
type: testharness
|
|
||||||
[Interface methods can be added]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.type.prototype.html]
|
|
||||||
type: testharness
|
|
||||||
[window.CanvasRenderingContext2D.prototype are not [[Writable\]\] and not [[Configurable\]\], and its methods are [[Configurable\]\].]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.type.replace.html]
|
|
||||||
type: testharness
|
|
||||||
[Interface methods can be overridden]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[initial.reset.different.html]
|
|
||||||
type: testharness
|
|
||||||
[Changing size resets canvas to transparent black]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[initial.reset.same.html]
|
|
||||||
type: testharness
|
|
||||||
[Setting size (not changing the value) resets canvas to transparent black]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[initial.reset.transform.html]
|
|
||||||
type: testharness
|
|
||||||
[Resetting the canvas state resets the current transformation matrix]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -21,12 +21,6 @@
|
||||||
[The DrawingStyle interface object should be exposed.]
|
[The DrawingStyle interface object should be exposed.]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[The CanvasGradient interface object should be exposed.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[The CanvasPattern interface object should be exposed.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[The Path interface object should be exposed.]
|
[The Path interface object should be exposed.]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue