From 7d813d8f25dd3804571e1016d81161af15f690ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 9 Aug 2017 16:23:49 +0200 Subject: [PATCH] style: Only zoom absolute lengths. As silly as it may seem to specify font-sizes using viewport units, we weren't handling zoom for them correctly either. Bug: 1388588 Reviewed-by: Manishearth MozReview-Commit-ID: 3Q6phYAu5CE --- .../style/properties/longhand/font.mako.rs | 13 +++++++-- components/style/values/computed/mod.rs | 3 +- components/style/values/specified/text.rs | 29 +++++++++++++------ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 8d8fcf017ec..96ba9199bf2 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -844,8 +844,11 @@ ${helpers.single_keyword_system("font-variant-caps", } /// Compute it against a given base font size - pub fn to_computed_value_against(&self, context: &Context, base_size: FontBaseSize) - -> NonNegativeAu { + pub fn to_computed_value_against( + &self, + context: &Context, + base_size: FontBaseSize, + ) -> NonNegativeAu { use values::specified::length::FontRelativeLength; match *self { SpecifiedValue::Length(LengthOrPercentage::Length( @@ -856,9 +859,13 @@ ${helpers.single_keyword_system("font-variant-caps", NoCalcLength::ServoCharacterWidth(value))) => { value.to_computed_value(base_size.resolve(context)).into() } - SpecifiedValue::Length(LengthOrPercentage::Length(ref l)) => { + SpecifiedValue::Length(LengthOrPercentage::Length( + NoCalcLength::Absolute(ref l))) => { context.maybe_zoom_text(l.to_computed_value(context).into()) } + SpecifiedValue::Length(LengthOrPercentage::Length(ref l)) => { + l.to_computed_value(context).into() + } SpecifiedValue::Length(LengthOrPercentage::Percentage(pc)) => { base_size.resolve(context).scale_by(pc.0).into() } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index a1206529f80..104c0fcd14a 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -135,8 +135,7 @@ impl<'a> Context<'a> { &self.builder } - - /// Apply text-zoom if enabled + /// Apply text-zoom if enabled. #[cfg(feature = "gecko")] pub fn maybe_zoom_text(&self, size: NonNegativeAu) -> NonNegativeAu { // We disable zoom for by unsetting the diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index 8341d6236f1..08a59e87ff6 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -84,6 +84,7 @@ impl ToComputedValue for LineHeight { #[inline] fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { + use values::specified::length::FontBaseSize; match *self { GenericLineHeight::Normal => { GenericLineHeight::Normal @@ -97,23 +98,33 @@ impl ToComputedValue for LineHeight { }, GenericLineHeight::Length(ref non_negative_lop) => { let result = match non_negative_lop.0 { + LengthOrPercentage::Length(NoCalcLength::Absolute(ref abs)) => { + context.maybe_zoom_text(abs.to_computed_value(context).into()) + } LengthOrPercentage::Length(ref length) => { - context.maybe_zoom_text(length.to_computed_value(context).into()) + length.to_computed_value(context).into() }, LengthOrPercentage::Percentage(ref p) => { - let font_relative_length = - Length::NoCalc(NoCalcLength::FontRelative(FontRelativeLength::Em(p.0))); - font_relative_length.to_computed_value(context).into() + FontRelativeLength::Em(p.0) + .to_computed_value( + context, + FontBaseSize::CurrentStyle, + ).into() } LengthOrPercentage::Calc(ref calc) => { let computed_calc = calc.to_computed_value_zoomed(context); let font_relative_length = - Length::NoCalc(NoCalcLength::FontRelative( - FontRelativeLength::Em(computed_calc.percentage()))); + FontRelativeLength::Em(computed_calc.percentage()) + .to_computed_value( + context, + FontBaseSize::CurrentStyle, + ); + let absolute_length = computed_calc.unclamped_length(); - computed_calc.clamping_mode.clamp( - absolute_length + font_relative_length.to_computed_value(context) - ).into() + computed_calc + .clamping_mode + .clamp(absolute_length + font_relative_length) + .into() } }; GenericLineHeight::Length(result)