Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non-QWERTY keyboards #11950

Merged
merged 2 commits into from Jul 6, 2016
Merged

Support non-QWERTY keyboards #11950

merged 2 commits into from Jul 6, 2016

Conversation

@jdm
Copy link
Member

jdm commented Jun 30, 2016

Using the ReceivedCharacter event from glutin, we can obtain the actual key characters that the user is pressing and releasing. This gets passed to the script thread along with the physical key data, since KeyboardEvent needs both pieces of information, where they get merged into a single logical key that gets processed by clients like TextInput without any special changes.

Tested by switching my macbook keyboard to dvorak and looking at the output of keypress/keyup/keydown event listeners, as well as playing with tests/html/textarea.html. Non-content keybindings like reload work as expected, too - the remapped keybinding triggers the reload action.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #4144
  • These changes do not require tests because I can't think of a way to test remapped keyboard input

Fixes #11991.


This change is Reviewable

@highfive
Copy link

highfive commented Jun 30, 2016

Heads up! This PR modifies the following files:

  • @asajeffrey: components/constellation/constellation.rs
  • @KiChjang: components/script/dom/document.rs, components/script/dom/keyboardevent.rs, components/script/textinput.rs, components/script_traits/script_msg.rs, components/script_traits/script_msg.rs, components/script/script_thread.rs, components/script/dom/bindings/str.rs, components/script_traits/lib.rs, components/script_traits/lib.rs
@highfive
Copy link

highfive commented Jun 30, 2016

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
@nox
Copy link
Member

nox commented Jun 30, 2016

Mac French keyboard here, 'a' works, but not shift etc to input '.' with 'shift-;'.

@paulrouget
Copy link
Contributor

paulrouget commented Jun 30, 2016

Mac French keyboard here, 'a' works, but not shift etc to input '.' with 'shift-;'.

What happens if you press "Shift + a"?

bors-servo added a commit that referenced this pull request Jun 30, 2016
Support non-QWERTY keyboards, take 2

See #11950.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11955)
<!-- Reviewable:end -->
@jdm jdm force-pushed the jdm:keylayout2 branch from 373e3d5 to d5a0204 Jun 30, 2016
@jdm
Copy link
Member Author

jdm commented Jun 30, 2016

Tested against a french keyboard and everything seems to be working as expected.

