From 14c632408ce8bea7aeac89c3c4e3af5858529299 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 18 Apr 2017 10:51:04 -0700 Subject: [PATCH] tidy and test fixes --- components/style/gecko_string_cache/mod.rs | 2 +- components/style/properties/data.py | 4 ++- components/style/properties/gecko.mako.rs | 1 + .../helpers/animated_properties.mako.rs | 3 +- .../style/properties/longhand/font.mako.rs | 34 ++++++++++++++----- .../style/properties/shorthand/font.mako.rs | 15 ++++---- ports/geckolib/glue.rs | 5 +-- 7 files changed, 44 insertions(+), 20 deletions(-) diff --git a/components/style/gecko_string_cache/mod.rs b/components/style/gecko_string_cache/mod.rs index 9db8374f9a55..82589b645ea0 100644 --- a/components/style/gecko_string_cache/mod.rs +++ b/components/style/gecko_string_cache/mod.rs @@ -11,8 +11,8 @@ use gecko_bindings::bindings::Gecko_Atomize; use gecko_bindings::bindings::Gecko_Atomize16; use gecko_bindings::bindings::Gecko_ReleaseAtom; use gecko_bindings::structs::nsIAtom; -use precomputed_hash::PrecomputedHash; use nsstring::nsAString; +use precomputed_hash::PrecomputedHash; use std::borrow::{Cow, Borrow}; use std::char::{self, DecodeUtf16}; use std::fmt::{self, Write}; diff --git a/components/style/properties/data.py b/components/style/properties/data.py index 50952d500cca..42998f5a1cb7 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -20,6 +20,7 @@ font_variant_ligatures font_variant_east_asian font_variant_numeric font_language_override""".split() + def maybe_moz_logical_alias(product, side, prop): if product == "gecko" and side[1]: axis, dir = side[0].split("-") @@ -38,9 +39,10 @@ def to_rust_ident(name): def to_camel_case(ident): return re.sub("(^|_|-)([a-z])", lambda m: m.group(2).upper(), ident.strip("_").strip("-")) + def to_camel_case_lower(ident): camel = to_camel_case(ident) - return camel[0].lower() + camel[1:] + return camel[0].lower() + camel[1:] def parse_aliases(value): diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 72cdf4e21a15..2c84a7120eac 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -95,6 +95,7 @@ pub struct ComputedValues { /// When this is Some, we compute font sizes by computing the keyword against /// the generic font, and then multiplying it by the ratio. pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>, + /// The cached system font. See longhand/font.mako.rs pub cached_system_font: Option, } diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 920d61147286..5e775f298316 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -360,7 +360,8 @@ impl AnimationValue { } /// Construct an AnimationValue from a property declaration - pub fn from_declaration(decl: &PropertyDeclaration, context: &mut Context, initial: &ComputedValues) -> Option { + pub fn from_declaration(decl: &PropertyDeclaration, context: &mut Context, + initial: &ComputedValues) -> Option { use error_reporting::StdoutErrorReporter; use properties::LonghandId; use properties::DeclaredValue; diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index bb7e193c80ca..59981c80c846 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -45,12 +45,12 @@ impl ToComputedValue for SpecifiedValue { type ComputedValue = computed_value::T; - fn to_computed_value(&self, context: &Context) -> computed_value::T { + fn to_computed_value(&self, _context: &Context) -> computed_value::T { match *self { SpecifiedValue::Value(v) => v, SpecifiedValue::System(_) => { <%self:nongecko_unreachable> - context.style.cached_system_font.as_ref().unwrap().${name} + _context.style.cached_system_font.as_ref().unwrap().${name} } } @@ -62,7 +62,7 @@ } -<%helpers:longhand name="font-family" animation_type="none" need_index="True" +<%helpers:longhand name="font-family" animation_type="none" need_index="True" boxed="${product == 'gecko'}" spec="https://drafts.csswg.org/css-fonts/#propdef-font-family"> use properties::longhands::system_font::SystemFont; use self::computed_value::{FontFamily, FamilyName}; @@ -1770,7 +1770,8 @@ ${helpers.single_keyword_system("font-variant-position", } -<%helpers:longhand name="font-language-override" products="gecko" animation_type="none" extra_prefixes="moz" +<%helpers:longhand name="font-language-override" products="gecko" animation_type="none" + extra_prefixes="moz" boxed="True" spec="https://drafts.csswg.org/css-fonts-3/#propdef-font-language-override"> use properties::longhands::system_font::SystemFont; use std::fmt; @@ -1858,7 +1859,7 @@ ${helpers.single_keyword_system("font-variant-position", type ComputedValue = computed_value::T; #[inline] - fn to_computed_value(&self, context: &Context) -> computed_value::T { + fn to_computed_value(&self, _context: &Context) -> computed_value::T { use std::ascii::AsciiExt; match *self { SpecifiedValue::Normal => computed_value::T(0), @@ -1875,7 +1876,7 @@ ${helpers.single_keyword_system("font-variant-position", } SpecifiedValue::System(_) => { <%self:nongecko_unreachable> - context.style.cached_system_font.as_ref().unwrap().font_language_override + _context.style.cached_system_font.as_ref().unwrap().font_language_override } } @@ -2100,6 +2101,21 @@ ${helpers.single_keyword("-moz-math-variant", % if product == "gecko": pub mod system_font { + //! We deal with system fonts here + //! + //! System fonts can only be set as a group via the font shorthand. + //! They resolve at compute time (not parse time -- this lets the + //! browser respond to changes to the OS font settings). + //! + //! While Gecko handles these as a separate property and keyword + //! values on each property indicating that the font should be picked + //! from the -x-system-font property, we avoid this. Instead, + //! each font longhand has a special SystemFont variant which contains + //! the specified system font. When the cascade function (in helpers) + //! detects that a value has a system font, it will resolve it, and + //! cache it on the ComputedValues. After this, it can be just fetched + //! whenever a font longhand on the same element needs the system font. + use app_units::Au; use cssparser::Parser; use properties::longhands; @@ -2190,7 +2206,8 @@ ${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), + 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_', ''))} @@ -2199,7 +2216,8 @@ ${helpers.single_keyword("-moz-math-variant", % endif ), % endfor - font_language_override: longhands::font_language_override::computed_value::T(system.languageOverride), + font_language_override: longhands::font_language_override::computed_value + ::T(system.languageOverride), system_font: *self, }; unsafe { bindings::Gecko_nsFont_Destroy(&mut system); } diff --git a/components/style/properties/shorthand/font.mako.rs b/components/style/properties/shorthand/font.mako.rs index ff3c96a15754..f82aea164ccc 100644 --- a/components/style/properties/shorthand/font.mako.rs +++ b/components/style/properties/shorthand/font.mako.rs @@ -19,6 +19,7 @@ spec="https://drafts.csswg.org/css-fonts-3/#propdef-font"> use properties::longhands::{font_family, font_style, font_weight, font_stretch}; use properties::longhands::{font_size, line_height, font_variant_caps}; + #[cfg(feature = "gecko")] use properties::longhands::system_font::SystemFont; <% gecko_sub_properties = "kerning language_override size_adjust \ @@ -31,7 +32,7 @@ use properties::longhands::font_${prop}; % endfor % endif - use properties::longhands::font_family::SpecifiedValue as FontFamily; + use self::font_family::SpecifiedValue as FontFamily; pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result { let mut nb_normals = 0; @@ -114,13 +115,13 @@ }) } - enum CheckSystemResult { - AllSystem(SystemFont), - SomeSystem, - None - } - % if product == "gecko": + enum CheckSystemResult { + AllSystem(SystemFont), + SomeSystem, + None + } + impl<'a> LonghandsToSerialize<'a> { /// Check if some or all members are system fonts fn check_system(&self) -> CheckSystemResult { diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 4894f841e070..599d34731750 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -1631,7 +1631,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetFontFamily(declarations: let mut parser = Parser::new(&string); if let Ok(family) = FontFamily::parse(&mut parser) { if parser.is_exhausted() { - let decl = PropertyDeclaration::FontFamily(family); + let decl = PropertyDeclaration::FontFamily(Box::new(family)); write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| { decls.push(decl, Importance::Normal); }) @@ -1956,7 +1956,8 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis .filter_map(|&(ref decl, imp)| { if imp == Importance::Normal { let property = TransitionProperty::from_declaration(decl); - let animation = AnimationValue::from_declaration(decl, &mut context, default_values); + let animation = AnimationValue::from_declaration(decl, &mut context, + default_values); debug_assert!(property.is_none() == animation.is_none(), "The failure condition of TransitionProperty::from_declaration \ and AnimationValue::from_declaration should be the same");