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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/google_input_tools/src/chrome/os/inputview/statemanager.js
diff --git a/third_party/google_input_tools/src/chrome/os/inputview/statemanager.js b/third_party/google_input_tools/src/chrome/os/inputview/statemanager.js
new file mode 100644
index 0000000000000000000000000000000000000000..a82c6ebf962c117104cf8d0bda67ef06ff3085ab
--- /dev/null
+++ b/third_party/google_input_tools/src/chrome/os/inputview/statemanager.js
@@ -0,0 +1,233 @@
+// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
+// limitations under the License.
+// See the License for the specific language governing permissions and
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// distributed under the License is distributed on an "AS-IS" BASIS,
+// Unless required by applicable law or agreed to in writing, software
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// You may obtain a copy of the License at
+// you may not use this file except in compliance with the License.
+// Licensed under the Apache License, Version 2.0 (the "License");
+//
+goog.provide('i18n.input.chrome.inputview.StateManager');
+
+goog.require('i18n.input.chrome.inputview.Covariance');
+
+
+/**
+ * The state for the input view keyboard.
+ *
+ * @constructor
+ */
+i18n.input.chrome.inputview.StateManager = function() {
+ /**
+ * The state of the keyboard.
+ *
+ * @type {number}
+ * @private
+ */
+ this.state_ = 0;
+
+ /**
+ * The sticky state.
+ *
+ * @type {number}
+ * @private
+ */
+ this.sticky_ = 0;
+
+ /**
+ * Bits to indicate which state key is down.
+ *
+ * @type {number}
+ * @private
+ */
+ this.stateKeyDown_ = 0;
+
+ /**
+ * Bits to track which state is in chording.
+ *
+ * @type {number}
+ * @private
+ */
+ this.chording_ = 0;
+
+ /**
+ * Whether the current keyset is in English mode.
+ *
+ * @type {boolean}
+ */
+ this.isEnMode = false;
+
+ /** @type {!i18n.input.chrome.inputview.Covariance} */
+ this.covariance = new i18n.input.chrome.inputview.Covariance();
+};
+
+
+/**
+ * Sets a state to keydown.
+ *
+ * @param {!i18n.input.chrome.inputview.StateType} stateType The state type.
+ * @param {boolean} isKeyDown True if the state key is down.
+ */
+i18n.input.chrome.inputview.StateManager.prototype.setKeyDown = function(
+ stateType, isKeyDown) {
+ if (isKeyDown) {
+ this.stateKeyDown_ |= stateType;
+ } else {
+ this.stateKeyDown_ &= ~stateType;
+ this.chording_ &= ~stateType;
+ }
+};
+
+
+/**
+ * True if the key is down.
+ *
+ * @param {!i18n.input.chrome.inputview.StateType} stateType .
+ * @return {boolean} .
+ */
+i18n.input.chrome.inputview.StateManager.prototype.isKeyDown = function(
+ stateType) {
+ return (this.stateKeyDown_ & stateType) != 0;
+};
+
+
+/**
+ * Triggers chording and record it for each key-downed state.
+ */
+i18n.input.chrome.inputview.StateManager.prototype.triggerChording =
+ function() {
+ this.chording_ |= this.stateKeyDown_;
+};
+
+
+/**
+ * True if the state is chording now.
+ *
+ * @param {!i18n.input.chrome.inputview.StateType} stateType The state type.
+ * @return {boolean} True if the state is chording.
+ */
+i18n.input.chrome.inputview.StateManager.prototype.isChording = function(
+ stateType) {
+ return (this.chording_ & stateType) != 0;
+};
+
+
+/**
+ * Sets a state to be sticky.
+ *
+ * @param {!i18n.input.chrome.inputview.StateType} stateType The state type.
+ * @param {boolean} isSticky True to set it sticky.
+ */
+i18n.input.chrome.inputview.StateManager.prototype.setSticky = function(
+ stateType, isSticky) {
+ if (isSticky) {
+ this.sticky_ |= stateType;
+ } else {
+ this.sticky_ &= ~stateType;
+ }
+};
+
+
+/**
+ * Is a state sticky.
+ *
+ * @param {!i18n.input.chrome.inputview.StateType} stateType The state
+ * type.
+ * @return {boolean} True if it is sticky.
+ */
+i18n.input.chrome.inputview.StateManager.prototype.isSticky = function(
+ stateType) {
+ return (this.sticky_ & stateType) != 0;
+};
+
+
+/**
+ * Sets a state.
+ *
+ * @param {!i18n.input.chrome.inputview.StateType} stateType The state
+ * type.
+ * @param {boolean} enable True to enable the state.
+ */
+i18n.input.chrome.inputview.StateManager.prototype.setState = function(
+ stateType, enable) {
+ if (enable) {
+ this.state_ = this.state_ | stateType;
+ } else {
+ this.state_ = this.state_ & ~stateType;
+ }
+};
+
+
+/**
+ * Toggle the state.
+ *
+ * @param {!i18n.input.chrome.inputview.StateType} stateType The state
+ * type.
+ * @param {boolean} isSticky True to set it sticky.
+ */
+i18n.input.chrome.inputview.StateManager.prototype.toggleState = function(
+ stateType, isSticky) {
+ var enable = !this.hasState(stateType);
+ this.setState(stateType, enable);
+ isSticky = enable ? isSticky : false;
+ this.setSticky(stateType, isSticky);
+};
+
+
+/**
+ * Is the state on.
+ *
+ * @param {!i18n.input.chrome.inputview.StateType} stateType The state
+ * type.
+ * @return {boolean} True if the state is on.
+ */
+i18n.input.chrome.inputview.StateManager.prototype.hasState = function(
+ stateType) {
+ return (this.state_ & stateType) != 0;
+};
+
+
+/**
+ * Gets the state.
+ *
+ * @return {number} The state.
+ */
+i18n.input.chrome.inputview.StateManager.prototype.getState =
+ function() {
+ return this.state_;
+};
+
+
+/**
+ * Clears unsticky state.
+ *
+ */
+i18n.input.chrome.inputview.StateManager.prototype.clearUnstickyState =
+ function() {
+ this.state_ = this.state_ & this.sticky_;
+};
+
+
+/**
+ * True if there is unsticky state.
+ *
+ * @return {boolean} True if there is unsticky state.
+ */
+i18n.input.chrome.inputview.StateManager.prototype.hasUnStickyState =
+ function() {
+ return this.state_ != this.sticky_;
+};
+
+
+/**
+ * Resets the state.
+ *
+ */
+i18n.input.chrome.inputview.StateManager.prototype.reset = function() {
+ this.state_ = 0;
+ this.sticky_ = 0;
+};

Powered by Google App Engine
This is Rietveld 408576698