@@ -233,7 +241,13 @@ impl Window {

fn handle_window_event(&self, event: glutin::Event) -> bool {
match event {
Event::KeyboardInput(element_state, _scan_code, Some(virtual_key_code)) => {
Event::ReceivedCharacter(ch) => {
assert!(self.pending_key_event_char.get().is_none());

This comment has been minimized.

@mbrubeck

mbrubeck Jun 30, 2016

Contributor

This assertion panics if I try to type a character using the Compose key (e.g. Compose+A+E to type æ).

@mbrubeck
Copy link
Contributor

mbrubeck commented Jun 30, 2016

My Linux/X11 dvorak key mapping still works with this patch, except for one corner case noted above.

@nox
Copy link
Member

nox commented Jul 1, 2016

@jdm It seems you didn't include my bincode bump that fixes the char serialization.

@jdm
Copy link
Member Author

jdm commented Jul 1, 2016

@nox It's... right there? In the PR?

@nox
Copy link
Member

nox commented Jul 1, 2016

Oh right, didn't look at the right commit.

@@ -69,6 +70,7 @@ impl KeyboardEvent {
cancelable: bool,
view: Option<&Window>,
_detail: i32,
ch: Option<char>,

This comment has been minimized.

@nox

nox Jul 2, 2016

Member

Why do we need both this and char_code?

This comment has been minimized.

@jdm

jdm Jul 2, 2016

Author Member

Because char_code isn't present in all key events, per spec.

@pcwalton
Copy link
Contributor

pcwalton commented Jul 2, 2016

@jdm Who would you like to review this?

@jdm
Copy link
Member Author

jdm commented Jul 2, 2016

Someone who wants to learn more about how we do keyboard input? I don't have a name in mind, unfortunately.

@bors-servo
Copy link
Contributor

bors-servo commented Jul 3, 2016

The latest upstream changes (presumably #12178) made this pull request unmergeable. Please resolve the merge conflicts.

@nox
Copy link
Member

nox commented Jul 4, 2016

SGTM. What do we need for this to get landed? What's blocking this to be reviewed?

@jdm
Copy link
Member Author

jdm commented Jul 4, 2016

Nothing's blocking it that I'm aware.

@emilio
Copy link
Member

emilio commented Jul 4, 2016

Looks good to me modulo the nits, the ipc-channel/bincode update, and the compose key, that is servo/glutin#101

-S-awaiting-review +S-needs-code-changes


Reviewed 12 of 12 files at r1.
Review status: 4 of 17 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed.


components/constellation/constellation.rs, line 809 [r1] (raw file):

            FromScriptMsg::SendKeyEvent(key, key_state, key_modifiers, ch) => {
                // FIXME: https://github.com/servo/ipc-channel/issues/84
                let ch = ch.map(|ch| ch as char);

This can be removed now right?


components/constellation/constellation.rs, line 1636 [r1] (raw file):

                };
                for (key, mods, state) in cmd {
                    let event = CompositorEvent::KeyEvent(key, state, mods, None);

Can we be consistent with the order here?

Either (ch, key, state, mods) or (key, state, mods, ch).


ports/glutin/window.rs, line 245 [r3] (raw file):

Previously, mbrubeck (Matt Brubeck) wrote…

This assertion panics if I try to type a character using the Compose key (e.g. Compose+A+E to type æ).

As Matt, I also happen to hit this assertion whenever I type a spanish character with the compose key (e.g. Compose + ' + a -> `á`).

It seems that glutin doesn't handle the specific compose key. I have a patch to add VirtualKeyCode::Compose to glutin, and then we should handle that in the key modifiers ignoring any character that arrives while pressing Composed (the actual character will arrive later).

Glutin also sends the composed character twice. I can look deeper into it, but meanwhile we can just check for pending_key_event_char.get() != Some(ch).


Comments from Reviewable

@emilio
Copy link
Member

emilio commented Jul 4, 2016

Ah, and I don't think I need to say this, but awesome work here, thanks for doing this Josh! :)

@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2016

💔 Test failed - linux-dev

@emilio
Copy link
Member

emilio commented Jul 6, 2016

Hm... need to update the cef port :/

…ues to a single byte.
@jdm jdm force-pushed the jdm:keylayout2 branch from 44e42b1 to 6496d73 Jul 6, 2016
@jdm
Copy link
Member Author

jdm commented Jul 6, 2016

@bors-servo: r=emilio

@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2016

📌 Commit 6496d73 has been approved by emilio

@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2016

Testing commit 6496d73 with merge a51c60c...

bors-servo added a commit that referenced this pull request Jul 6, 2016
Support non-QWERTY keyboards

Using the ReceivedCharacter event from glutin, we can obtain the actual key characters that the user is pressing and releasing. This gets passed to the script thread along with the physical key data, since KeyboardEvent needs both pieces of information, where they get merged into a single logical key that gets processed by clients like TextInput without any special changes.

Tested by switching my macbook keyboard to dvorak and looking at the output of keypress/keyup/keydown event listeners, as well as playing with tests/html/textarea.html. Non-content keybindings like reload work as expected, too - the remapped keybinding triggers the reload action.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #4144
- [X] These changes do not require tests because I can't think of a way to test remapped keyboard input

Fixes  #11991.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11950)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2016

💔 Test failed - linux-rel

@highfive
Copy link

highfive commented Jul 6, 2016

  ▶ FAIL [expected PASS] /css-transforms-1_dev/html/transform3d-translatez-001.htm
  └   → /css-transforms-1_dev/html/transform3d-translatez-001.htm 902d90a8d198625335e738587fdfe81dcc90392d
/css-transforms-1_dev/html/reference/transform3d-translatez-ref.htm b14318ccfd8a59b7b249d41521e178d617678823
Testing 902d90a8d198625335e738587fdfe81dcc90392d == b14318ccfd8a59b7b249d41521e178d617678823
/css-transforms-1_dev/html/transform3d-translatez-001.htm 902d90a8d198625335e738587fdfe81dcc90392d
/css-transforms-1_dev/html/reference/transform3d-translatez-notref.htm 902d90a8d198625335e738587fdfe81dcc90392d
Testing 902d90a8d198625335e738587fdfe81dcc90392d != 902d90a8d198625335e738587fdfe81dcc90392d
@KiChjang
Copy link
Member

KiChjang commented Jul 6, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2016

Previous build results for android, arm32, arm64, linux-dev, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows are reusable. Rebuilding only linux-rel...

@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2016

💔 Test failed - linux-rel

@nox
Copy link
Member

nox commented Jul 6, 2016

@nox nox added S-awaiting-merge and removed S-tests-failed labels Jul 6, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2016

Testing commit 6496d73 with merge 68fb9eb...

bors-servo added a commit that referenced this pull request Jul 6, 2016
Support non-QWERTY keyboards

Using the ReceivedCharacter event from glutin, we can obtain the actual key characters that the user is pressing and releasing. This gets passed to the script thread along with the physical key data, since KeyboardEvent needs both pieces of information, where they get merged into a single logical key that gets processed by clients like TextInput without any special changes.

Tested by switching my macbook keyboard to dvorak and looking at the output of keypress/keyup/keydown event listeners, as well as playing with tests/html/textarea.html. Non-content keybindings like reload work as expected, too - the remapped keybinding triggers the reload action.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #4144
- [X] These changes do not require tests because I can't think of a way to test remapped keyboard input

Fixes  #11991.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11950)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2016

@bors-servo bors-servo merged commit 6496d73 into servo:master Jul 6, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

10 participants
You can’t perform that action at this time.