mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Wrap in Arc<_> every object reflected in CSSOM.
See https://bugzilla.mozilla.org/show_bug.cgi?id=1281962#c5
This commit is contained in:
parent
94d5b28fe9
commit
ef5977f059
4 changed files with 50 additions and 49 deletions
|
@ -79,7 +79,7 @@ impl HTMLMetaElement {
|
||||||
if !content.is_empty() {
|
if !content.is_empty() {
|
||||||
if let Some(translated_rule) = ViewportRule::from_meta(&**content) {
|
if let Some(translated_rule) = ViewportRule::from_meta(&**content) {
|
||||||
*self.stylesheet.borrow_mut() = Some(Arc::new(Stylesheet {
|
*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,
|
origin: Origin::Author,
|
||||||
media: None,
|
media: None,
|
||||||
// Viewport constraints are always recomputed on resize; they don't need to
|
// Viewport constraints are always recomputed on resize; they don't need to
|
||||||
|
|
|
@ -164,7 +164,7 @@ fn get_animated_properties(keyframe: &Keyframe) -> Vec<TransitionProperty> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyframesAnimation {
|
impl KeyframesAnimation {
|
||||||
pub fn from_keyframes(keyframes: &[Keyframe]) -> Option<Self> {
|
pub fn from_keyframes(keyframes: &[Arc<Keyframe>]) -> Option<Self> {
|
||||||
if keyframes.is_empty() {
|
if keyframes.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ struct KeyframeListParser<'a> {
|
||||||
context: &'a ParserContext<'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 })
|
RuleListParser::new_for_nested_rule(input, KeyframeListParser { context: context })
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -225,12 +225,12 @@ pub fn parse_keyframe_list(context: &ParserContext, input: &mut Parser) -> Vec<K
|
||||||
enum Void {}
|
enum Void {}
|
||||||
impl<'a> AtRuleParser for KeyframeListParser<'a> {
|
impl<'a> AtRuleParser for KeyframeListParser<'a> {
|
||||||
type Prelude = Void;
|
type Prelude = Void;
|
||||||
type AtRule = Keyframe;
|
type AtRule = Arc<Keyframe>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> QualifiedRuleParser for KeyframeListParser<'a> {
|
impl<'a> QualifiedRuleParser for KeyframeListParser<'a> {
|
||||||
type Prelude = KeyframeSelector;
|
type Prelude = KeyframeSelector;
|
||||||
type QualifiedRule = Keyframe;
|
type QualifiedRule = Arc<Keyframe>;
|
||||||
|
|
||||||
fn parse_prelude(&self, input: &mut Parser) -> Result<Self::Prelude, ()> {
|
fn parse_prelude(&self, input: &mut Parser) -> Result<Self::Prelude, ()> {
|
||||||
let start = input.position();
|
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.
|
// `parse_important` is not called here, `!important` is not allowed in keyframe blocks.
|
||||||
}
|
}
|
||||||
Ok(Keyframe {
|
Ok(Arc::new(Keyframe {
|
||||||
selector: prelude,
|
selector: prelude,
|
||||||
declarations: Arc::new(declarations),
|
declarations: Arc::new(declarations),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ use smallvec::SmallVec;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
use std::sync::Arc;
|
||||||
use string_cache::{Atom, Namespace};
|
use string_cache::{Atom, Namespace};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use viewport::ViewportRule;
|
use viewport::ViewportRule;
|
||||||
|
@ -67,12 +68,12 @@ pub enum CSSRule {
|
||||||
// No Charset here, CSSCharsetRule has been removed from CSSOM
|
// No Charset here, CSSCharsetRule has been removed from CSSOM
|
||||||
// https://drafts.csswg.org/cssom/#changes-from-5-december-2013
|
// https://drafts.csswg.org/cssom/#changes-from-5-december-2013
|
||||||
|
|
||||||
Namespace(NamespaceRule),
|
Namespace(Arc<NamespaceRule>),
|
||||||
Style(StyleRule),
|
Style(Arc<StyleRule>),
|
||||||
Media(MediaRule),
|
Media(Arc<MediaRule>),
|
||||||
FontFace(FontFaceRule),
|
FontFace(Arc<FontFaceRule>),
|
||||||
Viewport(ViewportRule),
|
Viewport(Arc<ViewportRule>),
|
||||||
Keyframes(KeyframesRule),
|
Keyframes(Arc<KeyframesRule>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,13 +89,13 @@ pub struct NamespaceRule {
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub struct KeyframesRule {
|
pub struct KeyframesRule {
|
||||||
pub name: Atom,
|
pub name: Atom,
|
||||||
pub keyframes: Vec<Keyframe>,
|
pub keyframes: Vec<Arc<Keyframe>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub struct MediaRule {
|
pub struct MediaRule {
|
||||||
pub media_queries: MediaQueryList,
|
pub media_queries: Arc<MediaQueryList>,
|
||||||
pub rules: Vec<CSSRule>,
|
pub rules: Vec<CSSRule>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +111,7 @@ impl MediaRule {
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub struct StyleRule {
|
pub struct StyleRule {
|
||||||
pub selectors: Vec<Selector<TheSelectorImpl>>,
|
pub selectors: Vec<Selector<TheSelectorImpl>>,
|
||||||
pub declarations: PropertyDeclarationBlock,
|
pub declarations: Arc<PropertyDeclarationBlock>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -414,7 +415,7 @@ enum AtRulePrelude {
|
||||||
/// A @font-face rule prelude.
|
/// A @font-face rule prelude.
|
||||||
FontFace,
|
FontFace,
|
||||||
/// A @media rule prelude, with its media queries.
|
/// A @media rule prelude, with its media queries.
|
||||||
Media(MediaQueryList),
|
Media(Arc<MediaQueryList>),
|
||||||
/// A @viewport rule prelude.
|
/// A @viewport rule prelude.
|
||||||
Viewport,
|
Viewport,
|
||||||
/// A @keyframes rule, with its animation name.
|
/// 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 prefix = input.try(|input| input.expect_ident()).ok().map(|p| p.into());
|
||||||
let url = Namespace(Atom::from(try!(input.expect_url_or_string())));
|
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,
|
prefix: prefix,
|
||||||
url: url,
|
url: url,
|
||||||
})))
|
}))))
|
||||||
} else {
|
} else {
|
||||||
return Err(()) // "@namespace must be before any rule but @charset and @import"
|
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,
|
match_ignore_ascii_case! { name,
|
||||||
"media" => {
|
"media" => {
|
||||||
let media_queries = parse_media_query_list(input);
|
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" => {
|
"font-face" => {
|
||||||
Ok(AtRuleType::WithBlock(AtRulePrelude::FontFace))
|
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, ()> {
|
fn parse_block(&self, prelude: AtRulePrelude, input: &mut Parser) -> Result<CSSRule, ()> {
|
||||||
match prelude {
|
match prelude {
|
||||||
AtRulePrelude::FontFace => {
|
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) => {
|
AtRulePrelude::Media(media_queries) => {
|
||||||
Ok(CSSRule::Media(MediaRule {
|
Ok(CSSRule::Media(Arc::new(MediaRule {
|
||||||
media_queries: media_queries,
|
media_queries: media_queries,
|
||||||
rules: parse_nested_rules(self.context, input),
|
rules: parse_nested_rules(self.context, input),
|
||||||
}))
|
})))
|
||||||
}
|
}
|
||||||
AtRulePrelude::Viewport => {
|
AtRulePrelude::Viewport => {
|
||||||
ViewportRule::parse(input, self.context).map(CSSRule::Viewport)
|
Ok(CSSRule::Viewport(Arc::new(try!(ViewportRule::parse(input, self.context)))))
|
||||||
}
|
}
|
||||||
AtRulePrelude::Keyframes(name) => {
|
AtRulePrelude::Keyframes(name) => {
|
||||||
Ok(CSSRule::Keyframes(KeyframesRule {
|
Ok(CSSRule::Keyframes(Arc::new(KeyframesRule {
|
||||||
name: name,
|
name: name,
|
||||||
keyframes: parse_keyframe_list(&self.context, input),
|
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, ()> {
|
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,
|
selectors: prelude,
|
||||||
declarations: parse_property_declaration_list(self.context, input)
|
declarations: Arc::new(parse_property_declaration_list(self.context, input))
|
||||||
}))
|
})))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,11 +65,11 @@ fn test_parse_stylesheet() {
|
||||||
media: None,
|
media: None,
|
||||||
dirty_on_viewport_size_change: false,
|
dirty_on_viewport_size_change: false,
|
||||||
rules: vec![
|
rules: vec![
|
||||||
CSSRule::Namespace(NamespaceRule {
|
CSSRule::Namespace(Arc::new(NamespaceRule {
|
||||||
prefix: None,
|
prefix: None,
|
||||||
url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
|
url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
|
||||||
}),
|
})),
|
||||||
CSSRule::Style(StyleRule {
|
CSSRule::Style(Arc::new(StyleRule {
|
||||||
selectors: vec![
|
selectors: vec![
|
||||||
Selector {
|
Selector {
|
||||||
complex_selector: Arc::new(ComplexSelector {
|
complex_selector: Arc::new(ComplexSelector {
|
||||||
|
@ -97,7 +97,7 @@ fn test_parse_stylesheet() {
|
||||||
specificity: (0 << 20) + (1 << 10) + (1 << 0),
|
specificity: (0 << 20) + (1 << 10) + (1 << 0),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
declarations: PropertyDeclarationBlock {
|
declarations: Arc::new(PropertyDeclarationBlock {
|
||||||
declarations: Arc::new(vec![
|
declarations: Arc::new(vec![
|
||||||
(PropertyDeclaration::Display(DeclaredValue::Value(
|
(PropertyDeclaration::Display(DeclaredValue::Value(
|
||||||
longhands::display::SpecifiedValue::none)),
|
longhands::display::SpecifiedValue::none)),
|
||||||
|
@ -106,9 +106,9 @@ fn test_parse_stylesheet() {
|
||||||
Importance::Important),
|
Importance::Important),
|
||||||
]),
|
]),
|
||||||
important_count: 2,
|
important_count: 2,
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
CSSRule::Style(StyleRule {
|
})),
|
||||||
|
CSSRule::Style(Arc::new(StyleRule {
|
||||||
selectors: vec![
|
selectors: vec![
|
||||||
Selector {
|
Selector {
|
||||||
complex_selector: Arc::new(ComplexSelector {
|
complex_selector: Arc::new(ComplexSelector {
|
||||||
|
@ -145,16 +145,16 @@ fn test_parse_stylesheet() {
|
||||||
specificity: (0 << 20) + (0 << 10) + (1 << 0),
|
specificity: (0 << 20) + (0 << 10) + (1 << 0),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
declarations: PropertyDeclarationBlock {
|
declarations: Arc::new(PropertyDeclarationBlock {
|
||||||
declarations: Arc::new(vec![
|
declarations: Arc::new(vec![
|
||||||
(PropertyDeclaration::Display(DeclaredValue::Value(
|
(PropertyDeclaration::Display(DeclaredValue::Value(
|
||||||
longhands::display::SpecifiedValue::block)),
|
longhands::display::SpecifiedValue::block)),
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
]),
|
]),
|
||||||
important_count: 0,
|
important_count: 0,
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
CSSRule::Style(StyleRule {
|
})),
|
||||||
|
CSSRule::Style(Arc::new(StyleRule {
|
||||||
selectors: vec![
|
selectors: vec![
|
||||||
Selector {
|
Selector {
|
||||||
complex_selector: Arc::new(ComplexSelector {
|
complex_selector: Arc::new(ComplexSelector {
|
||||||
|
@ -180,7 +180,7 @@ fn test_parse_stylesheet() {
|
||||||
specificity: (1 << 20) + (1 << 10) + (0 << 0),
|
specificity: (1 << 20) + (1 << 10) + (0 << 0),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
declarations: PropertyDeclarationBlock {
|
declarations: Arc::new(PropertyDeclarationBlock {
|
||||||
declarations: Arc::new(vec![
|
declarations: Arc::new(vec![
|
||||||
(PropertyDeclaration::BackgroundColor(DeclaredValue::Value(
|
(PropertyDeclaration::BackgroundColor(DeclaredValue::Value(
|
||||||
longhands::background_color::SpecifiedValue {
|
longhands::background_color::SpecifiedValue {
|
||||||
|
@ -228,12 +228,12 @@ fn test_parse_stylesheet() {
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
]),
|
]),
|
||||||
important_count: 0,
|
important_count: 0,
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
CSSRule::Keyframes(KeyframesRule {
|
})),
|
||||||
|
CSSRule::Keyframes(Arc::new(KeyframesRule {
|
||||||
name: "foo".into(),
|
name: "foo".into(),
|
||||||
keyframes: vec![
|
keyframes: vec![
|
||||||
Keyframe {
|
Arc::new(Keyframe {
|
||||||
selector: KeyframeSelector::new_for_unit_testing(
|
selector: KeyframeSelector::new_for_unit_testing(
|
||||||
vec![KeyframePercentage::new(0.)]),
|
vec![KeyframePercentage::new(0.)]),
|
||||||
declarations: Arc::new(vec![
|
declarations: Arc::new(vec![
|
||||||
|
@ -241,8 +241,8 @@ fn test_parse_stylesheet() {
|
||||||
LengthOrPercentageOrAuto::Percentage(Percentage(0.)))),
|
LengthOrPercentageOrAuto::Percentage(Percentage(0.)))),
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
]),
|
]),
|
||||||
},
|
}),
|
||||||
Keyframe {
|
Arc::new(Keyframe {
|
||||||
selector: KeyframeSelector::new_for_unit_testing(
|
selector: KeyframeSelector::new_for_unit_testing(
|
||||||
vec![KeyframePercentage::new(1.)]),
|
vec![KeyframePercentage::new(1.)]),
|
||||||
declarations: Arc::new(vec![
|
declarations: Arc::new(vec![
|
||||||
|
@ -254,9 +254,9 @@ fn test_parse_stylesheet() {
|
||||||
vec![animation_play_state::SingleSpecifiedValue::running]))),
|
vec![animation_play_state::SingleSpecifiedValue::running]))),
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
]),
|
]),
|
||||||
},
|
}),
|
||||||
]
|
]
|
||||||
})
|
}))
|
||||||
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue