From 59f16b57e74f3e853e760cee43df70f605b8a531 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 21 Mar 2017 20:38:12 -0700 Subject: [PATCH] Bug 1349417 - Part 8: stylo: Serialize system fonts correctly; r?xidorn MozReview-Commit-ID: 4q1zZUcw6zF --- .../style/properties/longhand/font.mako.rs | 12 ++++++ .../style/properties/shorthand/font.mako.rs | 42 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 99d16bdc23b..bb7e193c80c 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -2103,7 +2103,9 @@ ${helpers.single_keyword("-moz-math-variant", use app_units::Au; use cssparser::Parser; use properties::longhands; + use std::fmt; use std::hash::{Hash, Hasher}; + use style_traits::ToCss; use values::computed::{ToComputedValue, Context}; <% system_fonts = """caption icon menu message-box small-caption status-bar @@ -2124,6 +2126,16 @@ ${helpers.single_keyword("-moz-math-variant", % endfor } + impl ToCss for SystemFont { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + dest.write_str(match *self { + % for font in system_fonts: + SystemFont::${to_camel_case(font)} => "${font}", + % endfor + }) + } + } + // ComputedValues are compared at times // so we need these impls. We don't want to // add Eq to Number (which contains a float) diff --git a/components/style/properties/shorthand/font.mako.rs b/components/style/properties/shorthand/font.mako.rs index 8be68523ff5..ff3c96a1575 100644 --- a/components/style/properties/shorthand/font.mako.rs +++ b/components/style/properties/shorthand/font.mako.rs @@ -114,9 +114,51 @@ }) } + enum CheckSystemResult { + AllSystem(SystemFont), + SomeSystem, + None + } + + % if product == "gecko": + impl<'a> LonghandsToSerialize<'a> { + /// Check if some or all members are system fonts + fn check_system(&self) -> CheckSystemResult { + let mut sys = None; + 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; + } + % endfor + if self.line_height != &line_height::get_initial_specified_value() { + all = false + } + if all { + CheckSystemResult::AllSystem(sys.unwrap()) + } else if sys.is_some() { + CheckSystemResult::SomeSystem + } else { + CheckSystemResult::None + } + } + } + % endif + // This may be a bit off, unsure, possibly needs changes impl<'a> ToCss for LonghandsToSerialize<'a> { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + % if product == "gecko": + match self.check_system() { + CheckSystemResult::AllSystem(sys) => return sys.to_css(dest), + CheckSystemResult::SomeSystem => return Ok(()), + CheckSystemResult::None => () + } + % endif % if product == "gecko" or data.testing: % for name in gecko_sub_properties: