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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.layouts.util');
15 goog.require('i18n.input.chrome.inputview.Css');
16 goog.require('i18n.input.chrome.inputview.elements.ElementType');
20 goog.scope(function() {
21 var ElementType = i18n.input.chrome.inputview.elements.ElementType;
30 i18n.input.chrome.inputview.layouts.util.keyId_ = 0;
34 * The prefix of the key id, it's overwritten by layout file.
38 i18n.input.chrome.inputview.layouts.util.keyIdPrefix = '';
41 * Resets id counter for keys in preparation for processing a new layout.
42 * @param {string} prefix The prefix for the key id.
44 i18n.input.chrome.inputview.layouts.util.setPrefix = function(prefix) {
45 i18n.input.chrome.inputview.layouts.util.keyIdPrefix = prefix;
46 i18n.input.chrome.inputview.layouts.util.keyId_ = 0;
50 * Creates a sequence of key with the same specification.
52 * @param {!Object} spec The specification.
53 * @param {number} num How many keys.
54 * @return {!Array.<Object>} The keys.
56 i18n.input.chrome.inputview.layouts.util.createKeySequence = function(spec,
59 for (var i = 0; i < num; i++) {
60 sequence.push(i18n.input.chrome.inputview.layouts.util.createKey(spec));
67 * Creates a soft key view.
69 * @param {!Object} spec The specification.
70 * @param {string=} opt_id The id.
71 * @return {!Object} The soft key view.
73 i18n.input.chrome.inputview.layouts.util.createKey = function(spec, opt_id) {
74 var id = i18n.input.chrome.inputview.layouts.util.keyIdPrefix +
75 i18n.input.chrome.inputview.layouts.util.keyId_++;
76 return i18n.input.chrome.inputview.layouts.util.createElem(
77 ElementType.SOFT_KEY_VIEW, spec, id);
82 * Creates a linear layout.
84 * @param {!Object} spec The specification.
85 * @param {string=} opt_id The id.
86 * @return {!Object} The linear layout.
88 i18n.input.chrome.inputview.layouts.util.createLinearLayout = function(spec,
90 return i18n.input.chrome.inputview.layouts.util.createElem(
91 ElementType.LINEAR_LAYOUT, spec, opt_id, spec['iconCssClass']);
96 * Creates an extended layout.
98 * @param {!Object} spec The specification.
99 * @param {string=} opt_id The id.
100 * @return {!Object} The extended layout.
102 i18n.input.chrome.inputview.layouts.util.createExtendedLayout = function(spec,
104 return i18n.input.chrome.inputview.layouts.util.createElem(
105 ElementType.EXTENDED_LAYOUT, spec, opt_id, spec['iconCssClass']);
110 * Creates a handwriting layout.
112 * @param {!Object} spec The specification.
113 * @param {string=} opt_id The id.
114 * @return {!Object} The handwriting layout.
116 i18n.input.chrome.inputview.layouts.util.createHandwritingLayout =
117 function(spec, opt_id) {
118 return i18n.input.chrome.inputview.layouts.util.createElem(
119 ElementType.HANDWRITING_LAYOUT, spec, opt_id);
124 * Creates a vertical layout.
126 * @param {!Object} spec The specification.
127 * @param {string=} opt_id The id.
128 * @return {!Object} The vertical layout.
130 i18n.input.chrome.inputview.layouts.util.createVerticalLayout = function(spec,
132 return i18n.input.chrome.inputview.layouts.util.createElem(
133 ElementType.VERTICAL_LAYOUT, spec, opt_id);
138 * Creates a layout view.
140 * @param {!Object} spec The specification.
141 * @param {string=} opt_id The id.
142 * @return {!Object} The view.
144 i18n.input.chrome.inputview.layouts.util.createLayoutView = function(spec,
146 return i18n.input.chrome.inputview.layouts.util.createElem(
147 ElementType.LAYOUT_VIEW, spec, opt_id);
152 * Creates a candidate view.
154 * @param {!Object} spec The specification.
155 * @param {string=} opt_id The id.
156 * @return {!Object} The view.
158 i18n.input.chrome.inputview.layouts.util.createCandidateView = function(spec,
160 return i18n.input.chrome.inputview.layouts.util.createElem(
161 ElementType.CANDIDATE_VIEW, spec, opt_id);
166 * Creates a canvas view.
168 * @param {!Object} spec The specification.
169 * @param {string=} opt_id The id.
170 * @return {!Object} The view.
172 i18n.input.chrome.inputview.layouts.util.createCanvasView = function(spec,
174 return i18n.input.chrome.inputview.layouts.util.createElem(
175 ElementType.CANVAS_VIEW, spec, opt_id);
180 * Creates the keyboard.
182 * @param {Object} spec The specification.
183 * @param {string=} opt_id The id.
184 * @return {Object} The keyboard.
186 i18n.input.chrome.inputview.layouts.util.createKeyboard = function(spec,
188 return i18n.input.chrome.inputview.layouts.util.createElem(
189 ElementType.KEYBOARD, spec, opt_id);
194 * Creates an element which could be any type, such as soft key view, layout,
197 * @param {!ElementType} type The type.
198 * @param {Object} spec The specification.
199 * @param {string=} opt_id The id.
200 * @param {i18n.input.chrome.inputview.Css=} opt_iconCssClass The Css class.
201 * @return {!Object} The element.
203 i18n.input.chrome.inputview.layouts.util.createElem = function(type, spec,
204 opt_id, opt_iconCssClass) {
206 for (var key in spec) {
207 newSpec[key] = spec[key];
209 newSpec['type'] = type;
211 newSpec['id'] = opt_id;
213 if (opt_iconCssClass) {
214 newSpec['iconCssClass'] = opt_iconCssClass;