Bug 1388588: Only zoom absolute lengths. r?Manishearth draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 09 Aug 2017 16:23:49 +0200
changeset 643292 5f071f99466fa39630965acb9d4a5fa5abb31d1f
parent 643291 9ad40b50531d4e4a3d35aaa92dad6cc0f4e74ebf
child 725261 fe1682882cdee7aa934652d91dd7d5ed2c648995
push id73050
push userbmo:emilio+bugs@crisal.io
push dateWed, 09 Aug 2017 14:53:42 +0000
reviewersManishearth
bugs1388588
milestone57.0a1
Bug 1388588: Only zoom absolute lengths. r?Manishearth As silly as it may seem to specify font-sizes using viewport units, we weren't handling zoom for them correctly either. MozReview-Commit-ID: 3Q6phYAu5CE
servo/components/style/properties/longhand/font.mako.rs
servo/components/style/values/computed/mod.rs
servo/components/style/values/specified/text.rs
--- a/servo/components/style/properties/longhand/font.mako.rs
+++ b/servo/components/style/properties/longhand/font.mako.rs
@@ -839,30 +839,37 @@ macro_rules! impl_gecko_keyword_conversi
                 }
                 SpecifiedValue::Larger => Some(LARGER_FONT_SIZE_RATIO),
                 SpecifiedValue::Smaller => Some(1. / LARGER_FONT_SIZE_RATIO),
                 _ => None,
             }
         }
 
         /// 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(
                         NoCalcLength::FontRelative(value))) => {
                     value.to_computed_value(context, base_size).into()
                 }
                 SpecifiedValue::Length(LengthOrPercentage::Length(
                         NoCalcLength::ServoCharacterWidth(value))) => {
                     value.to_computed_value(base_size.resolve(context)).into()
                 }
+                SpecifiedValue::Length(LengthOrPercentage::Length(
+                        NoCalcLength::Absolute(ref l))) => {
+                    context.maybe_zoom_text(l.to_computed_value(context).into())
+                }
                 SpecifiedValue::Length(LengthOrPercentage::Length(ref l)) => {
-                    context.maybe_zoom_text(l.to_computed_value(context).into())
+                    l.to_computed_value(context).into()
                 }
                 SpecifiedValue::Length(LengthOrPercentage::Percentage(pc)) => {
                     base_size.resolve(context).scale_by(pc.0).into()
                 }
                 SpecifiedValue::Length(LengthOrPercentage::Calc(ref calc)) => {
                     let calc = calc.to_computed_value_zoomed(context);
                     calc.to_used_value(Some(base_size.resolve(context))).unwrap().into()
                 }
--- a/servo/components/style/values/computed/mod.rs
+++ b/servo/components/style/values/computed/mod.rs
@@ -130,18 +130,17 @@ impl<'a> Context<'a> {
         self.builder.default_style()
     }
 
     /// The current style.
     pub fn style(&self) -> &StyleBuilder {
         &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 <svg:text> by unsetting the
         // -x-text-zoom property, which leads to a false value
         // in mAllowZoom
         if self.style().get_font().gecko.mAllowZoom {
             self.device().zoom_text(size.0).into()
         } else {
--- a/servo/components/style/values/specified/text.rs
+++ b/servo/components/style/values/specified/text.rs
@@ -79,46 +79,57 @@ impl Parse for LineHeight {
     }
 }
 
 impl ToComputedValue for LineHeight {
     type ComputedValue = ComputedLineHeight;
 
     #[inline]
     fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
+        use values::specified::length::FontBaseSize;
         match *self {
             GenericLineHeight::Normal => {
                 GenericLineHeight::Normal
             },
             #[cfg(feature = "gecko")]
             GenericLineHeight::MozBlockHeight => {
                 GenericLineHeight::MozBlockHeight
             },
             GenericLineHeight::Number(number) => {
                 GenericLineHeight::Number(number.to_computed_value(context))
             },
             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)
             }
         }
     }
 
     #[inline]