diff --git a/style/values/computed/length_percentage.rs b/style/values/computed/length_percentage.rs index 4b7a4b102..ea34c23f8 100644 --- a/style/values/computed/length_percentage.rs +++ b/style/values/computed/length_percentage.rs @@ -514,7 +514,7 @@ impl LengthPercentage { /// Returns the used value. #[inline] pub fn to_used_value(&self, containing_length: Au) -> Au { - Au::from_f32_px_truncate(self.to_pixel_length(containing_length).px()) + au_from_f32_px_trunc(self.to_pixel_length(containing_length).px()) } /// Returns the used value as CSSPixelLength. @@ -527,7 +527,7 @@ impl LengthPercentage { #[inline] pub fn maybe_to_used_value(&self, container_len: Option) -> Option { self.maybe_percentage_relative_to(container_len.map(Length::from)) - .map(|p| Au::from_f32_px_truncate(p.px())) + .map(|length| au_from_f32_px_trunc(length.px())) } /// If there are special rules for computing percentages in a value (e.g. @@ -554,6 +554,11 @@ impl LengthPercentage { } } +fn au_from_f32_px_trunc(px: f32) -> Au { + let float = (px * app_units::AU_PER_PX as f32).trunc(); + Au::from_f64_au(float as f64) +} + impl PartialEq for LengthPercentage { fn eq(&self, other: &Self) -> bool { self.unpack() == other.unpack()