mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add image usability checks to drawImage()
This commit is contained in:
parent
5f55cd5d71
commit
ed0973fb1c
9 changed files with 29 additions and 34 deletions
|
@ -13,7 +13,7 @@ use crate::dom::bindings::codegen::Bindings::HTMLImageElementBinding::HTMLImageE
|
|||
use crate::dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeBinding::NodeMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use crate::dom::bindings::error::Fallible;
|
||||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::refcounted::Trusted;
|
||||
use crate::dom::bindings::reflector::DomObject;
|
||||
|
@ -164,6 +164,26 @@ impl HTMLImageElement {
|
|||
pub fn get_url(&self) -> Option<ServoUrl> {
|
||||
self.current_request.borrow().parsed_url.clone()
|
||||
}
|
||||
// https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument
|
||||
pub fn is_usable(&self) -> Fallible<bool> {
|
||||
// If image has an intrinsic width or intrinsic height (or both) equal to zero, then return bad.
|
||||
match &self.current_request.borrow().image {
|
||||
Some(image) => {
|
||||
if image.width == 0 || image.height == 0 {
|
||||
return Ok(false);
|
||||
}
|
||||
},
|
||||
None => return Ok(false),
|
||||
}
|
||||
|
||||
match self.current_request.borrow().state {
|
||||
// If image's current request's state is broken, then throw an "InvalidStateError" DOMException.
|
||||
State::Broken => Err(Error::InvalidState),
|
||||
State::CompletelyAvailable => Ok(true),
|
||||
// If image is not fully decodable, then return bad.
|
||||
State::PartiallyAvailable | State::Unavailable => Ok(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The context required for asynchronously loading an external image.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue