mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #9689 - saurvs:master, r=jdm
Update some canvas properties as enums instead of DOMString Fixes https://github.com/servo/servo/issues/9617 I'm going to incrementally rollout commits and squash them finally. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9689) <!-- Reviewable:end -->
This commit is contained in:
commit
c68fbee03e
2 changed files with 42 additions and 30 deletions
|
@ -12,6 +12,8 @@ use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods;
|
use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods;
|
||||||
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding;
|
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding;
|
||||||
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasFillRule;
|
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasFillRule;
|
||||||
|
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasLineCap;
|
||||||
|
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasLineJoin;
|
||||||
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods;
|
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods;
|
||||||
use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods;
|
use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods;
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||||
|
@ -1209,39 +1211,43 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
|
||||||
fn LineCap(&self) -> DOMString {
|
fn LineCap(&self) -> CanvasLineCap {
|
||||||
let state = self.state.borrow();
|
match self.state.borrow().line_cap {
|
||||||
match state.line_cap {
|
LineCapStyle::Butt => CanvasLineCap::Butt,
|
||||||
LineCapStyle::Butt => DOMString::from("butt"),
|
LineCapStyle::Round => CanvasLineCap::Round,
|
||||||
LineCapStyle::Round => DOMString::from("round"),
|
LineCapStyle::Square => CanvasLineCap::Square,
|
||||||
LineCapStyle::Square => DOMString::from("square"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
|
||||||
fn SetLineCap(&self, cap_str: DOMString) {
|
fn SetLineCap(&self, cap: CanvasLineCap) {
|
||||||
if let Ok(cap) = LineCapStyle::from_str(&cap_str) {
|
let line_cap = match cap {
|
||||||
self.state.borrow_mut().line_cap = cap;
|
CanvasLineCap::Butt => LineCapStyle::Butt,
|
||||||
self.ipc_renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::SetLineCap(cap))).unwrap()
|
CanvasLineCap::Round => LineCapStyle::Round,
|
||||||
|
CanvasLineCap::Square => LineCapStyle::Square,
|
||||||
|
};
|
||||||
|
self.state.borrow_mut().line_cap = line_cap;
|
||||||
|
self.ipc_renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::SetLineCap(line_cap))).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
|
||||||
|
fn LineJoin(&self) -> CanvasLineJoin {
|
||||||
|
match self.state.borrow().line_join {
|
||||||
|
LineJoinStyle::Round => CanvasLineJoin::Round,
|
||||||
|
LineJoinStyle::Bevel => CanvasLineJoin::Bevel,
|
||||||
|
LineJoinStyle::Miter => CanvasLineJoin::Miter,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
|
||||||
fn LineJoin(&self) -> DOMString {
|
fn SetLineJoin(&self, join: CanvasLineJoin) {
|
||||||
let state = self.state.borrow();
|
let line_join = match join {
|
||||||
match state.line_join {
|
CanvasLineJoin::Round => LineJoinStyle::Round,
|
||||||
LineJoinStyle::Round => DOMString::from("round"),
|
CanvasLineJoin::Bevel => LineJoinStyle::Bevel,
|
||||||
LineJoinStyle::Bevel => DOMString::from("bevel"),
|
CanvasLineJoin::Miter => LineJoinStyle::Miter,
|
||||||
LineJoinStyle::Miter => DOMString::from("miter"),
|
};
|
||||||
}
|
self.state.borrow_mut().line_join = line_join;
|
||||||
}
|
self.ipc_renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::SetLineJoin(line_join))).unwrap();
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
|
|
||||||
fn SetLineJoin(&self, join_str: DOMString) {
|
|
||||||
if let Ok(join) = LineJoinStyle::from_str(&join_str) {
|
|
||||||
self.state.borrow_mut().line_join = join;
|
|
||||||
self.ipc_renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::SetLineJoin(join))).unwrap()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-miterlimit
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-miterlimit
|
||||||
|
|
|
@ -141,12 +141,18 @@ interface CanvasRenderingContext2D {
|
||||||
CanvasRenderingContext2D implements CanvasDrawingStyles;
|
CanvasRenderingContext2D implements CanvasDrawingStyles;
|
||||||
CanvasRenderingContext2D implements CanvasPathMethods;
|
CanvasRenderingContext2D implements CanvasPathMethods;
|
||||||
|
|
||||||
|
enum CanvasLineCap { "butt", "round", "square" };
|
||||||
|
enum CanvasLineJoin { "round", "bevel", "miter"};
|
||||||
|
enum CanvasTextAlign { "start", "end", "left", "right", "center" };
|
||||||
|
enum CanvasTextBaseline { "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" };
|
||||||
|
enum CanvasDirection { "ltr", "rtl", "inherit" };
|
||||||
|
|
||||||
[NoInterfaceObject]
|
[NoInterfaceObject]
|
||||||
interface CanvasDrawingStyles {
|
interface CanvasDrawingStyles {
|
||||||
// line caps/joins
|
// line caps/joins
|
||||||
attribute unrestricted double lineWidth; // (default 1)
|
attribute unrestricted double lineWidth; // (default 1)
|
||||||
attribute DOMString lineCap; // "butt", "round", "square" (default "butt")
|
attribute CanvasLineCap lineCap; // "butt", "round", "square" (default "butt")
|
||||||
attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter")
|
attribute CanvasLineJoin lineJoin; // "round", "bevel", "miter" (default "miter")
|
||||||
attribute unrestricted double miterLimit; // (default 10)
|
attribute unrestricted double miterLimit; // (default 10)
|
||||||
|
|
||||||
// dashed lines
|
// dashed lines
|
||||||
|
@ -156,10 +162,10 @@ interface CanvasDrawingStyles {
|
||||||
|
|
||||||
// text
|
// text
|
||||||
//attribute DOMString font; // (default 10px sans-serif)
|
//attribute DOMString font; // (default 10px sans-serif)
|
||||||
//attribute DOMString textAlign; // "start", "end", "left", "right", "center" (default: "start")
|
//attribute CanvasTextAlign textAlign; // "start", "end", "left", "right", "center" (default: "start")
|
||||||
//attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic",
|
//attribute CanvasTextBaseline textBaseline; // "top", "hanging", "middle", "alphabetic",
|
||||||
// "ideographic", "bottom" (default: "alphabetic")
|
// "ideographic", "bottom" (default: "alphabetic")
|
||||||
//attribute DOMString direction; // "ltr", "rtl", "inherit" (default: "inherit")
|
//attribute CanvasDirection direction; // "ltr", "rtl", "inherit" (default: "inherit")
|
||||||
};
|
};
|
||||||
|
|
||||||
[NoInterfaceObject]
|
[NoInterfaceObject]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue