mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Split out is_element and is_text_node into a helper trait.
This commit is contained in:
parent
66c736194d
commit
e6bbff110a
6 changed files with 50 additions and 39 deletions
|
@ -58,7 +58,7 @@ use style::attr::AttrValue;
|
|||
use style::computed_values::display;
|
||||
use style::context::SharedStyleContext;
|
||||
use style::data::PrivateStyleData;
|
||||
use style::dom::{OpaqueNode, PresentationalHintsSynthetizer, TDocument, TElement, TNode, UnsafeNode};
|
||||
use style::dom::{NodeInfo, OpaqueNode, PresentationalHintsSynthetizer, TDocument, TElement, TNode, UnsafeNode};
|
||||
use style::element_state::*;
|
||||
use style::properties::{ComputedValues, PropertyDeclarationBlock};
|
||||
use style::refcell::{Ref, RefCell, RefMut};
|
||||
|
@ -111,6 +111,18 @@ impl<'ln> ServoLayoutNode<'ln> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'ln> NodeInfo for ServoLayoutNode<'ln> {
|
||||
fn is_element(&self) -> bool {
|
||||
unsafe {
|
||||
self.node.is_element_for_layout()
|
||||
}
|
||||
}
|
||||
|
||||
fn is_text_node(&self) -> bool {
|
||||
self.script_type_id() == NodeTypeId::CharacterData(CharacterDataTypeId::Text)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ln> TNode for ServoLayoutNode<'ln> {
|
||||
type ConcreteElement = ServoLayoutElement<'ln>;
|
||||
type ConcreteDocument = ServoLayoutDocument<'ln>;
|
||||
|
@ -128,16 +140,6 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
|
|||
transmute(node)
|
||||
}
|
||||
|
||||
fn is_text_node(&self) -> bool {
|
||||
self.script_type_id() == NodeTypeId::CharacterData(CharacterDataTypeId::Text)
|
||||
}
|
||||
|
||||
fn is_element(&self) -> bool {
|
||||
unsafe {
|
||||
self.node.is_element_for_layout()
|
||||
}
|
||||
}
|
||||
|
||||
fn dump(self) {
|
||||
self.dump_indent(0);
|
||||
}
|
||||
|
@ -727,6 +729,15 @@ impl<'ln> ServoThreadSafeLayoutNode<'ln> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'ln> NodeInfo for ServoThreadSafeLayoutNode<'ln> {
|
||||
fn is_element(&self) -> bool {
|
||||
if let Some(LayoutNodeType::Element(_)) = self.type_id() { true } else { false }
|
||||
}
|
||||
fn is_text_node(&self) -> bool {
|
||||
if let Some(LayoutNodeType::Text) = self.type_id() { true } else { false }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
|
||||
type ConcreteThreadSafeLayoutElement = ServoThreadSafeLayoutElement<'ln>;
|
||||
type ChildrenIterator = ThreadSafeLayoutNodeChildrenIterator<Self>;
|
||||
|
|
|
@ -15,7 +15,7 @@ use std::sync::Arc;
|
|||
use string_cache::{Atom, Namespace};
|
||||
use style::computed_values::display;
|
||||
use style::context::SharedStyleContext;
|
||||
use style::dom::{PresentationalHintsSynthetizer, TNode};
|
||||
use style::dom::{NodeInfo, PresentationalHintsSynthetizer, TNode};
|
||||
use style::dom::OpaqueNode;
|
||||
use style::properties::ServoComputedValues;
|
||||
use style::refcell::{Ref, RefCell};
|
||||
|
@ -137,7 +137,7 @@ impl<ConcreteNode> Iterator for TreeIterator<ConcreteNode>
|
|||
|
||||
/// A thread-safe version of `LayoutNode`, used during flow construction. This type of layout
|
||||
/// node does not allow any parents or siblings of nodes to be accessed, to avoid races.
|
||||
pub trait ThreadSafeLayoutNode: Clone + Copy + Sized + PartialEq {
|
||||
pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
||||
type ConcreteThreadSafeLayoutElement:
|
||||
ThreadSafeLayoutElement<ConcreteThreadSafeLayoutNode = Self>
|
||||
+ ::selectors::Element<Impl=ServoSelectorImpl>;
|
||||
|
@ -171,9 +171,6 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + Sized + PartialEq {
|
|||
/// Returns an iterator over this node's children.
|
||||
fn children(&self) -> Self::ChildrenIterator;
|
||||
|
||||
#[inline]
|
||||
fn is_element(&self) -> bool { if let Some(LayoutNodeType::Element(_)) = self.type_id() { true } else { false } }
|
||||
|
||||
/// If this is an element, accesses the element data. Fails if this is not an element node.
|
||||
#[inline]
|
||||
fn as_element(&self) -> Self::ConcreteThreadSafeLayoutElement;
|
||||
|
|
|
@ -64,7 +64,16 @@ pub trait TRestyleDamage : Debug + PartialEq + BitOr<Output=Self> + Copy {
|
|||
fn rebuild_and_reflow() -> Self;
|
||||
}
|
||||
|
||||
pub trait TNode : Sized + Copy + Clone {
|
||||
/// Simple trait to provide basic information about the type of an element.
|
||||
///
|
||||
/// We avoid exposing the full type id, since computing it in the general case
|
||||
/// would be difficult for Gecko nodes.
|
||||
pub trait NodeInfo {
|
||||
fn is_element(&self) -> bool;
|
||||
fn is_text_node(&self) -> bool;
|
||||
}
|
||||
|
||||
pub trait TNode : Sized + Copy + Clone + NodeInfo {
|
||||
type ConcreteElement: TElement<ConcreteNode = Self, ConcreteDocument = Self::ConcreteDocument>;
|
||||
type ConcreteDocument: TDocument<ConcreteNode = Self, ConcreteElement = Self::ConcreteElement>;
|
||||
type ConcreteRestyleDamage: TRestyleDamage;
|
||||
|
@ -73,13 +82,6 @@ pub trait TNode : Sized + Copy + Clone {
|
|||
fn to_unsafe(&self) -> UnsafeNode;
|
||||
unsafe fn from_unsafe(n: &UnsafeNode) -> Self;
|
||||
|
||||
/// Returns whether this is a text node. It turns out that this is all the style system cares
|
||||
/// about, and thus obviates the need to compute the full type id, which would be expensive in
|
||||
/// Gecko.
|
||||
fn is_text_node(&self) -> bool;
|
||||
|
||||
fn is_element(&self) -> bool;
|
||||
|
||||
fn dump(self);
|
||||
|
||||
fn dump_style(self);
|
||||
|
|
|
@ -12,7 +12,7 @@ use cache::{LRUCache, SimpleHashCache};
|
|||
use cascade_info::CascadeInfo;
|
||||
use context::{SharedStyleContext, StyleContext};
|
||||
use data::PrivateStyleData;
|
||||
use dom::{TElement, TNode, TRestyleDamage, UnsafeNode};
|
||||
use dom::{NodeInfo, TElement, TNode, TRestyleDamage, UnsafeNode};
|
||||
use properties::{ComputedValues, PropertyDeclarationBlock, cascade};
|
||||
use properties::longhands::display::computed_value as display;
|
||||
use selector_impl::{PseudoElement, TheSelectorImpl};
|
||||
|
|
|
@ -32,7 +32,7 @@ use std::sync::{Arc, Mutex};
|
|||
use std::sync::atomic::{AtomicBool, AtomicPtr, Ordering};
|
||||
use style::arc_ptr_eq;
|
||||
use style::context::{LocalStyleContextCreationInfo, ReflowGoal, SharedStyleContext};
|
||||
use style::dom::{TDocument, TElement, TNode};
|
||||
use style::dom::{NodeInfo, TDocument, TElement, TNode};
|
||||
use style::error_reporting::StdoutErrorReporter;
|
||||
use style::gecko_selector_impl::{GeckoSelectorImpl, PseudoElement};
|
||||
use style::parallel;
|
||||
|
|
|
@ -40,7 +40,7 @@ use std::ptr;
|
|||
use std::sync::Arc;
|
||||
use style::data::PrivateStyleData;
|
||||
use style::dom::{OpaqueNode, PresentationalHintsSynthetizer};
|
||||
use style::dom::{TDocument, TElement, TNode, TRestyleDamage, UnsafeNode};
|
||||
use style::dom::{NodeInfo, TDocument, TElement, TNode, TRestyleDamage, UnsafeNode};
|
||||
use style::element_state::ElementState;
|
||||
use style::error_reporting::StdoutErrorReporter;
|
||||
use style::gecko_selector_impl::{GeckoSelectorImpl, NonTSPseudoClass, PseudoElement};
|
||||
|
@ -125,6 +125,19 @@ impl BitOr for GeckoRestyleDamage {
|
|||
}
|
||||
|
||||
|
||||
impl<'ln> NodeInfo for GeckoNode<'ln> {
|
||||
fn is_element(&self) -> bool {
|
||||
unsafe {
|
||||
Gecko_NodeIsElement(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_text_node(&self) -> bool {
|
||||
unsafe {
|
||||
Gecko_IsTextNode(self.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ln> TNode for GeckoNode<'ln> {
|
||||
type ConcreteDocument = GeckoDocument<'ln>;
|
||||
|
@ -140,18 +153,6 @@ impl<'ln> TNode for GeckoNode<'ln> {
|
|||
GeckoNode(&*(n.0 as *mut RawGeckoNode))
|
||||
}
|
||||
|
||||
fn is_text_node(&self) -> bool {
|
||||
unsafe {
|
||||
Gecko_IsTextNode(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_element(&self) -> bool {
|
||||
unsafe {
|
||||
Gecko_NodeIsElement(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
fn dump(self) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue