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

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: remove redandunt functions, variables 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..9120dbaf170c454bc1c88923106d5e0009b02aa4 100644
--- a/chrome/browser/resources/keyboard_overlay.js
+++ b/chrome/browser/resources/keyboard_overlay.js
@@ -120,17 +120,21 @@ function getModifiers(e) {
if (!e) {
return [];
}
- var modifiers = [];
- if (e.keyCode == 16 || e.shiftKey) {
- modifiers.push('SHIFT');
+ var isKeyDown = (e.type == 'keydown');
+ var keyCodeToModifier = {16: 'SHIFT', 17: 'CTRL', 18: 'ALT'};
+ var modifierWithKeyCode = keyCodeToModifier[e.keyCode];
+ var isPressed = {'SHIFT': e.shiftKey, 'CTRL': e.ctrlKey, 'ALT': e.altKey};
+ // if e.keyCode is one of Shift, Ctrl and Alt, isPressed should
+ // be changed because the key currently pressed
+ // does not affect the values of e.shiftKey, e.ctrlKey and e.altKey
+ if(modifierWithKeyCode){
+ isPressed[modifierWithKeyCode] = isKeyDown;
}
- if (e.keyCode == 17 || e.ctrlKey) {
- modifiers.push('CTRL');
- }
- if (e.keyCode == 18 || e.altKey) {
- modifiers.push('ALT');
- }
- return modifiers.sort();
+ // make the result array
+ return ['SHIFT', 'CTRL', 'ALT'].filter(
+ function(modifier) {
+ return isPressed[modifier];
+ }).sort();
}
/**
@@ -265,8 +269,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';
@@ -322,23 +325,14 @@ function update(e) {
}
/**
- * A callback furnction for the onkeydown event.
- */
-function keydown(e) {
- if (!getKeyboardOverlayId()) {
- return;
- }
- update(e);
-}
-
-/**
- * A callback furnction for the onkeyup event.
+ * A callback function for onkeydown and onkeyup events.
*/
-function keyup(e) {
+function handleKeyEvent(e){
+ var modifiers = getModifiers(e);
if (!getKeyboardOverlayId()) {
return;
}
- update();
+ update(modifiers);
}
/**
@@ -424,8 +418,8 @@ function initLayout() {
* A callback function for the onload event of the body element.
*/
function init() {
- document.addEventListener('keydown', keydown);
- document.addEventListener('keyup', keyup);
+ document.addEventListener('keydown', handleKeyEvent);
+ document.addEventListener('keyup', handleKeyEvent);
chrome.send('getKeyboardOverlayId');
}
« 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