aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorbors-servo <servo-ops@mozilla.com>2020-03-30 19:26:39 -0400
committerGitHub <noreply@github.com>2020-03-30 19:26:39 -0400
commit77b02393fb0fd3e17893f7f82492eeb741dd893e (patch)
tree8255cec780c1adbf4f1ddc7adabf2ef29f40c0cc /components/script/dom
parent70443291c953683aaa6320d5d13134afd80583c4 (diff)
parent8c405546a2023c3e098d9450c2d755392d3d5c9c (diff)
downloadservo-77b02393fb0fd3e17893f7f82492eeb741dd893e.tar.gz
servo-77b02393fb0fd3e17893f7f82492eeb741dd893e.zip
Auto merge of #26009 - SasiDharKM:master, r=jdm
Implementation for ImageBitmap <!-- Please describe your changes on the following line: --> Created the boilerplate code for the image bitmap implementation. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #20650 <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/imagebitmap.rs58
-rw-r--r--components/script/dom/mod.rs1
-rw-r--r--components/script/dom/webidls/ImageBitmap.webidl36
3 files changed, 95 insertions, 0 deletions
diff --git a/components/script/dom/imagebitmap.rs b/components/script/dom/imagebitmap.rs
new file mode 100644
index 00000000000..e5d3ec6098e
--- /dev/null
+++ b/components/script/dom/imagebitmap.rs
@@ -0,0 +1,58 @@
+/* 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::ImageBitmapBinding::ImageBitmapMethods;
+use crate::dom::bindings::root::DomRoot;
+use crate::dom::globalscope::GlobalScope;
+
+use crate::dom::bindings::error::Fallible;
+use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
+use dom_struct::dom_struct;
+
+use std::vec::Vec;
+
+#[dom_struct]
+pub struct ImageBitmap {
+ reflector_: Reflector,
+ width: u32,
+ height: u32,
+ bitmap_data: DomRefCell<Vec<u8>>,
+}
+
+impl ImageBitmap {
+ fn new_inherited(width_arg: u32, height_arg: u32) -> ImageBitmap {
+ ImageBitmap {
+ reflector_: Reflector::new(),
+ width: width_arg,
+ height: height_arg,
+ bitmap_data: DomRefCell::new(vec![]),
+ }
+ }
+
+ #[allow(dead_code)]
+ pub fn new(global: &GlobalScope, width: u32, height: u32) -> Fallible<DomRoot<ImageBitmap>> {
+ //assigning to a variable the return object of new_inherited
+ let imagebitmap = Box::new(ImageBitmap::new_inherited(width, height));
+
+ Ok(reflect_dom_object(imagebitmap, global))
+ }
+}
+
+impl ImageBitmapMethods for ImageBitmap {
+ // https://html.spec.whatwg.org/multipage/#dom-imagebitmap-height
+ fn Height(&self) -> u32 {
+ //to do: add a condition for checking detached internal slot
+ //and return 0 if set to true
+ self.height
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-imagebitmap-width
+ fn Width(&self) -> u32 {
+ //to do: add a condition to check detached internal slot
+ ////and return 0 if set to true
+ self.width
+ }
+}
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs
index 3691ba5a299..6cd85a3db60 100644
--- a/components/script/dom/mod.rs
+++ b/components/script/dom/mod.rs
@@ -408,6 +408,7 @@ pub mod htmlulistelement;
pub mod htmlunknownelement;
pub mod htmlvideoelement;
pub mod identityhub;
+pub mod imagebitmap;
pub mod imagedata;
pub mod inputevent;
pub mod keyboardevent;
diff --git a/components/script/dom/webidls/ImageBitmap.webidl b/components/script/dom/webidls/ImageBitmap.webidl
new file mode 100644
index 00000000000..ea49061a756
--- /dev/null
+++ b/components/script/dom/webidls/ImageBitmap.webidl
@@ -0,0 +1,36 @@
+/* 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/. */
+/*
+ * The origin of this IDL file is
+ * https://html.spec.whatwg.org/multipage/#imagebitmap
+ *
+ * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and Opera Software ASA.
+ * You are granted a license to use, reproduce and create derivative works of this document.
+ */
+
+//[Exposed=(Window,Worker), Serializable, Transferable]
+[Exposed=(Window,Worker)]
+interface ImageBitmap {
+ readonly attribute unsigned long width;
+ readonly attribute unsigned long height;
+ //void close();
+};
+
+typedef (CanvasImageSource or
+ Blob or
+ ImageData) ImageBitmapSource;
+
+enum ImageOrientation { "none", "flipY" };
+enum PremultiplyAlpha { "none", "premultiply", "default" };
+enum ColorSpaceConversion { "none", "default" };
+enum ResizeQuality { "pixelated", "low", "medium", "high" };
+
+dictionary ImageBitmapOptions {
+ ImageOrientation imageOrientation = "none";
+ PremultiplyAlpha premultiplyAlpha = "default";
+ ColorSpaceConversion colorSpaceConversion = "default";
+ [EnforceRange] unsigned long resizeWidth;
+ [EnforceRange] unsigned long resizeHeight;
+ ResizeQuality resizeQuality = "low";
+};