aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/canvaspattern.rs
diff options
context:
space:
mode:
authorHyowon Kim <hw1008.kim@samsung.com>2015-05-14 10:08:10 +0900
committerHyowon Kim <hw1008.kim@samsung.com>2015-06-13 14:35:13 +0900
commit00240e5550f52d49c0308e56498e177d357eb53c (patch)
treeced3ed2ce6657daf7b0102e1d81bc3097fe134ca /components/script/dom/canvaspattern.rs
parent2168ec3c96ca9e8e1174be22be07d1168061b4b6 (diff)
downloadservo-00240e5550f52d49c0308e56498e177d357eb53c.tar.gz
servo-00240e5550f52d49c0308e56498e177d357eb53c.zip
Implementation of pattern fill style for canvas.
Diffstat (limited to 'components/script/dom/canvaspattern.rs')
-rw-r--r--components/script/dom/canvaspattern.rs44
1 files changed, 43 insertions, 1 deletions
diff --git a/components/script/dom/canvaspattern.rs b/components/script/dom/canvaspattern.rs
index b8b2808d3b9..0be707a1147 100644
--- a/components/script/dom/canvaspattern.rs
+++ b/components/script/dom/canvaspattern.rs
@@ -2,12 +2,54 @@
* 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;
+use canvas_traits::{FillOrStrokeStyle, SurfaceStyle, RepetitionStyle};
+use dom::bindings::codegen::Bindings::CanvasPatternBinding;
+use dom::bindings::global::GlobalRef;
+use dom::bindings::js::{JSRef, Temporary};
+use dom::bindings::utils::{Reflector, reflect_dom_object};
+use dom::canvasgradient::ToFillOrStrokeStyle;
+use geom::size::Size2D;
// https://html.spec.whatwg.org/multipage/#canvaspattern
#[dom_struct]
pub struct CanvasPattern {
reflector_: Reflector,
+ surface_data: Vec<u8>,
+ surface_size: Size2D<i32>,
+ repeat_x: bool,
+ repeat_y: bool,
}
+impl CanvasPattern {
+ fn new_inherited(surface_data: Vec<u8>, surface_size: Size2D<i32>, repeat: RepetitionStyle) -> CanvasPattern {
+ let (x, y) = match repeat {
+ RepetitionStyle::Repeat => (true, true),
+ RepetitionStyle::RepeatX => (true, false),
+ RepetitionStyle::RepeatY => (false, true),
+ RepetitionStyle::NoRepeat => (false, false),
+ };
+ CanvasPattern {
+ reflector_: Reflector::new(),
+ surface_data: surface_data,
+ surface_size: surface_size,
+ repeat_x: x,
+ repeat_y: y,
+ }
+ }
+ pub fn new(global: GlobalRef,
+ surface_data: Vec<u8>,
+ surface_size: Size2D<i32>,
+ repeat: RepetitionStyle)
+ -> Temporary<CanvasPattern> {
+ reflect_dom_object(box CanvasPattern::new_inherited(surface_data, surface_size, repeat),
+ global, CanvasPatternBinding::Wrap)
+ }
+}
+
+impl<'a> ToFillOrStrokeStyle for JSRef<'a, CanvasPattern> {
+ fn to_fill_or_stroke_style(&self) -> FillOrStrokeStyle {
+ FillOrStrokeStyle::Surface(
+ SurfaceStyle::new(self.surface_data.clone(), self.surface_size, self.repeat_x, self.repeat_y))
+ }
+}