mirror of
https://github.com/servo/servo.git
synced 2025-08-18 11:55:39 +01:00
Merge normal and important declarations in style rules.
Have a single Vec instead of two. Fix #3426
This commit is contained in:
parent
577d2dc3fa
commit
16bbc2f26e
11 changed files with 248 additions and 221 deletions
|
@ -40,10 +40,10 @@ macro_rules! sizeof_checker (
|
|||
// Update the sizes here
|
||||
sizeof_checker!(size_event_target, EventTarget, 40);
|
||||
sizeof_checker!(size_node, Node, 160);
|
||||
sizeof_checker!(size_element, Element, 336);
|
||||
sizeof_checker!(size_htmlelement, HTMLElement, 352);
|
||||
sizeof_checker!(size_div, HTMLDivElement, 352);
|
||||
sizeof_checker!(size_span, HTMLSpanElement, 352);
|
||||
sizeof_checker!(size_element, Element, 328);
|
||||
sizeof_checker!(size_htmlelement, HTMLElement, 344);
|
||||
sizeof_checker!(size_div, HTMLDivElement, 344);
|
||||
sizeof_checker!(size_span, HTMLSpanElement, 344);
|
||||
sizeof_checker!(size_text, Text, 192);
|
||||
sizeof_checker!(size_characterdata, CharacterData, 192);
|
||||
sizeof_checker!(size_servothreadsafelayoutnode, ServoThreadSafeLayoutNode, 16);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
pub use cssparser::ToCss;
|
||||
pub use std::sync::Arc;
|
||||
pub use style::computed_values::display::T::inline_block;
|
||||
pub use style::properties::{DeclaredValue, PropertyDeclaration, PropertyDeclarationBlock};
|
||||
pub use style::properties::{DeclaredValue, PropertyDeclaration, PropertyDeclarationBlock, Importance};
|
||||
pub use style::values::specified::{BorderStyle, CSSColor, Length};
|
||||
pub use style::values::specified::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrAutoOrContent};
|
||||
pub use style::properties::longhands::outline_color::computed_value::T as ComputedColor;
|
||||
|
@ -18,37 +18,41 @@ fn property_declaration_block_should_serialize_correctly() {
|
|||
use style::properties::longhands::overflow_x::computed_value::T as OverflowXValue;
|
||||
use style::properties::longhands::overflow_y::computed_value::T as OverflowYContainer;
|
||||
|
||||
let mut normal = Vec::new();
|
||||
let mut important = Vec::new();
|
||||
let declarations = vec![
|
||||
(PropertyDeclaration::Width(
|
||||
DeclaredValue::Value(LengthOrPercentageOrAuto::Length(Length::from_px(70f32)))),
|
||||
Importance::Normal),
|
||||
|
||||
let length = DeclaredValue::Value(LengthOrPercentageOrAuto::Length(Length::from_px(70f32)));
|
||||
normal.push(PropertyDeclaration::Width(length));
|
||||
(PropertyDeclaration::MinHeight(
|
||||
DeclaredValue::Value(LengthOrPercentage::Length(Length::from_px(20f32)))),
|
||||
Importance::Normal),
|
||||
|
||||
let min_height = DeclaredValue::Value(LengthOrPercentage::Length(Length::from_px(20f32)));
|
||||
normal.push(PropertyDeclaration::MinHeight(min_height));
|
||||
(PropertyDeclaration::Height(
|
||||
DeclaredValue::Value(LengthOrPercentageOrAuto::Length(Length::from_px(20f32)))),
|
||||
Importance::Important),
|
||||
|
||||
let value = DeclaredValue::Value(inline_block);
|
||||
normal.push(PropertyDeclaration::Display(value));
|
||||
(PropertyDeclaration::Display(
|
||||
DeclaredValue::Value(inline_block)),
|
||||
Importance::Normal),
|
||||
|
||||
let overflow_x = DeclaredValue::Value(OverflowXValue::auto);
|
||||
normal.push(PropertyDeclaration::OverflowX(overflow_x));
|
||||
(PropertyDeclaration::OverflowX(
|
||||
DeclaredValue::Value(OverflowXValue::auto)),
|
||||
Importance::Normal),
|
||||
|
||||
let overflow_y = DeclaredValue::Value(OverflowYContainer(OverflowXValue::auto));
|
||||
normal.push(PropertyDeclaration::OverflowY(overflow_y));
|
||||
|
||||
let height = DeclaredValue::Value(LengthOrPercentageOrAuto::Length(Length::from_px(20f32)));
|
||||
important.push(PropertyDeclaration::Height(height));
|
||||
(PropertyDeclaration::OverflowY(
|
||||
DeclaredValue::Value(OverflowYContainer(OverflowXValue::auto))),
|
||||
Importance::Normal),
|
||||
];
|
||||
|
||||
let block = PropertyDeclarationBlock {
|
||||
normal: Arc::new(normal),
|
||||
important: Arc::new(important)
|
||||
declarations: Arc::new(declarations),
|
||||
};
|
||||
|
||||
let css_string = block.to_css_string();
|
||||
|
||||
assert_eq!(
|
||||
css_string,
|
||||
"width: 70px; min-height: 20px; display: inline-block; overflow: auto; height: 20px !important;"
|
||||
"width: 70px; min-height: 20px; height: 20px !important; display: inline-block; overflow: auto;"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -57,8 +61,7 @@ mod shorthand_serialization {
|
|||
|
||||
pub fn shorthand_properties_to_string(properties: Vec<PropertyDeclaration>) -> String {
|
||||
let block = PropertyDeclarationBlock {
|
||||
normal: Arc::new(properties),
|
||||
important: Arc::new(Vec::new())
|
||||
declarations: Arc::new(properties.into_iter().map(|d| (d, Importance::Normal)).collect()),
|
||||
};
|
||||
|
||||
block.to_css_string()
|
||||
|
|
|
@ -13,6 +13,7 @@ use style::error_reporting::ParseErrorReporter;
|
|||
use style::keyframes::{Keyframe, KeyframeSelector, KeyframePercentage};
|
||||
use style::parser::ParserContextExtraData;
|
||||
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, DeclaredValue, longhands};
|
||||
use style::properties::Importance;
|
||||
use style::properties::longhands::animation_play_state;
|
||||
use style::stylesheets::{Stylesheet, CSSRule, StyleRule, KeyframesRule, Origin};
|
||||
use style::values::specified::{LengthOrPercentageOrAuto, Percentage};
|
||||
|
@ -87,10 +88,10 @@ fn test_parse_stylesheet() {
|
|||
},
|
||||
],
|
||||
declarations: PropertyDeclarationBlock {
|
||||
normal: Arc::new(vec![]),
|
||||
important: Arc::new(vec![
|
||||
PropertyDeclaration::Display(DeclaredValue::Value(
|
||||
declarations: Arc::new(vec![
|
||||
(PropertyDeclaration::Display(DeclaredValue::Value(
|
||||
longhands::display::SpecifiedValue::none)),
|
||||
Importance::Important),
|
||||
]),
|
||||
},
|
||||
}),
|
||||
|
@ -132,11 +133,11 @@ fn test_parse_stylesheet() {
|
|||
},
|
||||
],
|
||||
declarations: PropertyDeclarationBlock {
|
||||
normal: Arc::new(vec![
|
||||
PropertyDeclaration::Display(DeclaredValue::Value(
|
||||
declarations: Arc::new(vec![
|
||||
(PropertyDeclaration::Display(DeclaredValue::Value(
|
||||
longhands::display::SpecifiedValue::block)),
|
||||
Importance::Normal),
|
||||
]),
|
||||
important: Arc::new(vec![]),
|
||||
},
|
||||
}),
|
||||
CSSRule::Style(StyleRule {
|
||||
|
@ -166,24 +167,31 @@ fn test_parse_stylesheet() {
|
|||
},
|
||||
],
|
||||
declarations: PropertyDeclarationBlock {
|
||||
normal: Arc::new(vec![
|
||||
PropertyDeclaration::BackgroundColor(DeclaredValue::Value(
|
||||
declarations: Arc::new(vec![
|
||||
(PropertyDeclaration::BackgroundColor(DeclaredValue::Value(
|
||||
longhands::background_color::SpecifiedValue {
|
||||
authored: Some("blue".to_owned()),
|
||||
parsed: cssparser::Color::RGBA(cssparser::RGBA {
|
||||
red: 0., green: 0., blue: 1., alpha: 1.
|
||||
}),
|
||||
}
|
||||
)),
|
||||
PropertyDeclaration::BackgroundPosition(DeclaredValue::Initial),
|
||||
PropertyDeclaration::BackgroundRepeat(DeclaredValue::Initial),
|
||||
PropertyDeclaration::BackgroundAttachment(DeclaredValue::Initial),
|
||||
PropertyDeclaration::BackgroundImage(DeclaredValue::Initial),
|
||||
PropertyDeclaration::BackgroundSize(DeclaredValue::Initial),
|
||||
PropertyDeclaration::BackgroundOrigin(DeclaredValue::Initial),
|
||||
PropertyDeclaration::BackgroundClip(DeclaredValue::Initial),
|
||||
)),
|
||||
Importance::Normal),
|
||||
(PropertyDeclaration::BackgroundPosition(DeclaredValue::Initial),
|
||||
Importance::Normal),
|
||||
(PropertyDeclaration::BackgroundRepeat(DeclaredValue::Initial),
|
||||
Importance::Normal),
|
||||
(PropertyDeclaration::BackgroundAttachment(DeclaredValue::Initial),
|
||||
Importance::Normal),
|
||||
(PropertyDeclaration::BackgroundImage(DeclaredValue::Initial),
|
||||
Importance::Normal),
|
||||
(PropertyDeclaration::BackgroundSize(DeclaredValue::Initial),
|
||||
Importance::Normal),
|
||||
(PropertyDeclaration::BackgroundOrigin(DeclaredValue::Initial),
|
||||
Importance::Normal),
|
||||
(PropertyDeclaration::BackgroundClip(DeclaredValue::Initial),
|
||||
Importance::Normal),
|
||||
]),
|
||||
important: Arc::new(vec![]),
|
||||
},
|
||||
}),
|
||||
CSSRule::Keyframes(KeyframesRule {
|
||||
|
@ -193,19 +201,22 @@ fn test_parse_stylesheet() {
|
|||
selector: KeyframeSelector::new_for_unit_testing(
|
||||
vec![KeyframePercentage::new(0.)]),
|
||||
declarations: Arc::new(vec![
|
||||
PropertyDeclaration::Width(DeclaredValue::Value(
|
||||
(PropertyDeclaration::Width(DeclaredValue::Value(
|
||||
LengthOrPercentageOrAuto::Percentage(Percentage(0.)))),
|
||||
Importance::Normal),
|
||||
]),
|
||||
},
|
||||
Keyframe {
|
||||
selector: KeyframeSelector::new_for_unit_testing(
|
||||
vec![KeyframePercentage::new(1.)]),
|
||||
declarations: Arc::new(vec![
|
||||
PropertyDeclaration::Width(DeclaredValue::Value(
|
||||
(PropertyDeclaration::Width(DeclaredValue::Value(
|
||||
LengthOrPercentageOrAuto::Percentage(Percentage(1.)))),
|
||||
PropertyDeclaration::AnimationPlayState(DeclaredValue::Value(
|
||||
Importance::Normal),
|
||||
(PropertyDeclaration::AnimationPlayState(DeclaredValue::Value(
|
||||
animation_play_state::SpecifiedValue(
|
||||
vec![animation_play_state::SingleSpecifiedValue::running]))),
|
||||
Importance::Normal),
|
||||
]),
|
||||
},
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue