Skip to content

Commit

Permalink
Remove code duplication in finding FrameTrees with a given pipeline id.
Browse files Browse the repository at this point in the history
  • Loading branch information
larsbergstrom committed Sep 12, 2013
1 parent 08b3902 commit 969a4e3
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/components/main/constellation.rs
Expand Up @@ -313,6 +313,15 @@ impl Constellation {
&self.navigation_context.current
}

/// Returns both the navigation context and pending frame trees whose keys are pipeline_id.
pub fn find_all(&mut self, pipeline_id: PipelineId) -> ~[@mut FrameTree] {
let matching_navi_frames = self.navigation_context.find_all(pipeline_id);
let matching_pending_frames = do self.pending_frames.iter().filter_map |frame_change| {
frame_change.after.find_mut(pipeline_id)
};
matching_navi_frames.move_iter().chain(matching_pending_frames).collect()
}

/// Handles loading pages, navigation, and granting access to the compositor
fn handle_request(&mut self, request: Msg) -> bool {
match request {
Expand Down Expand Up @@ -385,14 +394,8 @@ impl Constellation {
let url = make_url(failure, None);
pipeline.load(url);

let frame_trees: ~[@mut FrameTree] = {
let matching_navi_frames = self.navigation_context.find_all(pipeline_id);
let matching_pending_frames = do self.pending_frames.iter().filter_map |frame_change| {
frame_change.after.find_mut(pipeline_id)
};
matching_navi_frames.move_iter().chain(matching_pending_frames).collect()
};
for frame_tree in frame_trees.iter() {
let frames = self.find_all(pipeline_id);
for frame_tree in frames.iter() {
frame_tree.pipeline = pipeline;
};

Expand Down Expand Up @@ -456,14 +459,8 @@ impl Constellation {
}
}
// Traverse the navigation context and pending frames and tell each associated pipeline to resize.
let frame_trees: ~[@mut FrameTree] = {
let matching_navi_frames = self.navigation_context.find_all(pipeline_id);
let matching_pending_frames = do self.pending_frames.iter().filter_map |frame_change| {
frame_change.after.find_mut(pipeline_id)
};
matching_navi_frames.move_iter().chain(matching_pending_frames).collect()
};
for frame_tree in frame_trees.iter() {
let frames = self.find_all(pipeline_id);
for frame_tree in frames.iter() {
for child_frame_tree in frame_tree.children.mut_iter() {
let pipeline = &child_frame_tree.frame_tree.pipeline;
if pipeline.subpage_id.expect("Constellation: child frame does not have a
Expand Down

0 comments on commit 969a4e3

Please sign in to comment.