mirror of
https://github.com/servo/servo.git
synced 2025-07-19 13:23:46 +01:00
Auto merge of #18448 - Manishearth:viewport-round, r=emilio
stylo: Round down when computing viewport units r=emilio https://bugzilla.mozilla.org/show_bug.cgi?id=1396045 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18448) <!-- Reviewable:end -->
This commit is contained in:
commit
a3a3f4bf4f
1 changed files with 10 additions and 12 deletions
|
@ -198,23 +198,21 @@ impl ToCss for ViewportPercentageLength {
|
|||
impl ViewportPercentageLength {
|
||||
/// Computes the given viewport-relative length for the given viewport size.
|
||||
pub fn to_computed_value(&self, viewport_size: Size2D<Au>) -> Au {
|
||||
macro_rules! to_unit {
|
||||
($viewport_dimension:expr) => {
|
||||
$viewport_dimension.to_f32_px() / 100.0
|
||||
}
|
||||
}
|
||||
|
||||
let value = match *self {
|
||||
let (factor, length) = match *self {
|
||||
ViewportPercentageLength::Vw(length) =>
|
||||
length * to_unit!(viewport_size.width),
|
||||
(length, viewport_size.width),
|
||||
ViewportPercentageLength::Vh(length) =>
|
||||
length * to_unit!(viewport_size.height),
|
||||
(length, viewport_size.height),
|
||||
ViewportPercentageLength::Vmin(length) =>
|
||||
length * to_unit!(cmp::min(viewport_size.width, viewport_size.height)),
|
||||
(length, cmp::min(viewport_size.width, viewport_size.height)),
|
||||
ViewportPercentageLength::Vmax(length) =>
|
||||
length * to_unit!(cmp::max(viewport_size.width, viewport_size.height)),
|
||||
(length, cmp::max(viewport_size.width, viewport_size.height)),
|
||||
};
|
||||
Au::from_f32_px(value)
|
||||
|
||||
// See bug 989802. We truncate so that adding multiple viewport units
|
||||
// that add up to 100 does not overflow due to rounding differences
|
||||
let trunc_scaled = ((length.0 as f64) * factor as f64 / 100.).trunc();
|
||||
Au::from_f64_au(trunc_scaled)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue