Various cleanup in constellation.rs.

This commit is contained in:
Ms2ger 2014-11-17 18:27:22 +01:00
parent 2bda68f038
commit 4d3977b8f8

View file

@ -92,11 +92,8 @@ struct FrameTree {
impl FrameTree { impl FrameTree {
fn new(pipeline: Rc<Pipeline>, parent_pipeline: Option<Rc<Pipeline>>) -> FrameTree { fn new(pipeline: Rc<Pipeline>, parent_pipeline: Option<Rc<Pipeline>>) -> FrameTree {
FrameTree { FrameTree {
pipeline: pipeline.clone(), pipeline: pipeline,
parent: match parent_pipeline { parent: RefCell::new(parent_pipeline),
Some(ref pipeline) => RefCell::new(Some(pipeline.clone())),
None => RefCell::new(None),
},
children: RefCell::new(vec!()), children: RefCell::new(vec!()),
has_compositor_layer: Cell::new(false), has_compositor_layer: Cell::new(false),
} }
@ -147,15 +144,14 @@ pub struct FrameTreeDiff {
impl FrameTree { impl FrameTree {
fn to_sendable(&self) -> SendableFrameTree { fn to_sendable(&self) -> SendableFrameTree {
let sendable_frame_tree = SendableFrameTree { SendableFrameTree {
pipeline: self.pipeline.to_sendable(), pipeline: self.pipeline.to_sendable(),
children: self.children children: self.children
.borrow() .borrow()
.iter() .iter()
.map(|frame_tree| frame_tree.to_sendable()) .map(|frame_tree| frame_tree.to_sendable())
.collect(), .collect(),
}; }
sendable_frame_tree
} }
} }
@ -181,12 +177,15 @@ impl FrameTreeTraversal for Rc<FrameTree> {
fn replace_child(&self, id: PipelineId, new_child: Rc<FrameTree>) -> ReplaceResult { fn replace_child(&self, id: PipelineId, new_child: Rc<FrameTree>) -> ReplaceResult {
for frame_tree in self.iter() { for frame_tree in self.iter() {
let mut children = frame_tree.children.borrow_mut(); let mut children = frame_tree.children.borrow_mut();
let mut child = children.iter_mut() let child = children.iter_mut()
.find(|child| child.frame_tree.pipeline.id == id); .find(|child| child.frame_tree.pipeline.id == id);
for child in child.iter_mut() { match child {
Some(child) => {
*new_child.parent.borrow_mut() = child.frame_tree.parent.borrow().clone(); *new_child.parent.borrow_mut() = child.frame_tree.parent.borrow().clone();
return ReplacedNode(replace(&mut child.frame_tree, new_child)); return ReplacedNode(replace(&mut child.frame_tree, new_child));
} }
None => (),
}
} }
OriginalNode(new_child) OriginalNode(new_child)
} }
@ -216,14 +215,14 @@ struct FrameTreeIterator {
impl Iterator<Rc<FrameTree>> for FrameTreeIterator { impl Iterator<Rc<FrameTree>> for FrameTreeIterator {
fn next(&mut self) -> Option<Rc<FrameTree>> { fn next(&mut self) -> Option<Rc<FrameTree>> {
if !self.stack.is_empty() { match self.stack.pop() {
let next = self.stack.pop(); Some(next) => {
for cft in next.as_ref().unwrap().children.borrow().iter() { for cft in next.children.borrow().iter() {
self.stack.push(cft.frame_tree.clone()); self.stack.push(cft.frame_tree.clone());
} }
Some(next.unwrap()) Some(next)
} else { }
None None => None,
} }
} }
} }
@ -272,10 +271,11 @@ impl NavigationContext {
fn load(&mut self, frame_tree: Rc<FrameTree>) -> Vec<Rc<FrameTree>> { fn load(&mut self, frame_tree: Rc<FrameTree>) -> Vec<Rc<FrameTree>> {
debug!("navigating to {}", frame_tree.pipeline.id); debug!("navigating to {}", frame_tree.pipeline.id);
let evicted = replace(&mut self.next, vec!()); let evicted = replace(&mut self.next, vec!());
if self.current.is_some() { match self.current.take() {
self.previous.push(self.current.take().unwrap()); Some(current) => self.previous.push(current),
None => (),
} }
self.current = Some(frame_tree.clone()); self.current = Some(frame_tree);
evicted evicted
} }
@ -390,11 +390,11 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
/// Returns both the navigation context and pending frame trees whose keys are pipeline_id. /// Returns both the navigation context and pending frame trees whose keys are pipeline_id.
fn find_all(&mut self, pipeline_id: PipelineId) -> Vec<Rc<FrameTree>> { fn find_all(&mut self, pipeline_id: PipelineId) -> Vec<Rc<FrameTree>> {
let matching_navi_frames = self.navigation_context.find_all(pipeline_id); let mut matching_navi_frames = self.navigation_context.find_all(pipeline_id);
let matching_pending_frames = self.pending_frames.iter().filter_map(|frame_change| { matching_navi_frames.extend(self.pending_frames.iter().filter_map(|frame_change| {
frame_change.after.find(pipeline_id) frame_change.after.find(pipeline_id)
}); }));
matching_navi_frames.into_iter().chain(matching_pending_frames).collect() matching_navi_frames
} }
/// Handles loading pages, navigation, and granting access to the compositor /// Handles loading pages, navigation, and granting access to the compositor
@ -508,13 +508,13 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
let idx = self.pending_frames.iter().position(|pending| { let idx = self.pending_frames.iter().position(|pending| {
pending.after.pipeline.id == pipeline_id pending.after.pipeline.id == pipeline_id
}); });
idx.map(|idx| { match idx {
Some(idx) => {
debug!("removing pending frame change for failed pipeline"); debug!("removing pending frame change for failed pipeline");
force_pipeline_exit(&self.pending_frames[idx].after.pipeline); force_pipeline_exit(&self.pending_frames[idx].after.pipeline);
self.pending_frames.remove(idx) self.pending_frames.remove(idx);
}); },
if idx.is_none() { None => break,
break;
} }
} }
debug!("creating replacement pipeline for about:failure"); debug!("creating replacement pipeline for about:failure");
@ -797,7 +797,8 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
let pending_index = self.pending_frames.iter().rposition(|frame_change| { let pending_index = self.pending_frames.iter().rposition(|frame_change| {
frame_change.after.pipeline.id == pipeline_id frame_change.after.pipeline.id == pipeline_id
}); });
for &pending_index in pending_index.iter() { match pending_index {
Some(pending_index) => {
let frame_change = self.pending_frames.swap_remove(pending_index).unwrap(); let frame_change = self.pending_frames.swap_remove(pending_index).unwrap();
let to_add = frame_change.after.clone(); let to_add = frame_change.after.clone();
@ -858,6 +859,8 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
} }
self.grant_paint_permission(next_frame_tree, frame_change.navigation_type); self.grant_paint_permission(next_frame_tree, frame_change.navigation_type);
},
None => (),
} }
} }
@ -908,9 +911,9 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
} }
fn handle_evicted_frames(&mut self, evicted: Vec<Rc<FrameTree>>) { fn handle_evicted_frames(&mut self, evicted: Vec<Rc<FrameTree>>) {
for frame_tree in evicted.iter() { for frame_tree in evicted.into_iter() {
if !self.navigation_context.contains(frame_tree.pipeline.id) { if !self.navigation_context.contains(frame_tree.pipeline.id) {
self.close_pipelines(frame_tree.clone()); self.close_pipelines(frame_tree);
} else { } else {
let frames = frame_tree.children.borrow().iter() let frames = frame_tree.children.borrow().iter()
.map(|child| child.frame_tree.clone()).collect(); .map(|child| child.frame_tree.clone()).collect();
@ -979,8 +982,9 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
&None => return, &None => return,
}; };
let (child, parent) = let pair = self.find_child_parent_pair_in_frame_tree(current_frame_tree,
match self.find_child_parent_pair_in_frame_tree(current_frame_tree, pipeline_id) { pipeline_id);
let (child, parent) = match pair {
Some(pair) => pair, Some(pair) => pair,
None => return, None => return,
}; };