Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update some canvas properties as enums instead of DOMString #9689

Merged
merged 1 commit into from Feb 19, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Update some canvas properties as enums instead of DOMString

  • Loading branch information
saurvs committed Feb 19, 2016
commit 939560bd6e3367db9096850bca4c405e404bddbe
@@ -12,6 +12,8 @@ use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods;
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding;
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::ImageDataBinding::ImageDataMethods;
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
fn LineCap(&self) -> DOMString {
let state = self.state.borrow();
match state.line_cap {
LineCapStyle::Butt => DOMString::from("butt"),
LineCapStyle::Round => DOMString::from("round"),
LineCapStyle::Square => DOMString::from("square"),
fn LineCap(&self) -> CanvasLineCap {
match self.state.borrow().line_cap {
LineCapStyle::Butt => CanvasLineCap::Butt,
LineCapStyle::Round => CanvasLineCap::Round,
LineCapStyle::Square => CanvasLineCap::Square,
}
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
fn SetLineCap(&self, cap_str: DOMString) {
if let Ok(cap) = LineCapStyle::from_str(&cap_str) {
self.state.borrow_mut().line_cap = cap;
self.ipc_renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::SetLineCap(cap))).unwrap()
}
fn SetLineCap(&self, cap: CanvasLineCap) {
let line_cap = match cap {
CanvasLineCap::Butt => LineCapStyle::Butt,
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) -> DOMString {
let state = self.state.borrow();
match state.line_join {
LineJoinStyle::Round => DOMString::from("round"),
LineJoinStyle::Bevel => DOMString::from("bevel"),
LineJoinStyle::Miter => DOMString::from("miter"),
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
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()
}
fn SetLineJoin(&self, join: CanvasLineJoin) {
let line_join = match join {
CanvasLineJoin::Round => LineJoinStyle::Round,
CanvasLineJoin::Bevel => LineJoinStyle::Bevel,
CanvasLineJoin::Miter => LineJoinStyle::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-miterlimit
@@ -141,12 +141,18 @@ interface CanvasRenderingContext2D {
CanvasRenderingContext2D implements CanvasDrawingStyles;
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]
interface CanvasDrawingStyles {
// line caps/joins
attribute unrestricted double lineWidth; // (default 1)
attribute DOMString lineCap; // "butt", "round", "square" (default "butt")
attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter")
attribute CanvasLineCap lineCap; // "butt", "round", "square" (default "butt")
attribute CanvasLineJoin lineJoin; // "round", "bevel", "miter" (default "miter")
attribute unrestricted double miterLimit; // (default 10)

// dashed lines
@@ -156,10 +162,10 @@ interface CanvasDrawingStyles {

// text
//attribute DOMString font; // (default 10px sans-serif)
//attribute DOMString textAlign; // "start", "end", "left", "right", "center" (default: "start")
//attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic",
//attribute CanvasTextAlign textAlign; // "start", "end", "left", "right", "center" (default: "start")
//attribute CanvasTextBaseline textBaseline; // "top", "hanging", "middle", "alphabetic",
// "ideographic", "bottom" (default: "alphabetic")
//attribute DOMString direction; // "ltr", "rtl", "inherit" (default: "inherit")
//attribute CanvasDirection direction; // "ltr", "rtl", "inherit" (default: "inherit")
};

[NoInterfaceObject]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.