summaryrefslogtreecommitdiffstats
path: root/ui/keyboard
diff options
context:
space:
mode:
authorrsadam@chromium.org <rsadam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-20 18:49:36 +0000
committerrsadam@chromium.org <rsadam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-20 18:49:36 +0000
commit544e6f5a68db46bb0663a8b200e9df9fec1fc260 (patch)
tree1d51c4f173081bcd04244a7f4b14ac38f66670a4 /ui/keyboard
parent33abbda30215a6521987a221b8991eff32ad3284 (diff)
downloadchromium_src-544e6f5a68db46bb0663a8b200e9df9fec1fc260.zip
chromium_src-544e6f5a68db46bb0663a8b200e9df9fec1fc260.tar.gz
chromium_src-544e6f5a68db46bb0663a8b200e9df9fec1fc260.tar.bz2
Caches the shift key in the keyboard. Keyboard no longer has hard-coded dependencies on keyset.
BUG=293551 Review URL: https://chromiumcodereview.appspot.com/23526075 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224442 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/keyboard')
-rw-r--r--ui/keyboard/resources/elements/kb-keyboard.html51
-rw-r--r--ui/keyboard/resources/elements/kb-shift-key.html63
2 files changed, 63 insertions, 51 deletions
diff --git a/ui/keyboard/resources/elements/kb-keyboard.html b/ui/keyboard/resources/elements/kb-keyboard.html
index a16161b..d6f8437 100644
--- a/ui/keyboard/resources/elements/kb-keyboard.html
+++ b/ui/keyboard/resources/elements/kb-keyboard.html
@@ -7,7 +7,7 @@
<polymer-element name="kb-keyboard" on-key-over="keyOver" on-key-up="keyUp"
on-key-down="keyDown" on-key-longpress="keyLongpress" on-pointerup="up"
on-pointerdown="down" on-enable-sel="enableSel"
- on-enable-dbl="enableDbl" attributes="keyset layout rows capsLocked">
+ on-enable-dbl="enableDbl" attributes="keyset layout rows">
<template>
<style>
@host {
@@ -193,19 +193,7 @@
dblDetail_: null,
dblTimer_: null,
swipeHandler: null,
- capsLock: null,
-
- /**
- * Handles the state of the shift key.
- */
- keysetChanged: function() {
- // If capslock is enabled and the current keyset should be redirected,
- // changes to the keyset specified by capsLockTo.
- if (this.classList.contains('caps-locked') &&
- (this.keyset == this.capsLock.unlockedCase)) {
- this.keyset = this.capsLock.lockedCase;
- }
- },
+ shift: null,
ready: function() {
this.voiceInput_ = new VoiceInput(this);
@@ -299,6 +287,10 @@
}
break;
default:
+ // Non-control key pressed, notify control keys.
+ // Control keys are shift, control and alt.
+ if(this.shift)
+ this.shift.onNonControlKeyDown();
break;
}
@@ -409,7 +401,7 @@
if (swipeInProgress)
return;
this.lastPressedKey.classList.remove('active');
- if (this.lastPressedKey != event.target)
+ if (this.lastPressedKey.char != event.target.char)
return;
if (repeatKey.key == event.target) {
repeatKey.cancel();
@@ -430,8 +422,14 @@
var char = detail.char;
if (enterUpperOnSpace) {
enterUpperOnSpace = false;
- if (char == ' ')
- this.keyset = 'upper';
+ if (char == ' ') {
+ if(this.shift) {
+ this.keyset = this.shift.onSpaceAfterPunctuation();
+ } else {
+ console.error('Capitalization on space after punctuation \
+ enabled, but cannot find target keyset.');
+ }
+ }
}
switch(char) {
case 'Invalid':
@@ -514,22 +512,9 @@
}
}
this.classList.remove('caps-locked');
- this.cacheCapsLock();
- },
-
- /**
- * Caches the keyset transitions required when caps lock is enabled.
- */
- cacheCapsLock: function() {
- var shift = this.querySelector('kb-shift-key');
- if (shift) {
- shift.reset();
- // TODO(rsadam@): Change this such that the keyboard knows
- // only about the shift state. Move this logic into the shift key.
- this.capsLock = { 'lockedCase' : shift.lockedCase,
- 'unlockedCase' : shift.unlockedCase
- };
- }
+ this.shift = this.querySelector('kb-shift-key');
+ if(this.shift)
+ this.shift.reset();
},
/**
diff --git a/ui/keyboard/resources/elements/kb-shift-key.html b/ui/keyboard/resources/elements/kb-shift-key.html
index 41e7b4b..ed9fdb8 100644
--- a/ui/keyboard/resources/elements/kb-shift-key.html
+++ b/ui/keyboard/resources/elements/kb-shift-key.html
@@ -4,7 +4,8 @@
-- found in the LICENSE file.
-->
-<polymer-element name="kb-shift-key" attributes="unlockedCase lockedCase state"
+<polymer-element name="kb-shift-key"
+ attributes="lowerCaseKeysetId upperCaseKeysetId"
class="shift dark" char="Shift" extends="kb-key">
<script>
(function () {
@@ -39,11 +40,11 @@
Polymer('kb-shift-key', {
/**
* Defines how capslock effects keyset transition. We always transition
- * from the unlockedCase to the lockedCase if capslock is on.
+ * from the lowerCaseKeysetId to the upperCaseKeysetId if capslock is on.
* @type {string}
*/
- unlockedCase: 'lower',
- lockedCase: 'upper',
+ lowerCaseKeysetId: 'lower',
+ upperCaseKeysetId: 'upper',
up: function(event) {
if (state == KEY_STATES.PRESSED) {
@@ -69,7 +70,7 @@
// so ignore second press.
break;
default:
- console.error("Undefined shift key state: " + this.state);
+ console.error("Undefined shift key state: " + state);
break;
}
// Trigger parent behaviour.
@@ -78,7 +79,7 @@
// Populate double click transition details.
var detail = {};
detail.char = this.char || this.textContent;
- detail.toKeyset = this.lockedCase;
+ detail.toKeyset = this.upperCaseKeysetId;
detail.nextKeyset = undefined;
detail.callback = this.onDoubleClick;
this.fire('enable-dbl', detail);
@@ -87,14 +88,14 @@
generateLongPressTimer: function() {
return this.asyncMethod(function() {
var detail = this.populateDetails();
- if (this.state == KEY_STATES.LOCKED) {
+ if (state == KEY_STATES.LOCKED) {
// We don't care about the longpress if we are already
// capitalized.
return;
} else {
- this.state = KEY_STATES.LOCKED;
- detail.shiftState = KEY_STATES.LOCKED;
- detail.toKeyset = this.lockedCase;
+ state = KEY_STATES.LOCKED;
+ detail.toKeyset = this.upperCaseKeysetId;
+ detail.nextKeyset = undefined;
}
this.fire('key-longpress', detail);
}, null, LONGPRESS_DELAY_MSEC);
@@ -107,23 +108,49 @@
state = KEY_STATES.LOCKED;
},
+ /**
+ * Notifies shift key that a non-control key was pressed down.
+ * A control key is defined as one of shift, control or alt.
+ */
+ onNonControlKeyDown: function() {
+ // TODO(rsadam@): add logic for chording here.
+ switch (state) {
+ case (KEY_STATES.TAPPED):
+ state = KEY_STATES.UNLOCKED;
+ break;
+ case (KEY_STATES.PRESSED):
+ // Enter chording mode. First disable longpress timer.
+ clearTimeout(this.shiftLongPressTimer);
+ break;
+ default:
+ break;
+ }
+ },
+
+ /**
+ * Callback function for when a space is pressed after punctuation.
+ * @return {string} The keyset the keyboard should transition to.
+ */
+ onSpaceAfterPunctuation: function() {
+ state = KEY_STATES.TAPPED;
+ return this.upperCaseKeysetId;
+ },
+
populateDetails: function() {
var detail = this.super();
- detail.shiftState = this.state;
- switch(this.state) {
+ switch(state) {
case(KEY_STATES.LOCKED):
- detail.toKeyset = this.lockedCase;
+ detail.toKeyset = this.upperCaseKeysetId;
break;
case(KEY_STATES.UNLOCKED):
- detail.toKeyset = this.unlockedCase;
+ detail.toKeyset = this.lowerCaseKeysetId;
break;
case(KEY_STATES.PRESSED):
- detail.toKeyset = this.lockedCase;
- // detail.nextKeyset = this.unlockedCase;
+ detail.toKeyset = this.upperCaseKeysetId;
break;
case(KEY_STATES.TAPPED):
- detail.toKeyset = this.lockedCase;
- detail.nextKeyset = this.unlockedCase;
+ detail.toKeyset = this.upperCaseKeysetId;
+ detail.nextKeyset = this.lowerCaseKeysetId;
break;
}
return detail;