mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
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:
parent
bdd7cb9753
commit
728ce16b9d
1 changed files with 8 additions and 4 deletions
|
@ -358,8 +358,10 @@ impl HTMLImageElementMethods for HTMLImageElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-img-width
|
// https://html.spec.whatwg.org/multipage/#dom-img-width
|
||||||
fn Width(&self) -> u32 {
|
fn Width(&self) -> u32 {
|
||||||
let node = self.upcast::<Node>();
|
let node = self.upcast::<Node>();
|
||||||
let rect = node.bounding_content_box_or_zero();
|
match node.bounding_content_box() {
|
||||||
rect.size.width.to_px() as u32
|
Some(rect) => rect.size.width.to_px() as u32,
|
||||||
|
None => self.NaturalWidth(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-img-width
|
// 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
|
// https://html.spec.whatwg.org/multipage/#dom-img-height
|
||||||
fn Height(&self) -> u32 {
|
fn Height(&self) -> u32 {
|
||||||
let node = self.upcast::<Node>();
|
let node = self.upcast::<Node>();
|
||||||
let rect = node.bounding_content_box_or_zero();
|
match node.bounding_content_box() {
|
||||||
rect.size.height.to_px() as u32
|
Some(rect) => rect.size.height.to_px() as u32,
|
||||||
|
None => self.NaturalHeight(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-img-height
|
// https://html.spec.whatwg.org/multipage/#dom-img-height
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue