From 93b7d01324840a6723266a3b492b12b3bd576b4f Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Fri, 2 Mar 2018 17:48:10 +0000 Subject: [PATCH] style: Add font-optical-sizing property. Bug: 1435692 Reviewed-by: emilio --- components/style/properties/data.py | 2 +- .../style/properties/longhand/font.mako.rs | 35 +++++++++++----- .../style/properties/shorthand/font.mako.rs | 42 ++++++++++++++----- 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/components/style/properties/data.py b/components/style/properties/data.py index 5340e6afadf5..3b4c45029cb2 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -19,7 +19,7 @@ font_size_adjust font_variant_alternates font_variant_ligatures font_variant_east_asian font_variant_numeric font_language_override - font_feature_settings""".split() + font_feature_settings font_optical_sizing""".split() def maybe_moz_logical_alias(product, side, prop): diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 8da4af6a817e..1e24ca457413 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -15,15 +15,16 @@ ${helpers.predefined_type("font-family", spec="https://drafts.csswg.org/css-fonts/#propdef-font-family", servo_restyle_damage="rebuild_and_reflow")} -${helpers.single_keyword_system("font-style", - "normal italic oblique", - gecko_constant_prefix="NS_FONT_STYLE", - gecko_ffi_name="mFont.style", - spec="https://drafts.csswg.org/css-fonts/#propdef-font-style", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", - animation_value_type="discrete", - servo_restyle_damage="rebuild_and_reflow")} - +${helpers.single_keyword_system( + "font-style", + "normal italic oblique", + gecko_constant_prefix="NS_FONT_STYLE", + gecko_ffi_name="mFont.style", + spec="https://drafts.csswg.org/css-fonts/#propdef-font-style", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + animation_value_type="discrete", + servo_restyle_damage="rebuild_and_reflow" +)} <% font_variant_caps_custom_consts= { "small-caps": "SMALLCAPS", "all-small-caps": "ALLSMALL", @@ -180,6 +181,16 @@ ${helpers.predefined_type("font-language-override", flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-fonts-3/#propdef-font-language-override")} +${helpers.single_keyword_system("font-optical-sizing", + "auto none", + products="gecko", + gecko_pref="layout.css.font-variations.enabled", + gecko_ffi_name="mFont.opticalSizing", + gecko_constant_prefix="NS_FONT_OPTICAL_SIZING", + animation_value_type="discrete", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + spec="https://www.w3.org/TR/css-fonts-4/#font-optical-sizing-def")} + ${helpers.predefined_type("-x-lang", "XLang", products="gecko", @@ -278,9 +289,11 @@ ${helpers.predefined_type("-x-text-zoom", -moz-list -moz-field""".split() kw_font_props = """font_style font_variant_caps font_stretch font_kerning font_variant_position font_variant_ligatures - font_variant_east_asian font_variant_numeric""".split() + font_variant_east_asian font_variant_numeric + font_optical_sizing""".split() kw_cast = """font_style font_variant_caps font_stretch - font_kerning font_variant_position""".split() + font_kerning font_variant_position + font_optical_sizing""".split() %> #[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToCss)] pub enum SystemFont { diff --git a/components/style/properties/shorthand/font.mako.rs b/components/style/properties/shorthand/font.mako.rs index fc3f75f78e57..1a4c0d041182 100644 --- a/components/style/properties/shorthand/font.mako.rs +++ b/components/style/properties/shorthand/font.mako.rs @@ -10,6 +10,7 @@ font-size line-height font-family ${'font-size-adjust' if product == 'gecko' else ''} ${'font-kerning' if product == 'gecko' else ''} + ${'font-optical-sizing' if product == 'gecko' else ''} ${'font-variant-alternates' if product == 'gecko' else ''} ${'font-variant-east-asian' if product == 'gecko' else ''} ${'font-variant-ligatures' if product == 'gecko' else ''} @@ -30,7 +31,8 @@ gecko_sub_properties = "kerning language_override size_adjust \ variant_alternates variant_east_asian \ variant_ligatures variant_numeric \ - variant_position feature_settings".split() + variant_position feature_settings \ + optical_sizing".split() %> % if product == "gecko": % for prop in gecko_sub_properties: @@ -155,11 +157,19 @@ % endif % if product == "gecko": - % for name in gecko_sub_properties: - if self.font_${name} != &font_${name}::get_initial_specified_value() { - return Ok(()); - } - % endfor + if let Some(v) = self.font_optical_sizing { + if v != &font_optical_sizing::get_initial_specified_value() { + return Ok(()); + } + } + + % for name in gecko_sub_properties: + % if name != "optical_sizing": + if self.font_${name} != &font_${name}::get_initial_specified_value() { + return Ok(()); + } + % endif + % endfor % endif // In case of serialization for canvas font, we need to drop @@ -193,12 +203,22 @@ let mut all = true; % for prop in SYSTEM_FONT_LONGHANDS: - if let Some(s) = self.${prop}.get_system() { - debug_assert!(sys.is_none() || s == sys.unwrap()); - sys = Some(s); - } else { - all = false; + % if prop == "font_optical_sizing": + if let Some(value) = self.${prop} { + % else: + { + let value = self.${prop}; + % endif + match value.get_system() { + Some(s) => { + debug_assert!(sys.is_none() || s == sys.unwrap()); + sys = Some(s); + } + None => { + all = false; + } } + } % endfor if self.line_height != &LineHeight::normal() { all = false