Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: third_party/google_input_tools/src/chrome/os/inputview/statemanager.js

Issue 674153004: Add third_party/google-input-tools: Take 2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@google_input_tools
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
2 // limitations under the License.
3 // See the License for the specific language governing permissions and
4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5 // distributed under the License is distributed on an "AS-IS" BASIS,
6 // Unless required by applicable law or agreed to in writing, software
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // You may obtain a copy of the License at
11 // you may not use this file except in compliance with the License.
12 // Licensed under the Apache License, Version 2.0 (the "License");
13 //
14 goog.provide('i18n.input.chrome.inputview.StateManager');
15
16 goog.require('i18n.input.chrome.inputview.Covariance');
17
18
19 /**
20 * The state for the input view keyboard.
21 *
22 * @constructor
23 */
24 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} */
65 this.covariance = new i18n.input.chrome.inputview.Covariance();
66 };
67
68
69 /**
70 * Sets a state to keydown.
71 *
72 * @param {!i18n.input.chrome.inputview.StateType} stateType The state type.
73 * @param {boolean} isKeyDown True if the state key is down.
74 */
75 i18n.input.chrome.inputview.StateManager.prototype.setKeyDown = function(
76 stateType, isKeyDown) {
77 if (isKeyDown) {
78 this.stateKeyDown_ |= stateType;
79 } else {
80 this.stateKeyDown_ &= ~stateType;
81 this.chording_ &= ~stateType;
82 }
83 };
84
85
86 /**
87 * True if the key is down.
88 *
89 * @param {!i18n.input.chrome.inputview.StateType} stateType .
90 * @return {boolean} .
91 */
92 i18n.input.chrome.inputview.StateManager.prototype.isKeyDown = function(
93 stateType) {
94 return (this.stateKeyDown_ & stateType) != 0;
95 };
96
97
98 /**
99 * Triggers chording and record it for each key-downed state.
100 */
101 i18n.input.chrome.inputview.StateManager.prototype.triggerChording =
102 function() {
103 this.chording_ |= this.stateKeyDown_;
104 };
105
106
107 /**
108 * True if the state is chording now.
109 *
110 * @param {!i18n.input.chrome.inputview.StateType} stateType The state type.
111 * @return {boolean} True if the state is chording.
112 */
113 i18n.input.chrome.inputview.StateManager.prototype.isChording = function(
114 stateType) {
115 return (this.chording_ & stateType) != 0;
116 };
117
118
119 /**
120 * Sets a state to be sticky.
121 *
122 * @param {!i18n.input.chrome.inputview.StateType} stateType The state type.
123 * @param {boolean} isSticky True to set it sticky.
124 */
125 i18n.input.chrome.inputview.StateManager.prototype.setSticky = function(
126 stateType, isSticky) {
127 if (isSticky) {
128 this.sticky_ |= stateType;
129 } else {
130 this.sticky_ &= ~stateType;
131 }
132 };
133
134
135 /**
136 * Is a state sticky.
137 *
138 * @param {!i18n.input.chrome.inputview.StateType} stateType The state
139 * type.
140 * @return {boolean} True if it is sticky.
141 */
142 i18n.input.chrome.inputview.StateManager.prototype.isSticky = function(
143 stateType) {
144 return (this.sticky_ & stateType) != 0;
145 };
146
147
148 /**
149 * Sets a state.
150 *
151 * @param {!i18n.input.chrome.inputview.StateType} stateType The state
152 * type.
153 * @param {boolean} enable True to enable the state.
154 */
155 i18n.input.chrome.inputview.StateManager.prototype.setState = function(
156 stateType, enable) {
157 if (enable) {
158 this.state_ = this.state_ | stateType;
159 } else {
160 this.state_ = this.state_ & ~stateType;
161 }
162 };
163
164
165 /**
166 * Toggle the state.
167 *
168 * @param {!i18n.input.chrome.inputview.StateType} stateType The state
169 * type.
170 * @param {boolean} isSticky True to set it sticky.
171 */
172 i18n.input.chrome.inputview.StateManager.prototype.toggleState = function(
173 stateType, isSticky) {
174 var enable = !this.hasState(stateType);
175 this.setState(stateType, enable);
176 isSticky = enable ? isSticky : false;
177 this.setSticky(stateType, isSticky);
178 };
179
180
181 /**
182 * Is the state on.
183 *
184 * @param {!i18n.input.chrome.inputview.StateType} stateType The state
185 * type.
186 * @return {boolean} True if the state is on.
187 */
188 i18n.input.chrome.inputview.StateManager.prototype.hasState = function(
189 stateType) {
190 return (this.state_ & stateType) != 0;
191 };
192
193
194 /**
195 * Gets the state.
196 *
197 * @return {number} The state.
198 */
199 i18n.input.chrome.inputview.StateManager.prototype.getState =
200 function() {
201 return this.state_;
202 };
203
204
205 /**
206 * Clears unsticky state.
207 *
208 */
209 i18n.input.chrome.inputview.StateManager.prototype.clearUnstickyState =
210 function() {
211 this.state_ = this.state_ & this.sticky_;
212 };
213
214
215 /**
216 * True if there is unsticky state.
217 *
218 * @return {boolean} True if there is unsticky state.
219 */
220 i18n.input.chrome.inputview.StateManager.prototype.hasUnStickyState =
221 function() {
222 return this.state_ != this.sticky_;
223 };
224
225
226 /**
227 * Resets the state.
228 *
229 */
230 i18n.input.chrome.inputview.StateManager.prototype.reset = function() {
231 this.state_ = 0;
232 this.sticky_ = 0;
233 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698