Update to selectors 0.15

This commit is contained in:
Simon Sapin 2016-11-21 19:11:35 +01:00
parent a89ba50180
commit 82b13d50e3
21 changed files with 215 additions and 146 deletions

View file

@ -66,7 +66,7 @@ regex = "0.1.43"
rustc-serialize = "0.3"
script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
selectors = "0.14"
selectors = "0.15"
serde = "0.8"
servo_atoms = {path = "../atoms"}
servo_url = {path = "../url", features = ["servo"] }

View file

@ -73,7 +73,7 @@ use html5ever_atoms::{Prefix, LocalName, Namespace, QualName};
use parking_lot::RwLock;
use selectors::matching::{ElementFlags, MatchingReason, matches};
use selectors::matching::{HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS};
use selectors::parser::{AttrSelector, NamespaceConstraint, parse_author_origin_selector_list_from_str};
use selectors::parser::{AttrSelector, NamespaceConstraint};
use servo_atoms::Atom;
use std::ascii::AsciiExt;
use std::borrow::Cow;
@ -92,7 +92,7 @@ use style::properties::{DeclaredValue, Importance};
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
use style::properties::longhands::{background_image, border_spacing, font_family, font_size, overflow_x};
use style::restyle_hints::RESTYLE_SELF;
use style::selector_parser::{NonTSPseudoClass, RestyleDamage, ServoSelectorImpl};
use style::selector_parser::{NonTSPseudoClass, RestyleDamage, ServoSelectorImpl, SelectorParser};
use style::sink::Push;
use style::stylist::ApplicableDeclarationBlock;
use style::values::CSSFloat;
@ -1885,10 +1885,10 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-matches
fn Matches(&self, selectors: DOMString) -> Fallible<bool> {
match parse_author_origin_selector_list_from_str(&selectors) {
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
Err(()) => Err(Error::Syntax),
Ok(ref selectors) => {
Ok(matches(selectors, &Root::from_ref(self), None, MatchingReason::Other))
Ok(selectors) => {
Ok(matches(&selectors.0, &Root::from_ref(self), None, MatchingReason::Other))
}
}
}
@ -1900,13 +1900,13 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-closest
fn Closest(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
match parse_author_origin_selector_list_from_str(&selectors) {
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
Err(()) => Err(Error::Syntax),
Ok(ref selectors) => {
Ok(selectors) => {
let root = self.upcast::<Node>();
for element in root.inclusive_ancestors() {
if let Some(element) = Root::downcast::<Element>(element) {
if matches(selectors, &element, None, MatchingReason::Other) {
if matches(&selectors.0, &element, None, MatchingReason::Other) {
return Ok(Some(element));
}
}

View file

@ -72,7 +72,6 @@ use script_layout_interface::message::Msg;
use script_traits::UntrustedNodeAddress;
use selectors::matching::{MatchingReason, matches};
use selectors::parser::Selector;
use selectors::parser::parse_author_origin_selector_list_from_str;
use servo_url::ServoUrl;
use std::borrow::ToOwned;
use std::cell::{Cell, UnsafeCell};
@ -83,7 +82,7 @@ use std::mem;
use std::ops::Range;
use std::sync::Arc;
use style::dom::OpaqueNode;
use style::selector_parser::ServoSelectorImpl;
use style::selector_parser::{ServoSelectorImpl, SelectorParser};
use style::stylesheets::Stylesheet;
use style::thread_state;
use uuid::Uuid;
@ -690,13 +689,13 @@ impl Node {
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
pub fn query_selector(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
// Step 1.
match parse_author_origin_selector_list_from_str(&selectors) {
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
// Step 2.
Err(()) => Err(Error::Syntax),
// Step 3.
Ok(ref selectors) => {
Ok(selectors) => {
Ok(self.traverse_preorder().filter_map(Root::downcast).find(|element| {
matches(selectors, element, None, MatchingReason::Other)
matches(&selectors.0, element, None, MatchingReason::Other)
}))
}
}
@ -709,7 +708,7 @@ impl Node {
pub fn query_selector_iter(&self, selectors: DOMString)
-> Fallible<QuerySelectorIterator> {
// Step 1.
match parse_author_origin_selector_list_from_str(&selectors) {
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
// Step 2.
Err(()) => Err(Error::Syntax),
// Step 3.
@ -717,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))
Ok(QuerySelectorIterator::new(descendants, selectors.0))
}
}
}