mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
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. -->
This commit is contained in:
commit
77b02393fb
8 changed files with 99 additions and 30 deletions
58
components/script/dom/imagebitmap.rs
Normal file
58
components/script/dom/imagebitmap.rs
Normal file
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
36
components/script/dom/webidls/ImageBitmap.webidl
Normal file
36
components/script/dom/webidls/ImageBitmap.webidl
Normal file
|
@ -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";
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue