Created
February 8, 2016 13:37
-
-
Save paulrouget/668c3dcdb7dbfed7909a to your computer and use it in GitHub Desktop.
azerty.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs | |
index f75126c..c79e7da 100644 | |
--- a/components/compositing/compositor.rs | |
+++ b/components/compositing/compositor.rs | |
@@ -1111,8 +1111,8 @@ impl<Window: WindowMethods> IOCompositor<Window> { | |
self.on_navigation_window_event(direction); | |
} | |
- WindowEvent::KeyEvent(key, state, modifiers) => { | |
- self.on_key_event(key, state, modifiers); | |
+ WindowEvent::KeyEvent(key, character, state, modifiers) => { | |
+ self.on_key_event(key, character, state, modifiers); | |
} | |
WindowEvent::Quit => { | |
@@ -1453,8 +1453,8 @@ impl<Window: WindowMethods> IOCompositor<Window> { | |
self.constellation_chan.send(ConstellationMsg::Navigate(None, direction)).unwrap() | |
} | |
- fn on_key_event(&self, key: Key, state: KeyState, modifiers: KeyModifiers) { | |
- self.constellation_chan.send(ConstellationMsg::KeyEvent(key, state, modifiers)).unwrap() | |
+ fn on_key_event(&self, key: Key, character: Option<char>, state: KeyState, modifiers: KeyModifiers) { | |
+ self.constellation_chan.send(ConstellationMsg::KeyEvent(key, character, state, modifiers)).unwrap() | |
} | |
fn fill_paint_request_with_cached_layer_buffers(&mut self, paint_request: &mut PaintRequest) { | |
diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs | |
index 4bf9423..9ec54c8 100644 | |
--- a/components/compositing/constellation.rs | |
+++ b/components/compositing/constellation.rs | |
@@ -545,9 +545,9 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> | |
debug!("constellation got get-pipeline-title message"); | |
self.handle_get_pipeline_title_msg(pipeline_id); | |
} | |
- Request::Compositor(FromCompositorMsg::KeyEvent(key, state, modifiers)) => { | |
+ Request::Compositor(FromCompositorMsg::KeyEvent(key, character, state, modifiers)) => { | |
debug!("constellation got key event message"); | |
- self.handle_key_msg(key, state, modifiers); | |
+ self.handle_key_msg(key, character, state, modifiers); | |
} | |
// Load a new page from a typed url | |
// If there is already a pending page (self.pending_frames), it will not be overridden; | |
@@ -1093,7 +1093,7 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> | |
} | |
} | |
- fn handle_key_msg(&self, key: Key, state: KeyState, mods: KeyModifiers) { | |
+ fn handle_key_msg(&self, key: Key, character: Option<char>, state: KeyState, mods: KeyModifiers) { | |
// Send to the explicitly focused pipeline (if it exists), or the root | |
// frame's current pipeline. If neither exist, fall back to sending to | |
// the compositor below. | |
@@ -1104,7 +1104,7 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> | |
match target_pipeline_id { | |
Some(target_pipeline_id) => { | |
let pipeline = self.pipeline(target_pipeline_id); | |
- let event = CompositorEvent::KeyEvent(key, state, mods); | |
+ let event = CompositorEvent::KeyEvent(key, character, state, mods); | |
pipeline.script_chan.send( | |
ConstellationControlMsg::SendEvent(pipeline.id, event)).unwrap(); | |
} | |
@@ -1240,7 +1240,7 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> | |
WebDriverCommandMsg::SendKeys(pipeline_id, cmd) => { | |
let pipeline = self.pipeline(pipeline_id); | |
for (key, mods, state) in cmd { | |
- let event = CompositorEvent::KeyEvent(key, state, mods); | |
+ let event = CompositorEvent::KeyEvent(key, None, state, mods); // FIXME | |
pipeline.script_chan.send( | |
ConstellationControlMsg::SendEvent(pipeline.id, event)).unwrap(); | |
} | |
diff --git a/components/compositing/lib.rs b/components/compositing/lib.rs | |
index 6434c3a..a60e9cb 100644 | |
--- a/components/compositing/lib.rs | |
+++ b/components/compositing/lib.rs | |
@@ -91,7 +91,7 @@ pub enum CompositorMsg { | |
InitLoadUrl(Url), | |
/// Query the constellation to see if the current compositor output is stable | |
IsReadyToSaveImage(HashMap<PipelineId, Epoch>), | |
- KeyEvent(Key, KeyState, KeyModifiers), | |
+ KeyEvent(Key, Option<char>, KeyState, KeyModifiers), | |
LoadUrl(PipelineId, LoadData), | |
Navigate(Option<(PipelineId, SubpageId)>, NavigationDirection), | |
ResizedWindow(WindowSizeData), | |
diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs | |
index 181d743..576902e 100644 | |
--- a/components/compositing/windowing.rs | |
+++ b/components/compositing/windowing.rs | |
@@ -75,7 +75,7 @@ pub enum WindowEvent { | |
/// Sent when the user quits the application | |
Quit, | |
/// Sent when a key input state changes | |
- KeyEvent(Key, KeyState, KeyModifiers), | |
+ KeyEvent(Key, Option<char>, KeyState, KeyModifiers), | |
} | |
impl Debug for WindowEvent { | |
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs | |
index 3830661..d6e994f 100644 | |
--- a/components/script/dom/document.rs | |
+++ b/components/script/dom/document.rs | |
@@ -944,6 +944,7 @@ impl Document { | |
/// The entry point for all key processing for web content | |
pub fn dispatch_key_event(&self, | |
key: Key, | |
+ character: Option<char>, | |
state: KeyState, | |
modifiers: KeyModifiers, | |
compositor: &mut IpcSender<ScriptToCompositorMsg>) { | |
@@ -969,7 +970,7 @@ impl Document { | |
} | |
.to_owned()); | |
- let props = KeyboardEvent::key_properties(key, modifiers); | |
+ let props = KeyboardEvent::key_properties(key, character, modifiers); | |
let keyevent = KeyboardEvent::new(&self.window, | |
ev_type, | |
diff --git a/components/script/dom/keyboardevent.rs b/components/script/dom/keyboardevent.rs | |
index 9feb08b..aa75905 100644 | |
--- a/components/script/dom/keyboardevent.rs | |
+++ b/components/script/dom/keyboardevent.rs | |
@@ -111,14 +111,14 @@ impl KeyboardEvent { | |
Ok(event) | |
} | |
- pub fn key_properties(key: Key, mods: KeyModifiers) | |
+ pub fn key_properties(key: Key, character: Option<char>, mods: KeyModifiers) | |
-> KeyEventProperties { | |
KeyEventProperties { | |
- key_string: key_value(key, mods), | |
- code: code_value(key), | |
- location: key_location(key), | |
- char_code: key_charcode(key, mods), | |
- key_code: key_keycode(key), | |
+ key_string: key_value(key, mods), // layout dependent if no character, not layout dependent | |
+ code: code_value(key), // not layout dependent | |
+ location: key_location(key), // not layout dependent | |
+ char_code: key_charcode(key, mods), // layout dependent | |
+ key_code: key_keycode(key), // layout dependent if ascii, otherwise, not layout dependent | |
} | |
} | |
} | |
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs | |
index 4cae85d..3b38c1f 100644 | |
--- a/components/script/script_thread.rs | |
+++ b/components/script/script_thread.rs | |
@@ -2027,11 +2027,11 @@ impl ScriptThread { | |
} | |
} | |
- KeyEvent(key, state, modifiers) => { | |
+ KeyEvent(key, character, state, modifiers) => { | |
let page = get_page(&self.root_page(), pipeline_id); | |
let document = page.document(); | |
document.dispatch_key_event( | |
- key, state, modifiers, &mut self.compositor.borrow_mut()); | |
+ key, character, state, modifiers, &mut self.compositor.borrow_mut()); | |
} | |
} | |
} | |
diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs | |
index 83761f2..fe4f0c4 100644 | |
--- a/components/script_traits/lib.rs | |
+++ b/components/script_traits/lib.rs | |
@@ -225,7 +225,7 @@ pub enum CompositorEvent { | |
/// A touch event was generated with a touch ID and location. | |
TouchEvent(TouchEventType, TouchId, Point2D<f32>), | |
/// A key was pressed. | |
- KeyEvent(Key, KeyState, KeyModifiers), | |
+ KeyEvent(Key, Option<char>, KeyState, KeyModifiers), | |
} | |
/// An opaque wrapper around script<->layout channels to avoid leaking message types into | |
diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs | |
index 076ace8..bc66f30 100644 | |
--- a/ports/glutin/window.rs | |
+++ b/ports/glutin/window.rs | |
@@ -79,6 +79,7 @@ pub struct Window { | |
mouse_pos: Cell<Point2D<i32>>, | |
key_modifiers: Cell<KeyModifiers>, | |
+ current_character: Cell<Option<char>>, | |
} | |
#[cfg(feature = "window")] | |
@@ -116,6 +117,7 @@ impl Window { | |
mouse_pos: Cell::new(Point2D::new(0, 0)), | |
key_modifiers: Cell::new(KeyModifiers::empty()), | |
+ current_character: Cell::new(None), | |
}; | |
gl::clear_color(0.6, 0.6, 0.6, 1.0); | |
@@ -163,6 +165,9 @@ impl Window { | |
fn handle_window_event(&self, event: glutin::Event) -> bool { | |
match event { | |
+ Event::ReceivedCharacter(c) => { | |
+ self.current_character.set(Some(c)); | |
+ }, | |
Event::KeyboardInput(element_state, _scan_code, virtual_key_code) => { | |
if virtual_key_code.is_some() { | |
let virtual_key_code = virtual_key_code.unwrap(); | |
@@ -177,16 +182,20 @@ impl Window { | |
(_, VirtualKeyCode::LWin) => self.toggle_modifier(LEFT_SUPER), | |
(_, VirtualKeyCode::RWin) => self.toggle_modifier(RIGHT_SUPER), | |
(_, key_code) => { | |
+ let character = self.current_character.get(); | |
if let Ok(key) = Window::glutin_key_to_script_key(key_code) { | |
let state = match element_state { | |
ElementState::Pressed => KeyState::Pressed, | |
ElementState::Released => KeyState::Released, | |
}; | |
let modifiers = Window::glutin_mods_to_script_mods(self.key_modifiers.get()); | |
- self.event_queue.borrow_mut().push(WindowEvent::KeyEvent(key, state, modifiers)); | |
+ self.event_queue.borrow_mut().push(WindowEvent::KeyEvent(key, character, state, modifiers)); | |
} | |
} | |
} | |
+ if element_state == ElementState::Released { | |
+ self.current_character.set(None); | |
+ } | |
} | |
} | |
Event::Resized(width, height) => { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment