style: Add infrastructure to match :host.

This commit is contained in:
Emilio Cobos Álvarez 2018-03-08 22:03:42 +01:00
parent 1654f297ca
commit 9fa2618197
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
9 changed files with 159 additions and 41 deletions

View file

@ -274,6 +274,20 @@ impl NonTSPseudoClass {
}
}
impl ::selectors::parser::NonTSPseudoClass for NonTSPseudoClass {
type Impl = SelectorImpl;
#[inline]
fn is_active_or_hover(&self) -> bool {
matches!(*self, NonTSPseudoClass::Active | NonTSPseudoClass::Hover)
}
#[inline]
fn is_host(&self) -> bool {
false // TODO(emilio)
}
}
/// The dummy struct we use to implement our selector parsing.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SelectorImpl;
@ -291,12 +305,6 @@ impl ::selectors::SelectorImpl for SelectorImpl {
type PseudoElement = PseudoElement;
type NonTSPseudoClass = NonTSPseudoClass;
#[inline]
fn is_active_or_hover(pseudo_class: &Self::NonTSPseudoClass) -> bool {
matches!(*pseudo_class, NonTSPseudoClass::Active |
NonTSPseudoClass::Hover)
}
}
impl<'a> SelectorParser<'a> {

View file

@ -1822,12 +1822,21 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
#[inline]
fn parent_element(&self) -> Option<Self> {
// FIXME(emilio): This will need to jump across if the parent node is a
// shadow root to get the shadow host.
let parent_node = self.as_node().parent_node();
parent_node.and_then(|n| n.as_element())
}
#[inline]
fn parent_node_is_shadow_root(&self) -> bool {
self.as_node().parent_node().map_or(false, |p| p.is_shadow_root())
}
#[inline]
fn containing_shadow_host(&self) -> Option<Self> {
let shadow = self.containing_shadow()?;
Some(shadow.host())
}
#[inline]
fn pseudo_element_originating_element(&self) -> Option<Self> {
debug_assert!(self.implemented_pseudo_element().is_some());