script: Properly implement the image width and height getter.

Per https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-width:

    The IDL attributes width and height must return the rendered width and
    height of the image, in CSS pixels, if the image is being rendered, and is
    being rendered to a visual medium; or else the density-corrected intrinsic
    width and height of the image, in CSS pixels, if the image has intrinsic
    dimensions and is available but not being rendered to a visual medium; or
    else 0, if the image is not available or does not have intrinsic dimensions.
This commit is contained in:
Emilio Cobos Álvarez 2017-01-17 00:29:57 +01:00
parent bdd7cb9753
commit 728ce16b9d
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -358,8 +358,10 @@ impl HTMLImageElementMethods for HTMLImageElement {
// https://html.spec.whatwg.org/multipage/#dom-img-width
fn Width(&self) -> u32 {
let node = self.upcast::<Node>();
let rect = node.bounding_content_box_or_zero();
rect.size.width.to_px() as u32
match node.bounding_content_box() {
Some(rect) => rect.size.width.to_px() as u32,
None => self.NaturalWidth(),
}
}
// https://html.spec.whatwg.org/multipage/#dom-img-width
@ -370,8 +372,10 @@ impl HTMLImageElementMethods for HTMLImageElement {
// https://html.spec.whatwg.org/multipage/#dom-img-height
fn Height(&self) -> u32 {
let node = self.upcast::<Node>();
let rect = node.bounding_content_box_or_zero();
rect.size.height.to_px() as u32
match node.bounding_content_box() {
Some(rect) => rect.size.height.to_px() as u32,
None => self.NaturalHeight(),
}
}
// https://html.spec.whatwg.org/multipage/#dom-img-height