Chromium Code Reviews| Index: chrome/browser/resources/keyboard_overlay.js |
| diff --git a/chrome/browser/resources/keyboard_overlay.js b/chrome/browser/resources/keyboard_overlay.js |
| index 1d19496c1629e4dac6936966320b080262c9ddcd..554797af86c8278ae5a7b2562814528c9f301349 100644 |
| --- a/chrome/browser/resources/keyboard_overlay.js |
| +++ b/chrome/browser/resources/keyboard_overlay.js |
| @@ -120,15 +120,24 @@ function getModifiers(e) { |
| if (!e) { |
| return []; |
| } |
| + var isKeyDown = (e.type == 'keydown'); |
| + var modifierToKeyCode = {'SHIFT': 16, 'CTRL': 17, 'ALT': 18}; |
| var modifiers = []; |
|
mazda
2011/04/18 11:00:20
Please move the declaration right before line 137.
|
| - if (e.keyCode == 16 || e.shiftKey) { |
| - modifiers.push('SHIFT'); |
| - } |
| - if (e.keyCode == 17 || e.ctrlKey) { |
| - modifiers.push('CTRL'); |
| + var modifier; |
|
mazda
2011/04/18 11:00:20
How about moving modifier to for-loop?
for (var m
|
| + var pressed = {'SHIFT': e.shiftKey, 'CTRL': e.ctrlKey, 'ALT': e.altKey}; |
| + // if e.keyCode is one of Shift, Ctrl and Alt, pressed should |
| + // be changed because the key currently pressed |
| + // does not affect the values of e.shiftKey, e.ctrlKey and e.altKey |
| + for (modifier in modifierToKeyCode) { |
| + if (e.keyCode == modifierToKeyCode[modifier]) { |
| + pressed[modifier] = isKeyDown; |
| + } |
| } |
| - if (e.keyCode == 18 || e.altKey) { |
| - modifiers.push('ALT'); |
| + // make the result array |
| + for (modifier in pressed) { |
| + if (pressed[modifier]) { |
| + modifiers.push(modifier); |
| + } |
| } |
| return modifiers.sort(); |
| } |
| @@ -265,8 +274,7 @@ function getKeyTextValue(keyData) { |
| /** |
| * Updates the whole keyboard. |
| */ |
| -function update(e) { |
| - var modifiers = getModifiers(e); |
| +function update(modifiers) { |
| var instructions = document.getElementById('instructions'); |
| if (modifiers.length == 0) { |
| instructions.style.visibility = 'visible'; |
| @@ -325,20 +333,22 @@ function update(e) { |
| * A callback furnction for the onkeydown event. |
| */ |
| function keydown(e) { |
| + var modifiers = getModifiers(e); |
| if (!getKeyboardOverlayId()) { |
| return; |
| } |
| - update(e); |
| + update(modifiers); |
| } |
| /** |
| * A callback furnction for the onkeyup event. |
| */ |
| function keyup(e) { |
|
mazda
2011/04/18 11:00:20
How about merging this function into keydown?
|
| + var modifiers = getModifiers(e); |
| if (!getKeyboardOverlayId()) { |
| return; |
| } |
| - update(); |
| + update(modifiers); |
| } |
| /** |