aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/offscreencanvasrenderingcontext2d.rs
diff options
context:
space:
mode:
authorHanif Bin Ariffin <hanif.ariffin.4326@gmail.com>2019-10-21 05:24:49 -0400
committerHanif Bin Ariffin <hanif.ariffin.4326@gmail.com>2019-10-25 02:27:57 -0400
commit31ff2d43ccc835bffc99aac596dabae1d23cc5f7 (patch)
tree6b088758d3f921822c3888f8d5433dea56e74218 /components/script/dom/offscreencanvasrenderingcontext2d.rs
parent08af89bd8205ac28c98b9a079216fca438a9ed66 (diff)
downloadservo-31ff2d43ccc835bffc99aac596dabae1d23cc5f7.tar.gz
servo-31ff2d43ccc835bffc99aac596dabae1d23cc5f7.zip
Moved CanvasState out of canvasrenderingcontext
Cleaned up imports... Applied clang-tidy Moved CanvasState and some other files Next commit should remove pub modifier from members of CanvasState and use getters/setters instead. Members of CanvasState are now private and applied test-tidy Now have getters that return an immutable reference. Also, I have no idea what to name some_func.rs Removed need for some_func and made pub(crate)
Diffstat (limited to 'components/script/dom/offscreencanvasrenderingcontext2d.rs')
-rw-r--r--components/script/dom/offscreencanvasrenderingcontext2d.rs136
1 files changed, 71 insertions, 65 deletions
diff --git a/components/script/dom/offscreencanvasrenderingcontext2d.rs b/components/script/dom/offscreencanvasrenderingcontext2d.rs
index bb2d1e73e96..04e0a13032c 100644
--- a/components/script/dom/offscreencanvasrenderingcontext2d.rs
+++ b/components/script/dom/offscreencanvasrenderingcontext2d.rs
@@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+use crate::canvas_state::CanvasState;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasFillRule;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasImageSource;
@@ -18,7 +19,6 @@ use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::canvasgradient::CanvasGradient;
use crate::dom::canvaspattern::CanvasPattern;
-use crate::dom::canvasrenderingcontext2d::CanvasState;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlcanvaselement::HTMLCanvasElement;
use crate::dom::imagedata::ImageData;
@@ -85,81 +85,81 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
// https://html.spec.whatwg.org/multipage/#dom-context-2d-fillrect
fn FillRect(&self, x: f64, y: f64, width: f64, height: f64) {
- self.canvas_state.borrow().FillRect(x, y, width, height);
+ self.canvas_state.borrow().fill_rect(x, y, width, height);
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-clearrect
fn ClearRect(&self, x: f64, y: f64, width: f64, height: f64) {
- self.canvas_state.borrow().ClearRect(x, y, width, height);
+ self.canvas_state.borrow().clear_rect(x, y, width, height);
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokerect
fn StrokeRect(&self, x: f64, y: f64, width: f64, height: f64) {
- self.canvas_state.borrow().StrokeRect(x, y, width, height);
+ self.canvas_state.borrow().stroke_rect(x, y, width, height);
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsetx
fn ShadowOffsetX(&self) -> f64 {
- self.canvas_state.borrow().ShadowOffsetX()
+ self.canvas_state.borrow().shadow_offset_x()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsetx
fn SetShadowOffsetX(&self, value: f64) {
- self.canvas_state.borrow().SetShadowOffsetX(value)
+ self.canvas_state.borrow().set_shadow_offset_x(value)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsety
fn ShadowOffsetY(&self) -> f64 {
- self.canvas_state.borrow().ShadowOffsetY()
+ self.canvas_state.borrow().shadow_offset_y()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsety
fn SetShadowOffsetY(&self, value: f64) {
- self.canvas_state.borrow().SetShadowOffsetY(value)
+ self.canvas_state.borrow().set_shadow_offset_y(value)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowblur
fn ShadowBlur(&self) -> f64 {
- self.canvas_state.borrow().ShadowBlur()
+ self.canvas_state.borrow().shadow_blur()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowblur
fn SetShadowBlur(&self, value: f64) {
- self.canvas_state.borrow().SetShadowBlur(value)
+ self.canvas_state.borrow().set_shadow_blur(value)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowcolor
fn ShadowColor(&self) -> DOMString {
- self.canvas_state.borrow().ShadowColor()
+ self.canvas_state.borrow().shadow_color()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowcolor
fn SetShadowColor(&self, value: DOMString) {
- self.canvas_state.borrow().SetShadowColor(value)
+ self.canvas_state.borrow().set_shadow_color(value)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle
fn StrokeStyle(&self) -> StringOrCanvasGradientOrCanvasPattern {
- self.canvas_state.borrow().StrokeStyle()
+ self.canvas_state.borrow().stroke_style()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle
fn SetStrokeStyle(&self, value: StringOrCanvasGradientOrCanvasPattern) {
self.canvas_state
.borrow()
- .SetStrokeStyle(self.htmlcanvas.as_ref().map(|c| &**c), value)
+ .set_stroke_style(self.htmlcanvas.as_ref().map(|c| &**c), value)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle
fn FillStyle(&self) -> StringOrCanvasGradientOrCanvasPattern {
- self.canvas_state.borrow().FillStyle()
+ self.canvas_state.borrow().fill_style()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle
fn SetFillStyle(&self, value: StringOrCanvasGradientOrCanvasPattern) {
self.canvas_state
.borrow()
- .SetFillStyle(self.htmlcanvas.as_ref().map(|c| &**c), value)
+ .set_fill_style(self.htmlcanvas.as_ref().map(|c| &**c), value)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createlineargradient
@@ -172,7 +172,7 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
) -> DomRoot<CanvasGradient> {
self.canvas_state
.borrow()
- .CreateLinearGradient(&self.global(), x0, y0, x1, y1)
+ .create_linear_gradient(&self.global(), x0, y0, x1, y1)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createradialgradient
@@ -187,7 +187,7 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
) -> Fallible<DomRoot<CanvasGradient>> {
self.canvas_state
.borrow()
- .CreateRadialGradient(&self.global(), x0, y0, r0, x1, y1, r1)
+ .create_radial_gradient(&self.global(), x0, y0, r0, x1, y1, r1)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createpattern
@@ -198,119 +198,123 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
) -> Fallible<DomRoot<CanvasPattern>> {
self.canvas_state
.borrow()
- .CreatePattern(&self.global(), image, repetition)
+ .create_pattern(&self.global(), image, repetition)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-save
fn Save(&self) {
- self.canvas_state.borrow().Save()
+ self.canvas_state.borrow().save()
}
#[allow(unrooted_must_root)]
// https://html.spec.whatwg.org/multipage/#dom-context-2d-restore
fn Restore(&self) {
- self.canvas_state.borrow().Restore()
+ self.canvas_state.borrow().restore()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalalpha
fn GlobalAlpha(&self) -> f64 {
- self.canvas_state.borrow().GlobalAlpha()
+ self.canvas_state.borrow().global_alpha()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalalpha
fn SetGlobalAlpha(&self, alpha: f64) {
- self.canvas_state.borrow().SetGlobalAlpha(alpha)
+ self.canvas_state.borrow().set_global_alpha(alpha)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
fn GlobalCompositeOperation(&self) -> DOMString {
- self.canvas_state.borrow().GlobalCompositeOperation()
+ self.canvas_state.borrow().global_composite_operation()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
fn SetGlobalCompositeOperation(&self, op_str: DOMString) {
self.canvas_state
.borrow()
- .SetGlobalCompositeOperation(op_str)
+ .set_global_composite_operation(op_str)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled
fn ImageSmoothingEnabled(&self) -> bool {
- self.canvas_state.borrow().ImageSmoothingEnabled()
+ self.canvas_state.borrow().image_smoothing_enabled()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled
fn SetImageSmoothingEnabled(&self, value: bool) {
- self.canvas_state.borrow().SetImageSmoothingEnabled(value)
+ self.canvas_state
+ .borrow()
+ .set_image_smoothing_enabled(value)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-filltext
fn FillText(&self, text: DOMString, x: f64, y: f64, max_width: Option<f64>) {
- self.canvas_state.borrow().FillText(text, x, y, max_width)
+ self.canvas_state.borrow().fill_text(text, x, y, max_width)
}
// https://html.spec.whatwg.org/multipage/#textmetrics
fn MeasureText(&self, text: DOMString) -> DomRoot<TextMetrics> {
- self.canvas_state.borrow().MeasureText(&self.global(), text)
+ self.canvas_state
+ .borrow()
+ .measure_text(&self.global(), text)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth
fn LineWidth(&self) -> f64 {
- self.canvas_state.borrow().LineWidth()
+ self.canvas_state.borrow().line_width()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth
fn SetLineWidth(&self, width: f64) {
- self.canvas_state.borrow().SetLineWidth(width)
+ self.canvas_state.borrow().set_line_width(width)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
fn LineCap(&self) -> CanvasLineCap {
- self.canvas_state.borrow().LineCap()
+ self.canvas_state.borrow().line_cap()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
fn SetLineCap(&self, cap: CanvasLineCap) {
- self.canvas_state.borrow().SetLineCap(cap)
+ self.canvas_state.borrow().set_line_cap(cap)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
fn LineJoin(&self) -> CanvasLineJoin {
- self.canvas_state.borrow().LineJoin()
+ self.canvas_state.borrow().line_join()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
fn SetLineJoin(&self, join: CanvasLineJoin) {
- self.canvas_state.borrow().SetLineJoin(join)
+ self.canvas_state.borrow().set_line_join(join)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-miterlimit
fn MiterLimit(&self) -> f64 {
- self.canvas_state.borrow().MiterLimit()
+ self.canvas_state.borrow().miter_limit()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-miterlimit
fn SetMiterLimit(&self, limit: f64) {
- self.canvas_state.borrow().SetMiterLimit(limit)
+ self.canvas_state.borrow().set_miter_limit(limit)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
fn CreateImageData(&self, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
self.canvas_state
.borrow()
- .CreateImageData(&self.global(), sw, sh)
+ .create_image_data(&self.global(), sw, sh)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
fn CreateImageData_(&self, imagedata: &ImageData) -> Fallible<DomRoot<ImageData>> {
self.canvas_state
.borrow()
- .CreateImageData_(&self.global(), imagedata)
+ .create_image_data_(&self.global(), imagedata)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata
fn GetImageData(&self, sx: i32, sy: i32, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
- self.canvas_state.borrow().GetImageData(
+ self.canvas_state.borrow().get_image_data(
Size2D::new(self.width, self.height),
&self.global(),
sx,
@@ -322,7 +326,7 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
fn PutImageData(&self, imagedata: &ImageData, dx: i32, dy: i32) {
- self.canvas_state.borrow().PutImageData(
+ self.canvas_state.borrow().put_image_data(
Size2D::new(self.width, self.height),
imagedata,
dx,
@@ -342,7 +346,7 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
dirty_width: i32,
dirty_height: i32,
) {
- self.canvas_state.borrow().PutImageData_(
+ self.canvas_state.borrow().put_image_data_(
Size2D::new(self.width, self.height),
imagedata,
dx,
@@ -358,7 +362,7 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
fn DrawImage(&self, image: CanvasImageSource, dx: f64, dy: f64) -> ErrorResult {
self.canvas_state
.borrow()
- .DrawImage(self.htmlcanvas.as_ref().map(|c| &**c), image, dx, dy)
+ .draw_image(self.htmlcanvas.as_ref().map(|c| &**c), image, dx, dy)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
@@ -370,7 +374,7 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
dw: f64,
dh: f64,
) -> ErrorResult {
- self.canvas_state.borrow().DrawImage_(
+ self.canvas_state.borrow().draw_image_(
self.htmlcanvas.as_ref().map(|c| &**c),
image,
dx,
@@ -393,7 +397,7 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
dw: f64,
dh: f64,
) -> ErrorResult {
- self.canvas_state.borrow().DrawImage__(
+ self.canvas_state.borrow().draw_image__(
self.htmlcanvas.as_ref().map(|c| &**c),
image,
sx,
@@ -409,101 +413,103 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
// https://html.spec.whatwg.org/multipage/#dom-context-2d-beginpath
fn BeginPath(&self) {
- self.canvas_state.borrow().BeginPath()
+ self.canvas_state.borrow().begin_path()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-fill
fn Fill(&self, fill_rule: CanvasFillRule) {
- self.canvas_state.borrow().Fill(fill_rule)
+ self.canvas_state.borrow().fill(fill_rule)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-stroke
fn Stroke(&self) {
- self.canvas_state.borrow().Stroke()
+ self.canvas_state.borrow().stroke()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-clip
fn Clip(&self, fill_rule: CanvasFillRule) {
- self.canvas_state.borrow().Clip(fill_rule)
+ self.canvas_state.borrow().clip(fill_rule)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-ispointinpath
fn IsPointInPath(&self, x: f64, y: f64, fill_rule: CanvasFillRule) -> bool {
self.canvas_state
.borrow()
- .IsPointInPath(&self.global(), x, y, fill_rule)
+ .is_point_in_path(&self.global(), x, y, fill_rule)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-scale
fn Scale(&self, x: f64, y: f64) {
- self.canvas_state.borrow().Scale(x, y)
+ self.canvas_state.borrow().scale(x, y)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-rotate
fn Rotate(&self, angle: f64) {
- self.canvas_state.borrow().Rotate(angle)
+ self.canvas_state.borrow().rotate(angle)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-translate
fn Translate(&self, x: f64, y: f64) {
- self.canvas_state.borrow().Translate(x, y)
+ self.canvas_state.borrow().translate(x, y)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-transform
fn Transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
- self.canvas_state.borrow().Transform(a, b, c, d, e, f)
+ self.canvas_state.borrow().transform(a, b, c, d, e, f)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform
fn SetTransform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
- self.canvas_state.borrow().SetTransform(a, b, c, d, e, f)
+ self.canvas_state.borrow().set_transform(a, b, c, d, e, f)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-resettransform
fn ResetTransform(&self) {
- self.canvas_state.borrow().ResetTransform()
+ self.canvas_state.borrow().reset_transform()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-closepath
fn ClosePath(&self) {
- self.canvas_state.borrow().ClosePath()
+ self.canvas_state.borrow().close_path()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-moveto
fn MoveTo(&self, x: f64, y: f64) {
- self.canvas_state.borrow().MoveTo(x, y)
+ self.canvas_state.borrow().move_to(x, y)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-lineto
fn LineTo(&self, x: f64, y: f64) {
- self.canvas_state.borrow().LineTo(x, y)
+ self.canvas_state.borrow().line_to(x, y)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-rect
fn Rect(&self, x: f64, y: f64, width: f64, height: f64) {
- self.canvas_state.borrow().Rect(x, y, width, height)
+ self.canvas_state.borrow().rect(x, y, width, height)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-quadraticcurveto
fn QuadraticCurveTo(&self, cpx: f64, cpy: f64, x: f64, y: f64) {
- self.canvas_state.borrow().QuadraticCurveTo(cpx, cpy, x, y)
+ self.canvas_state
+ .borrow()
+ .quadratic_curve_to(cpx, cpy, x, y)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-beziercurveto
fn BezierCurveTo(&self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, x: f64, y: f64) {
self.canvas_state
.borrow()
- .BezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
+ .bezier_curve_to(cp1x, cp1y, cp2x, cp2y, x, y)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-arc
fn Arc(&self, x: f64, y: f64, r: f64, start: f64, end: f64, ccw: bool) -> ErrorResult {
- self.canvas_state.borrow().Arc(x, y, r, start, end, ccw)
+ self.canvas_state.borrow().arc(x, y, r, start, end, ccw)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-arcto
fn ArcTo(&self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, r: f64) -> ErrorResult {
- self.canvas_state.borrow().ArcTo(cp1x, cp1y, cp2x, cp2y, r)
+ self.canvas_state.borrow().arc_to(cp1x, cp1y, cp2x, cp2y, r)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-ellipse
@@ -520,6 +526,6 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
) -> ErrorResult {
self.canvas_state
.borrow()
- .Ellipse(x, y, rx, ry, rotation, start, end, ccw)
+ .ellipse(x, y, rx, ry, rotation, start, end, ccw)
}
}