mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
layout: Remove DisplayBoxes
to save memory and as one step toward an
`@`-free layout
This commit is contained in:
parent
f7cc49c30f
commit
64222f5772
4 changed files with 79 additions and 109 deletions
|
@ -21,6 +21,7 @@ use render_context::RenderContext;
|
|||
use text::TextRun;
|
||||
|
||||
use std::cast::transmute_region;
|
||||
use std::vec::VecIterator;
|
||||
use geom::{Point2D, Rect, Size2D, SideOffsets2D};
|
||||
use servo_net::image::base::Image;
|
||||
use servo_util::range::Range;
|
||||
|
@ -56,6 +57,11 @@ impl<E> DisplayList<E> {
|
|||
}
|
||||
debug!("Ending display list.")
|
||||
}
|
||||
|
||||
/// Returns a preorder iterator over the given display list.
|
||||
pub fn iter<'a>(&'a self) -> DisplayItemIterator<'a,E> {
|
||||
ParentDisplayItemIterator(self.list.iter())
|
||||
}
|
||||
}
|
||||
|
||||
/// One drawing command in the list.
|
||||
|
@ -118,6 +124,21 @@ pub struct ClipDisplayItem<E> {
|
|||
need_clip: bool
|
||||
}
|
||||
|
||||
pub enum DisplayItemIterator<'self,E> {
|
||||
EmptyDisplayItemIterator,
|
||||
ParentDisplayItemIterator(VecIterator<'self,DisplayItem<E>>),
|
||||
}
|
||||
|
||||
impl<'self,E> Iterator<&'self DisplayItem<E>> for DisplayItemIterator<'self,E> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<&'self DisplayItem<E>> {
|
||||
match *self {
|
||||
EmptyDisplayItemIterator => None,
|
||||
ParentDisplayItemIterator(ref mut subiterator) => subiterator.next(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> DisplayItem<E> {
|
||||
/// Renders this display item into the given render context.
|
||||
fn draw_into_context(&self, render_context: &mut RenderContext) {
|
||||
|
@ -212,5 +233,30 @@ impl<E> DisplayItem<E> {
|
|||
pub fn bounds(&self) -> Rect<Au> {
|
||||
self.base().bounds
|
||||
}
|
||||
|
||||
pub fn children<'a>(&'a self) -> DisplayItemIterator<'a,E> {
|
||||
match *self {
|
||||
ClipDisplayItemClass(ref clip) => ParentDisplayItemIterator(clip.child_list.iter()),
|
||||
SolidColorDisplayItemClass(*) |
|
||||
TextDisplayItemClass(*) |
|
||||
ImageDisplayItemClass(*) |
|
||||
BorderDisplayItemClass(*) => EmptyDisplayItemIterator,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn debug_str(&self) -> ~str {
|
||||
let class = match *self {
|
||||
SolidColorDisplayItemClass(_) => "SolidColor",
|
||||
TextDisplayItemClass(_) => "Text",
|
||||
ImageDisplayItemClass(_) => "Image",
|
||||
BorderDisplayItemClass(_) => "Border",
|
||||
ClipDisplayItemClass(_) => "Clip",
|
||||
};
|
||||
let mut string = format!("{} @ {:?}", class, self.base().bounds);
|
||||
for child in self.children() {
|
||||
string = format!("{}\n {}", string, child.debug_str());
|
||||
}
|
||||
string
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue