Skip to content

Commit

Permalink
Bug 1349417 - Part 8: stylo: Serialize system fonts correctly; r?xidorn
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: 4q1zZUcw6zF
  • Loading branch information
Manishearth committed Apr 21, 2017
1 parent 795ab74 commit 5a07227
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
12 changes: 12 additions & 0 deletions components/style/properties/longhand/font.mako.rs
Expand Up @@ -2183,7 +2183,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
Expand All @@ -2204,6 +2206,16 @@ ${helpers.single_keyword("-moz-math-variant",
% endfor
}

impl ToCss for SystemFont {
fn to_css<W>(&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)
Expand Down
42 changes: 42 additions & 0 deletions components/style/properties/shorthand/font.mako.rs
Expand Up @@ -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<W>(&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:
Expand Down

0 comments on commit 5a07227

Please sign in to comment.