mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
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:
commit
cfdb6af53b
6 changed files with 99 additions and 38 deletions
|
@ -715,12 +715,6 @@ pub mod root {
|
|||
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_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_BREAK_ALL: ::std::os::raw::c_uint = 1;
|
||||
pub const NS_STYLE_WORDBREAK_KEEP_ALL: ::std::os::raw::c_uint = 2;
|
||||
|
@ -6200,6 +6194,16 @@ pub mod root {
|
|||
#[repr(u8)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
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)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct WritingMode {
|
||||
|
@ -30352,7 +30356,7 @@ pub mod root {
|
|||
pub _bitfield_1: u8,
|
||||
pub mTextJustify: root::mozilla::StyleTextJustify,
|
||||
pub mTextTransform: u8,
|
||||
pub mWhiteSpace: u8,
|
||||
pub mWhiteSpace: root::mozilla::StyleWhiteSpace,
|
||||
pub mWordBreak: u8,
|
||||
pub mOverflowWrap: u8,
|
||||
pub mHyphens: root::mozilla::StyleHyphens,
|
||||
|
|
|
@ -715,12 +715,6 @@ pub mod root {
|
|||
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_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_BREAK_ALL: ::std::os::raw::c_uint = 1;
|
||||
pub const NS_STYLE_WORDBREAK_KEEP_ALL: ::std::os::raw::c_uint = 2;
|
||||
|
@ -6068,6 +6062,16 @@ pub mod root {
|
|||
#[repr(u8)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
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)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct WritingMode {
|
||||
|
@ -29833,7 +29837,7 @@ pub mod root {
|
|||
pub _bitfield_1: u8,
|
||||
pub mTextJustify: root::mozilla::StyleTextJustify,
|
||||
pub mTextTransform: u8,
|
||||
pub mWhiteSpace: u8,
|
||||
pub mWhiteSpace: root::mozilla::StyleWhiteSpace,
|
||||
pub mWordBreak: u8,
|
||||
pub mOverflowWrap: u8,
|
||||
pub mHyphens: root::mozilla::StyleHyphens,
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -635,7 +635,7 @@ ${helpers.single_keyword("text-align-last",
|
|||
<%helpers:single_keyword_computed name="white-space"
|
||||
values="normal pre nowrap pre-wrap pre-line"
|
||||
extra_gecko_values="-moz-pre-space"
|
||||
gecko_constant_prefix="NS_STYLE_WHITESPACE"
|
||||
gecko_enum_prefix="StyleWhiteSpace"
|
||||
needs_conversion="True"
|
||||
animation_value_type="none"
|
||||
spec="https://drafts.csswg.org/css-text/#propdef-white-space">
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue