diff options
Diffstat (limited to 'components/layout/wrapper.rs')
-rw-r--r-- | components/layout/wrapper.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index c59fb978e38..d42fa386ec2 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -43,6 +43,7 @@ use script::dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, NodeTypeId use script::dom::bindings::conversions::Castable; use script::dom::bindings::js::LayoutJS; use script::dom::characterdata::LayoutCharacterDataHelpers; +use script::dom::document::{Document, LayoutDocumentHelpers}; use script::dom::element; use script::dom::element::{Element, LayoutElementHelpers, RawLayoutElementHelpers}; use script::dom::htmlcanvaselement::{LayoutHTMLCanvasElementHelpers, HTMLCanvasData}; @@ -105,6 +106,12 @@ impl<'ln> LayoutNode<'ln> { } } + pub fn is_element(&self) -> bool { + unsafe { + self.node.is_element_for_layout() + } + } + pub fn dump(self) { self.dump_indent(0); } @@ -336,6 +343,30 @@ impl<'a> Iterator for LayoutTreeIterator<'a> { } } +// A wrapper around documents that ensures ayout can only ever access safe properties. +#[derive(Copy, Clone)] +pub struct LayoutDocument<'le> { + document: LayoutJS<Document>, + chain: PhantomData<&'le ()>, +} + +impl<'le> LayoutDocument<'le> { + pub fn as_node(&self) -> LayoutNode<'le> { + LayoutNode { + node: self.document.upcast(), + chain: PhantomData, + } + } + + pub fn root_node(&self) -> Option<LayoutNode<'le>> { + let mut node = self.as_node().first_child(); + while node.is_some() && !node.unwrap().is_element() { + node = node.unwrap().next_sibling(); + } + node + } +} + /// A wrapper around elements that ensures layout can only ever access safe properties. #[derive(Copy, Clone)] pub struct LayoutElement<'le> { |