style: Distinguish between the tree structures used for traversal and selector matching.

This patch renames TNode::parent_element to traversal_parent, since it returns
the parent from the perspective of traversal (which in Gecko uses the
flattened tree).  It also renames TNode::children to traversal_children
for the saem reason.

We keep parent_element and children functions on TNode to use for selector
matching, which must be done on the real DOM tree structure.
This commit is contained in:
Cameron McCormack 2017-06-09 12:05:39 +08:00
parent c465dd0375
commit c533097e20
11 changed files with 102 additions and 67 deletions

View file

@ -108,17 +108,27 @@ pub trait TNode : Sized + Copy + Clone + Debug + NodeInfo {
/// Get a node back from an `UnsafeNode`.
unsafe fn from_unsafe(n: &UnsafeNode) -> Self;
/// Returns an iterator over this node's children.
fn children(self) -> LayoutIterator<Self::ConcreteChildrenIterator>;
/// Converts self into an `OpaqueNode`.
fn opaque(&self) -> OpaqueNode;
/// Get this node's parent node.
fn parent_node(&self) -> Option<Self>;
/// Get this node's parent element if present.
fn parent_element(&self) -> Option<Self::ConcreteElement> {
self.parent_node().and_then(|n| n.as_element())
}
/// Returns an iterator over this node's children.
fn children(&self) -> LayoutIterator<Self::ConcreteChildrenIterator>;
/// Get this node's parent element from the perspective of a restyle
/// traversal.
fn traversal_parent(&self) -> Option<Self::ConcreteElement>;
/// Get this node's children from the perspective of a restyle traversal.
fn traversal_children(&self) -> LayoutIterator<Self::ConcreteChildrenIterator>;
/// Converts self into an `OpaqueNode`.
fn opaque(&self) -> OpaqueNode;
/// A debug id, only useful, mm... for debugging.
fn debug_id(self) -> usize;
@ -138,9 +148,6 @@ pub trait TNode : Sized + Copy + Clone + Debug + NodeInfo {
/// Set whether this node can be fragmented.
unsafe fn set_can_be_fragmented(&self, value: bool);
/// Get this node's parent node.
fn parent_node(&self) -> Option<Self>;
/// Whether this node is in the document right now needed to clear the
/// restyle data appropriately on some forced restyles.
fn is_in_doc(&self) -> bool;
@ -222,7 +229,7 @@ fn fmt_subtree<F, N: TNode>(f: &mut fmt::Formatter, stringify: &F, n: N, indent:
try!(write!(f, " "));
}
try!(stringify(f, n));
for kid in n.children() {
for kid in n.traversal_children() {
try!(writeln!(f, ""));
try!(fmt_subtree(f, stringify, kid, indent + 1));
}
@ -256,7 +263,7 @@ pub unsafe fn raw_note_descendants<E, B>(element: E) -> bool
break;
}
B::set(el);
curr = el.parent_element();
curr = el.traversal_parent();
}
// Note: We disable this assertion on servo because of bugs. See the
@ -297,7 +304,7 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone +
fn depth(&self) -> usize {
let mut depth = 0;
let mut curr = *self;
while let Some(parent) = curr.parent_element() {
while let Some(parent) = curr.traversal_parent() {
depth += 1;
curr = parent;
}
@ -315,11 +322,18 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone +
}
}
/// Get this node's parent element from the perspective of a restyle
/// traversal.
fn traversal_parent(&self) -> Option<Self> {
self.as_node().traversal_parent()
}
/// Returns the parent element we should inherit from.
///
/// This is pretty much always the parent element itself, except in the case
/// of Gecko's Native Anonymous Content, which may need to find the closest
/// non-NAC ancestor.
/// of Gecko's Native Anonymous Content, which uses the traversal parent
/// (i.e. the flattened tree parent) and which also may need to find the
/// closest non-NAC ancestor.
fn inheritance_parent(&self) -> Option<Self> {
self.parent_element()
}
@ -442,7 +456,7 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone +
let mut current = Some(*self);
while let Some(el) = current {
if !B::has(el) { return false; }
current = el.parent_element();
current = el.traversal_parent();
}
true