mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Enable unrestricted
types for CanvasRenderingContext2D
.
This commit is contained in:
parent
9cd1b2c158
commit
05c6d046dd
3 changed files with 68 additions and 42 deletions
|
@ -9,6 +9,7 @@ use dom::bindings::codegen::Bindings::CanvasGradientBinding;
|
|||
use dom::bindings::codegen::Bindings::CanvasGradientBinding::CanvasGradientMethods;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JSRef, Temporary};
|
||||
use dom::bindings::num::Finite;
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
use dom::canvasrenderingcontext2d::parse_color;
|
||||
|
||||
|
@ -41,7 +42,7 @@ impl CanvasGradient {
|
|||
}
|
||||
|
||||
impl<'a> CanvasGradientMethods for JSRef<'a, CanvasGradient> {
|
||||
fn AddColorStop(self, offset: f32, color: String) {
|
||||
fn AddColorStop(self, offset: Finite<f32>, color: String) {
|
||||
let default_black = RGBA {
|
||||
red: 0.0,
|
||||
green: 0.0,
|
||||
|
@ -50,7 +51,7 @@ impl<'a> CanvasGradientMethods for JSRef<'a, CanvasGradient> {
|
|||
};
|
||||
|
||||
self.stops.borrow_mut().push(CanvasGradientStop {
|
||||
offset: offset as f64,
|
||||
offset: (*offset) as f64,
|
||||
color: parse_color(color.as_slice()).unwrap_or(default_black),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ use dom::bindings::error::Error::{IndexSize, TypeError};
|
|||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::global::{GlobalRef, GlobalField};
|
||||
use dom::bindings::js::{JS, JSRef, LayoutJS, Temporary};
|
||||
use dom::bindings::num::Finite;
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
use dom::canvasgradient::{CanvasGradient, CanvasGradientStyle, ToFillOrStrokeStyle};
|
||||
use dom::htmlcanvaselement::{HTMLCanvasElement, HTMLCanvasElementHelpers};
|
||||
|
@ -383,7 +384,13 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
|
|||
Point2D(x as f32, y as f32))).unwrap();
|
||||
}
|
||||
|
||||
fn Arc(self, x: f64, y: f64, r: f64, start: f64, end: f64, ccw: bool) {
|
||||
fn Arc(self, x: Finite<f64>, y: Finite<f64>, r: Finite<f64>, start: Finite<f64>, end: Finite<f64>, ccw: bool) {
|
||||
let x = *x;
|
||||
let y = *y;
|
||||
let r = *r;
|
||||
let start = *start;
|
||||
let end = *end;
|
||||
|
||||
self.renderer.send(CanvasMsg::Arc(Point2D(x as f32, y as f32), r as f32,
|
||||
start as f32, end as f32, ccw)).unwrap();
|
||||
}
|
||||
|
@ -467,7 +474,10 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
|
|||
Ok(ImageData::new(self.global.root().r(), imagedata.Width(), imagedata.Height(), None))
|
||||
}
|
||||
|
||||
fn GetImageData(self, sx: f64, sy: f64, sw: f64, sh: f64) -> Fallible<Temporary<ImageData>> {
|
||||
fn GetImageData(self, sx: Finite<f64>, sy: Finite<f64>, sw: Finite<f64>, sh: Finite<f64>) -> Fallible<Temporary<ImageData>> {
|
||||
let sw = *sw;
|
||||
let sh = *sh;
|
||||
|
||||
if sw == 0.0 || sh == 0.0 {
|
||||
return Err(IndexSize)
|
||||
}
|
||||
|
@ -480,15 +490,15 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
|
|||
Ok(ImageData::new(self.global.root().r(), sw.abs().to_u32().unwrap(), sh.abs().to_u32().unwrap(), Some(data)))
|
||||
}
|
||||
|
||||
fn PutImageData(self, imagedata: JSRef<ImageData>, dx: f64, dy: f64) {
|
||||
fn PutImageData(self, imagedata: JSRef<ImageData>, dx: Finite<f64>, dy: Finite<f64>) {
|
||||
let data = imagedata.get_data_array(&self.global.root().r());
|
||||
let image_data_rect = Rect(Point2D(dx.to_i32().unwrap(), dy.to_i32().unwrap()), imagedata.get_size());
|
||||
let dirty_rect = None;
|
||||
self.renderer.send(CanvasMsg::PutImageData(data, image_data_rect, dirty_rect)).unwrap()
|
||||
}
|
||||
|
||||
fn PutImageData_(self, imagedata: JSRef<ImageData>, dx: f64, dy: f64,
|
||||
dirtyX: f64, dirtyY: f64, dirtyWidth: f64, dirtyHeight: f64) {
|
||||
fn PutImageData_(self, imagedata: JSRef<ImageData>, dx: Finite<f64>, dy: Finite<f64>,
|
||||
dirtyX: Finite<f64>, dirtyY: Finite<f64>, dirtyWidth: Finite<f64>, dirtyHeight: Finite<f64>) {
|
||||
let data = imagedata.get_data_array(&self.global.root().r());
|
||||
let image_data_rect = Rect(Point2D(dx.to_i32().unwrap(), dy.to_i32().unwrap()),
|
||||
Size2D(imagedata.Width().to_i32().unwrap(),
|
||||
|
@ -499,7 +509,13 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
|
|||
self.renderer.send(CanvasMsg::PutImageData(data, image_data_rect, dirty_rect)).unwrap()
|
||||
}
|
||||
|
||||
fn CreateLinearGradient(self, x0: f64, y0: f64, x1: f64, y1: f64) -> Fallible<Temporary<CanvasGradient>> {
|
||||
fn CreateLinearGradient(self, x0: Finite<f64>, y0: Finite<f64>,
|
||||
x1: Finite<f64>, y1: Finite<f64>) -> Fallible<Temporary<CanvasGradient>> {
|
||||
let x0 = *x0;
|
||||
let y0 = *y0;
|
||||
let x1 = *x1;
|
||||
let y1 = *y1;
|
||||
|
||||
if [x0, y0, x1, y1].iter().any(|x| x.is_nan() || x.is_infinite()) {
|
||||
return Err(TypeError("One of the arguments of createLinearGradient() is not a finite floating-point value.".to_owned()));
|
||||
}
|
||||
|
@ -507,7 +523,15 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
|
|||
CanvasGradientStyle::Linear(LinearGradientStyle::new(x0, y0, x1, y1, Vec::new()))))
|
||||
}
|
||||
|
||||
fn CreateRadialGradient(self, x0: f64, y0: f64, r0: f64, x1: f64, y1: f64, r1: f64) -> Fallible<Temporary<CanvasGradient>> {
|
||||
fn CreateRadialGradient(self, x0: Finite<f64>, y0: Finite<f64>, r0: Finite<f64>,
|
||||
x1: Finite<f64>, y1: Finite<f64>, r1: Finite<f64>) -> Fallible<Temporary<CanvasGradient>> {
|
||||
let x0 = *x0;
|
||||
let y0 = *y0;
|
||||
let r0 = *r0;
|
||||
let x1 = *x1;
|
||||
let y1 = *y1;
|
||||
let r1 = *r1;
|
||||
|
||||
if [x0, y0, r0, x1, y1, r1].iter().any(|x| x.is_nan() || x.is_infinite()) {
|
||||
return Err(TypeError("One of the arguments of createRadialGradient() is not a finite floating-point value.".to_owned()));
|
||||
}
|
||||
|
|
|
@ -31,21 +31,21 @@ interface CanvasRenderingContext2D {
|
|||
|
||||
// transformations (default transform is the identity matrix)
|
||||
// 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 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 setTransform(/*unrestricted*/ double a,
|
||||
/*unrestricted*/ double b,
|
||||
/*unrestricted*/ double c,
|
||||
/*unrestricted*/ double d,
|
||||
/*unrestricted*/ double e,
|
||||
/*unrestricted*/ double f);
|
||||
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 setTransform(unrestricted double a,
|
||||
unrestricted double b,
|
||||
unrestricted double c,
|
||||
unrestricted double d,
|
||||
unrestricted double e,
|
||||
unrestricted double f);
|
||||
//void resetTransform();
|
||||
|
||||
// compositing
|
||||
|
@ -71,15 +71,12 @@ interface CanvasRenderingContext2D {
|
|||
// attribute DOMString shadowColor; // (default transparent black)
|
||||
|
||||
// rects
|
||||
//void clearRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
|
||||
//[LenientFloat]
|
||||
void clearRect(double x, double y, double w, double h);
|
||||
//void fillRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
|
||||
void clearRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
|
||||
//[LenientFloat]
|
||||
void fillRect(double x, double y, double w, double h);
|
||||
//void strokeRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
|
||||
void fillRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
|
||||
//[LenientFloat]
|
||||
void strokeRect(double x, double y, double w, double h);
|
||||
void strokeRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
|
||||
|
||||
// path API (see also CanvasPathMethods)
|
||||
void beginPath();
|
||||
|
@ -108,11 +105,15 @@ interface CanvasRenderingContext2D {
|
|||
|
||||
// drawing images
|
||||
[Throws]
|
||||
void drawImage(CanvasImageSource image, /* unrestricted */ double dx, /* unrestricted */ double dy);
|
||||
void drawImage(CanvasImageSource image, unrestricted double dx, unrestricted double dy);
|
||||
[Throws]
|
||||
void drawImage(CanvasImageSource image, /* unrestricted */ double dx, /* unrestricted */ double dy, /* unrestricted */ double dw, /* unrestricted */ double dh);
|
||||
void drawImage(CanvasImageSource image, unrestricted double dx, unrestricted double dy,
|
||||
unrestricted double dw, unrestricted double dh);
|
||||
[Throws]
|
||||
void drawImage(CanvasImageSource image, /* unrestricted */ double sx, /* unrestricted */ double sy, /* unrestricted */ double sw, /* unrestricted */ double sh, /* unrestricted */ double dx, /* unrestricted */ double dy, /* unrestricted */ double dw, /* unrestricted */ double dh);
|
||||
void drawImage(CanvasImageSource image, unrestricted double sx, unrestricted double sy,
|
||||
unrestricted double sw, unrestricted double sh,
|
||||
unrestricted double dx, unrestricted double dy,
|
||||
unrestricted double dw, unrestricted double dh);
|
||||
|
||||
// hit regions
|
||||
//void addHitRegion(optional HitRegionOptions options);
|
||||
|
@ -120,7 +121,7 @@ interface CanvasRenderingContext2D {
|
|||
|
||||
// pixel manipulation
|
||||
[Throws]
|
||||
ImageData createImageData(double sw, double sh);
|
||||
ImageData createImageData(unrestricted double sw, unrestricted double sh);
|
||||
[Throws]
|
||||
ImageData createImageData(ImageData imagedata);
|
||||
[Throws]
|
||||
|
@ -133,16 +134,16 @@ interface CanvasRenderingContext2D {
|
|||
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 moveTo(unrestricted double x, unrestricted double y);
|
||||
void lineTo(unrestricted double x, unrestricted double y);
|
||||
void quadraticCurveTo(unrestricted double cpx, unrestricted double cpy, unrestricted double x, unrestricted double y);
|
||||
|
||||
void bezierCurveTo(/*unrestricted*/ double cp1x,
|
||||
/*unrestricted*/ double cp1y,
|
||||
/*unrestricted*/ double cp2x,
|
||||
/*unrestricted*/ double cp2y,
|
||||
/*unrestricted*/ double x,
|
||||
/*unrestricted*/ 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue