mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Make ChildrenIterator concrete.
This will allow us to specialize ChildrenIterator in the Gecko case to do something more interesting in some cases.
This commit is contained in:
parent
470368ecce
commit
b56297f2a5
3 changed files with 42 additions and 19 deletions
|
@ -115,6 +115,7 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
|
||||||
type ConcreteElement = ServoLayoutElement<'ln>;
|
type ConcreteElement = ServoLayoutElement<'ln>;
|
||||||
type ConcreteDocument = ServoLayoutDocument<'ln>;
|
type ConcreteDocument = ServoLayoutDocument<'ln>;
|
||||||
type ConcreteRestyleDamage = RestyleDamage;
|
type ConcreteRestyleDamage = RestyleDamage;
|
||||||
|
type ConcreteChildrenIterator = ServoChildrenIterator<'ln>;
|
||||||
|
|
||||||
fn to_unsafe(&self) -> UnsafeNode {
|
fn to_unsafe(&self) -> UnsafeNode {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -147,6 +148,12 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
|
||||||
self.dump_style_indent(0);
|
self.dump_style_indent(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn children(self) -> ServoChildrenIterator<'ln> {
|
||||||
|
ServoChildrenIterator {
|
||||||
|
current: self.first_child(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn opaque(&self) -> OpaqueNode {
|
fn opaque(&self) -> OpaqueNode {
|
||||||
unsafe { self.get_jsmanaged().opaque() }
|
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> {
|
impl<'ln> LayoutNode for ServoLayoutNode<'ln> {
|
||||||
type ConcreteThreadSafeLayoutNode = ServoThreadSafeLayoutNode<'ln>;
|
type ConcreteThreadSafeLayoutNode = ServoThreadSafeLayoutNode<'ln>;
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ pub trait TNode : Sized + Copy + Clone {
|
||||||
type ConcreteElement: TElement<ConcreteNode = Self, ConcreteDocument = Self::ConcreteDocument>;
|
type ConcreteElement: TElement<ConcreteNode = Self, ConcreteDocument = Self::ConcreteDocument>;
|
||||||
type ConcreteDocument: TDocument<ConcreteNode = Self, ConcreteElement = Self::ConcreteElement>;
|
type ConcreteDocument: TDocument<ConcreteNode = Self, ConcreteElement = Self::ConcreteElement>;
|
||||||
type ConcreteRestyleDamage: TRestyleDamage;
|
type ConcreteRestyleDamage: TRestyleDamage;
|
||||||
|
type ConcreteChildrenIterator: Iterator<Item = Self>;
|
||||||
|
|
||||||
fn to_unsafe(&self) -> UnsafeNode;
|
fn to_unsafe(&self) -> UnsafeNode;
|
||||||
unsafe fn from_unsafe(n: &UnsafeNode) -> Self;
|
unsafe fn from_unsafe(n: &UnsafeNode) -> Self;
|
||||||
|
@ -84,11 +85,7 @@ pub trait TNode : Sized + Copy + Clone {
|
||||||
fn dump_style(self);
|
fn dump_style(self);
|
||||||
|
|
||||||
/// Returns an iterator over this node's children.
|
/// Returns an iterator over this node's children.
|
||||||
fn children(self) -> ChildrenIterator<Self> {
|
fn children(self) -> Self::ConcreteChildrenIterator;
|
||||||
ChildrenIterator {
|
|
||||||
current: self.first_child(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Converts self into an `OpaqueNode`.
|
/// Converts self into an `OpaqueNode`.
|
||||||
fn opaque(&self) -> 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 ConcreteDocument = GeckoDocument<'ln>;
|
||||||
type ConcreteElement = GeckoElement<'ln>;
|
type ConcreteElement = GeckoElement<'ln>;
|
||||||
type ConcreteRestyleDamage = GeckoRestyleDamage;
|
type ConcreteRestyleDamage = GeckoRestyleDamage;
|
||||||
|
type ConcreteChildrenIterator = GeckoChildrenIterator<'ln>;
|
||||||
|
|
||||||
fn to_unsafe(&self) -> UnsafeNode {
|
fn to_unsafe(&self) -> UnsafeNode {
|
||||||
(self.node as usize, 0)
|
(self.node as usize, 0)
|
||||||
|
@ -163,6 +164,12 @@ impl<'ln> TNode for GeckoNode<'ln> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn children(self) -> GeckoChildrenIterator<'ln> {
|
||||||
|
GeckoChildrenIterator {
|
||||||
|
current: self.first_child(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn opaque(&self) -> OpaqueNode {
|
fn opaque(&self) -> OpaqueNode {
|
||||||
let ptr: uintptr_t = self.node as uintptr_t;
|
let ptr: uintptr_t = self.node as uintptr_t;
|
||||||
OpaqueNode(ptr)
|
OpaqueNode(ptr)
|
||||||
|
@ -341,6 +348,19 @@ impl<'ln> TNode for GeckoNode<'ln> {
|
||||||
unsafe fn set_dirty_on_viewport_size_changed(&self) {}
|
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)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct GeckoDocument<'ld> {
|
pub struct GeckoDocument<'ld> {
|
||||||
document: *mut RawGeckoDocument,
|
document: *mut RawGeckoDocument,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue