mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Arc all Vec<CSSRule>s, put in CSSRules type
This commit is contained in:
parent
ef74d8da3b
commit
2220fcdc0b
3 changed files with 18 additions and 10 deletions
|
@ -81,7 +81,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(Arc::new(RwLock::new(translated_rule)))],
|
rules: vec![CssRule::Viewport(Arc::new(RwLock::new(translated_rule)))].into(),
|
||||||
origin: Origin::Author,
|
origin: Origin::Author,
|
||||||
media: Default::default(),
|
media: Default::default(),
|
||||||
// Viewport constraints are always recomputed on resize; they don't need to
|
// Viewport constraints are always recomputed on resize; they don't need to
|
||||||
|
|
|
@ -380,7 +380,7 @@ impl Stylist {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mq_eval_changed(rules, before, after)
|
mq_eval_changed(&rules, before, after)
|
||||||
}) {
|
}) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,7 @@ impl Stylist {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
self.is_device_dirty |= stylesheets.iter().any(|stylesheet| {
|
self.is_device_dirty |= stylesheets.iter().any(|stylesheet| {
|
||||||
mq_eval_changed(&stylesheet.rules, &self.device, &device)
|
mq_eval_changed(&stylesheet.rules.0, &self.device, &device)
|
||||||
});
|
});
|
||||||
|
|
||||||
self.device = device;
|
self.device = device;
|
||||||
|
|
|
@ -39,12 +39,20 @@ pub enum Origin {
|
||||||
User,
|
User,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct CssRules(pub Arc<Vec<CssRule>>);
|
||||||
|
|
||||||
|
impl From<Vec<CssRule>> for CssRules {
|
||||||
|
fn from(other: Vec<CssRule>) -> Self {
|
||||||
|
CssRules(Arc::new(other))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Stylesheet {
|
pub struct Stylesheet {
|
||||||
/// List of rules in the order they were found (important for
|
/// List of rules in the order they were found (important for
|
||||||
/// cascading order)
|
/// cascading order)
|
||||||
pub rules: Vec<CssRule>,
|
pub rules: CssRules,
|
||||||
/// List of media associated with the Stylesheet.
|
/// List of media associated with the Stylesheet.
|
||||||
pub media: MediaList,
|
pub media: MediaList,
|
||||||
pub origin: Origin,
|
pub origin: Origin,
|
||||||
|
@ -89,7 +97,7 @@ impl CssRule {
|
||||||
CssRule::Media(ref lock) => {
|
CssRule::Media(ref lock) => {
|
||||||
let media_rule = lock.read();
|
let media_rule = lock.read();
|
||||||
let mq = media_rule.media_queries.read();
|
let mq = media_rule.media_queries.read();
|
||||||
f(&media_rule.rules, Some(&mq))
|
f(&media_rule.rules.0, Some(&mq))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +120,7 @@ pub struct KeyframesRule {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MediaRule {
|
pub struct MediaRule {
|
||||||
pub media_queries: Arc<RwLock<MediaList>>,
|
pub media_queries: Arc<RwLock<MediaList>>,
|
||||||
pub rules: Vec<CssRule>,
|
pub rules: CssRules,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -180,7 +188,7 @@ impl Stylesheet {
|
||||||
|
|
||||||
Stylesheet {
|
Stylesheet {
|
||||||
origin: origin,
|
origin: origin,
|
||||||
rules: rules,
|
rules: rules.into(),
|
||||||
media: Default::default(),
|
media: Default::default(),
|
||||||
dirty_on_viewport_size_change:
|
dirty_on_viewport_size_change:
|
||||||
input.seen_viewport_percentages(),
|
input.seen_viewport_percentages(),
|
||||||
|
@ -208,7 +216,7 @@ impl Stylesheet {
|
||||||
/// examined.
|
/// examined.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn effective_rules<F>(&self, device: &Device, mut f: F) where F: FnMut(&CssRule) {
|
pub fn effective_rules<F>(&self, device: &Device, mut f: F) where F: FnMut(&CssRule) {
|
||||||
effective_rules(&self.rules, device, &mut f);
|
effective_rules(&self.rules.0, device, &mut f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +259,7 @@ rule_filter! {
|
||||||
effective_keyframes_rules(Keyframes => KeyframesRule),
|
effective_keyframes_rules(Keyframes => KeyframesRule),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_nested_rules(context: &ParserContext, input: &mut Parser) -> Vec<CssRule> {
|
fn parse_nested_rules(context: &ParserContext, input: &mut Parser) -> CssRules {
|
||||||
let mut iter = RuleListParser::new_for_nested_rule(input,
|
let mut iter = RuleListParser::new_for_nested_rule(input,
|
||||||
NestedRuleParser { context: context });
|
NestedRuleParser { context: context });
|
||||||
let mut rules = Vec::new();
|
let mut rules = Vec::new();
|
||||||
|
@ -265,7 +273,7 @@ fn parse_nested_rules(context: &ParserContext, input: &mut Parser) -> Vec<CssRul
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rules
|
rules.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue