From dc167ca3435143665b147a48d1cd7172e8144ac5 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 21 Jun 2015 16:36:03 +0200 Subject: [PATCH] Implement type_id as inherent methods. This implies LayoutNode no longer needs to return an Option, as it never represents a pseudo-element. Also, fixes lies in the documentation. --- components/layout/construct.rs | 2 +- components/layout/css/matching.rs | 4 ++-- components/layout/wrapper.rs | 40 +++++++++++++++---------------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/components/layout/construct.rs b/components/layout/construct.rs index d3d21007242..27181f34e52 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -41,7 +41,7 @@ use table_row::TableRowFlow; use table_rowgroup::TableRowGroupFlow; use table_wrapper::TableWrapperFlow; use text::TextRunScanner; -use wrapper::{PostorderNodeMutTraversal, PseudoElementType, TLayoutNode, ThreadSafeLayoutNode}; +use wrapper::{PostorderNodeMutTraversal, PseudoElementType, ThreadSafeLayoutNode}; use gfx::display_list::OpaqueNode; use script::dom::characterdata::CharacterDataTypeId; diff --git a/components/layout/css/matching.rs b/components/layout/css/matching.rs index 8256d2b72f7..24356af6be8 100644 --- a/components/layout/css/matching.rs +++ b/components/layout/css/matching.rs @@ -13,7 +13,7 @@ use data::{LayoutDataAccess, LayoutDataWrapper}; use incremental::{self, RestyleDamage}; use opaque_node::OpaqueNodeMethods; use smallvec::SmallVec16; -use wrapper::{LayoutElement, LayoutNode, TLayoutNode}; +use wrapper::{LayoutElement, LayoutNode}; use script::dom::characterdata::CharacterDataTypeId; use script::dom::node::NodeTypeId; @@ -677,7 +677,7 @@ impl<'ln> MatchMethods for LayoutNode<'ln> { &mut None => panic!("no layout data"), &mut Some(ref mut layout_data) => { match self.type_id() { - Some(NodeTypeId::CharacterData(CharacterDataTypeId::Text)) => { + NodeTypeId::CharacterData(CharacterDataTypeId::Text) => { // Text nodes get a copy of the parent style. This ensures // that during fragment construction any non-inherited // CSS properties (such as vertical-align) are correctly diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 5a0b9ccd55b..be19fbc5b26 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -80,10 +80,6 @@ pub trait TLayoutNode { /// Creates a new layout node with the same lifetime as this layout node. unsafe fn new_with_this_lifetime(&self, node: &LayoutJS) -> Self; - /// Returns the type ID of this node. Fails if this node is borrowed mutably. Returns `None` - /// if this is a pseudo-element; otherwise, returns `Some`. - fn type_id(&self) -> Option; - /// Returns the interior of this node as a `LayoutJS`. This is highly unsafe for layout to /// call and as such is marked `unsafe`. unsafe fn get_jsmanaged<'a>(&'a self) -> &'a LayoutJS; @@ -118,12 +114,6 @@ impl<'ln> TLayoutNode for LayoutNode<'ln> { } } - fn type_id(&self) -> Option { - unsafe { - Some(self.node.type_id_for_layout()) - } - } - unsafe fn get_jsmanaged<'a>(&'a self) -> &'a LayoutJS { &self.node } @@ -136,6 +126,13 @@ impl<'ln> TLayoutNode for LayoutNode<'ln> { } impl<'ln> LayoutNode<'ln> { + /// Returns the type ID of this node. + pub fn type_id(&self) -> NodeTypeId { + unsafe { + self.node.type_id_for_layout() + } + } + pub fn dump(self) { self.dump_indent(0); } @@ -294,14 +291,14 @@ impl<'ln> TNode for LayoutNode<'ln> { fn is_element(&self) -> bool { match self.type_id() { - Some(NodeTypeId::Element(..)) => true, + NodeTypeId::Element(..) => true, _ => false } } fn is_document(&self) -> bool { match self.type_id() { - Some(NodeTypeId::Document(..)) => true, + NodeTypeId::Document(..) => true, _ => false } } @@ -630,15 +627,6 @@ impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> { } } - /// Returns `None` if this is a pseudo-element. - fn type_id(&self) -> Option { - if self.pseudo != PseudoElementType::Normal { - return None - } - - self.node.type_id() - } - unsafe fn get_jsmanaged<'a>(&'a self) -> &'a LayoutJS { self.node.get_jsmanaged() } @@ -676,6 +664,16 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { } } + /// Returns the type ID of this node. + /// Returns `None` if this is a pseudo-element; otherwise, returns `Some`. + pub fn type_id(&self) -> Option { + if self.pseudo != PseudoElementType::Normal { + return None + } + + Some(self.node.type_id()) + } + pub fn debug_id(self) -> usize { self.node.debug_id() }