style: Refactor querySelector to be generic over the query type, and implement a tree-walking variant of it.

Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
Emilio Cobos Álvarez 2017-10-22 01:19:26 +02:00
parent 4f997bf333
commit 2274fd7ef3
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 162 additions and 53 deletions

View file

@ -1620,21 +1620,19 @@ pub unsafe extern "C" fn Servo_SelectorList_QueryFirst(
selectors: RawServoSelectorListBorrowed,
) -> *const structs::RawGeckoElement {
use std::borrow::Borrow;
use style::dom_apis::{self, QuerySelectorResult, QuerySelectorKind};
use style::dom_apis::{self, QueryFirst};
let node = GeckoNode(node);
let selectors = ::selectors::SelectorList::from_ffi(selectors).borrow();
let mut result = QuerySelectorResult::new();
dom_apis::query_selector::<GeckoElement>(
let mut result = None;
dom_apis::query_selector::<GeckoElement, QueryFirst>(
node,
&selectors,
&mut result,
QuerySelectorKind::First,
node.owner_document_quirks_mode(),
);
result.first()
.map_or(ptr::null(), |e| e.0)
result.map_or(ptr::null(), |e| e.0)
}
#[no_mangle]