mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Sending key events through script task before processing them in the compositor.
Fixes #4163
This commit is contained in:
parent
f451005f4f
commit
b0552cb98e
10 changed files with 131 additions and 66 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
use compositor_layer::{CompositorData, CompositorLayer, DoesntWantScrollEvents};
|
||||
use compositor_layer::{WantsScrollEvents};
|
||||
use compositor_task;
|
||||
use compositor_task::{ChangePageLoadData, ChangePageTitle, ChangePaintState, ChangeReadyState};
|
||||
use compositor_task::{CompositorEventListener, CompositorProxy, CompositorReceiver};
|
||||
use compositor_task::{CompositorTask, CreateOrUpdateDescendantLayer, CreateOrUpdateRootLayer};
|
||||
|
@ -336,6 +337,10 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
}
|
||||
}
|
||||
|
||||
(compositor_task::KeyEvent(key, modified), NotShuttingDown) => {
|
||||
self.window.handle_key(key, modified);
|
||||
}
|
||||
|
||||
// When we are shutting_down, we need to avoid performing operations
|
||||
// such as Paint that may crash because we have begun tearing down
|
||||
// the rest of our resources.
|
||||
|
|
|
@ -20,6 +20,7 @@ use layers::layers::LayerBufferSet;
|
|||
use servo_msg::compositor_msg::{Epoch, LayerId, LayerMetadata, ReadyState};
|
||||
use servo_msg::compositor_msg::{PaintListener, PaintState, ScriptListener, ScrollPolicy};
|
||||
use servo_msg::constellation_msg::{ConstellationChan, LoadData, PipelineId};
|
||||
use servo_msg::constellation_msg::{Key, KeyState, KeyModifiers, Pressed};
|
||||
use servo_util::memory::MemoryProfilerChan;
|
||||
use servo_util::time::TimeProfilerChan;
|
||||
use std::comm::{channel, Sender, Receiver};
|
||||
|
@ -85,6 +86,12 @@ impl ScriptListener for Box<CompositorProxy+'static+Send> {
|
|||
fn set_title(&mut self, pipeline_id: PipelineId, title: Option<String>) {
|
||||
self.send(ChangePageTitle(pipeline_id, title))
|
||||
}
|
||||
|
||||
fn send_key_event(&mut self, key: Key, state: KeyState, modifiers: KeyModifiers) {
|
||||
if state == Pressed {
|
||||
self.send(KeyEvent(key, modifiers));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Information about each layer that the compositor keeps.
|
||||
|
@ -204,6 +211,8 @@ pub enum Msg {
|
|||
/// Indicates that the scrolling timeout with the given starting timestamp has happened and a
|
||||
/// composite should happen. (See the `scrolling` module.)
|
||||
ScrollTimeout(u64),
|
||||
/// Sends an unconsumed key event back to the compositor.
|
||||
KeyEvent(Key, KeyModifiers),
|
||||
}
|
||||
|
||||
impl Show for Msg {
|
||||
|
@ -226,6 +235,7 @@ impl Show for Msg {
|
|||
FrameTreeUpdateMsg(..) => write!(f, "FrameTreeUpdateMsg"),
|
||||
LoadComplete => write!(f, "LoadComplete"),
|
||||
ScrollTimeout(..) => write!(f, "ScrollTimeout"),
|
||||
KeyEvent(..) => write!(f, "KeyEvent"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use compositor_task::{GetGraphicsMetadata, CreateOrUpdateRootLayer, CreateOrUpda
|
|||
use compositor_task::{Exit, ChangeReadyState, LoadComplete, Paint, ScrollFragmentPoint, SetIds};
|
||||
use compositor_task::{SetLayerOrigin, ShutdownComplete, ChangePaintState, PaintMsgDiscarded};
|
||||
use compositor_task::{CompositorEventListener, CompositorReceiver, ScrollTimeout, ChangePageTitle};
|
||||
use compositor_task::{ChangePageLoadData, FrameTreeUpdateMsg};
|
||||
use compositor_task::{ChangePageLoadData, FrameTreeUpdateMsg, KeyEvent};
|
||||
use windowing::WindowEvent;
|
||||
|
||||
use geom::scale_factor::ScaleFactor;
|
||||
|
@ -106,7 +106,7 @@ impl CompositorEventListener for NullCompositor {
|
|||
SetLayerOrigin(..) | Paint(..) |
|
||||
ChangeReadyState(..) | ChangePaintState(..) | ScrollFragmentPoint(..) |
|
||||
LoadComplete | PaintMsgDiscarded(..) | ScrollTimeout(..) | ChangePageTitle(..) |
|
||||
ChangePageLoadData(..) => ()
|
||||
ChangePageLoadData(..) | KeyEvent(..) => ()
|
||||
}
|
||||
true
|
||||
}
|
||||
|
|
|
@ -123,5 +123,7 @@ pub trait WindowMethods {
|
|||
/// some type of platform-specific graphics context current. Returns true if the composite may
|
||||
/// proceed and false if it should not.
|
||||
fn prepare_for_composite(&self) -> bool;
|
||||
}
|
||||
|
||||
/// Process a key event.
|
||||
fn handle_key(&self, key: Key, mods: KeyModifiers);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use azure::azure_hl::Color;
|
||||
use constellation_msg::{Key, KeyState, KeyModifiers};
|
||||
use geom::point::Point2D;
|
||||
use geom::rect::Rect;
|
||||
use layers::platform::surface::NativeGraphicsMetadata;
|
||||
|
@ -115,4 +116,5 @@ pub trait ScriptListener {
|
|||
fn set_title(&mut self, pipeline_id: PipelineId, new_title: Option<String>);
|
||||
fn close(&mut self);
|
||||
fn dup(&mut self) -> Box<ScriptListener+'static>;
|
||||
fn send_key_event(&mut self, key: Key, state: KeyState, modifiers: KeyModifiers);
|
||||
}
|
||||
|
|
|
@ -505,11 +505,12 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> {
|
|||
} else if "keydown" == event.Type().as_slice() && !event.DefaultPrevented() &&
|
||||
(self.input_type.get() == InputText || self.input_type.get() == InputPassword) {
|
||||
let keyevent: Option<JSRef<KeyboardEvent>> = KeyboardEventCast::to_ref(event);
|
||||
keyevent.map(|event| {
|
||||
match self.textinput.borrow_mut().handle_keydown(event) {
|
||||
keyevent.map(|keyevent| {
|
||||
match self.textinput.borrow_mut().handle_keydown(keyevent) {
|
||||
TriggerDefaultAction => (),
|
||||
DispatchInput => {
|
||||
self.force_relayout();
|
||||
event.PreventDefault();
|
||||
}
|
||||
Nothing => (),
|
||||
}
|
||||
|
|
|
@ -946,6 +946,10 @@ impl ScriptTask {
|
|||
// TODO: if keypress event is canceled, prevent firing input events
|
||||
}
|
||||
|
||||
if !prevented {
|
||||
self.compositor.borrow_mut().send_key_event(key, state, modifiers);
|
||||
}
|
||||
|
||||
// This behavior is unspecced
|
||||
// We are supposed to dispatch synthetic click activation for Space and/or Return,
|
||||
// however *when* we do it is up to us
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue