diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index 27d8a5f6c62..63ccf68a541 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -186,6 +186,11 @@ impl Device { pub fn default_background_color(&self) -> RGBA { convert_nscolor_to_rgba(self.pres_context().mBackgroundColor) } + + /// Applies text zoom to a font-size or line-height value (see nsStyleFont::ZoomText). + pub fn zoom_text(&self, size: Au) -> Au { + size.scale_by(self.pres_context().mEffectiveTextZoom) + } } /// A expression for gecko contains a reference to the media feature, the value diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index be27f6bcdd4..edf160a0a94 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -2231,9 +2231,6 @@ fn static_assert() { ) } - // FIXME(bholley): Gecko has two different sizes, one of which (mSize) is the - // actual computed size, and the other of which (mFont.size) is the 'display - // size' which takes font zooming into account. We don't handle font zooming yet. pub fn set_font_size(&mut self, v: longhands::font_size::computed_value::T) { self.gecko.mSize = v.0; self.gecko.mScriptUnconstrainedSize = v.0; diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index f6b78a91749..f2f65e2dff0 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -830,17 +830,17 @@ ${helpers.single_keyword_system("font-variant-caps", value.to_computed_value(base_size.resolve(context)) } SpecifiedValue::Length(LengthOrPercentage::Length(ref l)) => { - l.to_computed_value(context) + context.maybe_zoom_text(l.to_computed_value(context)) } SpecifiedValue::Length(LengthOrPercentage::Percentage(pc)) => { base_size.resolve(context).scale_by(pc.0) } SpecifiedValue::Length(LengthOrPercentage::Calc(ref calc)) => { - let calc = calc.to_computed_value(context); + let calc = calc.to_computed_value_zoomed(context); calc.to_used_value(Some(base_size.resolve(context))).unwrap() } SpecifiedValue::Keyword(ref key, fraction) => { - key.to_computed_value(context).scale_by(fraction) + context.maybe_zoom_text(key.to_computed_value(context).scale_by(fraction)) } SpecifiedValue::Smaller => { FontRelativeLength::Em(1. / LARGER_FONT_SIZE_RATIO) @@ -960,7 +960,7 @@ ${helpers.single_keyword_system("font-variant-caps", context.builder.get_font().gecko().mGenericID != context.builder.get_parent_font().gecko().mGenericID { if let Some((kw, ratio)) = context.builder.font_size_keyword { - computed = kw.to_computed_value(context).scale_by(ratio); + computed = context.maybe_zoom_text(kw.to_computed_value(context).scale_by(ratio)); } } % endif @@ -990,7 +990,7 @@ ${helpers.single_keyword_system("font-variant-caps", // changes using the font_size_keyword. We also need to do this to // handle mathml scriptlevel changes let kw_inherited_size = context.builder.font_size_keyword.map(|(kw, ratio)| { - SpecifiedValue::Keyword(kw, ratio).to_computed_value(context) + context.maybe_zoom_text(SpecifiedValue::Keyword(kw, ratio).to_computed_value(context)) }); let parent_kw; let device = context.builder.device; @@ -1015,8 +1015,10 @@ ${helpers.single_keyword_system("font-variant-caps", pub fn cascade_initial_font_size(context: &mut Context) { // font-size's default ("medium") does not always // compute to the same value and depends on the font - let computed = longhands::font_size::get_initial_specified_value() - .to_computed_value(context); + let computed = context.maybe_zoom_text( + longhands::font_size::get_initial_specified_value() + .to_computed_value(context) + ); context.builder.mutate_font().set_font_size(computed); % if product == "gecko": let device = context.builder.device; diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 8682487f47d..29117a5cb8d 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -228,14 +228,14 @@ impl ToCss for CalcLengthOrPercentage { } } -impl ToComputedValue for specified::CalcLengthOrPercentage { - type ComputedValue = CalcLengthOrPercentage; - - fn to_computed_value(&self, context: &Context) -> 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 + where F: Fn(Au) -> Au { let mut length = Au(0); if let Some(absolute) = self.absolute { - length += absolute; + length += zoom_fn(absolute); } for val in &[self.vw.map(ViewportPercentageLength::Vw), @@ -263,6 +263,19 @@ impl ToComputedValue for 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)) + } +} + +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) + } + #[inline] fn from_computed_value(computed: &CalcLengthOrPercentage) -> Self { specified::CalcLengthOrPercentage { diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 75dea7bf87b..d2b49ef5e22 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -132,6 +132,26 @@ impl<'a> Context<'a> { pub fn style(&self) -> &StyleBuilder { &self.builder } + + + /// Apply text-zoom if enabled + #[cfg(feature = "gecko")] + pub fn maybe_zoom_text(&self, size: Au) -> Au { + // We disable zoom for 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) + } else { + size + } + } + + /// (Servo doesn't do text-zoom) + #[cfg(feature = "servo")] + pub fn maybe_zoom_text(&self, size: Au) -> Au { + size + } } /// An iterator over a slice of computed values