summaryrefslogtreecommitdiffstats
path: root/ui/keyboard
diff options
context:
space:
mode:
authorbshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-17 03:11:47 +0000
committerbshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-17 03:11:47 +0000
commit670f62a894c86a35e3a2b279ef884b5e785f11c9 (patch)
treedab671836cacc79ec711682cb9c2ad060497c238 /ui/keyboard
parent2c948e1b9528204a0af15f70e1721d52a8c8e478 (diff)
downloadchromium_src-670f62a894c86a35e3a2b279ef884b5e785f11c9.zip
chromium_src-670f62a894c86a35e3a2b279ef884b5e785f11c9.tar.gz
chromium_src-670f62a894c86a35e3a2b279ef884b5e785f11c9.tar.bz2
Prevent key dropping when fast typing
This CL prevents the key dropping that results from a second finger pressing a new key while the first finger still pressing the old key. It contributes a significant source of key dropping. Our approach is if there is a second finger down before the first finger release, the key under the first finger will call autoRelease to programmatic release itself. And any subsequent events on that key (keyup, keyout) will be ignored. BUG=301631 Review URL: https://codereview.chromium.org/26267006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229022 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/keyboard')
-rw-r--r--ui/keyboard/resources/elements/kb-altkey.html3
-rw-r--r--ui/keyboard/resources/elements/kb-key-base.html19
-rw-r--r--ui/keyboard/resources/elements/kb-keyboard.html15
-rw-r--r--ui/keyboard/resources/elements/kb-shift-key.html27
4 files changed, 52 insertions, 12 deletions
diff --git a/ui/keyboard/resources/elements/kb-altkey.html b/ui/keyboard/resources/elements/kb-altkey.html
index 42324cd..a5abc8e 100644
--- a/ui/keyboard/resources/elements/kb-altkey.html
+++ b/ui/keyboard/resources/elements/kb-altkey.html
@@ -53,6 +53,9 @@
char: this.char || this.textContent
};
this.fire('key-up', detail);
+ },
+ // TODO(bshe): kb-altkey should extend from kb-key-base.
+ autoRelease: function() {
}
});
</script>
diff --git a/ui/keyboard/resources/elements/kb-key-base.html b/ui/keyboard/resources/elements/kb-key-base.html
index 25f855f..dbc823a 100644
--- a/ui/keyboard/resources/elements/kb-key-base.html
+++ b/ui/keyboard/resources/elements/kb-key-base.html
@@ -69,6 +69,7 @@
repeat: false,
invert: false,
longPressTimer: null,
+ pointerId: undefined,
/**
* The keyset transition rules. It defines which keyset to transit to on
@@ -108,16 +109,34 @@
});
}
},
+
down: function(event) {
+ this.pointerId = event.pointerId;
var detail = this.populateDetails('down');
this.fire('key-down', detail);
this.longPressTimer = this.generateLongPressTimer();
},
out: function(event) {
this.classList.remove('active');
+ this.pointerId = undefined;
clearTimeout(this.longPressTimer);
},
up: function(event) {
+ this.autoRelease();
+ },
+
+ /**
+ * Releases the pressed key programmatically and fires key-up event. This
+ * should be called if a second key is pressed while the first key is not
+ * released yet.
+ */
+ autoRelease: function() {
+ if (this.pointerId === undefined)
+ return;
+
+ // Invalidates the pointerId so the subsequent pointerup event is a
+ // noop.
+ this.pointerId = undefined;
clearTimeout(this.longPressTimer);
var detail = this.populateDetails('up');
this.fire('key-up', detail);
diff --git a/ui/keyboard/resources/elements/kb-keyboard.html b/ui/keyboard/resources/elements/kb-keyboard.html
index d4944c7..2dd0d6f 100644
--- a/ui/keyboard/resources/elements/kb-keyboard.html
+++ b/ui/keyboard/resources/elements/kb-keyboard.html
@@ -327,8 +327,10 @@
if (this.skipEvent(detail))
return;
- if (this.lastPressedKey)
+ if (this.lastPressedKey) {
this.lastPressedKey.classList.remove('active');
+ this.lastPressedKey.autoRelease();
+ }
this.lastPressedKey = event.target;
this.lastPressedKey.classList.add('active');
repeatKey.cancel();
@@ -456,16 +458,19 @@
return;
if (swipeInProgress)
return;
- this.lastPressedKey.classList.remove('active');
+ if (this.lastPressedKey)
+ this.lastPressedKey.classList.remove('active');
// Keyset transition key. This is needed to transition from upper
// to lower case when we are not in caps mode, as well as when
// we're ending chording.
this.changeKeyset(detail);
- if (this.lastPressedKey.charValue != event.target.charValue)
+ if (this.lastPressedKey &&
+ this.lastPressedKey.charValue != event.target.charValue)
return;
if (repeatKey.key == event.target) {
repeatKey.cancel();
+ this.lastPressedKey = null;
return;
}
var toLayoutId = detail.toLayout;
@@ -509,6 +514,7 @@
this.keyTyped(detail);
else
insertText(char);
+ this.lastPressedKey = null;
},
/*
@@ -526,7 +532,8 @@
this.classList.add('caps-locked');
// Makes last pressed key inactive if transit to a new keyset on long
// press.
- this.lastPressedKey.classList.remove('active');
+ if (this.lastPressedKey)
+ this.lastPressedKey.classList.remove('active');
}
},
diff --git a/ui/keyboard/resources/elements/kb-shift-key.html b/ui/keyboard/resources/elements/kb-shift-key.html
index 99c4825..b2dac6b 100644
--- a/ui/keyboard/resources/elements/kb-shift-key.html
+++ b/ui/keyboard/resources/elements/kb-shift-key.html
@@ -56,16 +56,27 @@
upperCaseKeysetId: 'upper',
up: function(event) {
- if (state == KEY_STATES.PRESSED) {
- state = KEY_STATES.TAPPED;
- } else if (state == KEY_STATES.CHORDING) {
- // Leaves chording only if the pointer that triggered it is
- // released.
- if (event.pointerId == enterChordingEvent.pointerId)
+ if (state == KEY_STATES.CHORDING &&
+ event.pointerId != enterChordingEvent.pointerId) {
+ // Disables all other pointer events on shift keys when chording.
+ return;
+ }
+ switch (state) {
+ case KEY_STATES.PRESSED:
+ state = KEY_STATES.TAPPED;
+ break;
+ case KEY_STATES.CHORDING:
+ // Leaves chording only if the pointer that triggered it is
+ // released.
state = KEY_STATES.UNLOCKED;
- else
- return;
+ break;
+ default:
+ break;
}
+ // When releasing the shift key, it is not the same shift key that was
+ // pressed. Updates the pointerId of the releasing shift key to make
+ // sure key-up event fires correctly in kb-key-base.
+ this.pointerId = enterChordingEvent.pointerId;
this.super([event]);
},