Auto merge of #17121 - Manishearth:stylo-system-font-ser, r=upsuper

stylo: Fix serialization of system fonts

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17121)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-06-01 14:04:41 -07:00 committed by GitHub
commit cfdb6af53b
6 changed files with 99 additions and 38 deletions

View file

@ -715,12 +715,6 @@ pub mod root {
pub const NS_STYLE_VISIBILITY_VISIBLE: ::std::os::raw::c_uint = 1; pub const NS_STYLE_VISIBILITY_VISIBLE: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_VISIBILITY_COLLAPSE: ::std::os::raw::c_uint = 2; pub const NS_STYLE_VISIBILITY_COLLAPSE: ::std::os::raw::c_uint = 2;
pub const NS_STYLE_TABSIZE_INITIAL: ::std::os::raw::c_uint = 8; pub const NS_STYLE_TABSIZE_INITIAL: ::std::os::raw::c_uint = 8;
pub const NS_STYLE_WHITESPACE_NORMAL: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_WHITESPACE_PRE: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_WHITESPACE_NOWRAP: ::std::os::raw::c_uint = 2;
pub const NS_STYLE_WHITESPACE_PRE_WRAP: ::std::os::raw::c_uint = 3;
pub const NS_STYLE_WHITESPACE_PRE_LINE: ::std::os::raw::c_uint = 4;
pub const NS_STYLE_WHITESPACE_PRE_SPACE: ::std::os::raw::c_uint = 5;
pub const NS_STYLE_WORDBREAK_NORMAL: ::std::os::raw::c_uint = 0; pub const NS_STYLE_WORDBREAK_NORMAL: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_WORDBREAK_BREAK_ALL: ::std::os::raw::c_uint = 1; pub const NS_STYLE_WORDBREAK_BREAK_ALL: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_WORDBREAK_KEEP_ALL: ::std::os::raw::c_uint = 2; pub const NS_STYLE_WORDBREAK_KEEP_ALL: ::std::os::raw::c_uint = 2;
@ -6200,6 +6194,16 @@ pub mod root {
#[repr(u8)] #[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum StyleGridTrackBreadth { MaxContent = 1, MinContent = 2, } pub enum StyleGridTrackBreadth { MaxContent = 1, MinContent = 2, }
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum StyleWhiteSpace {
Normal = 0,
Pre = 1,
Nowrap = 2,
PreWrap = 3,
PreLine = 4,
PreSpace = 5,
}
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct WritingMode { pub struct WritingMode {
@ -30352,7 +30356,7 @@ pub mod root {
pub _bitfield_1: u8, pub _bitfield_1: u8,
pub mTextJustify: root::mozilla::StyleTextJustify, pub mTextJustify: root::mozilla::StyleTextJustify,
pub mTextTransform: u8, pub mTextTransform: u8,
pub mWhiteSpace: u8, pub mWhiteSpace: root::mozilla::StyleWhiteSpace,
pub mWordBreak: u8, pub mWordBreak: u8,
pub mOverflowWrap: u8, pub mOverflowWrap: u8,
pub mHyphens: root::mozilla::StyleHyphens, pub mHyphens: root::mozilla::StyleHyphens,

View file

@ -715,12 +715,6 @@ pub mod root {
pub const NS_STYLE_VISIBILITY_VISIBLE: ::std::os::raw::c_uint = 1; pub const NS_STYLE_VISIBILITY_VISIBLE: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_VISIBILITY_COLLAPSE: ::std::os::raw::c_uint = 2; pub const NS_STYLE_VISIBILITY_COLLAPSE: ::std::os::raw::c_uint = 2;
pub const NS_STYLE_TABSIZE_INITIAL: ::std::os::raw::c_uint = 8; pub const NS_STYLE_TABSIZE_INITIAL: ::std::os::raw::c_uint = 8;
pub const NS_STYLE_WHITESPACE_NORMAL: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_WHITESPACE_PRE: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_WHITESPACE_NOWRAP: ::std::os::raw::c_uint = 2;
pub const NS_STYLE_WHITESPACE_PRE_WRAP: ::std::os::raw::c_uint = 3;
pub const NS_STYLE_WHITESPACE_PRE_LINE: ::std::os::raw::c_uint = 4;
pub const NS_STYLE_WHITESPACE_PRE_SPACE: ::std::os::raw::c_uint = 5;
pub const NS_STYLE_WORDBREAK_NORMAL: ::std::os::raw::c_uint = 0; pub const NS_STYLE_WORDBREAK_NORMAL: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_WORDBREAK_BREAK_ALL: ::std::os::raw::c_uint = 1; pub const NS_STYLE_WORDBREAK_BREAK_ALL: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_WORDBREAK_KEEP_ALL: ::std::os::raw::c_uint = 2; pub const NS_STYLE_WORDBREAK_KEEP_ALL: ::std::os::raw::c_uint = 2;
@ -6068,6 +6062,16 @@ pub mod root {
#[repr(u8)] #[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum StyleGridTrackBreadth { MaxContent = 1, MinContent = 2, } pub enum StyleGridTrackBreadth { MaxContent = 1, MinContent = 2, }
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum StyleWhiteSpace {
Normal = 0,
Pre = 1,
Nowrap = 2,
PreWrap = 3,
PreLine = 4,
PreSpace = 5,
}
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct WritingMode { pub struct WritingMode {
@ -29833,7 +29837,7 @@ pub mod root {
pub _bitfield_1: u8, pub _bitfield_1: u8,
pub mTextJustify: root::mozilla::StyleTextJustify, pub mTextJustify: root::mozilla::StyleTextJustify,
pub mTextTransform: u8, pub mTextTransform: u8,
pub mWhiteSpace: u8, pub mWhiteSpace: root::mozilla::StyleWhiteSpace,
pub mWordBreak: u8, pub mWordBreak: u8,
pub mOverflowWrap: u8, pub mOverflowWrap: u8,
pub mHyphens: root::mozilla::StyleHyphens, pub mHyphens: root::mozilla::StyleHyphens,

View file

@ -512,7 +512,21 @@ impl ToCss for PropertyDeclarationBlock {
// Substep 2 & 3 // Substep 2 & 3
let mut current_longhands = Vec::new(); let mut current_longhands = Vec::new();
let mut important_count = 0; let mut important_count = 0;
let mut found_system = None;
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;
}
}
}
} else {
for &&(ref longhand, longhand_importance) in longhands.iter() { for &&(ref longhand, longhand_importance) in longhands.iter() {
if longhand.id().is_longhand_of(shorthand) { if longhand.id().is_longhand_of(shorthand) {
current_longhands.push(longhand); current_longhands.push(longhand);
@ -521,7 +535,6 @@ impl ToCss for PropertyDeclarationBlock {
} }
} }
} }
// Substep 1: // Substep 1:
// //
// Assuming that the PropertyDeclarationBlock contains no // Assuming that the PropertyDeclarationBlock contains no
@ -531,6 +544,7 @@ impl ToCss for PropertyDeclarationBlock {
if current_longhands.len() != properties.len() { if current_longhands.len() != properties.len() {
continue; continue;
} }
}
// Substep 4 // Substep 4
let is_important = important_count > 0; let is_important = important_count > 0;
@ -553,25 +567,33 @@ impl ToCss for PropertyDeclarationBlock {
// We avoid re-serializing if we're already an // We avoid re-serializing if we're already an
// AppendableValue::Css. // AppendableValue::Css.
let mut value = String::new(); let mut v = String::new();
let value = match appendable_value { let value = match (appendable_value, found_system) {
AppendableValue::Css { css, with_variables } => { (AppendableValue::Css { css, with_variables }, _) => {
debug_assert!(!css.is_empty()); debug_assert!(!css.is_empty());
AppendableValue::Css { AppendableValue::Css {
css: css, css: css,
with_variables: with_variables, with_variables: with_variables,
} }
} }
other @ _ => { #[cfg(feature = "gecko")]
append_declaration_value(&mut value, other)?; (_, Some(sys)) => {
sys.to_css(&mut v)?;
AppendableValue::Css {
css: &v,
with_variables: false,
}
}
(other, _) => {
append_declaration_value(&mut v, other)?;
// Substep 6 // Substep 6
if value.is_empty() { if v.is_empty() {
continue; continue;
} }
AppendableValue::Css { AppendableValue::Css {
css: &value, css: &v,
with_variables: false, with_variables: false,
} }
} }

View file

@ -635,7 +635,7 @@ ${helpers.single_keyword("text-align-last",
<%helpers:single_keyword_computed name="white-space" <%helpers:single_keyword_computed name="white-space"
values="normal pre nowrap pre-wrap pre-line" values="normal pre nowrap pre-wrap pre-line"
extra_gecko_values="-moz-pre-space" extra_gecko_values="-moz-pre-space"
gecko_constant_prefix="NS_STYLE_WHITESPACE" gecko_enum_prefix="StyleWhiteSpace"
needs_conversion="True" needs_conversion="True"
animation_value_type="none" animation_value_type="none"
spec="https://drafts.csswg.org/css-text/#propdef-white-space"> spec="https://drafts.csswg.org/css-text/#propdef-white-space">

View file

@ -32,6 +32,7 @@ use logical_geometry::WritingMode;
use media_queries::Device; use media_queries::Device;
use parser::{PARSING_MODE_DEFAULT, Parse, ParserContext}; use parser::{PARSING_MODE_DEFAULT, Parse, ParserContext};
use properties::animated_properties::TransitionProperty; use properties::animated_properties::TransitionProperty;
#[cfg(feature = "gecko")] use properties::longhands::system_font::SystemFont;
#[cfg(feature = "servo")] use servo_config::prefs::PREFS; #[cfg(feature = "servo")] use servo_config::prefs::PREFS;
use shared_lock::StylesheetGuards; use shared_lock::StylesheetGuards;
use style_traits::{HasViewportPercentage, ToCss}; 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 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. /// Returns whether the declaration may be serialized as part of a shorthand.
/// ///
/// This method returns false if this declaration contains variable or has a /// 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}; use properties::longhands::{font_size, line_height, font_variant_caps};
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use properties::longhands::system_font::SystemFont; use properties::longhands::system_font::SystemFont;
<% <%
gecko_sub_properties = "kerning language_override size_adjust \ gecko_sub_properties = "kerning language_override size_adjust \
variant_alternates variant_east_asian \ variant_alternates variant_east_asian \