Bug 1513405 - KeymapWrapper::ComputeDOMKeyCode() shouldn't ignore modifiers when computing keyCode value of non-printable key event r=karlt, masayuki
authorWilliam G Hatch <william@hatch.uno>
Wed, 09 Jan 2019 18:36:43 +0900
changeset 510510 2742b347ca238d6a8c475d8e79b556206d62d196
parent 510509 e4550e8b5a79edd04b29b77903412a94a949bbfc
child 510511 7543b4c2813c76e1e2a3cc70fea991e725654877
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt, masayuki
bugs1513405
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1513405 - KeymapWrapper::ComputeDOMKeyCode() shouldn't ignore modifiers when computing keyCode value of non-printable key event r=karlt, masayuki Some unusual keyboard layout may map a function key only with some modifiers. For example, Hatchak keyboard layout maps Tab key to "Digit3" key and Backspace key to Level3 Shift+"Digit3" key. So, when Level3 Shift is active, the modifier state of the "Digit3" key event shouldn't be ignored because computed keyCode value becomes DOM_VK_TAB (9) rather than DOM_VK_BACK_SPACE (8). This patch makes KeymapWrapper::ComputeDOMKeyCode() compute keyCode value of non-printable key event with its modifier state first. If it cannot map to a DOM keyCode value, then, it keeps ignoring the modifier state for backward compatibility and making web apps be able to identify the key as far as possible.
widget/gtk/nsGtkKeyUtils.cpp
--- a/widget/gtk/nsGtkKeyUtils.cpp
+++ b/widget/gtk/nsGtkKeyUtils.cpp
@@ -1093,28 +1093,41 @@ void KeymapWrapper::OnDirectionChanged(G
     uint32_t DOMKeyCode = GetDOMKeyCodeFromKeyPairs(keyval);
     NS_ASSERTION(DOMKeyCode, "All modifier keys must have a DOM keycode");
     return DOMKeyCode;
   }
 
   // If the key isn't printable, let's look at the key pairs.
   uint32_t charCode = GetCharCodeFor(aGdkKeyEvent);
   if (!charCode) {
-    // Always use unshifted keycode for the non-printable key.
-    // XXX It might be better to decide DOM keycode from all keyvals of
-    //     the hardware keycode.  However, I think that it's too excessive.
+    // Note that any key may be a function key because of some unusual keyboard
+    // layouts.  I.e., even if the pressed key is a printable key of en-US
+    // keyboard layout, we should expose the function key's keyCode value to
+    // web apps because web apps should handle the keydown/keyup events as
+    // inputted by usual keyboard layout.  For example, Hatchak keyboard
+    // maps Tab key to "Digit3" key and Level3 Shift makes it "Backspace".
+    // In this case, we should expose DOM_VK_BACK_SPACE (8).
+    uint32_t DOMKeyCode = GetDOMKeyCodeFromKeyPairs(keyval);
+    if (DOMKeyCode) {
+      // XXX If DOMKeyCode is a function key's keyCode value, it might be
+      //     better to consume necessary modifiers.  For example, if there is
+      //     no Control Pad section on keyboard like notebook, Delete key is
+      //     available only with Level3 Shift+"Backspace" key if using Hatchak.
+      //     If web apps accept Delete key operation only when no modifiers are
+      //     active, such users cannot use Delete key to do it.  However,
+      //     Chromium doesn't consume such necessary modifiers.  So, our default
+      //     behavior should keep not touching modifiers for compatibility, but
+      //     it might be better to add a pref to consume necessary modifiers.
+      return DOMKeyCode;
+    }
+    // If aGdkKeyEvent cannot be mapped to a DOM keyCode value, we should
+    // refer keyCode value without modifiers because web apps should be
+    // able to identify the key as far as possible.
     guint keyvalWithoutModifier = GetGDKKeyvalWithoutModifier(aGdkKeyEvent);
-    uint32_t DOMKeyCode = GetDOMKeyCodeFromKeyPairs(keyvalWithoutModifier);
-    if (!DOMKeyCode) {
-      // If the unshifted keyval couldn't be mapped to a DOM keycode,
-      // we should fallback to legacy logic, so, we should recompute with
-      // the keyval with aGdkKeyEvent.
-      DOMKeyCode = GetDOMKeyCodeFromKeyPairs(keyval);
-    }
-    return DOMKeyCode;
+    return GetDOMKeyCodeFromKeyPairs(keyvalWithoutModifier);
   }
 
   // printable numpad keys should be resolved here.
   switch (keyval) {
     case GDK_KP_Multiply:
       return NS_VK_MULTIPLY;
     case GDK_KP_Add:
       return NS_VK_ADD;