mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Auto merge of #18862 - emilio:stylo-element-closest, r=heycam
stylo: Use stylo for Element::Closest. Bug: 1407952 Reviewed-by: heycam MozReview-Commit-ID: 3H2piFT2CfF <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18862) <!-- Reviewable:end -->
This commit is contained in:
commit
20855c2304
1 changed files with 31 additions and 1 deletions
|
@ -6,7 +6,7 @@ use cssparser::{Parser, ParserInput};
|
||||||
use cssparser::ToCss as ParserToCss;
|
use cssparser::ToCss as ParserToCss;
|
||||||
use env_logger::LogBuilder;
|
use env_logger::LogBuilder;
|
||||||
use malloc_size_of::MallocSizeOfOps;
|
use malloc_size_of::MallocSizeOfOps;
|
||||||
use selectors::{self, Element};
|
use selectors::{self, Element, NthIndexCache};
|
||||||
use selectors::matching::{MatchingContext, MatchingMode, matches_selector};
|
use selectors::matching::{MatchingContext, MatchingMode, matches_selector};
|
||||||
use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
|
use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
|
||||||
use std::cell::RefCell;
|
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]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn Servo_SelectorList_Matches(
|
pub unsafe extern "C" fn Servo_SelectorList_Matches(
|
||||||
element: RawGeckoElementBorrowed,
|
element: RawGeckoElementBorrowed,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue