Pass all key events to the current constellation frame.

This commit is contained in:
Josh Matthews 2014-10-02 03:11:50 -04:00
parent c5e1b0d32e
commit 1c64dabb15
7 changed files with 304 additions and 9 deletions

View file

@ -13,7 +13,8 @@ use gfx::render_task;
use layers::geometry::DevicePixel;
use layout_traits::{LayoutControlChan, LayoutTaskFactory, ExitNowMsg};
use libc;
use script_traits::{ResizeMsg, ResizeInactiveMsg, ExitPipelineMsg};
use script_traits;
use script_traits::{ResizeMsg, ResizeInactiveMsg, ExitPipelineMsg, SendEventMsg};
use script_traits::{ScriptControlChan, ScriptTaskFactory};
use servo_msg::compositor_msg::LayerId;
use servo_msg::constellation_msg::{ConstellationChan, ExitMsg, FailureMsg, Failure, FrameRectMsg};
@ -21,6 +22,7 @@ use servo_msg::constellation_msg::{IFrameSandboxState, IFrameUnsandboxed, InitLo
use servo_msg::constellation_msg::{LoadCompleteMsg, LoadUrlMsg, LoadData, Msg, NavigateMsg};
use servo_msg::constellation_msg::{NavigationType, PipelineId, RendererReadyMsg, ResizedWindowMsg};
use servo_msg::constellation_msg::{ScriptLoadedURLInIFrameMsg, SubpageId, WindowSizeData};
use servo_msg::constellation_msg::{KeyEvent, Key, KeyState};
use servo_msg::constellation_msg;
use servo_net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient};
use servo_net::resource_task::ResourceTask;
@ -450,6 +452,10 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
debug!("constellation got window resize message");
self.handle_resized_window_msg(new_size);
}
KeyEvent(key, state) => {
debug!("constellation got key event message");
self.handle_key_msg(key, state);
}
}
true
}
@ -761,6 +767,13 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
.any(|current_frame| current_frame.contains(pipeline_id))
}
fn handle_key_msg(&self, key: Key, state: KeyState) {
self.current_frame().as_ref().map(|frame| {
let ScriptControlChan(ref chan) = frame.pipeline.script_chan;
chan.send(SendEventMsg(frame.pipeline.id, script_traits::KeyEvent(key, state)));
});
}
fn handle_renderer_ready_msg(&mut self, pipeline_id: PipelineId) {
debug!("Renderer {} ready to send paint msg", pipeline_id);
// This message could originate from a pipeline in the navigation context or