From f973a9720d615cc2b47db6f29b0c7e3ebc73e442 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 21 Mar 2017 20:38:12 -0700 Subject: [PATCH] stylo: System font support for font-size-adjust --- components/style/properties/data.py | 2 +- components/style/properties/gecko.mako.rs | 5 +- .../style/properties/longhand/font.mako.rs | 52 ++++++++++++++++++- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/components/style/properties/data.py b/components/style/properties/data.py index f53b73c9a8d..97519122a62 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -15,7 +15,7 @@ ALL_SIZES = [(size, False) for size in PHYSICAL_SIZES] + [(size, True) for size SYSTEM_FONT_LONGHANDS = """font_family font_size font_style font_variant_caps font_stretch font_kerning - font_variant_position font_weight""".split() + font_variant_position font_weight font_size_adjust""".split() def maybe_moz_logical_alias(product, side, prop): if product == "gecko" and side[1]: diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 16e7a1d0cf4..d124a45eaaf 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1405,10 +1405,7 @@ fn static_assert() { pub fn clone_font_size_adjust(&self) -> longhands::font_size_adjust::computed_value::T { use properties::longhands::font_size_adjust::computed_value::T; - match self.gecko.mFont.sizeAdjust { - -1.0 => T::None, - _ => T::Number(self.gecko.mFont.sizeAdjust), - } + T::from_gecko_adjust(self.gecko.mFont.sizeAdjust) } #[allow(non_snake_case)] diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 321aa51fae7..4bf21656772 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -821,6 +821,7 @@ ${helpers.single_keyword_system("font-variant-caps", <%helpers:longhand products="gecko" name="font-size-adjust" animation_type="normal" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size-adjust"> + use properties::longhands::system_font::SystemFont; use std::fmt; use style_traits::ToCss; use values::HasViewportPercentage; @@ -832,6 +833,7 @@ ${helpers.single_keyword_system("font-variant-caps", pub enum SpecifiedValue { None, Number(specified::Number), + System(SystemFont), } impl ToCss for SpecifiedValue { @@ -841,6 +843,7 @@ ${helpers.single_keyword_system("font-variant-caps", match *self { SpecifiedValue::None => dest.write_str("none"), SpecifiedValue::Number(number) => number.to_css(dest), + SpecifiedValue::System(_) => Ok(()), } } } @@ -852,6 +855,11 @@ ${helpers.single_keyword_system("font-variant-caps", match *self { SpecifiedValue::None => computed_value::T::None, SpecifiedValue::Number(ref n) => computed_value::T::Number(n.to_computed_value(context)), + SpecifiedValue::System(_) => { + <%self:nongecko_unreachable> + context.style.cached_system_font.as_ref().unwrap().font_size_adjust + + } } } @@ -863,6 +871,19 @@ ${helpers.single_keyword_system("font-variant-caps", } } + impl SpecifiedValue { + pub fn system_font(f: SystemFont) -> Self { + SpecifiedValue::System(f) + } + pub fn get_system(&self) -> Option { + if let SpecifiedValue::System(s) = *self { + Some(s) + } else { + None + } + } + } + pub mod computed_value { use properties::animated_properties::Interpolate; use std::fmt; @@ -887,6 +908,15 @@ ${helpers.single_keyword_system("font-variant-caps", } } + impl T { + pub fn from_gecko_adjust(gecko: f32) -> Self { + match gecko { + -1.0 => T::None, + _ => T::Number(gecko), + } + } + } + impl Interpolate for T { fn interpolate(&self, other: &Self, time: f64) -> Result { match (*self, *other) { @@ -1921,6 +1951,7 @@ ${helpers.single_keyword("-moz-math-variant", use app_units::Au; use cssparser::Parser; use properties::longhands; + use std::hash::{Hash, Hasher}; use values::computed::{ToComputedValue, Context}; <% system_fonts = """caption icon menu message-box small-caption status-bar @@ -1937,6 +1968,24 @@ ${helpers.single_keyword("-moz-math-variant", % endfor } + // ComputedValues are compared at times + // so we need these impls. We don't want to + // add Eq to Number (which contains a float) + // so instead we have an eq impl which skips the + // cached values + impl PartialEq for ComputedSystemFont { + fn eq(&self, other: &Self) -> bool { + self.system_font == other.system_font + } + } + impl Eq for ComputedSystemFont {} + + impl Hash for ComputedSystemFont { + fn hash(&self, hasher: &mut H) { + self.system_font.hash(hasher) + } + } + impl ToComputedValue for SystemFont { type ComputedValue = ComputedSystemFont; @@ -1973,6 +2022,7 @@ ${helpers.single_keyword("-moz-math-variant", font_family: longhands::font_family::computed_value::T(family), font_size: Au(system.size), font_weight: weight, + font_size_adjust: longhands::font_size_adjust::computed_value::T::from_gecko_adjust(system.sizeAdjust), % for kwprop in kw_font_props: ${kwprop}: longhands::${kwprop}::computed_value::T::from_gecko_keyword( system.${to_camel_case_lower(kwprop.replace('font_', ''))} as u32 @@ -2002,7 +2052,7 @@ ${helpers.single_keyword("-moz-math-variant", debug_assert!(system == context.style.cached_system_font.as_ref().unwrap().system_font) } - #[derive(Clone, Debug, PartialEq, Eq, Hash)] + #[derive(Clone, Debug)] pub struct ComputedSystemFont { % for name in SYSTEM_FONT_LONGHANDS: pub ${name}: longhands::${name}::computed_value::T,