diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 0e4dca33a1f..b5bcaa8242a 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -1596,10 +1596,9 @@ impl<'le> TElement for GeckoElement<'le> { V: Push, { use crate::properties::longhands::_x_lang::SpecifiedValue as SpecifiedLang; - use crate::properties::longhands::_x_text_zoom::SpecifiedValue as SpecifiedZoom; use crate::properties::longhands::color::SpecifiedValue as SpecifiedColor; use crate::stylesheets::layer_rule::LayerOrder; - use crate::values::specified::color::Color; + use crate::values::specified::{color::Color, font::XTextScale}; lazy_static! { static ref TABLE_COLOR_RULE: ApplicableDeclarationBlock = { let global_style_data = &*GLOBAL_STYLE_DATA; @@ -1627,10 +1626,10 @@ impl<'le> TElement for GeckoElement<'le> { LayerOrder::root(), ) }; - static ref SVG_TEXT_DISABLE_ZOOM_RULE: ApplicableDeclarationBlock = { + static ref SVG_TEXT_DISABLE_SCALE_RULE: ApplicableDeclarationBlock = { let global_style_data = &*GLOBAL_STYLE_DATA; let pdb = PropertyDeclarationBlock::with_one( - PropertyDeclaration::XTextZoom(SpecifiedZoom(false)), + PropertyDeclaration::XTextScale(XTextScale::None), Importance::Normal, ); let arc = Arc::new_leaked(global_style_data.shared_lock.wrap(pdb)); @@ -1653,7 +1652,7 @@ impl<'le> TElement for GeckoElement<'le> { } if ns == structs::kNameSpaceID_SVG as i32 { if self.local_name().as_ptr() == atom!("text").as_ptr() { - hints.push(SVG_TEXT_DISABLE_ZOOM_RULE.clone()); + hints.push(SVG_TEXT_DISABLE_SCALE_RULE.clone()); } } let declarations = diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index 441aadfafe4..dab60dcba2f 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -1028,28 +1028,31 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { builder.mutate_font().gecko_mut().mFont.size = min_font_size; } - /// is not affected by text zoom, and it uses a preshint - /// to disable it. We fix up the struct when this happens by - /// unzooming its contained font values, which will have been zoomed - /// in the parent. + /// is not affected by text zoom, and it uses a preshint to disable it. We fix up + /// the struct when this happens by unzooming its contained font values, which will have been + /// zoomed in the parent. /// - /// FIXME(emilio): Also, why doing this _before_ handling font-size? That - /// sounds wrong. + /// FIXME(emilio): Why doing this _before_ handling font-size? That sounds wrong. #[cfg(feature = "gecko")] fn unzoom_fonts_if_needed(&mut self) { - if !self.seen.contains(LonghandId::XTextZoom) { + if !self.seen.contains(LonghandId::XTextScale) { return; } let builder = &mut self.context.builder; - let parent_zoom = builder.get_parent_font().gecko().mAllowZoomAndMinSize; - let zoom = builder.get_font().gecko().mAllowZoomAndMinSize; - if zoom == parent_zoom { + let parent_text_scale = builder.get_parent_font().clone__x_text_scale(); + let text_scale = builder.get_font().clone__x_text_scale(); + if parent_text_scale == text_scale { return; } + debug_assert_ne!( + parent_text_scale.text_zoom_enabled(), + text_scale.text_zoom_enabled(), + "There's only one value that disables it" + ); debug_assert!( - !zoom, + !text_scale.text_zoom_enabled(), "We only ever disable text zoom (in svg:text), never enable it" ); let device = builder.device; @@ -1140,7 +1143,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { } let mut min = parent_font.mScriptMinSize; - if font.mAllowZoomAndMinSize { + if font.mXTextScale.text_zoom_enabled() { min = builder.device.zoom_text(min); } diff --git a/components/style/properties/data.py b/components/style/properties/data.py index 109689fb5de..195b773ca8d 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -503,7 +503,7 @@ class Longhand(Property): "UserSelect", "WordBreak", "XSpan", - "XTextZoom", + "XTextScale", "ZIndex", } if self.name == "overflow-y": diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index ebd58d3bc91..6391b357200 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -841,8 +841,7 @@ fn static_assert() { font-variant-alternates font-variant-east-asian font-variant-ligatures font-variant-numeric font-language-override font-feature-settings - font-variation-settings -moz-min-font-size-ratio - -x-text-zoom""" %> + font-variation-settings -moz-min-font-size-ratio""" %> <%self:impl_trait style_struct_name="Font" skip_longhands="${skip_font_longhands}"> @@ -943,27 +942,8 @@ fn static_assert() { }) } - #[allow(non_snake_case)] - pub fn set__x_text_zoom(&mut self, v: longhands::_x_text_zoom::computed_value::T) { - self.gecko.mAllowZoomAndMinSize = v.0; - } - #[allow(non_snake_case)] - pub fn copy__x_text_zoom_from(&mut self, other: &Self) { - self.gecko.mAllowZoomAndMinSize = other.gecko.mAllowZoomAndMinSize; - } - - #[allow(non_snake_case)] - pub fn reset__x_text_zoom(&mut self, other: &Self) { - self.copy__x_text_zoom_from(other) - } - - #[allow(non_snake_case)] - pub fn clone__x_text_zoom(&self) -> longhands::_x_text_zoom::computed_value::T { - longhands::_x_text_zoom::computed_value::T(self.gecko.mAllowZoomAndMinSize) - } - - <% impl_simple_type_with_conversion("font_language_override", "mFont.languageOverride") %> + ${impl_simple_type_with_conversion("font_language_override", "mFont.languageOverride")} ${impl_simple_type_with_conversion("font_variant_ligatures", "mFont.variantLigatures")} ${impl_simple_type_with_conversion("font_variant_east_asian", "mFont.variantEastAsian")} ${impl_simple_type_with_conversion("font_variant_numeric", "mFont.variantNumeric")} diff --git a/components/style/properties/longhands/font.mako.rs b/components/style/properties/longhands/font.mako.rs index c3833a25420..e116f305e28 100644 --- a/components/style/properties/longhands/font.mako.rs +++ b/components/style/properties/longhands/font.mako.rs @@ -331,9 +331,9 @@ ${helpers.predefined_type( )} ${helpers.predefined_type( - "-x-text-zoom", - "XTextZoom", - "computed::XTextZoom(true)", + "-x-text-scale", + "XTextScale", + "computed::XTextScale::All", engines="gecko", animation_value_type="none", enabled_in="", diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 17e74cf0cc2..c42e9de6e31 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -915,9 +915,7 @@ CASCADE_GROUPS = { # Cascade::fixup_font_stuff. "fonts_and_color": [ # Needed to properly compute the zoomed font-size. - # FIXME(emilio): This could probably just be a cascade flag - # like IN_SVG_SUBTREE or such, and we could nuke this property. - "-x-text-zoom", + "-x-text-scale", # Needed to do font-size computation in a language-dependent way. "-x-lang", # Needed for ruby to respect language-dependent min-font-size diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index 900a0a0dc5d..4f51f8a99ff 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -30,7 +30,7 @@ pub use crate::values::specified::font::{FontPalette, FontSynthesis}; pub use crate::values::specified::font::MozScriptSizeMultiplier; pub use crate::values::specified::font::{ FontVariantAlternates, FontVariantEastAsian, FontVariantLigatures, FontVariantNumeric, XLang, - XTextZoom, + XTextScale, }; pub use crate::values::specified::Integer as SpecifiedInteger; pub use crate::values::specified::Number as SpecifiedNumber; diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index ff1e0696bc9..54b33253955 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -71,7 +71,7 @@ pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumer pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis}; pub use self::font::{FontVariantAlternates, FontWeight}; pub use self::font::{FontVariantEastAsian, FontVariationSettings}; -pub use self::font::{MathDepth, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom}; +pub use self::font::{MathDepth, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextScale}; pub use self::image::{Gradient, Image, ImageRendering, LineDirection, MozImageRect}; pub use self::length::{CSSPixelLength, NonNegativeLength}; pub use self::length::{Length, LengthOrNumber, LengthPercentage, NonNegativeLengthOrNumber}; @@ -390,10 +390,7 @@ impl<'a> Context<'a> { /// Apply text-zoom if enabled. #[cfg(feature = "gecko")] pub fn maybe_zoom_text(&self, size: CSSPixelLength) -> CSSPixelLength { - // We disable zoom for by unsetting the - // -x-text-zoom property, which leads to a false value - // in mAllowZoomAndMinSize - if self.style().get_font().gecko.mAllowZoomAndMinSize { + if self.style().get_font().clone__x_text_scale().text_zoom_enabled() { self.device().zoom_text(size) } else { size diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index a73e658a2fc..4e0a730e9c5 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -1936,6 +1936,7 @@ impl MetricsOverride { Copy, Debug, MallocSizeOf, + Parse, PartialEq, SpecifiedValueInfo, ToComputedValue, @@ -1943,19 +1944,22 @@ impl MetricsOverride { ToResolvedValue, ToShmem, )] -/// text-zoom. Enable if true, disable if false -pub struct XTextZoom(#[css(skip)] pub bool); +#[repr(u8)] +/// How to do font-size scaling. +pub enum XTextScale { + /// Both min-font-size and text zoom are enabled. + All, + /// Text-only zoom is enabled, but min-font-size is not honored. + ZoomOnly, + /// Neither of them is enabled. + None, +} -impl Parse for XTextZoom { - fn parse<'i, 't>( - _: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - debug_assert!( - false, - "Should be set directly by presentation attributes only." - ); - Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) +impl XTextScale { + /// Returns whether text zoom is enabled. + #[inline] + pub fn text_zoom_enabled(self) -> bool { + self != Self::None } } diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index b0c155a81ab..f9c7d159119 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -58,7 +58,7 @@ pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumer pub use self::font::{FontSize, FontSizeAdjust, FontSizeKeyword, FontStretch, FontSynthesis}; pub use self::font::{FontVariantAlternates, FontWeight}; pub use self::font::{FontVariantEastAsian, FontVariationSettings}; -pub use self::font::{MathDepth, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom}; +pub use self::font::{MathDepth, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextScale}; pub use self::image::{EndingShape as GradientEndingShape, Gradient}; pub use self::image::{Image, ImageRendering, MozImageRect}; pub use self::length::{AbsoluteLength, CalcLengthPercentage, CharacterWidth};