add rect to FrameTree

This commit is contained in:
Tim Kuehn 2013-08-05 18:56:13 -07:00
parent 89c5083f86
commit f514a8b36a

View file

@ -9,6 +9,7 @@ use std::comm;
use std::comm::Port; use std::comm::Port;
use std::task; use std::task;
use geom::size::Size2D; use geom::size::Size2D;
use geom::rect::Rect;
use gfx::opts::Opts; use gfx::opts::Opts;
use pipeline::Pipeline; use pipeline::Pipeline;
use servo_msg::constellation_msg::{ConstellationChan, ExitMsg}; use servo_msg::constellation_msg::{ConstellationChan, ExitMsg};
@ -44,13 +45,14 @@ pub struct Constellation {
struct FrameTree { struct FrameTree {
pipeline: @mut Pipeline, pipeline: @mut Pipeline,
parent: Option<@mut Pipeline>, parent: Option<@mut Pipeline>,
children: ~[@mut FrameTree], children: ~[ChildFrameTree],
} }
// Need to clone the FrameTrees, but _not_ the Pipelines // Need to clone the FrameTrees, but _not_ the Pipelines
impl Clone for FrameTree { impl Clone for FrameTree {
fn clone(&self) -> FrameTree { fn clone(&self) -> FrameTree {
let mut children = do self.children.iter().map |&frame_tree| { let mut children = do self.children.iter().map |child_frame_tree| {
@mut (*frame_tree).clone() child_frame_tree.clone()
}; };
FrameTree { FrameTree {
pipeline: self.pipeline, pipeline: self.pipeline,
@ -60,15 +62,34 @@ impl Clone for FrameTree {
} }
} }
struct ChildFrameTree {
frame_tree: @mut FrameTree,
rect: Option<Rect<f32>>,
}
impl Clone for ChildFrameTree {
fn clone(&self) -> ChildFrameTree {
ChildFrameTree {
frame_tree: @mut (*self.frame_tree).clone(),
rect: self.rect.clone(),
}
}
}
pub struct SendableFrameTree { pub struct SendableFrameTree {
pipeline: Pipeline, pipeline: Pipeline,
children: ~[SendableFrameTree], children: ~[SendableChildFrameTree],
}
pub struct SendableChildFrameTree {
frame_tree: SendableFrameTree,
rect: Option<Rect<f32>>,
} }
impl SendableFrameTree { impl SendableFrameTree {
fn contains(&self, id: PipelineId) -> bool { fn contains(&self, id: PipelineId) -> bool {
self.pipeline.id == id || self.pipeline.id == id ||
do self.children.iter().any |frame_tree| { do self.children.iter().any |&SendableChildFrameTree { frame_tree: ref frame_tree, _ }| {
frame_tree.contains(id) frame_tree.contains(id)
} }
} }
@ -77,7 +98,7 @@ impl SendableFrameTree {
impl FrameTree { impl FrameTree {
fn contains(&self, id: PipelineId) -> bool { fn contains(&self, id: PipelineId) -> bool {
self.pipeline.id == id || self.pipeline.id == id ||
do self.children.iter().any |frame_tree| { do self.children.iter().any |&ChildFrameTree { frame_tree: ref frame_tree, _ }| {
frame_tree.contains(id) frame_tree.contains(id)
} }
} }
@ -85,7 +106,8 @@ impl FrameTree {
/// Returns the frame tree whose key is id /// Returns the frame tree whose key is id
fn find_mut(@mut self, id: PipelineId) -> Option<@mut FrameTree> { fn find_mut(@mut self, id: PipelineId) -> Option<@mut FrameTree> {
if self.pipeline.id == id { return Some(self); } if self.pipeline.id == id { return Some(self); }
let mut finder = do self.children.iter().filter_map |frame_tree| { let mut finder = do self.children.iter()
.filter_map |&ChildFrameTree { frame_tree: ref frame_tree, _ }| {
frame_tree.find_mut(id) frame_tree.find_mut(id)
}; };
finder.next() finder.next()
@ -95,7 +117,7 @@ impl FrameTree {
/// if the node to replace could not be found. /// if the node to replace could not be found.
fn replace_child(&mut self, id: PipelineId, new_child: @mut FrameTree) -> Either<@mut FrameTree, @mut FrameTree> { fn replace_child(&mut self, id: PipelineId, new_child: @mut FrameTree) -> Either<@mut FrameTree, @mut FrameTree> {
let new_child_cell = Cell::new(new_child); let new_child_cell = Cell::new(new_child);
for child in self.children.mut_iter() { for &ChildFrameTree { frame_tree: ref mut child, _ } in self.children.mut_iter() {
let new_child = new_child_cell.take(); let new_child = new_child_cell.take();
if child.pipeline.id == id { if child.pipeline.id == id {
new_child.parent = child.parent; new_child.parent = child.parent;
@ -125,6 +147,15 @@ impl FrameTree {
} }
} }
impl ChildFrameTree {
fn to_sendable(&self) -> SendableChildFrameTree {
SendableChildFrameTree {
frame_tree: self.frame_tree.to_sendable(),
rect: self.rect,
}
}
}
pub struct FrameTreeIterator { pub struct FrameTreeIterator {
priv stack: ~[@mut FrameTree], priv stack: ~[@mut FrameTree],
} }
@ -133,7 +164,9 @@ impl Iterator<@mut FrameTree> for FrameTreeIterator {
fn next(&mut self) -> Option<@mut FrameTree> { fn next(&mut self) -> Option<@mut FrameTree> {
if !self.stack.is_empty() { if !self.stack.is_empty() {
let next = self.stack.pop(); let next = self.stack.pop();
self.stack.push_all(next.children); for next.children.iter().advance |&ChildFrameTree { frame_tree, _ }| {
self.stack.push(frame_tree);
}
Some(next) Some(next)
} else { } else {
None None
@ -390,10 +423,13 @@ impl Constellation {
pipeline.load(url, None); pipeline.load(url, None);
} }
for frame_tree in frame_trees.iter() { for frame_tree in frame_trees.iter() {
frame_tree.children.push(@mut FrameTree { frame_tree.children.push(ChildFrameTree {
pipeline: pipeline, frame_tree: @mut FrameTree {
parent: Some(source_pipeline), pipeline: pipeline,
children: ~[], parent: Some(source_pipeline),
children: ~[],
},
rect: None
}); });
} }
self.pipelines.insert(pipeline.id, pipeline); self.pipelines.insert(pipeline.id, pipeline);
@ -558,7 +594,10 @@ impl Constellation {
let parent = next_frame_tree.find_mut(parent.id).expect( let parent = next_frame_tree.find_mut(parent.id).expect(
"Constellation: pending frame has a parent frame that is not "Constellation: pending frame has a parent frame that is not
active. This is a bug."); active. This is a bug.");
parent.children.push(to_add.take()); parent.children.push(ChildFrameTree {
frame_tree: to_add.take(),
rect: None,
});
} }
} }
} }