mirror of
https://github.com/servo/servo.git
synced 2025-06-14 03:14:29 +00:00
Support :scope pseudo-class in Element::{matches,closest} in Servo
This commit is contained in:
parent
ba44d18ddb
commit
0564a1e47b
1 changed files with 7 additions and 2 deletions
|
@ -87,6 +87,7 @@ use net_traits::request::CorsSettings;
|
||||||
use ref_filter_map::ref_filter_map;
|
use ref_filter_map::ref_filter_map;
|
||||||
use script_layout_interface::message::ReflowGoal;
|
use script_layout_interface::message::ReflowGoal;
|
||||||
use script_thread::ScriptThread;
|
use script_thread::ScriptThread;
|
||||||
|
use selectors::Element as SelectorsElement;
|
||||||
use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
|
use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
|
||||||
use selectors::matching::{ElementSelectorFlags, LocalMatchingContext, MatchingContext, MatchingMode};
|
use selectors::matching::{ElementSelectorFlags, LocalMatchingContext, MatchingContext, MatchingMode};
|
||||||
use selectors::matching::{HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS};
|
use selectors::matching::{HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS};
|
||||||
|
@ -2188,10 +2189,12 @@ impl ElementMethods for Element {
|
||||||
Err(_) => Err(Error::Syntax),
|
Err(_) => Err(Error::Syntax),
|
||||||
Ok(selectors) => {
|
Ok(selectors) => {
|
||||||
let quirks_mode = document_from_node(self).quirks_mode();
|
let quirks_mode = document_from_node(self).quirks_mode();
|
||||||
|
let root = DomRoot::from_ref(self);
|
||||||
// FIXME(bholley): Consider an nth-index cache here.
|
// FIXME(bholley): Consider an nth-index cache here.
|
||||||
let mut ctx = MatchingContext::new(MatchingMode::Normal, None, None,
|
let mut ctx = MatchingContext::new(MatchingMode::Normal, None, None,
|
||||||
quirks_mode);
|
quirks_mode);
|
||||||
Ok(matches_selector_list(&selectors, &DomRoot::from_ref(self), &mut ctx))
|
ctx.scope_element = Some(root.opaque());
|
||||||
|
Ok(matches_selector_list(&selectors, &root, &mut ctx))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2206,6 +2209,7 @@ impl ElementMethods for Element {
|
||||||
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
|
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
|
||||||
Err(_) => Err(Error::Syntax),
|
Err(_) => Err(Error::Syntax),
|
||||||
Ok(selectors) => {
|
Ok(selectors) => {
|
||||||
|
let self_root = DomRoot::from_ref(self);
|
||||||
let root = self.upcast::<Node>();
|
let root = self.upcast::<Node>();
|
||||||
for element in root.inclusive_ancestors() {
|
for element in root.inclusive_ancestors() {
|
||||||
if let Some(element) = DomRoot::downcast::<Element>(element) {
|
if let Some(element) = DomRoot::downcast::<Element>(element) {
|
||||||
|
@ -2213,6 +2217,7 @@ impl ElementMethods for Element {
|
||||||
// FIXME(bholley): Consider an nth-index cache here.
|
// FIXME(bholley): Consider an nth-index cache here.
|
||||||
let mut ctx = MatchingContext::new(MatchingMode::Normal, None, None,
|
let mut ctx = MatchingContext::new(MatchingMode::Normal, None, None,
|
||||||
quirks_mode);
|
quirks_mode);
|
||||||
|
ctx.scope_element = Some(self_root.opaque());
|
||||||
if matches_selector_list(&selectors, &element, &mut ctx) {
|
if matches_selector_list(&selectors, &element, &mut ctx) {
|
||||||
return Ok(Some(element));
|
return Ok(Some(element));
|
||||||
}
|
}
|
||||||
|
@ -2497,7 +2502,7 @@ impl VirtualMethods for Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ::selectors::Element for DomRoot<Element> {
|
impl<'a> SelectorsElement for DomRoot<Element> {
|
||||||
type Impl = SelectorImpl;
|
type Impl = SelectorImpl;
|
||||||
|
|
||||||
fn opaque(&self) -> ::selectors::OpaqueElement {
|
fn opaque(&self) -> ::selectors::OpaqueElement {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue