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

Side by Side Diff: third_party/google_input_tools/src/chrome/os/inputview/model.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.Model');
15
16 goog.require('goog.array');
17 goog.require('goog.events.EventTarget');
18 goog.require('goog.net.jsloader');
19 goog.require('i18n.input.chrome.inputview.ConditionName');
20 goog.require('i18n.input.chrome.inputview.Settings');
21 goog.require('i18n.input.chrome.inputview.SpecNodeName');
22 goog.require('i18n.input.chrome.inputview.StateManager');
23 goog.require('i18n.input.chrome.inputview.events.ConfigLoadedEvent');
24 goog.require('i18n.input.chrome.inputview.events.LayoutLoadedEvent');
25
26 goog.scope(function() {
27 var SpecNodeName = i18n.input.chrome.inputview.SpecNodeName;
28
29
30
31 /**
32 * The model.
33 * @constructor
34 * @extends {goog.events.EventTarget}
35 */
36 i18n.input.chrome.inputview.Model = function() {
37 goog.base(this);
38
39 /**
40 * The state manager.
41 *
42 * @type {!i18n.input.chrome.inputview.StateManager}
43 */
44 this.stateManager = new i18n.input.chrome.inputview.StateManager();
45
46 /**
47 * The configuration.
48 *
49 * @type {!i18n.input.chrome.inputview.Settings}
50 */
51 this.settings = new i18n.input.chrome.inputview.Settings();
52
53 /** @private {!Array.<string>} */
54 this.loadingResources_ = [];
55
56 goog.exportSymbol('google.ime.chrome.inputview.onLayoutLoaded',
57 goog.bind(this.onLayoutLoaded_, this));
58 goog.exportSymbol('google.ime.chrome.inputview.onConfigLoaded',
59 goog.bind(this.onConfigLoaded_, this));
60 };
61 var Model = i18n.input.chrome.inputview.Model;
62 goog.inherits(Model, goog.events.EventTarget);
63
64
65 /**
66 * The path to the layouts directory.
67 *
68 * @type {string}
69 * @private
70 */
71 Model.LAYOUTS_PATH_ =
72 '/inputview_layouts/';
73
74
75 /**
76 * The path to the content directory.
77 *
78 * @type {string}
79 * @private
80 */
81 Model.CONTENT_PATH_ =
82 '/config/';
83
84
85 /**
86 * Callback when configuration is loaded.
87 *
88 * @param {!Object} data The configuration data.
89 * @private
90 */
91 Model.prototype.onConfigLoaded_ = function(data) {
92 goog.array.remove(this.loadingResources_, this.getConfigUrl_(
93 data[SpecNodeName.ID]));
94 this.dispatchEvent(new i18n.input.chrome.inputview.events.ConfigLoadedEvent(
95 data));
96 };
97
98
99 /**
100 * Gets the layout url.
101 *
102 * @param {string} layout .
103 * @private
104 * @return {string} The url of the layout data.
105 */
106 Model.prototype.getLayoutUrl_ = function(layout) {
107 return Model.LAYOUTS_PATH_ + layout + '.js';
108 };
109
110
111 /**
112 * Gets the keyset configuration url.
113 *
114 * @param {string} keyset .
115 * @private
116 * @return {string} .
117 */
118 Model.prototype.getConfigUrl_ = function(keyset) {
119 // Strips out all the suffixes in the keyboard code.
120 var configId = keyset.replace(/\..*$/, '');
121 return Model.CONTENT_PATH_ + configId + '.js';
122 };
123
124
125 /**
126 * Callback when layout is loaded.
127 *
128 * @param {!Object} data The layout data.
129 * @private
130 */
131 Model.prototype.onLayoutLoaded_ = function(data) {
132 goog.array.remove(this.loadingResources_, this.getLayoutUrl_(data[
133 SpecNodeName.LAYOUT_ID]));
134 this.dispatchEvent(new i18n.input.chrome.inputview.events.LayoutLoadedEvent(
135 data));
136 };
137
138
139 /**
140 * Loads a layout.
141 *
142 * @param {string} layout The layout name.
143 */
144 Model.prototype.loadLayout = function(layout) {
145 var url = this.getLayoutUrl_(layout);
146 if (!goog.array.contains(this.loadingResources_, url)) {
147 this.loadingResources_.push(url);
148 goog.net.jsloader.load(url);
149 }
150 };
151
152
153 /**
154 * Loads the configuration for the keyboard code.
155 *
156 * @param {string} keyboardCode The keyboard code.
157 */
158 Model.prototype.loadConfig = function(keyboardCode) {
159 var url = this.getConfigUrl_(keyboardCode);
160 if (!goog.array.contains(this.loadingResources_, url)) {
161 this.loadingResources_.push(url);
162 goog.net.jsloader.load(url);
163 }
164 };
165
166 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698