servo/components/script/dom/offscreencanvasrenderingcontext2d.rs
bors-servo 3f30720bba
Auto merge of #23363 - Darkspirit:https, r=jdm
More https

* Disabled unused legacy TLS.
It will be disabled for Nightly 72 or 73 in 5-7 months and ride the [trains](https://wiki.mozilla.org/Release_Management/Calendar).
https://blog.mozilla.org/security/2018/10/15/removing-old-versions-of-tls/
* Updated MPL license in a few files.
It would be nice if a new version of https://pypi.org/project/servo_tidy/ could be released to update WebRender as well.
* Switched servo-deps.s3.amazonaws.com back to https.
This was recently regressed by 10585be25c and fc28073dfb.
* Made https the default protocol for address bar on desktop.
Press Ctrl+L on the Glutin port and enter `example.com`:
Servo previously assumed you meant `http://example.com/`, now it is `https://example.com/`.

---

- [x] `./mach build --release` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23363)
<!-- Reviewable:end -->
2019-05-14 08:21:17 -04:00

74 lines
2.7 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* 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::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::OffscreenCanvasRenderingContext2DBinding;
use crate::dom::bindings::codegen::Bindings::OffscreenCanvasRenderingContext2DBinding::OffscreenCanvasRenderingContext2DMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::canvasrenderingcontext2d::CanvasState;
use crate::dom::globalscope::GlobalScope;
use crate::dom::offscreencanvas::OffscreenCanvas;
use dom_struct::dom_struct;
use euclid::Size2D;
#[dom_struct]
pub struct OffscreenCanvasRenderingContext2D {
reflector_: Reflector,
canvas: Option<Dom<OffscreenCanvas>>,
canvas_state: DomRefCell<CanvasState>,
}
impl OffscreenCanvasRenderingContext2D {
pub fn new_inherited(
global: &GlobalScope,
canvas: Option<&OffscreenCanvas>,
size: Size2D<u64>,
) -> OffscreenCanvasRenderingContext2D {
OffscreenCanvasRenderingContext2D {
reflector_: Reflector::new(),
canvas: canvas.map(Dom::from_ref),
canvas_state: DomRefCell::new(CanvasState::new(global, size)),
}
}
pub fn new(
global: &GlobalScope,
canvas: &OffscreenCanvas,
size: Size2D<u64>,
) -> DomRoot<OffscreenCanvasRenderingContext2D> {
let boxed = Box::new(OffscreenCanvasRenderingContext2D::new_inherited(
global,
Some(canvas),
size,
));
reflect_dom_object(
boxed,
global,
OffscreenCanvasRenderingContext2DBinding::Wrap,
)
}
}
impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContext2D {
// https://html.spec.whatwg.org/multipage/offscreencontext2d-canvas
fn Canvas(&self) -> DomRoot<OffscreenCanvas> {
DomRoot::from_ref(self.canvas.as_ref().expect("No canvas."))
}
// 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);
}
// 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);
}
// 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);
}
}