Use selectors::SelectorList

This commit is contained in:
Simon Sapin 2016-11-21 19:48:11 +01:00
parent 81a3de3299
commit f044659b7c
5 changed files with 19 additions and 35 deletions

View file

@ -71,7 +71,7 @@ use script_layout_interface::{LayoutElementType, LayoutNodeType, TrustedNodeAddr
use script_layout_interface::message::Msg;
use script_traits::UntrustedNodeAddress;
use selectors::matching::{MatchingReason, matches};
use selectors::parser::Selector;
use selectors::parser::SelectorList;
use servo_url::ServoUrl;
use std::borrow::ToOwned;
use std::cell::{Cell, UnsafeCell};
@ -304,12 +304,12 @@ impl Node {
}
pub struct QuerySelectorIterator {
selectors: Vec<Selector<SelectorImpl>>,
selectors: SelectorList<SelectorImpl>,
iterator: TreeIterator,
}
impl<'a> QuerySelectorIterator {
fn new(iter: TreeIterator, selectors: Vec<Selector<SelectorImpl>>)
fn new(iter: TreeIterator, selectors: SelectorList<SelectorImpl>)
-> QuerySelectorIterator {
QuerySelectorIterator {
selectors: selectors,
@ -322,7 +322,7 @@ impl<'a> Iterator for QuerySelectorIterator {
type Item = Root<Node>;
fn next(&mut self) -> Option<Root<Node>> {
let selectors = &self.selectors;
let selectors = &self.selectors.0;
// TODO(cgaebel): Is it worth it to build a bloom filter here
// (instead of passing `None`)? Probably.
self.iterator.by_ref().filter_map(|node| {
@ -716,7 +716,7 @@ impl Node {
let mut descendants = self.traverse_preorder();
// Skip the root of the tree.
assert!(&*descendants.next().unwrap() == self);
Ok(QuerySelectorIterator::new(descendants, selectors.0))
Ok(QuerySelectorIterator::new(descendants, selectors))
}
}
}

View file

@ -17,7 +17,7 @@ use parking_lot::RwLock;
use parser::{ParserContext, ParserContextExtraData, log_css_error};
use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
use selector_parser::{SelectorImpl, SelectorParser};
use selectors::parser::{Selector, SelectorList};
use selectors::parser::SelectorList;
use servo_url::ServoUrl;
use std::cell::Cell;
use std::fmt;
@ -196,30 +196,15 @@ impl ToCss for MediaRule {
#[derive(Debug)]
pub struct StyleRule {
pub selectors: Vec<Selector<SelectorImpl>>,
pub selectors: SelectorList<SelectorImpl>,
pub block: Arc<RwLock<PropertyDeclarationBlock>>,
}
impl StyleRule {
/// Serialize the group of selectors for this rule.
///
/// https://drafts.csswg.org/cssom/#serialize-a-group-of-selectors
pub fn selectors_to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let mut iter = self.selectors.iter();
try!(iter.next().unwrap().to_css(dest));
for selector in iter {
try!(write!(dest, ", "));
try!(selector.to_css(dest));
}
Ok(())
}
}
impl ToCss for StyleRule {
// https://drafts.csswg.org/cssom/#serialize-a-css-rule CSSStyleRule
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
// Step 1
try!(self.selectors_to_css(dest));
try!(self.selectors.to_css(dest));
// Step 2
try!(dest.write_str(" { "));
// Step 3
@ -582,7 +567,7 @@ impl<'a, 'b> QualifiedRuleParser for NestedRuleParser<'a, 'b> {
fn parse_block(&mut self, prelude: SelectorList<SelectorImpl>, input: &mut Parser)
-> Result<CssRule, ()> {
Ok(CssRule::Style(Arc::new(RwLock::new(StyleRule {
selectors: prelude.0,
selectors: prelude,
block: Arc::new(RwLock::new(parse_property_declaration_list(self.context, input)))
}))))
}

View file

@ -189,7 +189,7 @@ impl Stylist {
match *rule {
CssRule::Style(ref style_rule) => {
let guard = style_rule.read();
for selector in &guard.selectors {
for selector in &guard.selectors.0 {
let map = if let Some(ref pseudo) = selector.pseudo_element {
pseudos_map
.entry(pseudo.clone())
@ -208,7 +208,7 @@ impl Stylist {
}
*rules_source_order += 1;
for selector in &guard.selectors {
for selector in &guard.selectors.0 {
state_deps.note_selector(&selector.complex_selector);
if selector.affects_siblings() {
sibling_affecting_selectors.push(selector.clone());