2 -- Copyright 2013 The Chromium Authors. All rights reserved.
3 -- Use of this source code is governed by a BSD-style license that can be
4 -- found in the LICENSE file.
7 <polymer-element name="kb-modifier-key" class="unlocked dark" extends="kb-key"
13 * The possible states of the key.
18 PRESSED: "pressed", // Key-down.
19 UNLOCKED: "unlocked", // Default state.
20 TAPPED: "tapped", // Key-down followed by key-up.
21 CHORDING: "chording", // Chording mode.
25 * A map of the state of all modifier keys.
30 Polymer('kb-modifier-key', {
32 if (this.state == KEY_STATES.PRESSED)
33 this.state = KEY_STATES.TAPPED;
35 this.state = KEY_STATES.UNLOCKED;
39 down: function(event) {
40 // First transition state so that populateDetails generates
43 case KEY_STATES.UNLOCKED:
44 this.state = KEY_STATES.PRESSED;
46 case KEY_STATES.TAPPED:
47 this.state = KEY_STATES.UNLOCKED;
49 case KEY_STATES.PRESSED:
50 case KEY_STATES.CHORDING:
51 // We pressed another key at the same time,
52 // so ignore second press.
55 console.error("Undefined key state: " + state);
62 * Returns whether the modifier for this key is active.
65 isActive: function() {
66 return this.state != KEY_STATES.UNLOCKED;
70 * Notifies key that a non-control keyed down.
71 * A control key is defined as one of shift, control or alt.
73 onNonControlKeyDown: function() {
75 case (KEY_STATES.PRESSED):
76 this.state = KEY_STATES.CHORDING;
82 * Notifies key that a non-control keyed was typed.
83 * A control key is defined as one of shift, control or alt.
85 onNonControlKeyTyped: function() {
87 case (KEY_STATES.TAPPED):
88 this.state = KEY_STATES.UNLOCKED;
94 * Called on a pointer-out event. Ends chording.
95 * @param {event} event The pointer-out event.
97 out: function(event) {
98 // TODO(rsadam): Add chording event so that we don't reset
99 // when shift-chording.
100 if (this.state == KEY_STATES.CHORDING) {
101 this.state = KEY_STATES.UNLOCKED;
106 * Overrides the autoRelease function to enable chording.
108 autoRelease: function() {
111 populateDetails: function(caller) {
112 var detail = this.super([caller]);
113 if (this.state != KEY_STATES.UNLOCKED)
114 detail.activeModifier = this.charValue;
119 * Resets the modifier key state.
122 this.state = KEY_STATES.UNLOCKED;
127 console.error("innerText not defined for kb-modifier-key: "
129 // All keys default to the unlock state.
130 if (!(this.innerText in states))
131 states[this.innerText] = KEY_STATES.UNLOCKED;
132 return states[this.innerText];
136 states[this.innerText] = value;