1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 * The possible states of the key.
13 PRESSED
: "pressed", // Key-down.
14 UNLOCKED
: "unlocked", // Default state.
15 TAPPED
: "tapped", // Key-down followed by key-up.
16 CHORDING
: "chording", // Chording mode.
20 * A map of the state of all modifier keys.
25 Polymer('kb-modifier-key', {
27 if (this.state
== KEY_STATES
.PRESSED
)
28 this.state
= KEY_STATES
.TAPPED
;
30 this.state
= KEY_STATES
.UNLOCKED
;
34 down: function(event
) {
35 // First transition state so that populateDetails generates
38 case KEY_STATES
.UNLOCKED
:
39 this.state
= KEY_STATES
.PRESSED
;
41 case KEY_STATES
.TAPPED
:
42 this.state
= KEY_STATES
.UNLOCKED
;
44 case KEY_STATES
.PRESSED
:
45 case KEY_STATES
.CHORDING
:
46 // We pressed another key at the same time,
47 // so ignore second press.
50 console
.error("Undefined key state: " + state
);
57 * Returns whether the modifier for this key is active.
60 isActive: function() {
61 return this.state
!= KEY_STATES
.UNLOCKED
;
65 * Notifies key that a non-control keyed down.
66 * A control key is defined as one of shift, control or alt.
68 onNonControlKeyDown: function() {
70 case (KEY_STATES
.PRESSED
):
71 this.state
= KEY_STATES
.CHORDING
;
77 * Notifies key that a non-control keyed was typed.
78 * A control key is defined as one of shift, control or alt.
80 onNonControlKeyTyped: function() {
82 case (KEY_STATES
.TAPPED
):
83 this.state
= KEY_STATES
.UNLOCKED
;
89 * Called on a pointer-out event. Ends chording.
90 * @param {event} event The pointer-out event.
92 out: function(event
) {
93 // TODO(rsadam): Add chording event so that we don't reset
94 // when shift-chording.
95 if (this.state
== KEY_STATES
.CHORDING
) {
96 this.state
= KEY_STATES
.UNLOCKED
;
101 * Overrides the autoRelease function to enable chording.
103 autoRelease: function() {
106 populateDetails: function(caller
) {
107 var detail
= this.super([caller
]);
108 if (this.state
!= KEY_STATES
.UNLOCKED
)
109 detail
.activeModifier
= this.charValue
;
114 * Resets the modifier key state.
117 this.state
= KEY_STATES
.UNLOCKED
;
121 var key
= this.charValue
;
123 console
.error("missing key for kb-modifier-key state: " + this);
124 // All keys default to the unlock state.
125 if (!(key
in states
))
126 states
[key
] = KEY_STATES
.UNLOCKED
;
131 var key
= this.charValue
;