Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/script/dom/htmlimageelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ use std::sync::Arc;
use string_cache::Atom;
use url::{Url, UrlParser};
use util::str::DOMString;
use dom::imagerequest::ImageRequest;

#[dom_struct]
pub struct HTMLImageElement {
htmlelement: HTMLElement,
url: DOMRefCell<Option<Url>>,
image: DOMRefCell<Option<Arc<Image>>>,
currentRequest: ImageRequest,
pendingRequest: ImageRequest,
}

impl HTMLImageElement {
Expand Down
67 changes: 67 additions & 0 deletions components/script/dom/imagerequest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* 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 http://mozilla.org/MPL/2.0/. */


use dom::url::URL;
use dom::bindings::global::GlobalRef;
use dom::imagedata::ImageData;
use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::codegen::Bindings::ImageRequestBinding;
use dom::bindings::codegen::Bindings::ImageRequestBinding::ImageRequestMethods;

// Unavailable
// The user agent hasn't obtained any image data, or has obtained some or all of the
// image data but hasn't yet decoded enough of the image to get the image dimensions.
// Partially available
// The user agent has obtained some of the image data and at least the image dimensions are available.
// Completely available
// The user agent has obtained all of the image data and at least the image dimensions are available.
// Broken
// The user agent has obtained all of the image data that it can, but it cannot even
// decode the image enough to get the image dimensions (e.g. the image is corrupted, or the format
// is not supported, or no data could be obtained).

#[dom_struct]
pub struct ImageRequest {
reflector_: Reflector,
state : ImageState,
currentUrl : URL,
imageData : ImageData,
}

//#[derive(JSTraceable, Clone, HeapSizeOf)]
pub enum ImageState {
Unavailable,
PartiallyAvailable,
CompletelyAvailable,
Broken,
}

impl ImageRequest {
fn new(global: GlobalRef, imageData : ImageData, currentUrl : DOMString) -> ImageRequest {
ImageRequest {
reflector_: Reflector::new(),
state : ImageState::Unavailable,
currentUrl : currentUrl,
imageData : imageData,
}
}
}


impl ImageRequestMethods for ImageRequest {

fn State(&self) -> ImageState {
self.state
}

fn CurrentUrl(&self) -> URL {
self.currentUrl
}

fn ImageData(&self) -> ImageData {
self.imageData
}
}
1 change: 1 addition & 0 deletions components/script/dom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ pub mod htmlulistelement;
pub mod htmlunknownelement;
pub mod htmlvideoelement;
pub mod imagedata;
pub mod imagerequest;
pub mod keyboardevent;
pub mod location;
pub mod messageevent;
Expand Down
18 changes: 18 additions & 0 deletions components/script/dom/webidls/ImageRequest.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 http://mozilla.org/MPL/2.0/. */
/*
* The origin of this IDL file is
* https://html.spec.whatwg.org/multipage/#imagerequest
*
* © 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.
*/

//[Constructor(ImageData imageData, URL currentUrl)]
interface ImageRequest {
readonly attribute ImageState state;
readonly attribute URL currentUrl;
readonly attribute ImageData imageData;
};