mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Introduce the LayoutIterator newtype and return it for all children() methods in style and layout.
This commit is contained in:
parent
e6bbff110a
commit
4aa3e589c0
4 changed files with 25 additions and 16 deletions
|
@ -58,7 +58,8 @@ use style::attr::AttrValue;
|
|||
use style::computed_values::display;
|
||||
use style::context::SharedStyleContext;
|
||||
use style::data::PrivateStyleData;
|
||||
use style::dom::{NodeInfo, OpaqueNode, PresentationalHintsSynthetizer, TDocument, TElement, TNode, UnsafeNode};
|
||||
use style::dom::{LayoutIterator, NodeInfo, OpaqueNode, PresentationalHintsSynthetizer, TDocument, TElement, TNode};
|
||||
use style::dom::UnsafeNode;
|
||||
use style::element_state::*;
|
||||
use style::properties::{ComputedValues, PropertyDeclarationBlock};
|
||||
use style::refcell::{Ref, RefCell, RefMut};
|
||||
|
@ -149,10 +150,10 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
|
|||
self.dump_style_indent(0);
|
||||
}
|
||||
|
||||
fn children(self) -> ServoChildrenIterator<'ln> {
|
||||
ServoChildrenIterator {
|
||||
fn children(self) -> LayoutIterator<ServoChildrenIterator<'ln>> {
|
||||
LayoutIterator(ServoChildrenIterator {
|
||||
current: self.first_child(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn opaque(&self) -> OpaqueNode {
|
||||
|
@ -771,8 +772,8 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
|
|||
self.node.debug_id()
|
||||
}
|
||||
|
||||
fn children(&self) -> Self::ChildrenIterator {
|
||||
ThreadSafeLayoutNodeChildrenIterator::new(*self)
|
||||
fn children(&self) -> LayoutIterator<Self::ChildrenIterator> {
|
||||
LayoutIterator(ThreadSafeLayoutNodeChildrenIterator::new(*self))
|
||||
}
|
||||
|
||||
fn as_element(&self) -> ServoThreadSafeLayoutElement<'ln> {
|
||||
|
|
|
@ -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::{NodeInfo, PresentationalHintsSynthetizer, TNode};
|
||||
use style::dom::{LayoutIterator, NodeInfo, PresentationalHintsSynthetizer, TNode};
|
||||
use style::dom::OpaqueNode;
|
||||
use style::properties::ServoComputedValues;
|
||||
use style::refcell::{Ref, RefCell};
|
||||
|
@ -81,10 +81,10 @@ pub trait LayoutNode: TNode {
|
|||
fn init_style_and_layout_data(&self, data: OpaqueStyleAndLayoutData);
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData>;
|
||||
|
||||
fn rev_children(self) -> ReverseChildrenIterator<Self> {
|
||||
ReverseChildrenIterator {
|
||||
fn rev_children(self) -> LayoutIterator<ReverseChildrenIterator<Self>> {
|
||||
LayoutIterator(ReverseChildrenIterator {
|
||||
current: self.last_child(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn traverse_preorder(self) -> TreeIterator<Self> {
|
||||
|
@ -169,7 +169,7 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
|||
fn debug_id(self) -> usize;
|
||||
|
||||
/// Returns an iterator over this node's children.
|
||||
fn children(&self) -> Self::ChildrenIterator;
|
||||
fn children(&self) -> LayoutIterator<Self::ChildrenIterator>;
|
||||
|
||||
/// If this is an element, accesses the element data. Fails if this is not an element node.
|
||||
#[inline]
|
||||
|
|
|
@ -73,6 +73,14 @@ pub trait NodeInfo {
|
|||
fn is_text_node(&self) -> bool;
|
||||
}
|
||||
|
||||
pub struct LayoutIterator<T>(pub T);
|
||||
impl<T, I> Iterator for LayoutIterator<T> where T: Iterator<Item=I>, I: NodeInfo {
|
||||
type Item = I;
|
||||
fn next(&mut self) -> Option<I> {
|
||||
self.0.next()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TNode : Sized + Copy + Clone + NodeInfo {
|
||||
type ConcreteElement: TElement<ConcreteNode = Self, ConcreteDocument = Self::ConcreteDocument>;
|
||||
type ConcreteDocument: TDocument<ConcreteNode = Self, ConcreteElement = Self::ConcreteElement>;
|
||||
|
@ -87,7 +95,7 @@ pub trait TNode : Sized + Copy + Clone + NodeInfo {
|
|||
fn dump_style(self);
|
||||
|
||||
/// Returns an iterator over this node's children.
|
||||
fn children(self) -> Self::ConcreteChildrenIterator;
|
||||
fn children(self) -> LayoutIterator<Self::ConcreteChildrenIterator>;
|
||||
|
||||
/// Converts self into an `OpaqueNode`.
|
||||
fn opaque(&self) -> OpaqueNode;
|
||||
|
|
|
@ -39,8 +39,8 @@ use std::ops::BitOr;
|
|||
use std::ptr;
|
||||
use std::sync::Arc;
|
||||
use style::data::PrivateStyleData;
|
||||
use style::dom::{LayoutIterator, NodeInfo, TDocument, TElement, TNode, TRestyleDamage, UnsafeNode};
|
||||
use style::dom::{OpaqueNode, PresentationalHintsSynthetizer};
|
||||
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};
|
||||
|
@ -161,12 +161,12 @@ impl<'ln> TNode for GeckoNode<'ln> {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
fn children(self) -> GeckoChildrenIterator<'ln> {
|
||||
fn children(self) -> LayoutIterator<GeckoChildrenIterator<'ln>> {
|
||||
let maybe_iter = unsafe { Gecko_MaybeCreateStyleChildrenIterator(self.0) };
|
||||
if let Some(iter) = maybe_iter.into_owned_opt() {
|
||||
GeckoChildrenIterator::GeckoIterator(iter)
|
||||
LayoutIterator(GeckoChildrenIterator::GeckoIterator(iter))
|
||||
} else {
|
||||
GeckoChildrenIterator::Current(self.first_child())
|
||||
LayoutIterator(GeckoChildrenIterator::Current(self.first_child()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue