Switch TestFrameNavigationObserver to DidCommitProvisionalLoadForFrame.
[chromium-blink-merge.git] / third_party / google_input_tools / src / chrome / os / inputview / statemanager.js
blob29544cd4c3de446a5f09d16117171e60bd3c02e7
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");
14 goog.provide('i18n.input.chrome.inputview.StateManager');
16 goog.require('i18n.input.chrome.inputview.Covariance');
18 goog.scope(function() {
22 /**
23 * The state for the input view keyboard.
25 * @constructor
27 i18n.input.chrome.inputview.StateManager = function() {
28 /** @type {!i18n.input.chrome.inputview.Covariance} */
29 this.covariance = new i18n.input.chrome.inputview.Covariance();
31 var StateManager = i18n.input.chrome.inputview.StateManager;
34 /** @type {string} */
35 StateManager.prototype.contextType = '';
38 /**
39 * The state of the keyboard.
41 * @type {number}
42 * @private
44 StateManager.prototype.state_ = 0;
47 /**
48 * The sticky state.
50 * @type {number}
51 * @private
53 StateManager.prototype.sticky_ = 0;
56 /**
57 * Bits to indicate which state key is down.
59 * @type {number}
60 * @private
62 StateManager.prototype.stateKeyDown_ = 0;
65 /**
66 * Bits to track which state is in chording.
68 * @type {number}
69 * @private
71 StateManager.prototype.chording_ = 0;
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.
79 * @private {number}
81 StateManager.prototype.finalSticky_ = 0;
84 /**
85 * Whether the current keyset is in English mode.
87 * @type {boolean}
89 StateManager.prototype.isEnMode = false;
92 /**
93 * Sets a state to keydown.
95 * @param {!i18n.input.chrome.inputview.StateType} stateType The state type.
96 * @param {boolean} isKeyDown True if the state key is down.
98 i18n.input.chrome.inputview.StateManager.prototype.setKeyDown = function(
99 stateType, isKeyDown) {
100 if (isKeyDown) {
101 this.stateKeyDown_ |= stateType;
102 } else {
103 this.stateKeyDown_ &= ~stateType;
104 this.chording_ &= ~stateType;
110 * True if the key is down.
112 * @param {!i18n.input.chrome.inputview.StateType} stateType .
113 * @return {boolean} .
115 i18n.input.chrome.inputview.StateManager.prototype.isKeyDown = function(
116 stateType) {
117 return (this.stateKeyDown_ & stateType) != 0;
122 * Triggers chording and record it for each key-downed state.
124 i18n.input.chrome.inputview.StateManager.prototype.triggerChording =
125 function() {
126 this.chording_ |= this.stateKeyDown_;
131 * True if the state is chording now.
133 * @param {!i18n.input.chrome.inputview.StateType} stateType The state type.
134 * @return {boolean} True if the state is chording.
136 i18n.input.chrome.inputview.StateManager.prototype.isChording = function(
137 stateType) {
138 return (this.chording_ & stateType) != 0;
143 * Is a state in final sticky.
145 * @param {i18n.input.chrome.inputview.StateType} stateType .
146 * @return {boolean} .
148 i18n.input.chrome.inputview.StateManager.prototype.isFinalSticky = function(
149 stateType) {
150 return (this.finalSticky_ & stateType) != 0;
155 * Sets a specific state to be final sticky.
157 * @param {i18n.input.chrome.inputview.StateType} stateType .
158 * @param {boolean} isFinalSticky .
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;
171 * Sets a state to be sticky.
173 * @param {!i18n.input.chrome.inputview.StateType} stateType The state type.
174 * @param {boolean} isSticky True to set it sticky.
176 i18n.input.chrome.inputview.StateManager.prototype.setSticky = function(
177 stateType, isSticky) {
178 if (isSticky) {
179 this.sticky_ |= stateType;
180 } else {
181 this.sticky_ &= ~stateType;
187 * Is a state sticky.
189 * @param {!i18n.input.chrome.inputview.StateType} stateType The state
190 * type.
191 * @return {boolean} True if it is sticky.
193 i18n.input.chrome.inputview.StateManager.prototype.isSticky = function(
194 stateType) {
195 return (this.sticky_ & stateType) != 0;
200 * Sets a state.
202 * @param {!i18n.input.chrome.inputview.StateType} stateType The state
203 * type.
204 * @param {boolean} enable True to enable the state.
206 i18n.input.chrome.inputview.StateManager.prototype.setState = function(
207 stateType, enable) {
208 if (enable) {
209 this.state_ = this.state_ | stateType;
210 } else {
211 this.state_ = this.state_ & ~stateType;
217 * Toggle the state.
219 * @param {!i18n.input.chrome.inputview.StateType} stateType The state
220 * type.
221 * @param {boolean} isSticky True to set it sticky.
223 i18n.input.chrome.inputview.StateManager.prototype.toggleState = function(
224 stateType, isSticky) {
225 var enable = !this.hasState(stateType);
226 this.setState(stateType, enable);
227 isSticky = enable ? isSticky : false;
228 this.setSticky(stateType, isSticky);
233 * Is the state on.
235 * @param {!i18n.input.chrome.inputview.StateType} stateType The state
236 * type.
237 * @return {boolean} True if the state is on.
239 i18n.input.chrome.inputview.StateManager.prototype.hasState = function(
240 stateType) {
241 return (this.state_ & stateType) != 0;
246 * Gets the state.
248 * @return {number} The state.
250 i18n.input.chrome.inputview.StateManager.prototype.getState =
251 function() {
252 return this.state_;
257 * Clears unsticky state.
260 i18n.input.chrome.inputview.StateManager.prototype.clearUnstickyState =
261 function() {
262 this.state_ = this.state_ & this.sticky_;
267 * True if there is unsticky state.
269 * @return {boolean} True if there is unsticky state.
271 i18n.input.chrome.inputview.StateManager.prototype.hasUnStickyState =
272 function() {
273 return this.state_ != this.sticky_;
278 * Resets the state.
281 i18n.input.chrome.inputview.StateManager.prototype.reset = function() {
282 this.state_ = 0;
283 this.sticky_ = 0;
286 }); // goog.scope