mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
stylo: Use stylo for Element::Closest.
Bug: 1407952 Reviewed-by: heycam MozReview-Commit-ID: 3H2piFT2CfF
This commit is contained in:
parent
ec00c660f0
commit
7fd2ac1704
1 changed files with 31 additions and 1 deletions
|
@ -6,7 +6,7 @@ use cssparser::{Parser, ParserInput};
|
|||
use cssparser::ToCss as ParserToCss;
|
||||
use env_logger::LogBuilder;
|
||||
use malloc_size_of::MallocSizeOfOps;
|
||||
use selectors::{self, Element};
|
||||
use selectors::{self, Element, NthIndexCache};
|
||||
use selectors::matching::{MatchingContext, MatchingMode, matches_selector};
|
||||
use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
|
||||
use std::cell::RefCell;
|
||||
|
@ -1520,6 +1520,36 @@ pub extern "C" fn Servo_StyleRule_SelectorMatchesElement(rule: RawServoStyleRule
|
|||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Servo_SelectorList_Closest<'a>(
|
||||
element: RawGeckoElementBorrowed<'a>,
|
||||
selectors: RawServoSelectorListBorrowed,
|
||||
) -> RawGeckoElementBorrowedOrNull<'a> {
|
||||
use std::borrow::Borrow;
|
||||
|
||||
let mut nth_index_cache = NthIndexCache::default();
|
||||
|
||||
let element = GeckoElement(element);
|
||||
let mut context = MatchingContext::new(
|
||||
MatchingMode::Normal,
|
||||
None,
|
||||
Some(&mut nth_index_cache),
|
||||
element.owner_document_quirks_mode(),
|
||||
);
|
||||
context.scope_element = Some(element.opaque());
|
||||
|
||||
let selectors = ::selectors::SelectorList::from_ffi(selectors).borrow();
|
||||
let mut current = Some(element);
|
||||
while let Some(element) = current.take() {
|
||||
if selectors::matching::matches_selector_list(&selectors, &element, &mut context) {
|
||||
return Some(element.0);
|
||||
}
|
||||
current = element.parent_element();
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Servo_SelectorList_Matches(
|
||||
element: RawGeckoElementBorrowed,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue