mirror of
https://github.com/servo/servo.git
synced 2025-08-11 00:15:32 +01:00
style: Share code for Element::Closest.
This commit is contained in:
parent
9e6c49d479
commit
f64f8b8be2
3 changed files with 47 additions and 40 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, NthIndexCache};
|
||||
use selectors::Element;
|
||||
use selectors::matching::{MatchingContext, MatchingMode, matches_selector};
|
||||
use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
|
||||
use std::cell::RefCell;
|
||||
|
@ -1526,28 +1526,13 @@ pub unsafe extern "C" fn Servo_SelectorList_Closest<'a>(
|
|||
selectors: RawServoSelectorListBorrowed,
|
||||
) -> RawGeckoElementBorrowedOrNull<'a> {
|
||||
use std::borrow::Borrow;
|
||||
|
||||
let mut nth_index_cache = NthIndexCache::default();
|
||||
use style::dom_apis;
|
||||
|
||||
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;
|
||||
dom_apis::element_closest(element, &selectors, element.owner_document_quirks_mode())
|
||||
.map(|e| e.0)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue