aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlcanvaselement.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2018-09-15 00:21:24 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2018-09-15 00:24:21 +0200
commit462a488d5580a6e538cb6b01f77c6f55816a8b65 (patch)
treeb4fa5f27ee595558a9116c01e8ccd6273baaa0d7 /components/script/dom/htmlcanvaselement.rs
parent3528ef30e56a1fce3e449eefa8f3c5bd06a595cd (diff)
downloadservo-462a488d5580a6e538cb6b01f77c6f55816a8b65.tar.gz
servo-462a488d5580a6e538cb6b01f77c6f55816a8b65.zip
Update HTMLCanvasElement WebIDL definition
Diffstat (limited to 'components/script/dom/htmlcanvaselement.rs')
-rw-r--r--components/script/dom/htmlcanvaselement.rs55
1 files changed, 27 insertions, 28 deletions
diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs
index 3854b29967b..cfc1ee9a3db 100644
--- a/components/script/dom/htmlcanvaselement.rs
+++ b/components/script/dom/htmlcanvaselement.rs
@@ -17,7 +17,7 @@ use dom::bindings::inheritance::Castable;
use dom::bindings::num::Finite;
use dom::bindings::reflector::DomObject;
use dom::bindings::root::{Dom, DomRoot, LayoutDom};
-use dom::bindings::str::DOMString;
+use dom::bindings::str::{DOMString, USVString};
use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers};
use dom::document::Document;
use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
@@ -191,12 +191,12 @@ impl HTMLCanvasElement {
pub fn get_or_init_webgl_context(
&self,
cx: *mut JSContext,
- attrs: Option<HandleValue>
+ options: HandleValue,
) -> Option<DomRoot<WebGLRenderingContext>> {
if self.context.borrow().is_none() {
let window = window_from_node(self);
let size = self.get_size();
- let attrs = Self::get_gl_attributes(cx, attrs)?;
+ let attrs = Self::get_gl_attributes(cx, options)?;
let maybe_ctx = WebGLRenderingContext::new(&window, self, WebGLVersion::WebGL1, size, attrs);
*self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(Dom::from_ref(&*ctx)));
@@ -212,7 +212,7 @@ impl HTMLCanvasElement {
pub fn get_or_init_webgl2_context(
&self,
cx: *mut JSContext,
- attrs: Option<HandleValue>
+ options: HandleValue,
) -> Option<DomRoot<WebGL2RenderingContext>> {
if !PREFS.is_webgl2_enabled() {
return None
@@ -220,7 +220,7 @@ impl HTMLCanvasElement {
if self.context.borrow().is_none() {
let window = window_from_node(self);
let size = self.get_size();
- let attrs = Self::get_gl_attributes(cx, attrs)?;
+ let attrs = Self::get_gl_attributes(cx, options)?;
let maybe_ctx = WebGL2RenderingContext::new(&window, self, size, attrs);
*self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL2(Dom::from_ref(&*ctx)));
@@ -243,12 +243,8 @@ impl HTMLCanvasElement {
}
#[allow(unsafe_code)]
- fn get_gl_attributes(cx: *mut JSContext, attrs: Option<HandleValue>) -> Option<GLContextAttributes> {
- let webgl_attributes = match attrs {
- Some(attrs) => attrs,
- None => return Some(GLContextAttributes::default()),
- };
- match unsafe { WebGLContextAttributes::new(cx, webgl_attributes) } {
+ fn get_gl_attributes(cx: *mut JSContext, options: HandleValue) -> Option<GLContextAttributes> {
+ match unsafe { WebGLContextAttributes::new(cx, options) } {
Ok(ConversionResult::Success(ref attrs)) => Some(From::from(attrs)),
Ok(ConversionResult::Failure(ref error)) => {
unsafe { throw_type_error(cx, &error); }
@@ -310,36 +306,39 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
// https://html.spec.whatwg.org/multipage/#dom-canvas-height
make_uint_setter!(SetHeight, "height", DEFAULT_HEIGHT);
- #[allow(unsafe_code)]
// https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext
- unsafe fn GetContext(&self,
- cx: *mut JSContext,
- id: DOMString,
- attributes: Vec<HandleValue>)
- -> Option<RenderingContext> {
+ #[allow(unsafe_code)]
+ unsafe fn GetContext(
+ &self,
+ cx: *mut JSContext,
+ id: DOMString,
+ options: HandleValue,
+ ) -> Option<RenderingContext> {
match &*id {
"2d" => {
self.get_or_init_2d_context()
.map(RenderingContext::CanvasRenderingContext2D)
}
"webgl" | "experimental-webgl" => {
- self.get_or_init_webgl_context(cx, attributes.get(0).cloned())
+ self.get_or_init_webgl_context(cx, options)
.map(RenderingContext::WebGLRenderingContext)
}
"webgl2" | "experimental-webgl2" => {
- self.get_or_init_webgl2_context(cx, attributes.get(0).cloned())
+ self.get_or_init_webgl2_context(cx, options)
.map(RenderingContext::WebGL2RenderingContext)
}
_ => None
}
}
- #[allow(unsafe_code)]
// https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl
- unsafe fn ToDataURL(&self,
- _context: *mut JSContext,
- _mime_type: Option<DOMString>,
- _arguments: Vec<HandleValue>) -> Fallible<DOMString> {
+ #[allow(unsafe_code)]
+ unsafe fn ToDataURL(
+ &self,
+ _context: *mut JSContext,
+ _mime_type: Option<DOMString>,
+ _quality: HandleValue,
+ ) -> Fallible<USVString> {
// Step 1.
if let Some(CanvasContext::Context2d(ref context)) = *self.context.borrow() {
if !context.origin_is_clean() {
@@ -349,7 +348,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
// Step 2.
if self.Width() == 0 || self.Height() == 0 {
- return Ok(DOMString::from("data:,"));
+ return Ok(USVString("data:,".into()));
}
// Step 3.
@@ -363,13 +362,13 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
Some(CanvasContext::WebGL(ref context)) => {
match context.get_image_data(self.Width(), self.Height()) {
Some(data) => data,
- None => return Ok("data:,".into()),
+ None => return Ok(USVString("data:,".into())),
}
}
Some(CanvasContext::WebGL2(ref context)) => {
match context.base_context().get_image_data(self.Width(), self.Height()) {
Some(data) => data,
- None => return Ok("data:,".into()),
+ None => return Ok(USVString("data:,".into())),
}
}
None => {
@@ -388,7 +387,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
}
let encoded = base64::encode(&encoded);
- Ok(DOMString::from(format!("data:{};base64,{}", mime_type, encoded)))
+ Ok(USVString(format!("data:{};base64,{}", mime_type, encoded)))
}
}