Make DeclaredValue store CSSWideKeyword

Rather than having separate variant for each CSS-wide keyword.
This commit is contained in:
Xidorn Quan 2017-02-28 18:53:51 +11:00
parent 29fd30601e
commit 03f6d21cb5
10 changed files with 120 additions and 115 deletions

View file

@ -9,7 +9,7 @@
use Atom; use Atom;
use cssparser::{Delimiter, Parser, SourcePosition, Token, TokenSerializationType}; use cssparser::{Delimiter, Parser, SourcePosition, Token, TokenSerializationType};
use parser::ParserContext; use parser::ParserContext;
use properties::DeclaredValue; use properties::{CSSWideKeyword, DeclaredValue};
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
@ -362,11 +362,13 @@ pub fn cascade<'a>(custom_properties: &mut Option<HashMap<&'a Name, BorrowedSpec
}); });
}, },
DeclaredValue::WithVariables(_) => unreachable!(), DeclaredValue::WithVariables(_) => unreachable!(),
DeclaredValue::Initial => { DeclaredValue::CSSWideKeyword(keyword) => match keyword {
map.remove(&name); CSSWideKeyword::Initial => {
map.remove(&name);
}
CSSWideKeyword::Unset | // Custom properties are inherited by default.
CSSWideKeyword::Inherit => {} // The inherited value is what we already have.
} }
DeclaredValue::Unset | // Custom properties are inherited by default.
DeclaredValue::Inherit => {} // The inherited value is what we already have.
} }
} }

View file

