summaryrefslogtreecommitdiffstats
path: root/ui/keyboard
diff options
context:
space:
mode:
authorrsadam@chromium.org <rsadam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-29 00:36:54 +0000
committerrsadam@chromium.org <rsadam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-29 00:36:54 +0000
commitbb6fdc802447752d0d69ca20a736a854e973a739 (patch)
tree2ff590c2836325e88f735cf5d19ffa0082db3cbf /ui/keyboard
parent8845bb444fe460ccbb7664a5537fcd885be4ebb5 (diff)
downloadchromium_src-bb6fdc802447752d0d69ca20a736a854e973a739.zip
chromium_src-bb6fdc802447752d0d69ca20a736a854e973a739.tar.gz
chromium_src-bb6fdc802447752d0d69ca20a736a854e973a739.tar.bz2
Fixes modifier handling for repeat keys.
BUG=312344 Review URL: https://codereview.chromium.org/46043004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231462 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/keyboard')
-rw-r--r--ui/keyboard/resources/elements/kb-key-codes.html19
-rw-r--r--ui/keyboard/resources/elements/kb-keyboard.html26
-rw-r--r--ui/keyboard/resources/elements/kb-keyset.html8
-rw-r--r--ui/keyboard/resources/elements/kb-modifier-key.html4
-rw-r--r--ui/keyboard/resources/elements/kb-shift-key.html37
5 files changed, 66 insertions, 28 deletions
diff --git a/ui/keyboard/resources/elements/kb-key-codes.html b/ui/keyboard/resources/elements/kb-key-codes.html
index 4f7bc82..d076ec5 100644
--- a/ui/keyboard/resources/elements/kb-key-codes.html
+++ b/ui/keyboard/resources/elements/kb-key-codes.html
@@ -29,7 +29,9 @@
// keyCode attribute for kb-key or kb-keysequence elements to refer to
// indices in this table in order to emulate a physical keyboard with an
// alternate layout. Not all keys on a virtual keyboard are required to
- // have keyCodes.
+ // have keyCodes. The shiftModifier specifies whether to always include or
+ // exclude the shift modifer when sending key events for this key. If it's
+ // undefined, it will defer to state of the keyboard.
// TODO(rsadam): Correctly propagate shutdown keycode. This is currently
// ignored due to chromoting (crbug/146609)
var keyCodes = {
@@ -38,10 +40,10 @@
'\n': {keyCode: 0x0D, shiftModifier: false},
'Esc': {keyCode: 0x1B, shiftModifier: false},
' ': {keyCode: 0x20, shiftModifier: false},
- 'Arrow-Left': {keyCode: 0x25, shiftModifier: false},
- 'Arrow-Up': {keyCode: 0x26, shiftModifier: false},
- 'Arrow-Right': {keyCode: 0x27, shiftModifier: false},
- 'Arrow-Down': {keyCode: 0x28, shiftModifier: false},
+ 'Arrow-Left': {keyCode: 0x25, shiftModifier: undefined},
+ 'Arrow-Up': {keyCode: 0x26, shiftModifier: undefined},
+ 'Arrow-Right': {keyCode: 0x27, shiftModifier: undefined},
+ 'Arrow-Down': {keyCode: 0x28, shiftModifier: undefined},
'0': {keyCode: 0x30, shiftModifier: false},
')': {keyCode: 0x30, shiftModifier: true},
'1': {keyCode: 0x31, shiftModifier: false},
@@ -186,13 +188,16 @@
var keyCode = detail.keyCode;
// The shift modifier is handled specially. Some charactares like '+'
// {keyCode: 0xBB, shiftModifier: true}, are available on non-upper
- // keysets, and so we rely on caching the correct shiftModifier.
+ // keysets, and so we rely on caching the correct shiftModifier. If
+ // the cached value of the shiftModifier is undefined, we defer to
+ // the shiftModifier in the detail.
var shiftModifier = detail.shiftModifier;
if (keyCode == undefined) {
var state = this.GetKeyCodeAndModifiers(char);
if (state) {
keyCode = state.keyCode;
- shiftModifier = state.shiftModifier;
+ shiftModifier = (state.shiftModifier == undefined) ?
+ shiftModifier : state.shiftModifier;
} else {
// Keycode not defined.
return;
diff --git a/ui/keyboard/resources/elements/kb-keyboard.html b/ui/keyboard/resources/elements/kb-keyboard.html
index adc05b3..b047138 100644
--- a/ui/keyboard/resources/elements/kb-keyboard.html
+++ b/ui/keyboard/resources/elements/kb-keyboard.html
@@ -369,6 +369,7 @@
return;
if (detail.repeat) {
this.keyTyped(detail);
+ this.onNonControlKeyTyped();
repeatKey.key = this.lastPressedKey;
var self = this;
repeatKey.timer = setTimeout(function() {
@@ -546,12 +547,7 @@
}
if(!this.keyTyped(detail))
insertText(char);
- if (this.ctrl)
- this.ctrl.onNonControlKeyUp();
- if (this.alt)
- this.alt.onNonControlKeyUp();
- this.classList.remove('ctrl-active');
- this.classList.remove('alt-active');
+ this.onNonControlKeyTyped();
},
/*
@@ -612,6 +608,22 @@
},
/**
+ * Notifies the modifier keys that a non-control key was typed. This
+ * lets them reset sticky behaviour. A non-control key is defined as
+ * any key that is not Control, Alt, or Shift.
+ */
+ onNonControlKeyTyped: function() {
+ if (this.shift)
+ this.shift.onNonControlKeyTyped();
+ if (this.ctrl)
+ this.ctrl.onNonControlKeyTyped();
+ if (this.alt)
+ this.alt.onNonControlKeyTyped();
+ this.classList.remove('ctrl-active');
+ this.classList.remove('alt-active');
+ },
+
+ /**
* Indicate if the keyboard is ready for user input.
* @type {boolean}
*/
@@ -663,6 +675,8 @@
*/
keyTyped: function(detail) {
var builder = this.$.keyCodeMetadata;
+ if (this.shift)
+ detail.shiftModifier = this.shift.isActive();
if (this.ctrl)
detail.controlModifier = this.ctrl.isActive();
if (this.alt)
diff --git a/ui/keyboard/resources/elements/kb-keyset.html b/ui/keyboard/resources/elements/kb-keyset.html
index 55d20c1..933e7ba 100644
--- a/ui/keyboard/resources/elements/kb-keyset.html
+++ b/ui/keyboard/resources/elements/kb-keyset.html
@@ -27,6 +27,14 @@
nextKeyset: undefined,
// TODO(bshe): support select keyset on down, long and dbl events.
keyUp: function(event, detail) {
+ switch (detail.char) {
+ case 'Shift':
+ case 'Alt':
+ case 'Ctrl':
+ return;
+ default:
+ break;
+ }
if (!detail.toKeyset)
detail.toKeyset = this.nextKeyset;
},
diff --git a/ui/keyboard/resources/elements/kb-modifier-key.html b/ui/keyboard/resources/elements/kb-modifier-key.html
index 343a594..ebe9cf7 100644
--- a/ui/keyboard/resources/elements/kb-modifier-key.html
+++ b/ui/keyboard/resources/elements/kb-modifier-key.html
@@ -64,10 +64,10 @@
},
/**
- * Notifies key that a non-control keyed up.
+ * Notifies key that a non-control keyed was typed.
* A control key is defined as one of shift, control or alt.
*/
- onNonControlKeyUp: function() {
+ onNonControlKeyTyped: function() {
switch(this.state) {
case (KEY_STATES.TAPPED):
this.state = KEY_STATES.UNLOCKED;
diff --git a/ui/keyboard/resources/elements/kb-shift-key.html b/ui/keyboard/resources/elements/kb-shift-key.html
index b2dac6b..12f568c 100644
--- a/ui/keyboard/resources/elements/kb-shift-key.html
+++ b/ui/keyboard/resources/elements/kb-shift-key.html
@@ -144,6 +144,11 @@
}, null, LONGPRESS_DELAY_MSEC);
},
+ // @return Whether the shift modifier is currently active.
+ isActive: function() {
+ return state != KEY_STATES.UNLOCKED;
+ },
+
/**
* Callback function for when a double click is triggered.
*/
@@ -156,19 +161,25 @@
* A control key is defined as one of shift, control or alt.
*/
onNonControlKeyDown: function() {
- switch (state) {
- case (KEY_STATES.TAPPED):
- state = KEY_STATES.UNLOCKED;
- break;
- case (KEY_STATES.PRESSED):
- state = KEY_STATES.CHORDING;
- // Disable longpress timer.
- clearTimeout(shiftLongPressTimer);
- break;
- default:
- break;
- }
- },
+ switch (state) {
+ case (KEY_STATES.PRESSED):
+ state = KEY_STATES.CHORDING;
+ // Disable longpress timer.
+ clearTimeout(shiftLongPressTimer);
+ break;
+ default:
+ break;
+ }
+ },
+
+ /**
+ * Notifies key that a non-control keyed was typed.
+ * A control key is defined as one of shift, control or alt.
+ */
+ onNonControlKeyTyped: function() {
+ if (state == KEY_STATES.TAPPED)
+ state = KEY_STATES.UNLOCKED;
+ },
/**
* Callback function for when a space is pressed after punctuation.