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

Unified Diff: chrome/browser/resources/keyboard_overlay.js

Issue 6873045: Fix the problem that releasing a key after pressing multiple modifiers corrupts keyboard overlay (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 8 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698