diff --git a/servo/components/style/properties/longhand/font.mako.rs b/servo/components/style/properties/longhand/font.mako.rs index 5d849c746cfb..c95ea97c2f7b 100644 --- a/servo/components/style/properties/longhand/font.mako.rs +++ b/servo/components/style/properties/longhand/font.mako.rs @@ -859,7 +859,7 @@ ${helpers.single_keyword_system("font-variant-caps", base_size.resolve(context).scale_by(pc.0).into() } SpecifiedValue::Length(LengthOrPercentage::Calc(ref calc)) => { - let calc = calc.to_computed_value_zoomed(context); + let calc = calc.to_computed_value_zoomed(context, base_size); calc.to_used_value(Some(base_size.resolve(context))).unwrap().into() } SpecifiedValue::Keyword(ref key, fraction) => { diff --git a/servo/components/style/values/computed/length.rs b/servo/components/style/values/computed/length.rs index d29f5aa87fc8..8c90d38eefa0 100644 --- a/servo/components/style/values/computed/length.rs +++ b/servo/components/style/values/computed/length.rs @@ -217,7 +217,8 @@ impl ToCss for CalcLengthOrPercentage { impl specified::CalcLengthOrPercentage { /// Compute the value, zooming any absolute units by the zoom function. - fn to_computed_value_with_zoom(&self, context: &Context, zoom_fn: F) -> CalcLengthOrPercentage + fn to_computed_value_with_zoom(&self, context: &Context, zoom_fn: F, + base_size: FontBaseSize) -> CalcLengthOrPercentage where F: Fn(Au) -> Au { let mut length = Au(0); @@ -239,7 +240,7 @@ impl specified::CalcLengthOrPercentage { self.ex.map(FontRelativeLength::Ex), self.rem.map(FontRelativeLength::Rem)] { if let Some(val) = *val { - length += val.to_computed_value(context, FontBaseSize::CurrentStyle); + length += val.to_computed_value(context, base_size); } } @@ -251,8 +252,8 @@ impl specified::CalcLengthOrPercentage { } /// Compute font-size or line-height taking into account text-zoom if necessary. - pub fn to_computed_value_zoomed(&self, context: &Context) -> CalcLengthOrPercentage { - self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs.into()).0) + pub fn to_computed_value_zoomed(&self, context: &Context, base_size: FontBaseSize) -> CalcLengthOrPercentage { + self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs.into()).0, base_size) } } @@ -260,7 +261,8 @@ impl ToComputedValue for specified::CalcLengthOrPercentage { type ComputedValue = CalcLengthOrPercentage; fn to_computed_value(&self, context: &Context) -> CalcLengthOrPercentage { - self.to_computed_value_with_zoom(context, |abs| abs) + // normal properties don't zoom, and compute em units against the current style's font-size + self.to_computed_value_with_zoom(context, |abs| abs, FontBaseSize::CurrentStyle) } #[inline] diff --git a/servo/components/style/values/specified/length.rs b/servo/components/style/values/specified/length.rs index 490161a4df1c..c816e5420206 100644 --- a/servo/components/style/values/specified/length.rs +++ b/servo/components/style/values/specified/length.rs @@ -80,6 +80,7 @@ impl ToCss for FontRelativeLength { } /// A source to resolve font-relative units against +#[derive(Clone, Copy, Debug, PartialEq)] pub enum FontBaseSize { /// Use the font-size of the current element CurrentStyle, diff --git a/servo/components/style/values/specified/text.rs b/servo/components/style/values/specified/text.rs index 08a59e87ff6e..0f4163c3fdd4 100644 --- a/servo/components/style/values/specified/text.rs +++ b/servo/components/style/values/specified/text.rs @@ -112,7 +112,7 @@ impl ToComputedValue for LineHeight { ).into() } LengthOrPercentage::Calc(ref calc) => { - let computed_calc = calc.to_computed_value_zoomed(context); + let computed_calc = calc.to_computed_value_zoomed(context, FontBaseSize::CurrentStyle); let font_relative_length = FontRelativeLength::Em(computed_calc.percentage()) .to_computed_value(