Fixes a bug where the window size may not get passed to a new root pipeline.

This commit is contained in:
Glenn Watson 2015-03-24 10:08:44 +10:00
parent 5ce7d8accf
commit 30ac159721
2 changed files with 34 additions and 31 deletions

View file

@ -7,6 +7,7 @@ use pipeline::{Pipeline, CompositionPipeline};
use compositor_task::CompositorProxy;
use compositor_task::Msg as CompositorMsg;
use devtools_traits::{DevtoolsControlChan, DevtoolsControlMsg};
use geom::point::Point2D;
use geom::rect::{Rect, TypedRect};
use geom::scale_factor::ScaleFactor;
use gfx::font_cache_task::FontCacheTask;
@ -220,23 +221,10 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
}
}
/// Gets the current window_size rect for an existing pipeline. This is used
/// to initialize the window size for a new pipeline, but may be None
/// when a new frame is loading.
fn get_window_size_data_for_pipeline(&self, pipeline_id: PipelineId) -> Option<WindowSizeData> {
self.pipeline(pipeline_id).rect.map(|rect| {
WindowSizeData {
visible_viewport: rect.size,
initial_viewport: rect.size * ScaleFactor::new(1.0),
device_pixel_ratio: self.window_size.device_pixel_ratio,
}
})
}
/// Helper function for creating a pipeline
fn new_pipeline(&mut self,
parent_info: Option<(PipelineId, SubpageId)>,
initial_window_size: Option<WindowSizeData>,
initial_window_rect: Option<TypedRect<PagePx, f32>>,
script_channel: Option<ScriptControlChan>,
load_data: LoadData)
-> PipelineId {
@ -255,9 +243,10 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
self.storage_task.clone(),
self.time_profiler_chan.clone(),
self.memory_profiler_chan.clone(),
initial_window_size,
initial_window_rect,
script_channel,
load_data);
load_data,
self.window_size.device_pixel_ratio);
assert!(!self.pipelines.contains_key(&pipeline_id));
self.pipelines.insert(pipeline_id, pipeline);
@ -433,16 +422,16 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
}
debug!("creating replacement pipeline for about:failure");
let window_size = self.get_window_size_data_for_pipeline(pipeline_id);
let new_pipeline_id = self.new_pipeline(parent_info, window_size, None,
let window_rect = self.pipeline(pipeline_id).rect;
let new_pipeline_id = self.new_pipeline(parent_info, window_rect, None,
LoadData::new(Url::parse("about:failure").unwrap()));
self.push_pending_frame(new_pipeline_id, Some(pipeline_id));
}
fn handle_init_load(&mut self, url: Url) {
let window_size = self.window_size;
let root_pipeline_id = self.new_pipeline(None, Some(window_size), None, LoadData::new(url));
let window_rect = Rect(Point2D::zero(), self.window_size.visible_viewport);
let root_pipeline_id = self.new_pipeline(None, Some(window_rect), None, LoadData::new(url));
self.push_pending_frame(root_pipeline_id, None);
}
@ -508,11 +497,11 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
let old_pipeline_id = old_subpage_id.map(|old_subpage_id| {
self.find_subpage(containing_pipeline_id, old_subpage_id).id
});
let window_size = old_pipeline_id.and_then(|old_pipeline_id| {
self.get_window_size_data_for_pipeline(old_pipeline_id)
let window_rect = old_pipeline_id.and_then(|old_pipeline_id| {
self.pipeline(old_pipeline_id).rect
});
let new_pipeline_id = self.new_pipeline(Some((containing_pipeline_id, new_subpage_id)),
window_size,
window_rect,
script_chan,
LoadData::new(url));
self.subpage_map.insert((containing_pipeline_id, new_subpage_id), new_pipeline_id);
@ -551,8 +540,8 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
// changes would be overridden by changing the subframe associated with source_id.
// Create the new pipeline
let window_size = self.get_window_size_data_for_pipeline(source_id);
let new_pipeline_id = self.new_pipeline(None, window_size, None, load_data);
let window_rect = self.pipeline(source_id).rect;
let new_pipeline_id = self.new_pipeline(None, window_rect, None, load_data);
self.push_pending_frame(new_pipeline_id, Some(source_id));
// Send message to ScriptTask that will suspend all timers

View file

@ -9,16 +9,18 @@ use script_traits::{NewLayoutInfo, ConstellationControlMsg};
use devtools_traits::DevtoolsControlChan;
use geom::rect::{TypedRect};
use geom::scale_factor::ScaleFactor;
use gfx::paint_task::Msg as PaintMsg;
use gfx::paint_task::{PaintChan, PaintTask};
use gfx::font_cache_task::FontCacheTask;
use layers::geometry::DevicePixel;
use msg::constellation_msg::{ConstellationChan, Failure, FrameId, PipelineId, SubpageId};
use msg::constellation_msg::{LoadData, WindowSizeData, PipelineExitType};
use net::image_cache_task::ImageCacheTask;
use net::resource_task::ResourceTask;
use net::storage_task::StorageTask;
use url::Url;
use util::geometry::{PagePx};
use util::geometry::{PagePx, ViewportPx};
use util::memory::MemoryProfilerChan;
use util::time::TimeProfilerChan;
use std::sync::mpsc::{Receiver, channel};
@ -63,9 +65,10 @@ impl Pipeline {
storage_task: StorageTask,
time_profiler_chan: TimeProfilerChan,
memory_profiler_chan: MemoryProfilerChan,
window_size: Option<WindowSizeData>,
window_rect: Option<TypedRect<PagePx, f32>>,
script_chan: Option<ScriptControlChan>,
load_data: LoadData)
load_data: LoadData,
device_pixel_ratio: ScaleFactor<ViewportPx, DevicePixel, f32>)
-> Pipeline
where LTF: LayoutTaskFactory, STF:ScriptTaskFactory {
let layout_pair = ScriptTaskFactory::create_layout_channel(None::<&mut STF>);
@ -82,6 +85,15 @@ impl Pipeline {
let script_chan = match script_chan {
None => {
let (script_chan, script_port) = channel();
let window_size = window_rect.map(|rect| {
WindowSizeData {
visible_viewport: rect.size,
initial_viewport: rect.size * ScaleFactor::new(1.0),
device_pixel_ratio: device_pixel_ratio,
}
});
ScriptTaskFactory::create(None::<&mut STF>,
id,
parent_info,
@ -147,7 +159,8 @@ impl Pipeline {
paint_chan,
layout_shutdown_port,
paint_shutdown_port,
load_data.url)
load_data.url,
window_rect)
}
pub fn new(id: PipelineId,
@ -157,7 +170,8 @@ impl Pipeline {
paint_chan: PaintChan,
layout_shutdown_port: Receiver<()>,
paint_shutdown_port: Receiver<()>,
url: Url)
url: Url,
rect: Option<TypedRect<PagePx, f32>>)
-> Pipeline {
Pipeline {
id: id,
@ -170,7 +184,7 @@ impl Pipeline {
url: url,
title: None,
children: vec!(),
rect: None,
rect: rect,
}
}