@ -267,30 +267,32 @@
% endif % endif
} }
DeclaredValue::WithVariables(_) => unreachable!(), DeclaredValue::WithVariables(_) => unreachable!(),
% if not data.current_style_struct.inherited: DeclaredValue::CSSWideKeyword(keyword) => match keyword {
DeclaredValue::Unset | % if not data.current_style_struct.inherited:
% endif CSSWideKeyword::Unset |
DeclaredValue::Initial => { % endif
// We assume that it's faster to use copy_*_from rather than CSSWideKeyword::Initial => {
// set_*(get_initial_value()); // We assume that it's faster to use copy_*_from rather than
let initial_struct = default_style // set_*(get_initial_value());
.get_${data.current_style_struct.name_lower}(); let initial_struct = default_style
context.mutate_style().mutate_${data.current_style_struct.name_lower}() .get_${data.current_style_struct.name_lower}();
.copy_${property.ident}_from(initial_struct ${maybe_wm}); context.mutate_style().mutate_${data.current_style_struct.name_lower}()
}, .copy_${property.ident}_from(initial_struct ${maybe_wm});
% if data.current_style_struct.inherited: },
DeclaredValue::Unset | % if data.current_style_struct.inherited:
% endif CSSWideKeyword::Unset |
DeclaredValue::Inherit => { % endif
// This is a bit slow, but this is rare so it shouldn't CSSWideKeyword::Inherit => {
// matter. // This is a bit slow, but this is rare so it shouldn't
// // matter.
// FIXME: is it still? //
*cacheable = false; // FIXME: is it still?
let inherited_struct = *cacheable = false;
inherited_style.get_${data.current_style_struct.name_lower}(); let inherited_struct =
context.mutate_style().mutate_${data.current_style_struct.name_lower}() inherited_style.get_${data.current_style_struct.name_lower}();
.copy_${property.ident}_from(inherited_struct ${maybe_wm}); context.mutate_style().mutate_${data.current_style_struct.name_lower}()
.copy_${property.ident}_from(inherited_struct ${maybe_wm});
}
} }
} }
}, error_reporter); }, error_reporter);
@ -324,9 +326,7 @@
-> Result<DeclaredValue<SpecifiedValue>, ()> { -> Result<DeclaredValue<SpecifiedValue>, ()> {
% endif % endif
match input.try(|i| CSSWideKeyword::parse(context, i)) { match input.try(|i| CSSWideKeyword::parse(context, i)) {
Ok(CSSWideKeyword::Inherit) => Ok(DeclaredValue::Inherit), Ok(keyword) => Ok(DeclaredValue::CSSWideKeyword(keyword)),
Ok(CSSWideKeyword::Initial) => Ok(DeclaredValue::Initial),
Ok(CSSWideKeyword::Unset) => Ok(DeclaredValue::Unset),
Err(()) => { Err(()) => {
input.look_for_var_functions(); input.look_for_var_functions();
let start = input.position(); let start = input.position();
@ -483,8 +483,8 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use cssparser::Parser; use cssparser::Parser;
use parser::ParserContext; use parser::ParserContext;
use properties::{DeclaredValue, PropertyDeclaration, UnparsedValue}; use properties::{CSSWideKeyword, DeclaredValue, PropertyDeclaration};
use properties::{ShorthandId, longhands}; use properties::{ShorthandId, UnparsedValue, longhands};
use properties::declaration_block::Importance; use properties::declaration_block::Importance;
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
@ -563,9 +563,11 @@
let mut with_variables = false; let mut with_variables = false;
% for sub_property in shorthand.sub_properties: % for sub_property in shorthand.sub_properties:
match *self.${sub_property.ident} { match *self.${sub_property.ident} {
DeclaredValue::Initial => all_flags &= ALL_INITIAL, DeclaredValue::CSSWideKeyword(keyword) => match keyword {
DeclaredValue::Inherit => all_flags &= ALL_INHERIT, CSSWideKeyword::Initial => all_flags &= ALL_INITIAL,
DeclaredValue::Unset => all_flags &= ALL_UNSET, CSSWideKeyword::Inherit => all_flags &= ALL_INHERIT,
CSSWideKeyword::Unset => all_flags &= ALL_UNSET,
},
DeclaredValue::WithVariables(_) => with_variables = true, DeclaredValue::WithVariables(_) => with_variables = true,
DeclaredValue::Value(..) => { DeclaredValue::Value(..) => {
all_flags = SerializeFlags::empty(); all_flags = SerializeFlags::empty();

View file

@ -8,7 +8,7 @@ use app_units::Au;
use cssparser::{Color as CSSParserColor, Parser, RGBA}; use cssparser::{Color as CSSParserColor, Parser, RGBA};
use euclid::{Point2D, Size2D}; use euclid::{Point2D, Size2D};
#[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSPropertyID; #[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSPropertyID;
use properties::{DeclaredValue, PropertyDeclaration}; use properties::{CSSWideKeyword, DeclaredValue, PropertyDeclaration};
use properties::longhands; use properties::longhands;
use properties::longhands::background_size::computed_value::T as BackgroundSize; use properties::longhands::background_size::computed_value::T as BackgroundSize;
use properties::longhands::font_weight::computed_value::T as FontWeight; use properties::longhands::font_weight::computed_value::T as FontWeight;
@ -287,21 +287,23 @@ impl AnimationValue {
// https://bugzilla.mozilla.org/show_bug.cgi?id=1326131 // https://bugzilla.mozilla.org/show_bug.cgi?id=1326131
DeclaredValue::WithVariables(_) => unimplemented!(), DeclaredValue::WithVariables(_) => unimplemented!(),
DeclaredValue::Value(ref val) => val.to_computed_value(context), DeclaredValue::Value(ref val) => val.to_computed_value(context),
% if not prop.style_struct.inherited: DeclaredValue::CSSWideKeyword(keyword) => match keyword {
DeclaredValue::Unset | % if not prop.style_struct.inherited:
% endif CSSWideKeyword::Unset |
DeclaredValue::Initial => { % endif
let initial_struct = initial.get_${prop.style_struct.name_lower}(); CSSWideKeyword::Initial => {
initial_struct.clone_${prop.ident}() let initial_struct = initial.get_${prop.style_struct.name_lower}();
}, initial_struct.clone_${prop.ident}()
% if prop.style_struct.inherited: },
DeclaredValue::Unset | % if prop.style_struct.inherited:
% endif CSSWideKeyword::Unset |
DeclaredValue::Inherit => { % endif
let inherit_struct = context.inherited_style CSSWideKeyword::Inherit => {
.get_${prop.style_struct.name_lower}(); let inherit_struct = context.inherited_style
inherit_struct.clone_${prop.ident}() .get_${prop.style_struct.name_lower}();
}, inherit_struct.clone_${prop.ident}()
},
}
}; };
Some(AnimationValue::${prop.camel_case}(computed)) Some(AnimationValue::${prop.camel_case}(computed))
} }

View file

@ -365,7 +365,13 @@ impl PropertyDeclarationIdSet {
}) })
.unwrap_or( .unwrap_or(
// Invalid at computed-value time. // Invalid at computed-value time.
DeclaredValue::${"Inherit" if property.style_struct.inherited else "Initial"} DeclaredValue::CSSWideKeyword(
% if property.style_struct.inherited:
CSSWideKeyword::Inherit
% else:
CSSWideKeyword::Initial
% endif
)
) )
); );
} }
@ -374,6 +380,7 @@ impl PropertyDeclarationIdSet {
/// An enum to represent a CSS Wide keyword. /// An enum to represent a CSS Wide keyword.
#[derive(Copy, Clone, PartialEq, Eq, Debug)] #[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum CSSWideKeyword { pub enum CSSWideKeyword {
/// The `initial` keyword. /// The `initial` keyword.
Initial, Initial,
@ -383,6 +390,16 @@ pub enum CSSWideKeyword {
Unset, Unset,
} }
impl ToCss for CSSWideKeyword {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
dest.write_str(match *self {
CSSWideKeyword::Initial => "initial",
CSSWideKeyword::Inherit => "inherit",
CSSWideKeyword::Unset => "unset",
})
}
}
impl Parse for CSSWideKeyword { impl Parse for CSSWideKeyword {
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let ident = input.expect_ident()?; let ident = input.expect_ident()?;
@ -545,12 +562,8 @@ pub enum DeclaredValue<T> {
Value(T), Value(T),
/// An unparsed value that contains `var()` functions. /// An unparsed value that contains `var()` functions.
WithVariables(Box<UnparsedValue>), WithVariables(Box<UnparsedValue>),
/// The `initial` keyword. /// An CSS-wide keyword.
Initial, CSSWideKeyword(CSSWideKeyword),
/// The `inherit` keyword.
Inherit,
/// The `unset` keyword.
Unset,
} }
/// An unparsed property value that contains `var()` functions. /// An unparsed property value that contains `var()` functions.
@ -575,9 +588,7 @@ impl<T: HasViewportPercentage> HasViewportPercentage for DeclaredValue<T> {
panic!("DeclaredValue::has_viewport_percentage without \ panic!("DeclaredValue::has_viewport_percentage without \
resolving variables!") resolving variables!")
}, },
DeclaredValue::Initial | DeclaredValue::CSSWideKeyword(_) => false,
DeclaredValue::Inherit |
DeclaredValue::Unset => false,
} }
} }
} }
@ -595,9 +606,7 @@ impl<T: ToCss> ToCss for DeclaredValue<T> {
} }
Ok(()) Ok(())
}, },
DeclaredValue::Initial => dest.write_str("initial"), DeclaredValue::CSSWideKeyword(ref keyword) => keyword.to_css(dest),
DeclaredValue::Inherit => dest.write_str("inherit"),
DeclaredValue::Unset => dest.write_str("unset"),
} }
} }
} }
@ -969,9 +978,7 @@ impl PropertyDeclaration {
match id { match id {
PropertyId::Custom(name) => { PropertyId::Custom(name) => {
let value = match input.try(|i| CSSWideKeyword::parse(context, i)) { let value = match input.try(|i| CSSWideKeyword::parse(context, i)) {
Ok(CSSWideKeyword::Unset) => DeclaredValue::Unset, Ok(keyword) => DeclaredValue::CSSWideKeyword(keyword),
Ok(CSSWideKeyword::Inherit) => DeclaredValue::Inherit,
Ok(CSSWideKeyword::Initial) => DeclaredValue::Initial,
Err(()) => match ::custom_properties::SpecifiedValue::parse(context, input) { Err(()) => match ::custom_properties::SpecifiedValue::parse(context, input) {
Ok(value) => DeclaredValue::Value(value), Ok(value) => DeclaredValue::Value(value),
Err(()) => return PropertyDeclarationParseResult::InvalidValue, Err(()) => return PropertyDeclarationParseResult::InvalidValue,
@ -1029,26 +1036,11 @@ impl PropertyDeclaration {
${property_pref_check(shorthand)} ${property_pref_check(shorthand)}
match input.try(|i| CSSWideKeyword::parse(context, i)) { match input.try(|i| CSSWideKeyword::parse(context, i)) {
Ok(CSSWideKeyword::Inherit) => { Ok(keyword) => {
% for sub_property in shorthand.sub_properties: % for sub_property in shorthand.sub_properties:
result_list.push(( result_list.push((
PropertyDeclaration::${sub_property.camel_case}( PropertyDeclaration::${sub_property.camel_case}(
DeclaredValue::Inherit), Importance::Normal)); DeclaredValue::CSSWideKeyword(keyword)), Importance::Normal));
% endfor
PropertyDeclarationParseResult::ValidOrIgnoredDeclaration
},
Ok(CSSWideKeyword::Initial) => {
% for sub_property in shorthand.sub_properties:
result_list.push((
PropertyDeclaration::${sub_property.camel_case}(
DeclaredValue::Initial), Importance::Normal));
% endfor
PropertyDeclarationParseResult::ValidOrIgnoredDeclaration
},
Ok(CSSWideKeyword::Unset) => {
% for sub_property in shorthand.sub_properties:
result_list.push((PropertyDeclaration::${sub_property.camel_case}(
DeclaredValue::Unset), Importance::Normal));
% endfor % endfor
PropertyDeclarationParseResult::ValidOrIgnoredDeclaration PropertyDeclarationParseResult::ValidOrIgnoredDeclaration
}, },

View file

@ -23,9 +23,8 @@
*x_value == y_container.0 *x_value == y_container.0
}, },
(&DeclaredValue::WithVariables(_), &DeclaredValue::WithVariables(_)) => true, (&DeclaredValue::WithVariables(_), &DeclaredValue::WithVariables(_)) => true,
(&DeclaredValue::Initial, &DeclaredValue::Initial) => true, (&DeclaredValue::CSSWideKeyword(x_keyword),
(&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true, &DeclaredValue::CSSWideKeyword(y_keyword)) => x_keyword == y_keyword,
(&DeclaredValue::Unset, &DeclaredValue::Unset) => true,
_ => false _ => false
}; };
@ -359,9 +358,8 @@ macro_rules! try_parse_one {
(&DeclaredValue::Value(ref x_value), &DeclaredValue::Value(ref y_value)) => { (&DeclaredValue::Value(ref x_value), &DeclaredValue::Value(ref y_value)) => {
*x_value == *y_value *x_value == *y_value
}, },
(&DeclaredValue::Initial, &DeclaredValue::Initial) => true, (&DeclaredValue::CSSWideKeyword(x_keyword),
(&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true, &DeclaredValue::CSSWideKeyword(y_keyword)) => x_keyword == y_keyword,
(&DeclaredValue::Unset, &DeclaredValue::Unset) => true,
(x, y) => { *x == *y }, (x, y) => { *x == *y },
}; };

View file

@ -99,21 +99,24 @@
impl<'a> LonghandsToSerialize<'a> { impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self.list_style_position { match *self.list_style_position {
DeclaredValue::Initial => try!(write!(dest, "outside")), DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial) =>
try!(write!(dest, "outside")),
_ => try!(self.list_style_position.to_css(dest)) _ => try!(self.list_style_position.to_css(dest))
} }
try!(write!(dest, " ")); try!(write!(dest, " "));
match *self.list_style_image { match *self.list_style_image {
DeclaredValue::Initial => try!(write!(dest, "none")), DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial) =>
try!(write!(dest, "none")),
_ => try!(self.list_style_image.to_css(dest)) _ => try!(self.list_style_image.to_css(dest))
}; };
try!(write!(dest, " ")); try!(write!(dest, " "));
match *self.list_style_type { match *self.list_style_type {
DeclaredValue::Initial => write!(dest, "disc"), DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial) =>
write!(dest, "disc"),
_ => self.list_style_type.to_css(dest) _ => self.list_style_type.to_css(dest)
} }
} }

View file

@ -57,12 +57,13 @@
try!(write!(dest, " ")); try!(write!(dest, " "));
match *self.outline_style { match *self.outline_style {
DeclaredValue::Initial => try!(write!(dest, "none")), DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial) =>
try!(write!(dest, "none")),
_ => try!(self.outline_style.to_css(dest)) _ => try!(self.outline_style.to_css(dest))
}; };
match *self.outline_color { match *self.outline_color {
DeclaredValue::Initial => Ok(()), DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial) => Ok(()),
_ => { _ => {
try!(write!(dest, " ")); try!(write!(dest, " "));
self.outline_color.to_css(dest) self.outline_color.to_css(dest)

View file

@ -40,14 +40,16 @@
impl<'a> LonghandsToSerialize<'a> { impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self.flex_direction { match *self.flex_direction {
DeclaredValue::Initial => try!(write!(dest, "row")), DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial) =>
try!(write!(dest, "row")),
_ => try!(self.flex_direction.to_css(dest)) _ => try!(self.flex_direction.to_css(dest))
}; };
try!(write!(dest, " ")); try!(write!(dest, " "));
match *self.flex_wrap { match *self.flex_wrap {
DeclaredValue::Initial => write!(dest, "nowrap"), DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial) =>
write!(dest, "nowrap"),
_ => self.flex_wrap.to_css(dest) _ => self.flex_wrap.to_css(dest)
} }
} }

View file

@ -7,7 +7,8 @@ use media_queries::CSSErrorReporterTest;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use style::computed_values::display::T::inline_block; use style::computed_values::display::T::inline_block;
use style::parser::ParserContext; use style::parser::ParserContext;
use style::properties::{DeclaredValue, PropertyDeclaration, PropertyDeclarationBlock, Importance, PropertyId}; use style::properties::{CSSWideKeyword, DeclaredValue, PropertyDeclaration};
use style::properties::{PropertyDeclarationBlock, Importance, PropertyId};
use style::properties::longhands::outline_color::computed_value::T as ComputedColor; use style::properties::longhands::outline_color::computed_value::T as ComputedColor;
use style::properties::parse_property_declaration_list; use style::properties::parse_property_declaration_list;
use style::stylesheets::Origin; use style::stylesheets::Origin;
@ -376,7 +377,7 @@ mod shorthand_serialization {
let mut properties = Vec::new(); let mut properties = Vec::new();
let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32))); let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32)));
let style = DeclaredValue::Initial; let style = DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial);
let color = DeclaredValue::Value(CSSColor { let color = DeclaredValue::Value(CSSColor {
parsed: ComputedColor::RGBA(RGBA::new(255, 0, 0, 255)), parsed: ComputedColor::RGBA(RGBA::new(255, 0, 0, 255)),
authored: None authored: None
@ -396,7 +397,7 @@ mod shorthand_serialization {
let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32))); let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32)));
let style = DeclaredValue::Value(BorderStyle::solid); let style = DeclaredValue::Value(BorderStyle::solid);
let color = DeclaredValue::Initial; let color = DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial);
properties.push(PropertyDeclaration::BorderTopWidth(width)); properties.push(PropertyDeclaration::BorderTopWidth(width));
properties.push(PropertyDeclaration::BorderTopStyle(style)); properties.push(PropertyDeclaration::BorderTopStyle(style));
@ -412,7 +413,7 @@ mod shorthand_serialization {
let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32))); let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32)));
let style = DeclaredValue::Value(BorderStyle::solid); let style = DeclaredValue::Value(BorderStyle::solid);
let color = DeclaredValue::Initial; let color = DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial);
properties.push(PropertyDeclaration::BorderRightWidth(width)); properties.push(PropertyDeclaration::BorderRightWidth(width));
properties.push(PropertyDeclaration::BorderRightStyle(style)); properties.push(PropertyDeclaration::BorderRightStyle(style));
@ -428,7 +429,7 @@ mod shorthand_serialization {
let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32))); let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32)));
let style = DeclaredValue::Value(BorderStyle::solid); let style = DeclaredValue::Value(BorderStyle::solid);
let color = DeclaredValue::Initial; let color = DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial);
properties.push(PropertyDeclaration::BorderBottomWidth(width)); properties.push(PropertyDeclaration::BorderBottomWidth(width));
properties.push(PropertyDeclaration::BorderBottomStyle(style)); properties.push(PropertyDeclaration::BorderBottomStyle(style));
@ -444,7 +445,7 @@ mod shorthand_serialization {
let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32))); let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32)));
let style = DeclaredValue::Value(BorderStyle::solid); let style = DeclaredValue::Value(BorderStyle::solid);
let color = DeclaredValue::Initial; let color = DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial);
properties.push(PropertyDeclaration::BorderLeftWidth(width)); properties.push(PropertyDeclaration::BorderLeftWidth(width));
properties.push(PropertyDeclaration::BorderLeftStyle(style)); properties.push(PropertyDeclaration::BorderLeftStyle(style));
@ -460,7 +461,7 @@ mod shorthand_serialization {
let top_width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32))); let top_width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32)));
let top_style = DeclaredValue::Value(BorderStyle::solid); let top_style = DeclaredValue::Value(BorderStyle::solid);
let top_color = DeclaredValue::Initial; let top_color = DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial);
properties.push(PropertyDeclaration::BorderTopWidth(top_width)); properties.push(PropertyDeclaration::BorderTopWidth(top_width));
properties.push(PropertyDeclaration::BorderTopStyle(top_style)); properties.push(PropertyDeclaration::BorderTopStyle(top_style));
@ -468,7 +469,7 @@ mod shorthand_serialization {
let right_width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32))); let right_width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32)));
let right_style = DeclaredValue::Value(BorderStyle::solid); let right_style = DeclaredValue::Value(BorderStyle::solid);
let right_color = DeclaredValue::Initial; let right_color = DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial);
properties.push(PropertyDeclaration::BorderRightWidth(right_width)); properties.push(PropertyDeclaration::BorderRightWidth(right_width));
properties.push(PropertyDeclaration::BorderRightStyle(right_style)); properties.push(PropertyDeclaration::BorderRightStyle(right_style));
@ -476,7 +477,7 @@ mod shorthand_serialization {
let bottom_width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32))); let bottom_width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32)));
let bottom_style = DeclaredValue::Value(BorderStyle::solid); let bottom_style = DeclaredValue::Value(BorderStyle::solid);
let bottom_color = DeclaredValue::Initial; let bottom_color = DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial);
properties.push(PropertyDeclaration::BorderBottomWidth(bottom_width)); properties.push(PropertyDeclaration::BorderBottomWidth(bottom_width));
properties.push(PropertyDeclaration::BorderBottomStyle(bottom_style)); properties.push(PropertyDeclaration::BorderBottomStyle(bottom_style));
@ -484,7 +485,7 @@ mod shorthand_serialization {
let left_width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32))); let left_width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32)));
let left_style = DeclaredValue::Value(BorderStyle::solid); let left_style = DeclaredValue::Value(BorderStyle::solid);
let left_color = DeclaredValue::Initial; let left_color = DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial);
properties.push(PropertyDeclaration::BorderLeftWidth(left_width)); properties.push(PropertyDeclaration::BorderLeftWidth(left_width));
properties.push(PropertyDeclaration::BorderLeftStyle(left_style)); properties.push(PropertyDeclaration::BorderLeftStyle(left_style));
@ -522,8 +523,8 @@ mod shorthand_serialization {
fn list_style_should_show_all_properties_even_if_only_one_is_set() { fn list_style_should_show_all_properties_even_if_only_one_is_set() {
let mut properties = Vec::new(); let mut properties = Vec::new();
let position = DeclaredValue::Initial; let position = DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial);
let image = DeclaredValue::Initial; let image = DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial);
let style_type = DeclaredValue::Value(ListStyleType::disc); let style_type = DeclaredValue::Value(ListStyleType::disc);
properties.push(PropertyDeclaration::ListStylePosition(position)); properties.push(PropertyDeclaration::ListStylePosition(position));
@ -565,7 +566,7 @@ mod shorthand_serialization {
let width = DeclaredValue::Value(WidthContainer(Length::from_px(4f32))); let width = DeclaredValue::Value(WidthContainer(Length::from_px(4f32)));
let style = DeclaredValue::Value(Either::Second(BorderStyle::solid)); let style = DeclaredValue::Value(Either::Second(BorderStyle::solid));
let color = DeclaredValue::Initial; let color = DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial);
properties.push(PropertyDeclaration::OutlineWidth(width)); properties.push(PropertyDeclaration::OutlineWidth(width));
properties.push(PropertyDeclaration::OutlineStyle(style)); properties.push(PropertyDeclaration::OutlineStyle(style));
@ -580,7 +581,7 @@ mod shorthand_serialization {
let mut properties = Vec::new(); let mut properties = Vec::new();
let width = DeclaredValue::Value(WidthContainer(Length::from_px(4f32))); let width = DeclaredValue::Value(WidthContainer(Length::from_px(4f32)));
let style = DeclaredValue::Initial; let style = DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial);
let color = DeclaredValue::Value(CSSColor { let color = DeclaredValue::Value(CSSColor {
parsed: ComputedColor::RGBA(RGBA::new(255, 0, 0, 255)), parsed: ComputedColor::RGBA(RGBA::new(255, 0, 0, 255)),
authored: None authored: None

View file

@ -17,7 +17,8 @@ use style::error_reporting::ParseErrorReporter;
use style::keyframes::{Keyframe, KeyframeSelector, KeyframePercentage}; use style::keyframes::{Keyframe, KeyframeSelector, KeyframePercentage};
use style::parser::ParserContextExtraData; use style::parser::ParserContextExtraData;
use style::properties::Importance; use style::properties::Importance;
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, DeclaredValue, longhands}; use style::properties::{CSSWideKeyword, PropertyDeclaration, PropertyDeclarationBlock};
use style::properties::{DeclaredValue, longhands};
use style::properties::longhands::animation_play_state; use style::properties::longhands::animation_play_state;
use style::stylesheets::{Origin, Namespaces}; use style::stylesheets::{Origin, Namespaces};
use style::stylesheets::{Stylesheet, NamespaceRule, CssRule, CssRules, StyleRule, KeyframesRule}; use style::stylesheets::{Stylesheet, NamespaceRule, CssRule, CssRules, StyleRule, KeyframesRule};
@ -102,7 +103,8 @@ fn test_parse_stylesheet() {
(PropertyDeclaration::Display(DeclaredValue::Value( (PropertyDeclaration::Display(DeclaredValue::Value(
longhands::display::SpecifiedValue::none)), longhands::display::SpecifiedValue::none)),
Importance::Important), Importance::Important),
(PropertyDeclaration::Custom(Atom::from("a"), DeclaredValue::Inherit), (PropertyDeclaration::Custom(Atom::from("a"),
DeclaredValue::CSSWideKeyword(CSSWideKeyword::Inherit)),
Importance::Important), Importance::Important),
], ],
important_count: 2, important_count: 2,