Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stylo: Traverse anonymous children when styling #12911

Merged
merged 4 commits into from Aug 26, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Make ChildrenIterator concrete.

This will allow us to specialize ChildrenIterator in the Gecko case to do
something more interesting in some cases.
  • Loading branch information
bholley committed Aug 26, 2016
commit b56297f2a57eb79ed47b3aa3a1daf82f29d36b4b
@@ -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() }
}
@@ -280,6 +287,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>;

@@ -68,6 +68,7 @@ pub trait TNode : Sized + Copy + Clone {
type ConcreteElement: TElement<ConcreteNode = Self, ConcreteDocument = Self::ConcreteDocument>;
type ConcreteDocument: TDocument<ConcreteNode = Self, ConcreteElement = Self::ConcreteElement>;
type ConcreteRestyleDamage: TRestyleDamage;
type ConcreteChildrenIterator: Iterator<Item = Self>;

fn to_unsafe(&self) -> UnsafeNode;
unsafe fn from_unsafe(n: &UnsafeNode) -> Self;
@@ -84,11 +85,7 @@ pub trait TNode : Sized + Copy + Clone {
fn dump_style(self);

/// Returns an iterator over this node's children.
fn children(self) -> ChildrenIterator<Self> {
ChildrenIterator {
current: self.first_child(),
}
}
fn children(self) -> Self::ConcreteChildrenIterator;

/// Converts self into an `OpaqueNode`.
fn opaque(&self) -> OpaqueNode;
@@ -244,17 +241,3 @@ pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + Pre
}
}
}

pub struct ChildrenIterator<ConcreteNode> where ConcreteNode: TNode {
current: Option<ConcreteNode>,
}

impl<ConcreteNode> Iterator for ChildrenIterator<ConcreteNode>
where ConcreteNode: TNode {
type Item = ConcreteNode;
fn next(&mut self) -> Option<ConcreteNode> {
let node = self.current;
self.current = node.and_then(|node| node.next_sibling());
node
}
}
@@ -134,6 +134,7 @@ impl<'ln> TNode for GeckoNode<'ln> {
type ConcreteDocument = GeckoDocument<'ln>;
type ConcreteElement = GeckoElement<'ln>;
type ConcreteRestyleDamage = GeckoRestyleDamage;
type ConcreteChildrenIterator = GeckoChildrenIterator<'ln>;

fn to_unsafe(&self) -> UnsafeNode {
(self.node as usize, 0)
@@ -163,6 +164,12 @@ impl<'ln> TNode for GeckoNode<'ln> {
unimplemented!()
}

fn children(self) -> GeckoChildrenIterator<'ln> {
GeckoChildrenIterator {
current: self.first_child(),
}
}

fn opaque(&self) -> OpaqueNode {
let ptr: uintptr_t = self.node as uintptr_t;
OpaqueNode(ptr)
@@ -341,6 +348,19 @@ impl<'ln> TNode for GeckoNode<'ln> {
unsafe fn set_dirty_on_viewport_size_changed(&self) {}
}

pub struct GeckoChildrenIterator<'a> {
current: Option<GeckoNode<'a>>,
}

impl<'a> Iterator for GeckoChildrenIterator<'a> {
type Item = GeckoNode<'a>;
fn next(&mut self) -> Option<GeckoNode<'a>> {
let node = self.current;
self.current = node.and_then(|node| node.next_sibling());
node
}
}

#[derive(Clone, Copy)]
pub struct GeckoDocument<'ld> {
document: *mut RawGeckoDocument,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.