Skip to content
Permalink
Browse files
formatted the code to follow Tidy principles.
  • Loading branch information
ramyananth committed Apr 24, 2020
1 parent 6ff3333 commit 37e026db073e3466304b1e9367605bf66343b18c
Showing 3 changed files with 60 additions and 49 deletions.
@@ -12,16 +12,16 @@ use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use dom_struct::dom_struct;

use std::vec::Vec;
use std::cell::Cell;
use std::vec::Vec;

#[dom_struct]
pub struct ImageBitmap {
reflector_: Reflector,
width: u32,
height: u32,
bitmap_data: DomRefCell<Vec<u8>>,
origin_clean: Cell<bool>
origin_clean: Cell<bool>,
}

impl ImageBitmap {
@@ -31,8 +31,7 @@ impl ImageBitmap {
width: width_arg,
height: height_arg,
bitmap_data: DomRefCell::new(vec![]),
origin_clean: Cell::new(true)
//origin_clean: origin_clean_arg
origin_clean: Cell::new(true),
}
}

@@ -7,6 +7,9 @@ use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
DocumentMethods, DocumentReadyState,
};
use crate::dom::bindings::codegen::Bindings::HistoryBinding::HistoryBinding::HistoryMethods;
use crate::dom::bindings::codegen::Bindings::ImageBitmapBinding::{
ImageBitmapOptions, ImageBitmapSource,
};
use crate::dom::bindings::codegen::Bindings::MediaQueryListBinding::MediaQueryListBinding::MediaQueryListMethods;
use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
use crate::dom::bindings::codegen::Bindings::VoidFunctionBinding::VoidFunction;
@@ -37,6 +40,7 @@ use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::hashchangeevent::HashChangeEvent;
use crate::dom::history::History;
use crate::dom::imagebitmap::ImageBitmap;
use crate::dom::location::Location;
use crate::dom::mediaquerylist::{MediaQueryList, MediaQueryListMatchState};
use crate::dom::mediaquerylistevent::MediaQueryListEvent;
@@ -67,7 +71,6 @@ use crate::task_manager::TaskManager;
use crate::task_source::{TaskSource, TaskSourceName};
use crate::timers::{IsInterval, TimerCallback};
use crate::webdriver_handlers::jsval_to_webdriver;
use crate::dom::imagebitmap::ImageBitmap;
use app_units::Au;
use base64;
use bluetooth_traits::BluetoothRequest;
@@ -140,7 +143,6 @@ use style_traits::{CSSPixel, DevicePixel, ParsingMode};
use url::Position;
use webrender_api::units::{DeviceIntPoint, DeviceIntSize, LayoutPixel};
use webrender_api::{DocumentId, ExternalScrollId};
use crate::dom::bindings::codegen::Bindings::ImageBitmapBinding::{ImageBitmapSource, ImageBitmapOptions};

/// Current state of the window object
#[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)]
@@ -891,59 +893,63 @@ impl WindowMethods for Window {
.queue_function_as_microtask(callback);
}

// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-createimagebitmap
fn CreateImageBitmap(&self, image: ImageBitmapSource, options: &ImageBitmapOptions) -> Rc<Promise> {
// https://html.spec.whatwg.org/multipage/#dom-createimagebitmap
fn CreateImageBitmap(
&self,
image: ImageBitmapSource,
options: &ImageBitmapOptions,
) -> Rc<Promise> {
let global = self.global();
let in_realm_proof = AlreadyInRealm::assert(&global);
let p = Promise::new_in_current_realm(&global, InRealm::Already(&in_realm_proof));
if options.resizeWidth.unwrap() == 0 {
p.reject_error(Error::InvalidState)
}

if options.resizeHeight.unwrap() == 0 {
p.reject_error(Error::InvalidState)
}

let image_bitmap = ImageBitmap::new(&global,0,0).unwrap();
let image_bitmap = ImageBitmap::new(&global, 0, 0).unwrap();

let promise = match image {
ImageBitmapSource::HTMLCanvasElement(ref canvas) => {
// https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument
if !canvas.is_valid() {
p.reject_error(Error::InvalidState)
}

if let Some((data, size)) = canvas.fetch_all_data() {
let data = DomRefCell::new(data
.map(|data| data.to_vec())
.unwrap_or_else(|| vec![0; size.area() as usize * 4]));

let data = DomRefCell::new(
data.map(|data| data.to_vec())
.unwrap_or_else(|| vec![0; size.area() as usize * 4]),
);

image_bitmap.set_bitmap_data(data);
image_bitmap.set_origin_clean(canvas.origin_is_clean());
p.resolve_native(&(image_bitmap));
}
p
}
},
ImageBitmapSource::OffscreenCanvas(ref canvas) => {
// https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument
if !canvas.is_valid() {
p.reject_error(Error::InvalidState)
}

if let Some((data, size)) = canvas.fetch_all_data() {
let data = DomRefCell::new(data
.map(|data| data.to_vec())
.unwrap_or_else(|| vec![0; size.area() as usize * 4]));

let data = DomRefCell::new(
data.map(|data| data.to_vec())
.unwrap_or_else(|| vec![0; size.area() as usize * 4]),
);

image_bitmap.set_bitmap_data(data);
image_bitmap.set_origin_clean(canvas.origin_is_clean());
p.resolve_native(&(image_bitmap));
}
p
}
_ => {
p
}
},
_ => p,
};
promise
}
@@ -3,6 +3,9 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::dom::bindings::cell::{DomRefCell, Ref};
use crate::dom::bindings::codegen::Bindings::ImageBitmapBinding::{
ImageBitmapOptions, ImageBitmapSource,
};
use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
use crate::dom::bindings::codegen::Bindings::VoidFunctionBinding::VoidFunction;
use crate::dom::bindings::codegen::Bindings::WorkerBinding::WorkerType;
@@ -18,14 +21,15 @@ use crate::dom::bindings::trace::RootedTraceableBox;
use crate::dom::crypto::Crypto;
use crate::dom::dedicatedworkerglobalscope::DedicatedWorkerGlobalScope;
use crate::dom::globalscope::GlobalScope;
use crate::dom::imagebitmap::ImageBitmap;
use crate::dom::performance::Performance;
use crate::dom::promise::Promise;
use crate::dom::serviceworkerglobalscope::ServiceWorkerGlobalScope;
use crate::dom::window::{base64_atob, base64_btoa};
use crate::dom::workerlocation::WorkerLocation;
use crate::dom::workernavigator::WorkerNavigator;
use crate::fetch;
use crate::realms::{enter_realm, InRealm, AlreadyInRealm};
use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
use crate::script_runtime::JSContext;
use crate::script_runtime::{get_reports, CommonScriptMsg, Runtime, ScriptChan, ScriptPort};
use crate::task::TaskCanceller;
@@ -58,8 +62,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use time::precise_time_ns;
use uuid::Uuid;
use crate::dom::bindings::codegen::Bindings::ImageBitmapBinding::{ImageBitmapSource, ImageBitmapOptions};
use crate::dom::imagebitmap::ImageBitmap;

pub fn prepare_workerscope_init(
global: &GlobalScope,
@@ -378,59 +380,63 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
)
}

// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-createimagebitmap
fn CreateImageBitmap(&self, image: ImageBitmapSource, options: &ImageBitmapOptions) -> Rc<Promise> {
// https://html.spec.whatwg.org/multipage/#dom-createimagebitmap
fn CreateImageBitmap(
&self,
image: ImageBitmapSource,
options: &ImageBitmapOptions,
) -> Rc<Promise> {
let global = self.global();
let in_realm_proof = AlreadyInRealm::assert(&global);
let p = Promise::new_in_current_realm(&global, InRealm::Already(&in_realm_proof));
if options.resizeWidth.unwrap() == 0 {
p.reject_error(Error::InvalidState)
}

if options.resizeHeight.unwrap() == 0 {
p.reject_error(Error::InvalidState)
}

let image_bitmap = ImageBitmap::new(&global,0,0).unwrap();
let image_bitmap = ImageBitmap::new(&global, 0, 0).unwrap();

let promise = match image {
ImageBitmapSource::HTMLCanvasElement(ref canvas) => {
// https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument
if !canvas.is_valid() {
p.reject_error(Error::InvalidState)
}

if let Some((data, size)) = canvas.fetch_all_data() {
let data = DomRefCell::new(data
.map(|data| data.to_vec())
.unwrap_or_else(|| vec![0; size.area() as usize * 4]));

let data = DomRefCell::new(
data.map(|data| data.to_vec())
.unwrap_or_else(|| vec![0; size.area() as usize * 4]),
);

image_bitmap.set_bitmap_data(data);
image_bitmap.set_origin_clean(canvas.origin_is_clean());
p.resolve_native(&(image_bitmap));
}
p
}
},
ImageBitmapSource::OffscreenCanvas(ref canvas) => {
// https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument
if !canvas.is_valid() {
p.reject_error(Error::InvalidState)
}

if let Some((data, size)) = canvas.fetch_all_data() {
let data = DomRefCell::new(data
.map(|data| data.to_vec())
.unwrap_or_else(|| vec![0; size.area() as usize * 4]));

let data = DomRefCell::new(
data.map(|data| data.to_vec())
.unwrap_or_else(|| vec![0; size.area() as usize * 4]),
);

image_bitmap.set_bitmap_data(data);
image_bitmap.set_origin_clean(canvas.origin_is_clean());
p.resolve_native(&(image_bitmap));
}
p
}
_ => {
p
}
},
_ => p,
};
promise
}

0 comments on commit 37e026d

Please sign in to comment.