OLD | NEW |
1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. | 1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. |
2 // limitations under the License. | 2 // limitations under the License. |
3 // See the License for the specific language governing permissions and | 3 // See the License for the specific language governing permissions and |
4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
5 // distributed under the License is distributed on an "AS-IS" BASIS, | 5 // distributed under the License is distributed on an "AS-IS" BASIS, |
6 // Unless required by applicable law or agreed to in writing, software | 6 // Unless required by applicable law or agreed to in writing, software |
7 // | 7 // |
8 // http://www.apache.org/licenses/LICENSE-2.0 | 8 // http://www.apache.org/licenses/LICENSE-2.0 |
9 // | 9 // |
10 // You may obtain a copy of the License at | 10 // You may obtain a copy of the License at |
11 // you may not use this file except in compliance with the License. | 11 // you may not use this file except in compliance with the License. |
12 // Licensed under the Apache License, Version 2.0 (the "License"); | 12 // Licensed under the Apache License, Version 2.0 (the "License"); |
13 // | 13 // |
14 goog.provide('i18n.input.chrome.inputview.StateManager'); | 14 goog.provide('i18n.input.chrome.inputview.StateManager'); |
15 | 15 |
16 goog.require('i18n.input.chrome.inputview.Covariance'); | 16 goog.require('i18n.input.chrome.inputview.Covariance'); |
17 | 17 |
| 18 goog.scope(function() { |
| 19 |
| 20 |
18 | 21 |
19 /** | 22 /** |
20 * The state for the input view keyboard. | 23 * The state for the input view keyboard. |
21 * | 24 * |
22 * @constructor | 25 * @constructor |
23 */ | 26 */ |
24 i18n.input.chrome.inputview.StateManager = function() { | 27 i18n.input.chrome.inputview.StateManager = function() { |
25 /** | |
26 * The state of the keyboard. | |
27 * | |
28 * @type {number} | |
29 * @private | |
30 */ | |
31 this.state_ = 0; | |
32 | |
33 /** | |
34 * The sticky state. | |
35 * | |
36 * @type {number} | |
37 * @private | |
38 */ | |
39 this.sticky_ = 0; | |
40 | |
41 /** | |
42 * Bits to indicate which state key is down. | |
43 * | |
44 * @type {number} | |
45 * @private | |
46 */ | |
47 this.stateKeyDown_ = 0; | |
48 | |
49 /** | |
50 * Bits to track which state is in chording. | |
51 * | |
52 * @type {number} | |
53 * @private | |
54 */ | |
55 this.chording_ = 0; | |
56 | |
57 /** | |
58 * Whether the current keyset is in English mode. | |
59 * | |
60 * @type {boolean} | |
61 */ | |
62 this.isEnMode = false; | |
63 | |
64 /** @type {!i18n.input.chrome.inputview.Covariance} */ | 28 /** @type {!i18n.input.chrome.inputview.Covariance} */ |
65 this.covariance = new i18n.input.chrome.inputview.Covariance(); | 29 this.covariance = new i18n.input.chrome.inputview.Covariance(); |
66 }; | 30 }; |
| 31 var StateManager = i18n.input.chrome.inputview.StateManager; |
| 32 |
| 33 |
| 34 /** @type {string} */ |
| 35 StateManager.prototype.contextType = ''; |
67 | 36 |
68 | 37 |
69 /** | 38 /** |
| 39 * The state of the keyboard. |
| 40 * |
| 41 * @type {number} |
| 42 * @private |
| 43 */ |
| 44 StateManager.prototype.state_ = 0; |
| 45 |
| 46 |
| 47 /** |
| 48 * The sticky state. |
| 49 * |
| 50 * @type {number} |
| 51 * @private |
| 52 */ |
| 53 StateManager.prototype.sticky_ = 0; |
| 54 |
| 55 |
| 56 /** |
| 57 * Bits to indicate which state key is down. |
| 58 * |
| 59 * @type {number} |
| 60 * @private |
| 61 */ |
| 62 StateManager.prototype.stateKeyDown_ = 0; |
| 63 |
| 64 |
| 65 /** |
| 66 * Bits to track which state is in chording. |
| 67 * |
| 68 * @type {number} |
| 69 * @private |
| 70 */ |
| 71 StateManager.prototype.chording_ = 0; |
| 72 |
| 73 |
| 74 /** |
| 75 * A flag to temporary compatible with the current modifier key state |
| 76 * managerment, this bit indicates the sticky is set by double_click or long |
| 77 * press which won't be canceled by keyup or text commit. |
| 78 * |
| 79 * @private {number} |
| 80 */ |
| 81 StateManager.prototype.finalSticky_ = 0; |
| 82 |
| 83 |
| 84 /** |
| 85 * Whether the current keyset is in English mode. |
| 86 * |
| 87 * @type {boolean} |
| 88 */ |
| 89 StateManager.prototype.isEnMode = false; |
| 90 |
| 91 |
| 92 /** |
70 * Sets a state to keydown. | 93 * Sets a state to keydown. |
71 * | 94 * |
72 * @param {!i18n.input.chrome.inputview.StateType} stateType The state type. | 95 * @param {!i18n.input.chrome.inputview.StateType} stateType The state type. |
73 * @param {boolean} isKeyDown True if the state key is down. | 96 * @param {boolean} isKeyDown True if the state key is down. |
74 */ | 97 */ |
75 i18n.input.chrome.inputview.StateManager.prototype.setKeyDown = function( | 98 i18n.input.chrome.inputview.StateManager.prototype.setKeyDown = function( |
76 stateType, isKeyDown) { | 99 stateType, isKeyDown) { |
77 if (isKeyDown) { | 100 if (isKeyDown) { |
78 this.stateKeyDown_ |= stateType; | 101 this.stateKeyDown_ |= stateType; |
79 } else { | 102 } else { |
(...skipping 30 matching lines...) Expand all Loading... |
110 * @param {!i18n.input.chrome.inputview.StateType} stateType The state type. | 133 * @param {!i18n.input.chrome.inputview.StateType} stateType The state type. |
111 * @return {boolean} True if the state is chording. | 134 * @return {boolean} True if the state is chording. |
112 */ | 135 */ |
113 i18n.input.chrome.inputview.StateManager.prototype.isChording = function( | 136 i18n.input.chrome.inputview.StateManager.prototype.isChording = function( |
114 stateType) { | 137 stateType) { |
115 return (this.chording_ & stateType) != 0; | 138 return (this.chording_ & stateType) != 0; |
116 }; | 139 }; |
117 | 140 |
118 | 141 |
119 /** | 142 /** |
| 143 * Is a state in final sticky. |
| 144 * |
| 145 * @param {i18n.input.chrome.inputview.StateType} stateType . |
| 146 * @return {boolean} . |
| 147 */ |
| 148 i18n.input.chrome.inputview.StateManager.prototype.isFinalSticky = function( |
| 149 stateType) { |
| 150 return (this.finalSticky_ & stateType) != 0; |
| 151 }; |
| 152 |
| 153 |
| 154 /** |
| 155 * Sets a specific state to be final sticky. |
| 156 * |
| 157 * @param {i18n.input.chrome.inputview.StateType} stateType . |
| 158 * @param {boolean} isFinalSticky . |
| 159 */ |
| 160 i18n.input.chrome.inputview.StateManager.prototype.setFinalSticky = function( |
| 161 stateType, isFinalSticky) { |
| 162 if (isFinalSticky) { |
| 163 this.finalSticky_ |= stateType; |
| 164 } else { |
| 165 this.finalSticky_ &= ~stateType; |
| 166 } |
| 167 }; |
| 168 |
| 169 |
| 170 /** |
120 * Sets a state to be sticky. | 171 * Sets a state to be sticky. |
121 * | 172 * |
122 * @param {!i18n.input.chrome.inputview.StateType} stateType The state type. | 173 * @param {!i18n.input.chrome.inputview.StateType} stateType The state type. |
123 * @param {boolean} isSticky True to set it sticky. | 174 * @param {boolean} isSticky True to set it sticky. |
124 */ | 175 */ |
125 i18n.input.chrome.inputview.StateManager.prototype.setSticky = function( | 176 i18n.input.chrome.inputview.StateManager.prototype.setSticky = function( |
126 stateType, isSticky) { | 177 stateType, isSticky) { |
127 if (isSticky) { | 178 if (isSticky) { |
128 this.sticky_ |= stateType; | 179 this.sticky_ |= stateType; |
129 } else { | 180 } else { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 275 |
225 | 276 |
226 /** | 277 /** |
227 * Resets the state. | 278 * Resets the state. |
228 * | 279 * |
229 */ | 280 */ |
230 i18n.input.chrome.inputview.StateManager.prototype.reset = function() { | 281 i18n.input.chrome.inputview.StateManager.prototype.reset = function() { |
231 this.state_ = 0; | 282 this.state_ = 0; |
232 this.sticky_ = 0; | 283 this.sticky_ = 0; |
233 }; | 284 }; |
| 285 |
| 286 }); // goog.scope |
OLD | NEW |