mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
style: Define a CascadeLevel enum, and make the rule tree operate on it.
We'll use this level to know where to stop replacing nodes in the tree.
This commit is contained in:
parent
31ecc9b692
commit
314f2ce714
6 changed files with 144 additions and 64 deletions
|
@ -11,7 +11,7 @@ use style::error_reporting::ParseErrorReporter;
|
|||
use style::media_queries::MediaList;
|
||||
use style::parser::ParserContextExtraData;
|
||||
use style::properties::{longhands, DeclaredValue, Importance, PropertyDeclaration, PropertyDeclarationBlock};
|
||||
use style::rule_tree::{RuleTree, StrongRuleNode, StyleSource};
|
||||
use style::rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource};
|
||||
use style::stylesheets::{Origin, Stylesheet, CssRule};
|
||||
use test::{self, Bencher};
|
||||
|
||||
|
@ -40,7 +40,7 @@ impl<'a> Drop for AutoGCRuleTree<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_rules(css: &str) -> Vec<(StyleSource, Importance)> {
|
||||
fn parse_rules(css: &str) -> Vec<(StyleSource, CascadeLevel)> {
|
||||
let s = Stylesheet::from_str(css,
|
||||
ServoUrl::parse("http://localhost").unwrap(),
|
||||
Origin::Author,
|
||||
|
@ -57,15 +57,15 @@ fn parse_rules(css: &str) -> Vec<(StyleSource, Importance)> {
|
|||
_ => None,
|
||||
}
|
||||
}).cloned().map(StyleSource::Style).map(|s| {
|
||||
(s, Importance::Normal)
|
||||
(s, CascadeLevel::UserNormal)
|
||||
}).collect()
|
||||
}
|
||||
|
||||
fn test_insertion(rule_tree: &RuleTree, rules: Vec<(StyleSource, Importance)>) -> StrongRuleNode {
|
||||
fn test_insertion(rule_tree: &RuleTree, rules: Vec<(StyleSource, CascadeLevel)>) -> StrongRuleNode {
|
||||
rule_tree.insert_ordered_rules(rules.into_iter())
|
||||
}
|
||||
|
||||
fn test_insertion_style_attribute(rule_tree: &RuleTree, rules: &[(StyleSource, Importance)]) -> StrongRuleNode {
|
||||
fn test_insertion_style_attribute(rule_tree: &RuleTree, rules: &[(StyleSource, CascadeLevel)]) -> StrongRuleNode {
|
||||
let mut rules = rules.to_vec();
|
||||
rules.push((StyleSource::Declarations(Arc::new(RwLock::new(PropertyDeclarationBlock {
|
||||
declarations: vec![
|
||||
|
@ -74,7 +74,7 @@ fn test_insertion_style_attribute(rule_tree: &RuleTree, rules: &[(StyleSource, I
|
|||
Importance::Normal),
|
||||
],
|
||||
important_count: 0,
|
||||
}))), Importance::Normal));
|
||||
}))), CascadeLevel::UserNormal));
|
||||
test_insertion(rule_tree, rules)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ use servo_atoms::Atom;
|
|||
use std::sync::Arc;
|
||||
use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, DeclaredValue};
|
||||
use style::properties::{longhands, Importance};
|
||||
use style::rule_tree::CascadeLevel;
|
||||
use style::selector_parser::SelectorParser;
|
||||
use style::stylesheets::StyleRule;
|
||||
use style::stylist::{Rule, SelectorMap};
|
||||
|
@ -113,7 +114,9 @@ fn test_get_universal_rules() {
|
|||
let map = get_mock_map(&["*|*", "#foo > *|*", ".klass", "#id"]);
|
||||
let mut decls = vec![];
|
||||
|
||||
map.get_universal_rules(&mut decls);
|
||||
map.get_universal_rules(&mut decls,
|
||||
CascadeLevel::UserNormal,
|
||||
CascadeLevel::UserImportant);
|
||||
|
||||
assert_eq!(decls.len(), 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue