diff options
-rw-r--r-- | components/layout/display_list_builder.rs | 9 | ||||
-rw-r--r-- | components/layout/fragment.rs | 9 | ||||
-rw-r--r-- | components/style/gecko/conversions.rs | 2 | ||||
-rw-r--r-- | components/style/properties/helpers/animated_properties.mako.rs | 8 | ||||
-rw-r--r-- | components/style/properties/longhand/font.mako.rs | 3 | ||||
-rw-r--r-- | components/style/properties/longhand/inherited_text.mako.rs | 3 | ||||
-rw-r--r-- | components/style/values/computed/length.rs | 13 | ||||
-rw-r--r-- | components/style/values/specified/position.rs | 2 | ||||
-rw-r--r-- | components/style/viewport.rs | 3 |
9 files changed, 32 insertions, 20 deletions
diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 36336b94b44..63ec70b7096 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -2803,12 +2803,13 @@ struct StopRun { stop_count: usize, } -fn position_to_offset(position: LengthOrPercentage, Au(total_length): Au) -> f32 { +fn position_to_offset(position: LengthOrPercentage, total_length: Au) -> f32 { match position { - LengthOrPercentage::Length(Au(length)) => length as f32 / total_length as f32, + LengthOrPercentage::Length(Au(length)) => length as f32 / total_length.0 as f32, LengthOrPercentage::Percentage(percentage) => percentage as f32, - LengthOrPercentage::Calc(calc) => - calc.percentage() + (calc.length().0 as f32) / (total_length as f32), + LengthOrPercentage::Calc(calc) => { + calc.to_used_value(Some(total_length)).unwrap().0 as f32 / total_length.0 as f32 + }, } } diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 11b82bceb61..c0991ea2535 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -1504,7 +1504,11 @@ impl Fragment { result_inline } LengthOrPercentageOrAuto::Length(length) => length, - LengthOrPercentageOrAuto::Calc(calc) => calc.length(), + LengthOrPercentageOrAuto::Calc(calc) => { + // TODO(nox): This is probably wrong, because it accounts neither for + // clamping (not sure if necessary here) nor percentage. + calc.unclamped_length() + }, }; let size_constraint = self.size_constraint(None, Direction::Inline); @@ -2233,8 +2237,7 @@ impl Fragment { offset -= minimum_line_metrics.space_needed().scale_by(percentage) } vertical_align::T::LengthOrPercentage(LengthOrPercentage::Calc(formula)) => { - offset -= minimum_line_metrics.space_needed().scale_by(formula.percentage()) + - formula.length() + offset -= formula.to_used_value(Some(minimum_line_metrics.space_needed())).unwrap() } } } diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index 4271f5885aa..1899a9799e1 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -24,7 +24,7 @@ impl From<CalcLengthOrPercentage> for nsStyleCoord_CalcValue { fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue { let has_percentage = other.percentage.is_some(); nsStyleCoord_CalcValue { - mLength: other.length().0, + mLength: other.unclamped_length().0, mPercent: other.percentage.unwrap_or(0.0), mHasPercent: has_percentage, } diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 85f8ec9281f..071454dd2ba 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -1035,7 +1035,7 @@ impl Animatable for CalcLengthOrPercentage { } } - let length = self.length().add_weighted(&other.length(), self_portion, other_portion)?; + let length = self.unclamped_length().add_weighted(&other.unclamped_length(), self_portion, other_portion)?; let percentage = add_weighted_half(self.percentage, other.percentage, self_portion, other_portion)?; Ok(CalcLengthOrPercentage::with_clamping_mode(length, percentage, self.clamping_mode)) } @@ -1047,7 +1047,7 @@ impl Animatable for CalcLengthOrPercentage { #[inline] fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> { - let length_diff = (self.length().0 - other.length().0) as f64; + let length_diff = (self.unclamped_length().0 - other.unclamped_length().0) as f64; let percentage_diff = (self.percentage() - other.percentage()) as f64; Ok(length_diff * length_diff + percentage_diff * percentage_diff) } @@ -1112,7 +1112,7 @@ impl Animatable for LengthOrPercentage { (this, other) => { let this: CalcLengthOrPercentage = From::from(this); let other: CalcLengthOrPercentage = From::from(other); - let length_diff = (this.length().0 - other.length().0) as f64; + let length_diff = (this.unclamped_length().0 - other.unclamped_length().0) as f64; let percentage_diff = (this.percentage() - other.percentage()) as f64; Ok(length_diff * length_diff + percentage_diff * percentage_diff) } @@ -1186,7 +1186,7 @@ impl Animatable for LengthOrPercentageOrAuto { let this: Option<CalcLengthOrPercentage> = From::from(this); let other: Option<CalcLengthOrPercentage> = From::from(other); if let (Some(this), Some(other)) = (this, other) { - let length_diff = (this.length().0 - other.length().0) as f64; + let length_diff = (this.unclamped_length().0 - other.unclamped_length().0) as f64; let percentage_diff = (this.percentage() - other.percentage()) as f64; Ok(length_diff * length_diff + percentage_diff * percentage_diff) } else { diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index aed5221e4b6..9d2ec4215d4 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -800,8 +800,7 @@ ${helpers.single_keyword_system("font-variant-caps", } SpecifiedValue::Length(LengthOrPercentage::Calc(ref calc)) => { let calc = calc.to_computed_value(context); - calc.length() + base_size.resolve(context) - .scale_by(calc.percentage()) + calc.to_used_value(Some(base_size.resolve(context))).unwrap() } SpecifiedValue::Keyword(ref key, fraction) => { key.to_computed_value(context).scale_by(fraction) diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index b2d57a72393..a1f6dfc0418 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -132,7 +132,8 @@ let calc = calc.to_computed_value(context); let fr = specified::FontRelativeLength::Em(calc.percentage()); let fr = specified::Length::NoCalc(specified::NoCalcLength::FontRelative(fr)); - computed_value::T::Length(calc.length() + fr.to_computed_value(context)) + let length = calc.unclamped_length(); + computed_value::T::Length(calc.clamping_mode.clamp(length + fr.to_computed_value(context))) } } } diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index f361f1c4cb8..89702468570 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -88,12 +88,21 @@ impl CalcLengthOrPercentage { } } + /// Returns this `calc()` as a `<length>`. + /// + /// Panics in debug mode if a percentage is present in the expression. #[inline] - #[allow(missing_docs)] pub fn length(&self) -> Au { + debug_assert!(self.percentage.is_none()); self.clamping_mode.clamp(self.length) } + /// Returns the `<length>` component of this `calc()`, unclamped. + #[inline] + pub fn unclamped_length(&self) -> Au { + self.length + } + #[inline] #[allow(missing_docs)] pub fn percentage(&self) -> CSSFloat { @@ -245,7 +254,7 @@ impl LengthOrPercentage { match *self { Length(l) => (l, NotNaN::new(0.0).unwrap()), Percentage(p) => (Au(0), NotNaN::new(p).unwrap()), - Calc(c) => (c.length(), NotNaN::new(c.percentage()).unwrap()), + Calc(c) => (c.unclamped_length(), NotNaN::new(c.percentage()).unwrap()), } } diff --git a/components/style/values/specified/position.rs b/components/style/values/specified/position.rs index abeef00fe21..c2991ede864 100644 --- a/components/style/values/specified/position.rs +++ b/components/style/values/specified/position.rs @@ -241,7 +241,7 @@ impl<S: Side> ToComputedValue for PositionComponent<S> { }, ComputedLengthOrPercentage::Calc(calc) => { let p = 1. - calc.percentage.unwrap_or(0.); - ComputedLengthOrPercentage::Calc(CalcLengthOrPercentage::new(-calc.length(), Some(p))) + ComputedLengthOrPercentage::Calc(CalcLengthOrPercentage::new(-calc.unclamped_length(), Some(p))) }, } }, diff --git a/components/style/viewport.rs b/components/style/viewport.rs index c887614ad57..0953d9a4b7a 100644 --- a/components/style/viewport.rs +++ b/components/style/viewport.rs @@ -718,8 +718,7 @@ impl MaybeNew for ViewportConstraints { Some(initial_viewport.$dimension.scale_by(value.0)), LengthOrPercentageOrAuto::Auto => None, LengthOrPercentageOrAuto::Calc(ref calc) => { - let calc = calc.to_computed_value(&context); - Some(initial_viewport.$dimension.scale_by(calc.percentage()) + calc.length()) + calc.to_computed_value(&context).to_used_value(Some(initial_viewport.$dimension)) } }, ViewportLength::ExtendToZoom => { |