Implement window.frameElement, change window.parent to make use of it.

This commit is contained in:
Glenn Watson 2015-02-05 10:01:04 +10:00
parent 5436922169
commit 1e0e98b63c
10 changed files with 88 additions and 74 deletions

View file

@ -191,7 +191,7 @@ impl FrameTreeTraversal for Rc<FrameTree> {
/// Returns the frame tree whose subpage is id
fn find_with_subpage_id(&self, id: Option<SubpageId>) -> Option<Rc<FrameTree>> {
self.iter().find(|frame_tree| id == frame_tree.pipeline.borrow().subpage_id)
self.iter().find(|frame_tree| id == frame_tree.pipeline.borrow().subpage_id())
}
/// Replaces a node of the frame tree in place. Returns the node that was removed or the
@ -392,14 +392,12 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
/// Helper function for creating a pipeline
fn new_pipeline(&mut self,
id: PipelineId,
subpage_id: Option<SubpageId>,
parent_id: Option<PipelineId>,
parent: Option<(PipelineId, SubpageId)>,
script_pipeline: Option<Rc<Pipeline>>,
load_data: LoadData)
-> Rc<Pipeline> {
let pipe = Pipeline::create::<LTF, STF>(id,
subpage_id,
parent_id,
parent,
self.chan.clone(),
self.compositor_proxy.clone_compositor_proxy(),
self.devtools_chan.clone(),
@ -454,8 +452,8 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
self.handle_exit();
return false;
}
ConstellationMsg::Failure(Failure { pipeline_id, subpage_id }) => {
self.handle_failure_msg(pipeline_id, subpage_id);
ConstellationMsg::Failure(Failure { pipeline_id, parent }) => {
self.handle_failure_msg(pipeline_id, parent);
}
// This should only be called once per constellation, and only by the browser
ConstellationMsg::InitLoadUrl(url) => {
@ -530,8 +528,8 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
self.compositor_proxy.send(CompositorMsg::ShutdownComplete);
}
fn handle_failure_msg(&mut self, pipeline_id: PipelineId, subpage_id: Option<SubpageId>) {
debug!("handling failure message from pipeline {:?}, {:?}", pipeline_id, subpage_id);
fn handle_failure_msg(&mut self, pipeline_id: PipelineId, parent: Option<(PipelineId, SubpageId)>) {
debug!("handling failure message from pipeline {:?}, {:?}", pipeline_id, parent);
if opts::get().hard_fail {
// It's quite difficult to make Servo exit cleanly if some tasks have failed.
@ -572,7 +570,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
let new_id = self.get_next_pipeline_id();
let new_frame_id = self.get_next_frame_id();
let pipeline = self.new_pipeline(new_id, subpage_id, None, None,
let pipeline = self.new_pipeline(new_id, parent, None,
LoadData::new(Url::parse("about:failure").unwrap()));
self.browse(Some(pipeline_id),
@ -599,7 +597,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
fn handle_init_load(&mut self, url: Url) {
let next_pipeline_id = self.get_next_pipeline_id();
let next_frame_id = self.get_next_frame_id();
let pipeline = self.new_pipeline(next_pipeline_id, None, None, None, LoadData::new(url));
let pipeline = self.new_pipeline(next_pipeline_id, None, None, LoadData::new(url));
self.browse(None,
Rc::new(FrameTree::new(next_frame_id, pipeline.clone(), None)),
NavigationType::Load);
@ -614,7 +612,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
// Returns true if a child frame tree's subpage id matches the given subpage id
let subpage_eq = |&:child_frame_tree: & &mut ChildFrameTree| {
child_frame_tree.frame_tree.pipeline.borrow().
subpage_id.expect("Constellation:
subpage_id().expect("Constellation:
child frame does not have a subpage id. This should not be possible.")
== subpage_id
};
@ -784,8 +782,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
let new_frame_pipeline_id = self.get_next_pipeline_id();
let pipeline = self.new_pipeline(
new_frame_pipeline_id,
Some(new_subpage_id),
Some(containing_page_pipeline_id),
Some((containing_page_pipeline_id, new_subpage_id)),
script_pipeline,
LoadData::new(url)
);
@ -829,11 +826,10 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
// changes would be overridden by changing the subframe associated with source_id.
let parent = source_frame.parent.clone();
let subpage_id = source_frame.pipeline.borrow().subpage_id;
let parent_id = source_frame.pipeline.borrow().parent_id;
let parent_id = source_frame.pipeline.borrow().parent;
let next_pipeline_id = self.get_next_pipeline_id();
let next_frame_id = self.get_next_frame_id();
let pipeline = self.new_pipeline(next_pipeline_id, subpage_id, parent_id, None, load_data);
let pipeline = self.new_pipeline(next_pipeline_id, parent_id, None, load_data);
self.browse(Some(source_id),
Rc::new(FrameTree::new(next_frame_id,
pipeline.clone(),
@ -979,7 +975,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
// Add to_add to parent's children, if it is not the root
let parent = &to_add.parent;
for parent in parent.borrow().iter() {
let subpage_id = to_add.pipeline.borrow().subpage_id
let subpage_id = to_add.pipeline.borrow().subpage_id()
.expect("Constellation:
Child frame's subpage id is None. This should be impossible.");
let rect = self.pending_sizes.remove(&(parent.id, subpage_id));

View file

@ -23,8 +23,7 @@ use std::sync::mpsc::{Receiver, channel};
/// A uniquely-identifiable pipeline of script task, layout task, and paint task.
pub struct Pipeline {
pub id: PipelineId,
pub subpage_id: Option<SubpageId>,
pub parent_id: Option<PipelineId>,
pub parent: Option<(PipelineId, SubpageId)>,
pub script_chan: ScriptControlChan,
pub layout_chan: LayoutControlChan,
pub paint_chan: PaintChan,
@ -49,8 +48,7 @@ impl Pipeline {
/// Returns the channels wrapped in a struct.
/// If script_pipeline is not None, then subpage_id must also be not None.
pub fn create<LTF,STF>(id: PipelineId,
subpage_id: Option<SubpageId>,
parent_id: Option<PipelineId>,
parent: Option<(PipelineId, SubpageId)>,
constellation_chan: ConstellationChan,
compositor_proxy: Box<CompositorProxy+'static+Send>,
devtools_chan: Option<DevtoolsControlChan>,
@ -72,7 +70,7 @@ impl Pipeline {
let failure = Failure {
pipeline_id: id,
subpage_id: subpage_id,
parent: parent,
};
let script_chan = match script_pipeline {
@ -97,7 +95,7 @@ impl Pipeline {
let new_layout_info = NewLayoutInfo {
old_pipeline_id: spipe.id.clone(),
new_pipeline_id: id,
subpage_id: subpage_id.expect("script_pipeline != None but subpage_id == None"),
subpage_id: parent.expect("script_pipeline != None but subpage_id == None").1,
layout_chan: ScriptTaskFactory::clone_layout_channel(None::<&mut STF>, &layout_pair),
};
@ -131,8 +129,7 @@ impl Pipeline {
layout_shutdown_chan);
Pipeline::new(id,
subpage_id,
parent_id,
parent,
script_chan,
LayoutControlChan(pipeline_chan),
paint_chan,
@ -142,8 +139,7 @@ impl Pipeline {
}
pub fn new(id: PipelineId,
subpage_id: Option<SubpageId>,
parent_id: Option<PipelineId>,
parent: Option<(PipelineId, SubpageId)>,
script_chan: ScriptControlChan,
layout_chan: LayoutControlChan,
paint_chan: PaintChan,
@ -153,8 +149,7 @@ impl Pipeline {
-> Pipeline {
Pipeline {
id: id,
subpage_id: subpage_id,
parent_id: parent_id,
parent: parent,
script_chan: script_chan,
layout_chan: layout_chan,
paint_chan: paint_chan,
@ -167,7 +162,9 @@ impl Pipeline {
pub fn load(&self) {
let ScriptControlChan(ref chan) = self.script_chan;
chan.send(ConstellationControlMsg::Load(self.id, self.parent_id, self.load_data.clone())).unwrap();
chan.send(ConstellationControlMsg::Load(self.id,
self.parent,
self.load_data.clone())).unwrap();
}
pub fn grant_paint_permission(&self) {
@ -212,4 +209,8 @@ impl Pipeline {
paint_chan: self.paint_chan.clone(),
}
}
pub fn subpage_id(&self) -> Option<SubpageId> {
self.parent.map(|parent| parent.1)
}
}