style: Share code for Element::Matches.

This commit is contained in:
Emilio Cobos Álvarez 2017-10-13 12:50:38 +02:00
parent 085a0db056
commit 9e6c49d479
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
4 changed files with 47 additions and 21 deletions

View file

@ -107,6 +107,7 @@ use style::CaseSensitivityExt;
use style::applicable_declarations::ApplicableDeclarationBlock;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
use style::context::QuirksMode;
use style::dom_apis;
use style::element_state::*;
use style::invalidation::element::restyle_hints::RESTYLE_SELF;
use style::properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
@ -2197,18 +2198,16 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-matches
fn Matches(&self, selectors: DOMString) -> Fallible<bool> {
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
Err(_) => Err(Error::Syntax),
Ok(selectors) => {
let quirks_mode = document_from_node(self).quirks_mode();
let root = DomRoot::from_ref(self);
// FIXME(bholley): Consider an nth-index cache here.
let mut ctx = MatchingContext::new(MatchingMode::Normal, None, None,
quirks_mode);
ctx.scope_element = Some(root.opaque());
Ok(matches_selector_list(&selectors, &root, &mut ctx))
}
}
let selectors =
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
Err(_) => return Err(Error::Syntax),
Ok(selectors) => selectors,
};
let quirks_mode = document_from_node(self).quirks_mode();
let element = DomRoot::from_ref(self);
Ok(dom_apis::element_matches(&element, &selectors, quirks_mode))
}
// https://dom.spec.whatwg.org/#dom-element-webkitmatchesselector