From 99f6d6f1b88d5f34c3092546626fa239e75d1c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 11 Jan 2019 01:07:22 +0100 Subject: [PATCH] style: Three-value position syntax uses calc() as its computed value representation. This restores the previous behavior of using calc(). Note that background-position / object-position, which test this, weren't hitting the assertion because they use another codepath. I didn't add more extensive tests for this because it's well tested for those two properties, and because this is legacy anyway, see the comment in the test. I did add the assertion to the codepath those two properties hit. Differential Revision: https://phabricator.services.mozilla.com/D16176 --- components/style/gecko/conversions.rs | 7 ++++++- components/style/values/specified/position.rs | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index 89cce99beb0..345e199a9a6 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -22,8 +22,8 @@ use crate::values::computed::transform::Matrix3D; use crate::values::computed::url::ComputedImageUrl; use crate::values::computed::{Angle, Gradient, Image}; use crate::values::computed::{Integer, LengthPercentage}; +use crate::values::computed::{Length, Percentage, TextAlign}; use crate::values::computed::{LengthPercentageOrAuto, NonNegativeLengthPercentageOrAuto}; -use crate::values::computed::{Percentage, TextAlign}; use crate::values::generics::box_::VerticalAlign; use crate::values::generics::grid::{TrackListValue, TrackSize}; use crate::values::generics::image::{CompatMode, GradientItem, Image as GenericImage}; @@ -35,6 +35,11 @@ use style_traits::values::specified::AllowedNumericType; impl From for nsStyleCoord_CalcValue { fn from(other: LengthPercentage) -> nsStyleCoord_CalcValue { + debug_assert!( + other.was_calc || + other.percentage.is_none() || + other.unclamped_length() == Length::zero() + ); let has_percentage = other.percentage.is_some(); nsStyleCoord_CalcValue { mLength: other.unclamped_length().to_i32_au(), diff --git a/components/style/values/specified/position.rs b/components/style/values/specified/position.rs index d13bc579f02..b9006ee799b 100644 --- a/components/style/values/specified/position.rs +++ b/components/style/values/specified/position.rs @@ -263,11 +263,12 @@ impl ToComputedValue for PositionComponent { let length = length.to_computed_value(context); let p = Percentage(1. - length.percentage()); let l = -length.unclamped_length(); + // We represent ` ` as `calc(100% - )`. ComputedLengthPercentage::with_clamping_mode( l, Some(p), length.clamping_mode, - length.was_calc, + /* was_calc = */ true, ) }, PositionComponent::Side(_, Some(ref length)) |