mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Share code for Element::Matches.
This commit is contained in:
parent
085a0db056
commit
9e6c49d479
4 changed files with 47 additions and 21 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue