mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
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.
This commit is contained in:
parent
f0034b4ac9
commit
dc167ca343
3 changed files with 22 additions and 24 deletions
|
@ -41,7 +41,7 @@ use table_row::TableRowFlow;
|
||||||
use table_rowgroup::TableRowGroupFlow;
|
use table_rowgroup::TableRowGroupFlow;
|
||||||
use table_wrapper::TableWrapperFlow;
|
use table_wrapper::TableWrapperFlow;
|
||||||
use text::TextRunScanner;
|
use text::TextRunScanner;
|
||||||
use wrapper::{PostorderNodeMutTraversal, PseudoElementType, TLayoutNode, ThreadSafeLayoutNode};
|
use wrapper::{PostorderNodeMutTraversal, PseudoElementType, ThreadSafeLayoutNode};
|
||||||
|
|
||||||
use gfx::display_list::OpaqueNode;
|
use gfx::display_list::OpaqueNode;
|
||||||
use script::dom::characterdata::CharacterDataTypeId;
|
use script::dom::characterdata::CharacterDataTypeId;
|
||||||
|
|
|
@ -13,7 +13,7 @@ use data::{LayoutDataAccess, LayoutDataWrapper};
|
||||||
use incremental::{self, RestyleDamage};
|
use incremental::{self, RestyleDamage};
|
||||||
use opaque_node::OpaqueNodeMethods;
|
use opaque_node::OpaqueNodeMethods;
|
||||||
use smallvec::SmallVec16;
|
use smallvec::SmallVec16;
|
||||||
use wrapper::{LayoutElement, LayoutNode, TLayoutNode};
|
use wrapper::{LayoutElement, LayoutNode};
|
||||||
|
|
||||||
use script::dom::characterdata::CharacterDataTypeId;
|
use script::dom::characterdata::CharacterDataTypeId;
|
||||||
use script::dom::node::NodeTypeId;
|
use script::dom::node::NodeTypeId;
|
||||||
|
@ -677,7 +677,7 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
|
||||||
&mut None => panic!("no layout data"),
|
&mut None => panic!("no layout data"),
|
||||||
&mut Some(ref mut layout_data) => {
|
&mut Some(ref mut layout_data) => {
|
||||||
match self.type_id() {
|
match self.type_id() {
|
||||||
Some(NodeTypeId::CharacterData(CharacterDataTypeId::Text)) => {
|
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => {
|
||||||
// Text nodes get a copy of the parent style. This ensures
|
// Text nodes get a copy of the parent style. This ensures
|
||||||
// that during fragment construction any non-inherited
|
// that during fragment construction any non-inherited
|
||||||
// CSS properties (such as vertical-align) are correctly
|
// CSS properties (such as vertical-align) are correctly
|
||||||
|
|
|
@ -80,10 +80,6 @@ pub trait TLayoutNode {
|
||||||
/// Creates a new layout node with the same lifetime as this layout node.
|
/// Creates a new layout node with the same lifetime as this layout node.
|
||||||
unsafe fn new_with_this_lifetime(&self, node: &LayoutJS<Node>) -> Self;
|
unsafe fn new_with_this_lifetime(&self, node: &LayoutJS<Node>) -> 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<NodeTypeId>;
|
|
||||||
|
|
||||||
/// Returns the interior of this node as a `LayoutJS`. This is highly unsafe for layout to
|
/// Returns the interior of this node as a `LayoutJS`. This is highly unsafe for layout to
|
||||||
/// call and as such is marked `unsafe`.
|
/// call and as such is marked `unsafe`.
|
||||||
unsafe fn get_jsmanaged<'a>(&'a self) -> &'a LayoutJS<Node>;
|
unsafe fn get_jsmanaged<'a>(&'a self) -> &'a LayoutJS<Node>;
|
||||||
|
@ -118,12 +114,6 @@ impl<'ln> TLayoutNode for LayoutNode<'ln> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_id(&self) -> Option<NodeTypeId> {
|
|
||||||
unsafe {
|
|
||||||
Some(self.node.type_id_for_layout())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn get_jsmanaged<'a>(&'a self) -> &'a LayoutJS<Node> {
|
unsafe fn get_jsmanaged<'a>(&'a self) -> &'a LayoutJS<Node> {
|
||||||
&self.node
|
&self.node
|
||||||
}
|
}
|
||||||
|
@ -136,6 +126,13 @@ impl<'ln> TLayoutNode for LayoutNode<'ln> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ln> 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) {
|
pub fn dump(self) {
|
||||||
self.dump_indent(0);
|
self.dump_indent(0);
|
||||||
}
|
}
|
||||||
|
@ -294,14 +291,14 @@ impl<'ln> TNode for LayoutNode<'ln> {
|
||||||
|
|
||||||
fn is_element(&self) -> bool {
|
fn is_element(&self) -> bool {
|
||||||
match self.type_id() {
|
match self.type_id() {
|
||||||
Some(NodeTypeId::Element(..)) => true,
|
NodeTypeId::Element(..) => true,
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_document(&self) -> bool {
|
fn is_document(&self) -> bool {
|
||||||
match self.type_id() {
|
match self.type_id() {
|
||||||
Some(NodeTypeId::Document(..)) => true,
|
NodeTypeId::Document(..) => true,
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -630,15 +627,6 @@ impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `None` if this is a pseudo-element.
|
|
||||||
fn type_id(&self) -> Option<NodeTypeId> {
|
|
||||||
if self.pseudo != PseudoElementType::Normal {
|
|
||||||
return None
|
|
||||||
}
|
|
||||||
|
|
||||||
self.node.type_id()
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn get_jsmanaged<'a>(&'a self) -> &'a LayoutJS<Node> {
|
unsafe fn get_jsmanaged<'a>(&'a self) -> &'a LayoutJS<Node> {
|
||||||
self.node.get_jsmanaged()
|
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<NodeTypeId> {
|
||||||
|
if self.pseudo != PseudoElementType::Normal {
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(self.node.type_id())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn debug_id(self) -> usize {
|
pub fn debug_id(self) -> usize {
|
||||||
self.node.debug_id()
|
self.node.debug_id()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue