Auto merge of #13202 - emilio:rule-tree, r=SimonSapin,Manishearth,emilio

Rule tree, v1

<!-- Please describe your changes on the following line: -->
---

<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] There are tests for these changes OR

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

This patch introduces infrastructure for the rule tree, and constructs it.

We don't use it yet, nor have good heuristics for GC'ing it, but this should not
happen anymore once we store the rule node reference in the node.

I haven't messed up with memory orders because I want to do a try run with it,
then mess with them.

<!-- Reviewable:start -->
---

This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13202)

<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-11-05 17:11:24 -05:00 committed by GitHub
commit ac0475971b
21 changed files with 931 additions and 553 deletions

View file

@ -11,6 +11,7 @@ use std::sync::Arc;
use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, DeclaredValue};
use style::properties::{longhands, Importance};
use style::selector_matching::{Rule, SelectorMap};
use style::stylesheets::StyleRule;
use style::thread_state;
/// Helper method to get some Rules from selector strings.
@ -18,18 +19,26 @@ use style::thread_state;
fn get_mock_rules(css_selectors: &[&str]) -> Vec<Vec<Rule>> {
css_selectors.iter().enumerate().map(|(i, selectors)| {
let context = ParserContext::new();
parse_selector_list(&context, &mut Parser::new(*selectors))
.unwrap().into_iter().map(|s| {
let selectors =
parse_selector_list(&context, &mut Parser::new(*selectors)).unwrap();
let rule = Arc::new(RwLock::new(StyleRule {
selectors: selectors,
block: Arc::new(RwLock::new(PropertyDeclarationBlock {
declarations: vec![
(PropertyDeclaration::Display(DeclaredValue::Value(
longhands::display::SpecifiedValue::block)),
Importance::Normal),
],
important_count: 0,
})),
}));
let guard = rule.read();
guard.selectors.iter().map(|s| {
Rule {
selector: s.complex_selector.clone(),
declarations: Arc::new(RwLock::new(PropertyDeclarationBlock {
declarations: vec![
(PropertyDeclaration::Display(DeclaredValue::Value(
longhands::display::SpecifiedValue::block)),
Importance::Normal),
],
important_count: 0,
})),
style_rule: rule.clone(),
specificity: s.specificity,
source_order: i,
}