style: Add bindings for ShadowRoot.

This adds TShadowRoot to the `dom` module.

Right now it barely adds uses of it, but this is a prerequisite to fix a bunch
of Shadow DOM bugs and separate it from the XBL mess.
This commit is contained in:
Emilio Cobos Álvarez 2018-03-03 22:14:36 +01:00
parent df079286c2
commit 2f0df1b421
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 118 additions and 38 deletions

View file

@ -66,7 +66,7 @@ use style::attr::AttrValue;
use style::context::SharedStyleContext;
use style::data::ElementData;
use style::dom::{DomChildren, LayoutIterator, NodeInfo, OpaqueNode};
use style::dom::{TDocument, TElement, TNode};
use style::dom::{TDocument, TElement, TNode, TShadowRoot};
use style::element_state::*;
use style::font_metrics::ServoMetricsProvider;
use style::properties::{ComputedValues, PropertyDeclarationBlock};
@ -150,9 +150,28 @@ impl<'ln> NodeInfo for ServoLayoutNode<'ln> {
}
}
#[derive(Clone, Copy)]
enum Impossible { }
#[derive(Clone, Copy)]
pub struct ShadowRoot<'lr>(Impossible, PhantomData<&'lr ()>);
impl<'lr> TShadowRoot for ShadowRoot<'lr> {
type ConcreteNode = ServoLayoutNode<'lr>;
fn as_node(&self) -> Self::ConcreteNode {
match self.0 { }
}
fn host(&self) -> ServoLayoutElement<'lr> {
match self.0 { }
}
}
impl<'ln> TNode for ServoLayoutNode<'ln> {
type ConcreteDocument = ServoLayoutDocument<'ln>;
type ConcreteElement = ServoLayoutElement<'ln>;
type ConcreteShadowRoot = ShadowRoot<'ln>;
fn parent_node(&self) -> Option<Self> {
unsafe {
@ -208,6 +227,10 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
self.node.downcast().map(ServoLayoutDocument::from_layout_js)
}
fn as_shadow_root(&self) -> Option<ShadowRoot<'ln>> {
None
}
fn is_in_document(&self) -> bool {
unsafe { self.node.get_flag(NodeFlags::IS_IN_DOC) }
}
@ -489,11 +512,11 @@ impl<'le> TElement for ServoLayoutElement<'le> {
.map(|v| String::from(v as &str))
}
fn match_element_lang(&self,
override_lang: Option<Option<SelectorAttrValue>>,
value: &PseudoClassStringArg)
-> bool
{
fn match_element_lang(
&self,
override_lang: Option<Option<SelectorAttrValue>>,
value: &PseudoClassStringArg,
) -> bool {
// Servo supports :lang() from CSS Selectors 4, which can take a comma-
// separated list of language tags in the pseudo-class, and which
// performs RFC 4647 extended filtering matching on them.
@ -535,6 +558,10 @@ impl<'le> TElement for ServoLayoutElement<'le> {
self.element.synthesize_presentational_hints_for_legacy_attributes(hints);
}
}
fn shadow_root(&self) -> Option<ShadowRoot<'le>> {
None
}
}
impl<'le> PartialEq for ServoLayoutElement<'le> {