style: Optimize QuerySelector in shadow trees.

Pretty much the same setup we have for document.

We have the awkwardness of having to check containing shadow manually for
ShadowRoot because it's not available in TNode (and making it available added a
bit more complexity that wasn't worth it IMO).

Bug: 1464428
Reviewed-by: xidorn
MozReview-Commit-ID: CqOh0sLHf6o
This commit is contained in:
Emilio Cobos Álvarez 2018-05-25 16:56:41 +02:00
parent 82e97b8ec5
commit 38cbada278
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 103 additions and 42 deletions

View file

@ -135,14 +135,17 @@ pub trait TDocument: Sized + Copy + Clone {
fn quirks_mode(&self) -> QuirksMode;
/// Get a list of elements with a given ID in this document, sorted by
/// document position.
/// tree position.
///
/// Can return an error to signal that this list is not available, or also
/// return an empty slice.
fn elements_with_id(
fn elements_with_id<'a>(
&self,
_id: &Atom,
) -> Result<&[<Self::ConcreteNode as TNode>::ConcreteElement], ()> {
) -> Result<&'a [<Self::ConcreteNode as TNode>::ConcreteElement], ()>
where
Self: 'a,
{
Err(())
}
}
@ -342,6 +345,21 @@ pub trait TShadowRoot: Sized + Copy + Clone + PartialEq {
fn style_data<'a>(&self) -> &'a CascadeData
where
Self: 'a;
/// Get a list of elements with a given ID in this shadow root, sorted by
/// tree position.
///
/// Can return an error to signal that this list is not available, or also
/// return an empty slice.
fn elements_with_id<'a>(
&self,
_id: &Atom,
) -> Result<&'a [<Self::ConcreteNode as TNode>::ConcreteElement], ()>
where
Self: 'a,
{
Err(())
}
}
/// The element trait, the main abstraction the style crate acts over.