stylo: Fix serialization of system fonts

This commit is contained in:
Manish Goregaokar 2017-05-12 17:36:05 -07:00 committed by Manish Goregaokar
parent 6a638876fd
commit 7123e5333f
3 changed files with 76 additions and 23 deletions

View file

@ -512,24 +512,38 @@ impl ToCss for PropertyDeclarationBlock {
// Substep 2 & 3
let mut current_longhands = Vec::new();
let mut important_count = 0;
let mut found_system = None;
for &&(ref longhand, longhand_importance) in longhands.iter() {
if longhand.id().is_longhand_of(shorthand) {
current_longhands.push(longhand);
if longhand_importance.important() {
important_count += 1;
if shorthand == ShorthandId::Font && longhands.iter().any(|&&(ref l, _)| l.get_system().is_some()) {
for &&(ref longhand, longhand_importance) in longhands.iter() {
if longhand.get_system().is_some() || longhand.is_default_line_height() {
current_longhands.push(longhand);
if found_system.is_none() {
found_system = longhand.get_system();
}
if longhand_importance.important() {
important_count += 1;
}
}
}
}
// Substep 1:
//
// Assuming that the PropertyDeclarationBlock contains no
// duplicate entries, if the current_longhands length is
// equal to the properties length, it means that the
// properties that map to shorthand are present in longhands
if current_longhands.len() != properties.len() {
continue;
} else {
for &&(ref longhand, longhand_importance) in longhands.iter() {
if longhand.id().is_longhand_of(shorthand) {
current_longhands.push(longhand);
if longhand_importance.important() {
important_count += 1;
}
}
}
// Substep 1:
//
// Assuming that the PropertyDeclarationBlock contains no
// duplicate entries, if the current_longhands length is
// equal to the properties length, it means that the
// properties that map to shorthand are present in longhands
if current_longhands.len() != properties.len() {
continue;
}
}
// Substep 4
@ -553,25 +567,33 @@ impl ToCss for PropertyDeclarationBlock {
// We avoid re-serializing if we're already an
// AppendableValue::Css.
let mut value = String::new();
let value = match appendable_value {
AppendableValue::Css { css, with_variables } => {
let mut v = String::new();
let value = match (appendable_value, found_system) {
(AppendableValue::Css { css, with_variables }, _) => {
debug_assert!(!css.is_empty());
AppendableValue::Css {
css: css,
with_variables: with_variables,
}
}
other @ _ => {
append_declaration_value(&mut value, other)?;
#[cfg(feature = "gecko")]
(_, Some(sys)) => {
sys.to_css(&mut v)?;
AppendableValue::Css {
css: &v,
with_variables: false,
}
}
(other, _) => {
append_declaration_value(&mut v, other)?;
// Substep 6
if value.is_empty() {
if v.is_empty() {
continue;
}
AppendableValue::Css {
css: &value,
css: &v,
with_variables: false,
}
}

View file

@ -32,6 +32,7 @@ use logical_geometry::WritingMode;
use media_queries::Device;
use parser::{PARSING_MODE_DEFAULT, Parse, ParserContext};
use properties::animated_properties::TransitionProperty;
#[cfg(feature = "gecko")] use properties::longhands::system_font::SystemFont;
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
use shared_lock::StylesheetGuards;
use style_traits::{HasViewportPercentage, ToCss};
@ -53,7 +54,7 @@ macro_rules! property_name {
}
<%!
from data import Method, Keyword, to_rust_ident, to_camel_case
from data import Method, Keyword, to_rust_ident, to_camel_case, SYSTEM_FONT_LONGHANDS
import os.path
%>
@ -1247,6 +1248,35 @@ impl PropertyDeclaration {
}
}
/// Returns whether or not the property is set by a system font
#[cfg(feature = "gecko")]
pub fn get_system(&self) -> Option<SystemFont> {
match *self {
% for prop in SYSTEM_FONT_LONGHANDS:
PropertyDeclaration::${to_camel_case(prop)}(ref prop) => {
prop.get_system()
}
% endfor
_ => None,
}
}
/// Is it the default value of line-height?
///
/// (using match because it generates less code than)
pub fn is_default_line_height(&self) -> bool {
match *self {
PropertyDeclaration::LineHeight(longhands::line_height::SpecifiedValue::Normal) => true,
_ => false
}
}
#[cfg(feature = "servo")]
/// Dummy method to avoid cfg()s
pub fn get_system(&self) -> Option<()> {
None
}
/// Returns whether the declaration may be serialized as part of a shorthand.
///
/// This method returns false if this declaration contains variable or has a

View file

@ -22,6 +22,7 @@
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 \
variant_alternates variant_east_asian \