mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Implement HTMLImageElement decode
Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
parent
98057799ac
commit
ba359083e5
4 changed files with 33 additions and 0 deletions
|
@ -41,6 +41,7 @@ use crate::resource_thread::CoreResourceThreadPool;
|
||||||
// ======================================================================
|
// ======================================================================
|
||||||
|
|
||||||
fn decode_bytes_sync(key: LoadKey, bytes: &[u8], cors: CorsStatus) -> DecoderMsg {
|
fn decode_bytes_sync(key: LoadKey, bytes: &[u8], cors: CorsStatus) -> DecoderMsg {
|
||||||
|
// decode
|
||||||
let image = load_from_memory(bytes, cors);
|
let image = load_from_memory(bytes, cors);
|
||||||
DecoderMsg { key, image }
|
DecoderMsg { key, image }
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ pub enum DOMErrorName {
|
||||||
TimeoutError = DOMExceptionConstants::TIMEOUT_ERR,
|
TimeoutError = DOMExceptionConstants::TIMEOUT_ERR,
|
||||||
InvalidNodeTypeError = DOMExceptionConstants::INVALID_NODE_TYPE_ERR,
|
InvalidNodeTypeError = DOMExceptionConstants::INVALID_NODE_TYPE_ERR,
|
||||||
DataCloneError = DOMExceptionConstants::DATA_CLONE_ERR,
|
DataCloneError = DOMExceptionConstants::DATA_CLONE_ERR,
|
||||||
|
EncodingError,
|
||||||
NotReadableError,
|
NotReadableError,
|
||||||
OperationError,
|
OperationError,
|
||||||
}
|
}
|
||||||
|
@ -70,6 +71,7 @@ impl DOMErrorName {
|
||||||
"TimeoutError" => Some(DOMErrorName::TimeoutError),
|
"TimeoutError" => Some(DOMErrorName::TimeoutError),
|
||||||
"InvalidNodeTypeError" => Some(DOMErrorName::InvalidNodeTypeError),
|
"InvalidNodeTypeError" => Some(DOMErrorName::InvalidNodeTypeError),
|
||||||
"DataCloneError" => Some(DOMErrorName::DataCloneError),
|
"DataCloneError" => Some(DOMErrorName::DataCloneError),
|
||||||
|
"EncodingError" => Some(DOMErrorName::EncodingError),
|
||||||
"NotReadableError" => Some(DOMErrorName::NotReadableError),
|
"NotReadableError" => Some(DOMErrorName::NotReadableError),
|
||||||
"OperationError" => Some(DOMErrorName::OperationError),
|
"OperationError" => Some(DOMErrorName::OperationError),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -115,6 +117,9 @@ impl DOMException {
|
||||||
"The supplied node is incorrect or has an incorrect ancestor for this operation."
|
"The supplied node is incorrect or has an incorrect ancestor for this operation."
|
||||||
},
|
},
|
||||||
DOMErrorName::DataCloneError => "The object can not be cloned.",
|
DOMErrorName::DataCloneError => "The object can not be cloned.",
|
||||||
|
DOMErrorName::EncodingError => {
|
||||||
|
"The encoding operation (either encoded or decoding) failed."
|
||||||
|
},
|
||||||
DOMErrorName::NotReadableError => "The I/O read operation failed.",
|
DOMErrorName::NotReadableError => "The I/O read operation failed.",
|
||||||
DOMErrorName::OperationError => {
|
DOMErrorName::OperationError => {
|
||||||
"The operation failed for an operation-specific reason."
|
"The operation failed for an operation-specific reason."
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
use std::rc::Rc;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::{char, i32, mem};
|
use std::{char, i32, mem};
|
||||||
|
|
||||||
|
@ -47,6 +48,8 @@ use style::values::specified::AbsoluteLength;
|
||||||
use style_traits::ParsingMode;
|
use style_traits::ParsingMode;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
use super::domexception::DOMErrorName;
|
||||||
|
use super::types::DOMException;
|
||||||
use crate::document_loader::{LoadBlocker, LoadType};
|
use crate::document_loader::{LoadBlocker, LoadType};
|
||||||
use crate::dom::activation::Activatable;
|
use crate::dom::activation::Activatable;
|
||||||
use crate::dom::attr::Attr;
|
use crate::dom::attr::Attr;
|
||||||
|
@ -84,6 +87,7 @@ use crate::dom::node::{
|
||||||
UnbindContext,
|
UnbindContext,
|
||||||
};
|
};
|
||||||
use crate::dom::performanceresourcetiming::InitiatorType;
|
use crate::dom::performanceresourcetiming::InitiatorType;
|
||||||
|
use crate::dom::promise::Promise;
|
||||||
use crate::dom::values::UNSIGNED_LONG_MAX;
|
use crate::dom::values::UNSIGNED_LONG_MAX;
|
||||||
use crate::dom::virtualmethods::VirtualMethods;
|
use crate::dom::virtualmethods::VirtualMethods;
|
||||||
use crate::dom::window::Window;
|
use crate::dom::window::Window;
|
||||||
|
@ -1605,6 +1609,26 @@ impl HTMLImageElementMethods for HTMLImageElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-decode>
|
||||||
|
fn Decode(&self) -> Rc<Promise> {
|
||||||
|
// Step 1
|
||||||
|
let promise = Promise::new(&self.global());
|
||||||
|
|
||||||
|
// Step 2
|
||||||
|
let document = document_from_node(self);
|
||||||
|
if !document.is_fully_active() {
|
||||||
|
promise.reject_native(&DOMException::new(
|
||||||
|
&self.global(),
|
||||||
|
DOMErrorName::EncodingError,
|
||||||
|
));
|
||||||
|
} else if self.current_request.borrow().image.is_some() {
|
||||||
|
promise.resolve_native(&());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 3
|
||||||
|
promise
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-img-name
|
// https://html.spec.whatwg.org/multipage/#dom-img-name
|
||||||
make_getter!(Name, "name");
|
make_getter!(Name, "name");
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,9 @@ interface HTMLImageElement : HTMLElement {
|
||||||
readonly attribute USVString currentSrc;
|
readonly attribute USVString currentSrc;
|
||||||
[CEReactions]
|
[CEReactions]
|
||||||
attribute DOMString referrerPolicy;
|
attribute DOMString referrerPolicy;
|
||||||
|
|
||||||
|
Promise<undefined> decode();
|
||||||
|
|
||||||
// also has obsolete members
|
// also has obsolete members
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue