aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/dom_traversal.rs
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2019-12-07 21:41:26 +0100
committerSimon Sapin <simon.sapin@exyr.org>2019-12-10 15:11:53 +0100
commit8996be3c5efa4ef93fd0af332a05bbcbb4905810 (patch)
treea181b75beb8617de2d5b760953b2a7addc532850 /components/layout_2020/dom_traversal.rs
parentb73eb49a580cdf3eaf0cc2153524e49165ed0fc5 (diff)
downloadservo-8996be3c5efa4ef93fd0af332a05bbcbb4905810.tar.gz
servo-8996be3c5efa4ef93fd0af332a05bbcbb4905810.zip
Don’t assume replaced elements have an intrinsic size
Diffstat (limited to 'components/layout_2020/dom_traversal.rs')
-rw-r--r--components/layout_2020/dom_traversal.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/components/layout_2020/dom_traversal.rs b/components/layout_2020/dom_traversal.rs
index 056103d7205..56ee72d67ca 100644
--- a/components/layout_2020/dom_traversal.rs
+++ b/components/layout_2020/dom_traversal.rs
@@ -17,7 +17,6 @@ use std::sync::Arc;
use style::dom::TNode;
use style::properties::ComputedValues;
use style::selector_parser::PseudoElement;
-use style::values::computed::Length;
#[derive(Clone, Copy)]
pub enum WhichPseudoElement {
@@ -299,7 +298,10 @@ impl Drop for BoxSlot<'_> {
pub(crate) trait NodeExt<'dom>: 'dom + Copy + LayoutNode + Send + Sync {
fn is_element(self) -> bool;
fn as_text(self) -> Option<String>;
- fn as_image(self) -> Option<(Option<Arc<NetImage>>, Vec2<Length>)>;
+
+ /// Returns the image if it’s loaded, and its size in image pixels
+ /// adjusted for `image_density`.
+ fn as_image(self) -> Option<(Option<Arc<NetImage>>, Vec2<f64>)>;
fn first_child(self) -> Option<Self>;
fn next_sibling(self) -> Option<Self>;
fn parent_node(self) -> Option<Self>;
@@ -328,7 +330,7 @@ where
}
}
- fn as_image(self) -> Option<(Option<Arc<NetImage>>, Vec2<Length>)> {
+ fn as_image(self) -> Option<(Option<Arc<NetImage>>, Vec2<f64>)> {
let node = self.to_threadsafe();
let (resource, metadata) = node.image_data()?;
let (width, height) = resource
@@ -336,14 +338,14 @@ where
.map(|image| (image.width, image.height))
.or_else(|| metadata.map(|metadata| (metadata.width, metadata.height)))
.unwrap_or((0, 0));
- let (mut width, mut height) = (width as f32, height as f32);
+ let (mut width, mut height) = (width as f64, height as f64);
if let Some(density) = node.image_density().filter(|density| *density != 1.) {
- width = (width as f64 / density) as f32;
- height = (height as f64 / density) as f32;
+ width = width / density;
+ height = height / density;
}
let size = Vec2 {
- x: Length::new(width),
- y: Length::new(height),
+ x: width,
+ y: height,
};
Some((resource, size))
}