diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2016-08-25 17:04:29 +0200 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2016-08-31 02:34:03 +0200 |
commit | ef5977f059b8b5a61192647d753d6695e0929843 (patch) | |
tree | 723d427d7760b4a7c617dd20f2d9212f67639814 | |
parent | 94d5b28fe95bda5d8caa734e04f27b1d978d607c (diff) | |
download | servo-ef5977f059b8b5a61192647d753d6695e0929843.tar.gz servo-ef5977f059b8b5a61192647d753d6695e0929843.zip |
Wrap in Arc<_> every object reflected in CSSOM.
See https://bugzilla.mozilla.org/show_bug.cgi?id=1281962#c5
-rw-r--r-- | components/script/dom/htmlmetaelement.rs | 2 | ||||
-rw-r--r-- | components/style/keyframes.rs | 12 | ||||
-rw-r--r-- | components/style/stylesheets.rs | 45 | ||||
-rw-r--r-- | tests/unit/style/stylesheets.rs | 40 |
4 files changed, 50 insertions, 49 deletions
diff --git a/components/script/dom/htmlmetaelement.rs b/components/script/dom/htmlmetaelement.rs index b8c2cd423fa..e6f86f41d86 100644 --- a/components/script/dom/htmlmetaelement.rs +++ b/components/script/dom/htmlmetaelement.rs @@ -79,7 +79,7 @@ impl HTMLMetaElement { if !content.is_empty() { if let Some(translated_rule) = ViewportRule::from_meta(&**content) { *self.stylesheet.borrow_mut() = Some(Arc::new(Stylesheet { - rules: vec![CSSRule::Viewport(translated_rule)], + rules: vec![CSSRule::Viewport(Arc::new(translated_rule))], origin: Origin::Author, media: None, // Viewport constraints are always recomputed on resize; they don't need to diff --git a/components/style/keyframes.rs b/components/style/keyframes.rs index 56bf4607d4d..16620eccc3b 100644 --- a/components/style/keyframes.rs +++ b/components/style/keyframes.rs @@ -164,7 +164,7 @@ fn get_animated_properties(keyframe: &Keyframe) -> Vec<TransitionProperty> { } impl KeyframesAnimation { - pub fn from_keyframes(keyframes: &[Keyframe]) -> Option<Self> { + pub fn from_keyframes(keyframes: &[Arc<Keyframe>]) -> Option<Self> { if keyframes.is_empty() { return None; } @@ -216,7 +216,7 @@ struct KeyframeListParser<'a> { context: &'a ParserContext<'a>, } -pub fn parse_keyframe_list(context: &ParserContext, input: &mut Parser) -> Vec<Keyframe> { +pub fn parse_keyframe_list(context: &ParserContext, input: &mut Parser) -> Vec<Arc<Keyframe>> { RuleListParser::new_for_nested_rule(input, KeyframeListParser { context: context }) .filter_map(Result::ok) .collect() @@ -225,12 +225,12 @@ pub fn parse_keyframe_list(context: &ParserContext, input: &mut Parser) -> Vec<K enum Void {} impl<'a> AtRuleParser for KeyframeListParser<'a> { type Prelude = Void; - type AtRule = Keyframe; + type AtRule = Arc<Keyframe>; } impl<'a> QualifiedRuleParser for KeyframeListParser<'a> { type Prelude = KeyframeSelector; - type QualifiedRule = Keyframe; + type QualifiedRule = Arc<Keyframe>; fn parse_prelude(&self, input: &mut Parser) -> Result<Self::Prelude, ()> { let start = input.position(); @@ -263,10 +263,10 @@ impl<'a> QualifiedRuleParser for KeyframeListParser<'a> { } // `parse_important` is not called here, `!important` is not allowed in keyframe blocks. } - Ok(Keyframe { + Ok(Arc::new(Keyframe { selector: prelude, declarations: Arc::new(declarations), - }) + })) } } diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index 56566fd2e91..6c4f452f7d9 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -19,6 +19,7 @@ use smallvec::SmallVec; use std::cell::Cell; use std::iter::Iterator; use std::slice; +use std::sync::Arc; use string_cache::{Atom, Namespace}; use url::Url; use viewport::ViewportRule; @@ -67,12 +68,12 @@ pub enum CSSRule { // No Charset here, CSSCharsetRule has been removed from CSSOM // https://drafts.csswg.org/cssom/#changes-from-5-december-2013 - Namespace(NamespaceRule), - Style(StyleRule), - Media(MediaRule), - FontFace(FontFaceRule), - Viewport(ViewportRule), - Keyframes(KeyframesRule), + Namespace(Arc<NamespaceRule>), + Style(Arc<StyleRule>), + Media(Arc<MediaRule>), + FontFace(Arc<FontFaceRule>), + Viewport(Arc<ViewportRule>), + Keyframes(Arc<KeyframesRule>), } @@ -88,13 +89,13 @@ pub struct NamespaceRule { #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct KeyframesRule { pub name: Atom, - pub keyframes: Vec<Keyframe>, + pub keyframes: Vec<Arc<Keyframe>>, } #[derive(Debug, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct MediaRule { - pub media_queries: MediaQueryList, + pub media_queries: Arc<MediaQueryList>, pub rules: Vec<CSSRule>, } @@ -110,7 +111,7 @@ impl MediaRule { #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct StyleRule { pub selectors: Vec<Selector<TheSelectorImpl>>, - pub declarations: PropertyDeclarationBlock, + pub declarations: Arc<PropertyDeclarationBlock>, } @@ -414,7 +415,7 @@ enum AtRulePrelude { /// A @font-face rule prelude. FontFace, /// A @media rule prelude, with its media queries. - Media(MediaQueryList), + Media(Arc<MediaQueryList>), /// A @viewport rule prelude. Viewport, /// A @keyframes rule, with its animation name. @@ -444,10 +445,10 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> { let prefix = input.try(|input| input.expect_ident()).ok().map(|p| p.into()); let url = Namespace(Atom::from(try!(input.expect_url_or_string()))); - return Ok(AtRuleType::WithoutBlock(CSSRule::Namespace(NamespaceRule { + return Ok(AtRuleType::WithoutBlock(CSSRule::Namespace(Arc::new(NamespaceRule { prefix: prefix, url: url, - }))) + })))) } else { return Err(()) // "@namespace must be before any rule but @charset and @import" } @@ -501,7 +502,7 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> { match_ignore_ascii_case! { name, "media" => { let media_queries = parse_media_query_list(input); - Ok(AtRuleType::WithBlock(AtRulePrelude::Media(media_queries))) + Ok(AtRuleType::WithBlock(AtRulePrelude::Media(Arc::new(media_queries)))) }, "font-face" => { Ok(AtRuleType::WithBlock(AtRulePrelude::FontFace)) @@ -529,22 +530,22 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> { fn parse_block(&self, prelude: AtRulePrelude, input: &mut Parser) -> Result<CSSRule, ()> { match prelude { AtRulePrelude::FontFace => { - parse_font_face_block(self.context, input).map(CSSRule::FontFace) + Ok(CSSRule::FontFace(Arc::new(try!(parse_font_face_block(self.context, input))))) } AtRulePrelude::Media(media_queries) => { - Ok(CSSRule::Media(MediaRule { + Ok(CSSRule::Media(Arc::new(MediaRule { media_queries: media_queries, rules: parse_nested_rules(self.context, input), - })) + }))) } AtRulePrelude::Viewport => { - ViewportRule::parse(input, self.context).map(CSSRule::Viewport) + Ok(CSSRule::Viewport(Arc::new(try!(ViewportRule::parse(input, self.context))))) } AtRulePrelude::Keyframes(name) => { - Ok(CSSRule::Keyframes(KeyframesRule { + Ok(CSSRule::Keyframes(Arc::new(KeyframesRule { name: name, keyframes: parse_keyframe_list(&self.context, input), - })) + }))) } } } @@ -559,9 +560,9 @@ impl<'a, 'b> QualifiedRuleParser for NestedRuleParser<'a, 'b> { } fn parse_block(&self, prelude: Vec<Selector<TheSelectorImpl>>, input: &mut Parser) -> Result<CSSRule, ()> { - Ok(CSSRule::Style(StyleRule { + Ok(CSSRule::Style(Arc::new(StyleRule { selectors: prelude, - declarations: parse_property_declaration_list(self.context, input) - })) + declarations: Arc::new(parse_property_declaration_list(self.context, input)) + }))) } } diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs index 0b74df734e8..49eb451d7f7 100644 --- a/tests/unit/style/stylesheets.rs +++ b/tests/unit/style/stylesheets.rs @@ -65,11 +65,11 @@ fn test_parse_stylesheet() { media: None, dirty_on_viewport_size_change: false, rules: vec![ - CSSRule::Namespace(NamespaceRule { + CSSRule::Namespace(Arc::new(NamespaceRule { prefix: None, url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml")) - }), - CSSRule::Style(StyleRule { + })), + CSSRule::Style(Arc::new(StyleRule { selectors: vec![ Selector { complex_selector: Arc::new(ComplexSelector { @@ -97,7 +97,7 @@ fn test_parse_stylesheet() { specificity: (0 << 20) + (1 << 10) + (1 << 0), }, ], - declarations: PropertyDeclarationBlock { + declarations: Arc::new(PropertyDeclarationBlock { declarations: Arc::new(vec![ (PropertyDeclaration::Display(DeclaredValue::Value( longhands::display::SpecifiedValue::none)), @@ -106,9 +106,9 @@ fn test_parse_stylesheet() { Importance::Important), ]), important_count: 2, - }, - }), - CSSRule::Style(StyleRule { + }), + })), + CSSRule::Style(Arc::new(StyleRule { selectors: vec![ Selector { complex_selector: Arc::new(ComplexSelector { @@ -145,16 +145,16 @@ fn test_parse_stylesheet() { specificity: (0 << 20) + (0 << 10) + (1 << 0), }, ], - declarations: PropertyDeclarationBlock { + declarations: Arc::new(PropertyDeclarationBlock { declarations: Arc::new(vec![ (PropertyDeclaration::Display(DeclaredValue::Value( longhands::display::SpecifiedValue::block)), Importance::Normal), ]), important_count: 0, - }, - }), - CSSRule::Style(StyleRule { + }), + })), + CSSRule::Style(Arc::new(StyleRule { selectors: vec![ Selector { complex_selector: Arc::new(ComplexSelector { @@ -180,7 +180,7 @@ fn test_parse_stylesheet() { specificity: (1 << 20) + (1 << 10) + (0 << 0), }, ], - declarations: PropertyDeclarationBlock { + declarations: Arc::new(PropertyDeclarationBlock { declarations: Arc::new(vec![ (PropertyDeclaration::BackgroundColor(DeclaredValue::Value( longhands::background_color::SpecifiedValue { @@ -228,12 +228,12 @@ fn test_parse_stylesheet() { Importance::Normal), ]), important_count: 0, - }, - }), - CSSRule::Keyframes(KeyframesRule { + }), + })), + CSSRule::Keyframes(Arc::new(KeyframesRule { name: "foo".into(), keyframes: vec![ - Keyframe { + Arc::new(Keyframe { selector: KeyframeSelector::new_for_unit_testing( vec![KeyframePercentage::new(0.)]), declarations: Arc::new(vec![ @@ -241,8 +241,8 @@ fn test_parse_stylesheet() { LengthOrPercentageOrAuto::Percentage(Percentage(0.)))), Importance::Normal), ]), - }, - Keyframe { + }), + Arc::new(Keyframe { selector: KeyframeSelector::new_for_unit_testing( vec![KeyframePercentage::new(1.)]), declarations: Arc::new(vec![ @@ -254,9 +254,9 @@ fn test_parse_stylesheet() { vec![animation_play_state::SingleSpecifiedValue::running]))), Importance::Normal), ]), - }, + }), ] - }) + })) ], }); |