OLD | NEW |
1 <!-- | 1 <!-- |
2 -- Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 3 -- Use of this source code is governed by a BSD-style license that can be |
4 -- found in the LICENSE file. | 4 -- found in the LICENSE file. |
5 --> | 5 --> |
6 | 6 |
7 <polymer-element name="kb-key-base" | 7 <polymer-element name="kb-key-base" |
8 on-pointerdown="down" on-pointerup="up" on-pointerout="out" | 8 on-pointerdown="down" on-pointerup="up" on-pointerout="out" |
9 attributes="accents char invert repeat superscript toKeyset toLayout"> | 9 attributes="accents char invert repeat superscript toKeyset toLayout"> |
10 <script> | 10 <script> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 if (keyValues.length < MINIMUM_NUM_OF_RULE_ELEMENTS) { | 102 if (keyValues.length < MINIMUM_NUM_OF_RULE_ELEMENTS) { |
103 console.error('Invalid keyset rules: ' + element); | 103 console.error('Invalid keyset rules: ' + element); |
104 return; | 104 return; |
105 } | 105 } |
106 self.keysetRules[keyValues[EVENT_TYPE]] = [keyValues[TO_KEYSET], | 106 self.keysetRules[keyValues[EVENT_TYPE]] = [keyValues[TO_KEYSET], |
107 (keyValues[NEXT_KEYSET] ? keyValues[NEXT_KEYSET] : null)]; | 107 (keyValues[NEXT_KEYSET] ? keyValues[NEXT_KEYSET] : null)]; |
108 }); | 108 }); |
109 } | 109 } |
110 }, | 110 }, |
111 down: function(event) { | 111 down: function(event) { |
112 var detail = { | 112 var detail = this.PopulateDetails(); |
113 char: this.charValue, | |
114 toLayout: this.toLayout, | |
115 repeat: this.repeat | |
116 }; | |
117 if (this.keysetRules && this.keysetRules.down != undefined) { | 113 if (this.keysetRules && this.keysetRules.down != undefined) { |
118 detail.toKeyset = this.keysetRules.down[TO_KEYSET - OFFSET]; | 114 detail.toKeyset = this.keysetRules.down[TO_KEYSET - OFFSET]; |
119 detail.nextKeyset = this.keysetRules.down[NEXT_KEYSET - OFFSET]; | 115 detail.nextKeyset = this.keysetRules.down[NEXT_KEYSET - OFFSET]; |
120 } | 116 } |
121 this.fire('key-down', detail); | 117 this.fire('key-down', detail); |
122 this.longPressTimer = this.asyncMethod(function() { | 118 this.longPressTimer = this.asyncMethod(function() { |
123 var detail = { | 119 var detail = { |
124 char: this.charValue, | 120 char: this.charValue, |
125 superscript: this.superscript | 121 superscript: this.superscript |
126 }; | 122 }; |
127 if (this.keysetRules && this.keysetRules.long != undefined) { | 123 if (this.keysetRules && this.keysetRules.long != undefined) { |
128 detail.toKeyset = this.keysetRules.long[TO_KEYSET - OFFSET]; | 124 detail.toKeyset = this.keysetRules.long[TO_KEYSET - OFFSET]; |
129 detail.nextKeyset = this.keysetRules.long[NEXT_KEYSET - OFFSET]; | 125 detail.nextKeyset = this.keysetRules.long[NEXT_KEYSET - OFFSET]; |
130 } | 126 } |
131 this.fire('key-longpress', detail); | 127 this.fire('key-longpress', detail); |
132 }, null, LONGPRESS_DELAY_MSEC); | 128 }, null, LONGPRESS_DELAY_MSEC); |
133 }, | 129 }, |
134 out: function(event) { | 130 out: function(event) { |
135 clearTimeout(this.longPressTimer); | 131 clearTimeout(this.longPressTimer); |
136 }, | 132 }, |
137 up: function(event) { | 133 up: function(event) { |
138 clearTimeout(this.longPressTimer); | 134 clearTimeout(this.longPressTimer); |
139 var detail = { | 135 var detail = this.PopulateDetails(); |
140 char: this.charValue, | |
141 toLayout: this.toLayout | |
142 }; | |
143 if (this.keysetRules && this.keysetRules.up != undefined) { | 136 if (this.keysetRules && this.keysetRules.up != undefined) { |
144 detail.toKeyset = this.keysetRules.up[TO_KEYSET - OFFSET]; | 137 detail.toKeyset = this.keysetRules.up[TO_KEYSET - OFFSET]; |
145 detail.nextKeyset = this.keysetRules.up[NEXT_KEYSET - OFFSET]; | 138 detail.nextKeyset = this.keysetRules.up[NEXT_KEYSET - OFFSET]; |
146 } | 139 } |
147 this.fire('key-up', detail); | 140 this.fire('key-up', detail); |
148 }, | 141 }, |
149 | 142 |
150 /** | 143 /** |
151 * Character value associated with the key. Typically, the value is a | 144 * Character value associated with the key. Typically, the value is a |
152 * single charcater, but may be multi-character in cases like a ".com" | 145 * single charcater, but may be multi-character in cases like a ".com" |
153 * button. | 146 * button. |
154 * @type {string} | 147 * @type {string} |
155 */ | 148 */ |
156 get charValue() { | 149 get charValue() { |
157 return this.char || this.textContent; | 150 return this.char || this.textContent; |
158 }, | 151 }, |
| 152 |
| 153 PopulateDetails: function() { |
| 154 return { |
| 155 char: this.charValue, |
| 156 toLayout: this.toLayout, |
| 157 repeat: this.repeat |
| 158 }; |
| 159 }, |
159 }); | 160 }); |
160 </script> | 161 </script> |
161 </polymer-element> | 162 </polymer-element> |
OLD | NEW |