Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1091)

Unified Diff: ui/events/keycodes/keyboard_code_conversion_mac.mm

Issue 1706683002: [Mac] Produce correct DomKey when Ctrl/Shift/Command is down (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test case for Ctrl+Shift+foo Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/keycodes/keyboard_code_conversion_mac.mm
diff --git a/ui/events/keycodes/keyboard_code_conversion_mac.mm b/ui/events/keycodes/keyboard_code_conversion_mac.mm
index f435f4ed2b966d19a8524ccc2fe63ef61c93c91f..bfc7e725a99412da8ed0d75c52389ee446bf8df5 100644
--- a/ui/events/keycodes/keyboard_code_conversion_mac.mm
+++ b/ui/events/keycodes/keyboard_code_conversion_mac.mm
@@ -746,8 +746,22 @@ DomKey DomKeyFromNSEvent(NSEvent* event) {
// doesn't.
if ([event type] == NSKeyDown || [event type] == NSKeyUp) {
NSString* characters = [event characters];
- if ([characters length] > 0)
- return DomKeyFromCharCode([characters characterAtIndex:0]);
+ if ([characters length] > 0) {
+ unichar dom_key_char =
+ [characters characterAtIndex:[characters length] - 1];
chongz 2016/02/17 22:54:05 Use last character because e.g. On French keyboard
+ if ([event modifierFlags] != 0 && std::iscntrl(dom_key_char)) {
+ // According to spec if the key combination produces a non-printable
+ // character, the key value should be the character without modifiers.
+ // See https://w3c.github.io/uievents/#keys-guidelines
+ NSString* unmodified_characters = [event charactersIgnoringModifiers];
+ if ([unmodified_characters length] > 0) {
+ unichar unmodified_char = [unmodified_characters
+ characterAtIndex:[unmodified_characters length] - 1];
+ dom_key_char = unmodified_char;
+ }
+ }
+ return DomKeyFromCharCode(dom_key_char);
+ }
}
return DomKeyFromKeyCode([event keyCode]);
}
« no previous file with comments | « content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698