From b262fc16e0eed30347df2590c14e7ebc74de2bb4 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 4 Feb 2015 00:04:12 +0800 Subject: [PATCH 1/2] Modified constellation key event handler to deal with missing frames --- components/compositing/constellation.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 45324165d0d..c59184f8631 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -885,11 +885,17 @@ impl Constellation { } fn handle_key_msg(&self, key: Key, state: KeyState, mods: KeyModifiers) { - self.current_frame().as_ref().map(|frame| { - let ScriptControlChan(ref chan) = frame.pipeline.borrow().script_chan; - chan.send(ConstellationControlMsg::SendEvent( - frame.pipeline.borrow().id, CompositorEvent::KeyEvent(key, state, mods))).unwrap(); - }); + match *self.current_frame() { + Some(ref frame) => { + let ScriptControlChan(ref chan) = frame.pipeline.borrow().script_chan; + chan.send(ConstellationControlMsg::SendEvent( + frame.pipeline.borrow().id, + CompositorEvent::KeyEvent(key, state, mods))).unwrap(); + }, + None => self.compositor_proxy.clone_compositor_proxy() + .send(CompositorMsg::KeyEvent(key, mods)) + } + } fn handle_get_pipeline_title_msg(&mut self, pipeline_id: PipelineId) { From 37cb876f4ea6c39390c359be068f352e2d47d8a0 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 4 Feb 2015 10:30:23 +0800 Subject: [PATCH 2/2] Changed Msg::KeyEvent to take in KeyState and moved the checks in CompositorTask::send_key_event to Compositor::handle_browser_message --- components/compositing/compositor.rs | 6 ++++-- components/compositing/compositor_task.rs | 6 ++---- components/compositing/constellation.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index f09eb6b51a8..a556bf958b4 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -358,8 +358,10 @@ impl IOCompositor { } } - (Msg::KeyEvent(key, modified), ShutdownState::NotShuttingDown) => { - self.window.handle_key(key, modified); + (Msg::KeyEvent(key, state, modified), ShutdownState::NotShuttingDown) => { + if state == KeyState::Pressed { + self.window.handle_key(key, modified); + } } (Msg::SetCursor(cursor), ShutdownState::NotShuttingDown) => { diff --git a/components/compositing/compositor_task.rs b/components/compositing/compositor_task.rs index 7eaf56798a2..e2f21d0910e 100644 --- a/components/compositing/compositor_task.rs +++ b/components/compositing/compositor_task.rs @@ -91,9 +91,7 @@ impl ScriptListener for Box { } fn send_key_event(&mut self, key: Key, state: KeyState, modifiers: KeyModifiers) { - if state == KeyState::Pressed { - self.send(Msg::KeyEvent(key, modifiers)); - } + self.send(Msg::KeyEvent(key, state, modifiers)); } } @@ -218,7 +216,7 @@ pub enum Msg { /// composite should happen. (See the `scrolling` module.) ScrollTimeout(u64), /// Sends an unconsumed key event back to the compositor. - KeyEvent(Key, KeyModifiers), + KeyEvent(Key, KeyState, KeyModifiers), /// Changes the cursor. SetCursor(Cursor), /// Informs the compositor that the paint task for the given pipeline has exited. diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index c59184f8631..6b71bcc1c78 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -893,7 +893,7 @@ impl Constellation { CompositorEvent::KeyEvent(key, state, mods))).unwrap(); }, None => self.compositor_proxy.clone_compositor_proxy() - .send(CompositorMsg::KeyEvent(key, mods)) + .send(CompositorMsg::KeyEvent(key, state, mods)) } }