scripts from inactive pipelines resize upon navigating to their pages

This commit is contained in:
Tim Kuehn 2013-07-08 18:34:04 -07:00
parent 9f6cbf91c6
commit 8b8d2f5a4b
3 changed files with 50 additions and 15 deletions

View file

@ -11,10 +11,10 @@ use std::task;
use gfx::opts::Opts; use gfx::opts::Opts;
use gfx::render_task::{PaintPermissionGranted, PaintPermissionRevoked}; use gfx::render_task::{PaintPermissionGranted, PaintPermissionRevoked};
use pipeline::Pipeline; use pipeline::Pipeline;
use servo_msg::constellation_msg::{CompositorAck, ConstellationChan, ExitMsg}; use servo_msg::constellation_msg::{CompositorAck, ConstellationChan, ExitMsg, LoadUrlMsg};
use servo_msg::constellation_msg::{LoadUrlMsg, Msg, NavigateMsg, RendererReadyMsg}; use servo_msg::constellation_msg::{Msg, NavigateMsg, RendererReadyMsg, ResizedWindowBroadcast};
use servo_msg::constellation_msg; use servo_msg::constellation_msg;
use script::script_task::ExecuteMsg; use script::script_task::{ResizeInactiveMsg, ExecuteMsg};
use servo_net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient}; use servo_net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient};
use servo_net::resource_task::ResourceTask; use servo_net::resource_task::ResourceTask;
use servo_net::resource_task; use servo_net::resource_task;
@ -199,6 +199,17 @@ impl Constellation {
} }
} }
ResizedWindowBroadcast(new_size) => match self.current_painter {
Some(current_painter_id) => for self.pipelines.iter().advance |(&id, pipeline)| {
if current_painter_id != id {
pipeline.script_chan.send(ResizeInactiveMsg(new_size));
}
},
None => for self.pipelines.iter().advance |(_, pipeline)| {
pipeline.script_chan.send(ResizeInactiveMsg(new_size));
},
},
// Acknowledgement from the compositor that it has updated its active pipeline id // Acknowledgement from the compositor that it has updated its active pipeline id
CompositorAck(id) => { CompositorAck(id) => {
self.grant_paint_permission(id); self.grant_paint_permission(id);

View file

@ -7,6 +7,7 @@
use std::comm::{Chan, SharedChan}; use std::comm::{Chan, SharedChan};
use extra::net::url::Url; use extra::net::url::Url;
use geom::size::Size2D;
#[deriving(Clone)] #[deriving(Clone)]
pub struct ConstellationChan { pub struct ConstellationChan {
@ -30,6 +31,7 @@ pub enum Msg {
ExitMsg(Chan<()>), ExitMsg(Chan<()>),
RendererReadyMsg(uint), RendererReadyMsg(uint),
CompositorAck(uint), CompositorAck(uint),
ResizedWindowBroadcast(Size2D<uint>),
} }
/// Represents the two different ways to which a page can be navigated /// Represents the two different ways to which a page can be navigated

View file

@ -20,7 +20,7 @@ use layout_interface::{ReflowDocumentDamage, ReflowForDisplay, ReflowForScriptQu
use layout_interface::ReflowMsg; use layout_interface::ReflowMsg;
use layout_interface; use layout_interface;
use servo_msg::constellation_msg::{ConstellationChan, LoadUrlMsg, NavigationDirection}; use servo_msg::constellation_msg::{ConstellationChan, LoadUrlMsg, NavigationDirection};
use servo_msg::constellation_msg::RendererReadyMsg; use servo_msg::constellation_msg::{RendererReadyMsg, ResizedWindowBroadcast};
use servo_msg::constellation_msg; use servo_msg::constellation_msg;
use std::cast::transmute; use std::cast::transmute;
@ -63,6 +63,8 @@ pub enum ScriptMsg {
FireTimerMsg(~TimerData), FireTimerMsg(~TimerData),
/// Notifies script that reflow is finished. /// Notifies script that reflow is finished.
ReflowCompleteMsg, ReflowCompleteMsg,
/// Notifies script that window has been resized but to not take immediate action.
ResizeInactiveMsg(Size2D<uint>),
/// Exits the constellation. /// Exits the constellation.
ExitMsg, ExitMsg,
} }
@ -143,8 +145,8 @@ pub struct ScriptTask {
/// Cached copy of the most recent url loaded by the script /// Cached copy of the most recent url loaded by the script
/// TODO(tkuehn): this currently does not follow any particular caching policy /// TODO(tkuehn): this currently does not follow any particular caching policy
/// and simply caches pages forever (!). /// and simply caches pages forever (!). The bool indicates if reflow is required
last_loaded_url: Option<Url>, last_loaded_url: Option<(Url, bool)>,
} }
fn global_script_context_key(_: @ScriptTask) {} fn global_script_context_key(_: @ScriptTask) {}
@ -284,6 +286,7 @@ impl ScriptTask {
FireTimerMsg(timer_data) => self.handle_fire_timer_msg(timer_data), FireTimerMsg(timer_data) => self.handle_fire_timer_msg(timer_data),
NavigateMsg(direction) => self.handle_navigate_msg(direction), NavigateMsg(direction) => self.handle_navigate_msg(direction),
ReflowCompleteMsg => self.handle_reflow_complete_msg(), ReflowCompleteMsg => self.handle_reflow_complete_msg(),
ResizeInactiveMsg(new_size) => self.handle_resize_inactive_msg(new_size),
ExitMsg => { ExitMsg => {
self.handle_exit_msg(); self.handle_exit_msg();
return false return false
@ -343,6 +346,15 @@ impl ScriptTask {
self.constellation_chan.send(constellation_msg::NavigateMsg(direction)); self.constellation_chan.send(constellation_msg::NavigateMsg(direction));
} }
/// Window was resized, but this script was not active, so don't reflow yet
fn handle_resize_inactive_msg(&mut self, new_size: Size2D<uint>) {
self.window_size = new_size;
let last_loaded_url = replace(&mut self.last_loaded_url, None);
for last_loaded_url.iter().advance |last_loaded_url| {
self.last_loaded_url = Some((last_loaded_url.first(), true));
}
}
/// Handles a request to exit the script task and shut down layout. /// Handles a request to exit the script task and shut down layout.
fn handle_exit_msg(&mut self) { fn handle_exit_msg(&mut self) {
self.join_layout(); self.join_layout();
@ -356,9 +368,18 @@ impl ScriptTask {
/// The entry point to document loading. Defines bindings, sets up the window and document /// The entry point to document loading. Defines bindings, sets up the window and document
/// objects, parses HTML and CSS, and kicks off initial layout. /// objects, parses HTML and CSS, and kicks off initial layout.
fn load(&mut self, url: Url) { fn load(&mut self, url: Url) {
for self.last_loaded_url.iter().advance |last_loaded_url| { let last_loaded_url = replace(&mut self.last_loaded_url, None);
if url == *last_loaded_url { return; } for last_loaded_url.iter().advance |last_loaded_url| {
let (ref last_loaded_url, needs_reflow) = *last_loaded_url;
if *last_loaded_url == url {
if needs_reflow {
self.reflow_all(ReflowForDisplay);
self.last_loaded_url = Some((last_loaded_url.clone(), false));
} }
return;
}
}
// Define the script DOM bindings. // Define the script DOM bindings.
// //
// FIXME: Can this be done earlier, to save the flag? // FIXME: Can this be done earlier, to save the flag?
@ -425,7 +446,7 @@ impl ScriptTask {
~"???", ~"???",
1); 1);
} }
self.last_loaded_url = Some(url); self.last_loaded_url = Some((url, false));
} }
/// Sends a ping to layout and waits for the response. The response will arrive when the /// Sends a ping to layout and waits for the response. The response will arrive when the
@ -546,6 +567,7 @@ impl ScriptTask {
if self.root_frame.is_some() { if self.root_frame.is_some() {
self.reflow(ReflowForDisplay) self.reflow(ReflowForDisplay)
} }
self.constellation_chan.send(ResizedWindowBroadcast(self.window_size));
} }
// FIXME(pcwalton): This reflows the entire document and is not incremental-y. // FIXME(pcwalton): This reflows the entire document and is not incremental-y.