Merge fx-team to central, a=merge
authorWes Kocher <wkocher@mozilla.com>
Thu, 25 Aug 2016 17:13:23 -0700
changeset 311207 a551f534773cf2d6933f78ce7d82a7a33a99643e
parent 311205 8f6cbb5a8f4a748cd9fd104e58e840ca6e86b253 (current diff)
parent 311206 c0c2f6077694008794c06900943654db0143c2b9 (diff)
child 311244 acc68453a53fc33a96824652ae699c917bfdbdbd
child 311268 9cf22baefd87aa586ba95815136a0315f8fcef5a
child 311317 a7be6d4320fa85d1a4703bbb9219f1ee78e71592
push id30604
push userkwierso@gmail.com
push dateFri, 26 Aug 2016 00:13:27 +0000
treeherdermozilla-central@a551f534773c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone51.0a1
first release with
nightly linux32
a551f534773c / 51.0a1 / 20160826030226 / files
nightly linux64
a551f534773c / 51.0a1 / 20160826030226 / files
nightly mac
a551f534773c / 51.0a1 / 20160826030226 / files
nightly win32
a551f534773c / 51.0a1 / 20160826030226 / files
nightly win64
a551f534773c / 51.0a1 / 20160826030226 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge fx-team to central, a=merge
--- a/devtools/client/shared/key-shortcuts.js
+++ b/devtools/client/shared/key-shortcuts.js
@@ -138,16 +138,17 @@ KeyShortcuts.parseElectronKey = function
     // Match any single character
     shortcut.key = key.toLowerCase();
   } else if (key in ElectronKeysMapping) {
     // Maps the others manually to DOM API DOM_VK_*
     key = ElectronKeysMapping[key];
     shortcut.keyCode = KeyCodes[key];
     // Used only to stringify the shortcut
     shortcut.keyCodeString = key;
+    shortcut.key = key;
   } else {
     console.error("Unsupported key:", key);
     return null;
   }
 
   return shortcut;
 };
 
@@ -194,21 +195,27 @@ KeyShortcuts.prototype = {
     // Shift is a special modifier, it may implicitely be required if the
     // expected key is a special character accessible via shift.
     if (shortcut.shift != event.shiftKey && event.key &&
         event.key.match(/[a-zA-Z]/)) {
       return false;
     }
     if (shortcut.keyCode) {
       return event.keyCode == shortcut.keyCode;
+    } else if (event.key in ElectronKeysMapping) {
+      return ElectronKeysMapping[event.key] === shortcut.key;
     }
+
+    // get the key from the keyCode if key is not provided.
+    let key = event.key || String.fromCharCode(event.keyCode);
+
     // For character keys, we match if the final character is the expected one.
     // But for digits we also accept indirect match to please azerty keyboard,
     // which requires Shift to be pressed to get digits.
-    return event.key.toLowerCase() == shortcut.key ||
+    return key.toLowerCase() == shortcut.key ||
       (shortcut.key.match(/[0-9]/) &&
        event.keyCode == shortcut.key.charCodeAt(0));
   },
 
   handleEvent(event) {
     for (let [key, shortcut] of this.keys) {
       if (this.doesEventMatchShortcut(event, shortcut)) {
         this.eventEmitter.emit(key, event);
--- a/devtools/client/shared/test/browser_key_shortcuts.js
+++ b/devtools/client/shared/test/browser_key_shortcuts.js
@@ -5,16 +5,17 @@ var isOSX = Services.appinfo.OS === "Dar
 
 add_task(function* () {
   let shortcuts = new KeyShortcuts({
     window
   });
   yield testSimple(shortcuts);
   yield testNonLetterCharacter(shortcuts);
   yield testPlusCharacter(shortcuts);
+  yield testFunctionKey(shortcuts);
   yield testMixup(shortcuts);
   yield testLooseDigits(shortcuts);
   yield testExactModifiers(shortcuts);
   yield testLooseShiftModifier(shortcuts);
   yield testStrictLetterShiftModifier(shortcuts);
   yield testAltModifier(shortcuts);
   yield testCommandOrControlModifier(shortcuts);
   yield testCtrlModifier(shortcuts);
@@ -61,16 +62,27 @@ function testNonLetterCharacter(shortcut
   let onKey = once(shortcuts, "[", (key, event) => {
     is(event.key, "[");
   });
 
   EventUtils.synthesizeKey("[", {}, window);
   yield onKey;
 }
 
+function testFunctionKey(shortcuts) {
+  info("Test function key shortcuts");
+
+  let onKey = once(shortcuts, "F12", (key, event) => {
+    is(event.key, "F12");
+  });
+
+  EventUtils.synthesizeKey("F12", { keyCode: 123 }, window);
+  yield onKey;
+}
+
 // Plus is special. It's keycode is the one for "=". That's because it requires
 // shift to be pressed and is behind "=" key. So it should be considered as a
 // character key
 function testPlusCharacter(shortcuts) {
   info("Test 'Plus' key shortcuts");
 
   let onKey = once(shortcuts, "Plus", (key, event) => {
     is(event.key, "+");