servo: Merge #12911 - stylo: Traverse anonymous children when styling (from bholley:traverse_anonymous_children); r=emilio

The corresponding Gecko changes are at https://bugzilla.mozilla.org/show_bug.cgi?id=1292662

Source-Repo: https://github.com/servo/servo
Source-Revision: 8e39313321791cade116b3a5f34a36d8cf99c0f2
This commit is contained in:
Bobby Holley
2016-08-26 12:17:40 -05:00
parent c27d7b4b62
commit 10f9947076
5 changed files with 127 additions and 85 deletions

View File

@@ -115,6 +115,7 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
type ConcreteElement = ServoLayoutElement<'ln>;
type ConcreteDocument = ServoLayoutDocument<'ln>;
type ConcreteRestyleDamage = RestyleDamage;
type ConcreteChildrenIterator = ServoChildrenIterator<'ln>;
fn to_unsafe(&self) -> UnsafeNode {
unsafe {
@@ -147,6 +148,12 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
self.dump_style_indent(0);
}
fn children(self) -> ServoChildrenIterator<'ln> {
ServoChildrenIterator {
current: self.first_child(),
}
}
fn opaque(&self) -> OpaqueNode {
unsafe { self.get_jsmanaged().opaque() }
}
@@ -163,10 +170,6 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
self.opaque().0
}
fn children_count(&self) -> u32 {
unsafe { self.node.children_count() }
}
fn as_element(&self) -> Option<ServoLayoutElement<'ln>> {
as_element(self.node)
}
@@ -280,6 +283,19 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
}
}
pub struct ServoChildrenIterator<'a> {
current: Option<ServoLayoutNode<'a>>,
}
impl<'a> Iterator for ServoChildrenIterator<'a> {
type Item = ServoLayoutNode<'a>;
fn next(&mut self) -> Option<ServoLayoutNode<'a>> {
let node = self.current;
self.current = node.and_then(|node| node.next_sibling());
node
}
}
impl<'ln> LayoutNode for ServoLayoutNode<'ln> {
type ConcreteThreadSafeLayoutNode = ServoThreadSafeLayoutNode<'ln>;