OLD | NEW |
1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. | 1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. |
2 // limitations under the License. | 2 // limitations under the License. |
3 // See the License for the specific language governing permissions and | 3 // See the License for the specific language governing permissions and |
4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
5 // distributed under the License is distributed on an "AS-IS" BASIS, | 5 // distributed under the License is distributed on an "AS-IS" BASIS, |
6 // Unless required by applicable law or agreed to in writing, software | 6 // Unless required by applicable law or agreed to in writing, software |
7 // | 7 // |
8 // http://www.apache.org/licenses/LICENSE-2.0 | 8 // http://www.apache.org/licenses/LICENSE-2.0 |
9 // | 9 // |
10 // You may obtain a copy of the License at | 10 // You may obtain a copy of the License at |
11 // you may not use this file except in compliance with the License. | 11 // you may not use this file except in compliance with the License. |
12 // Licensed under the Apache License, Version 2.0 (the "License"); | 12 // Licensed under the Apache License, Version 2.0 (the "License"); |
13 // | 13 // |
14 goog.provide('i18n.input.chrome.inputview.layouts.util'); | 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'); | 15 goog.require('i18n.input.chrome.inputview.elements.ElementType'); |
17 | 16 |
18 | 17 |
19 | 18 |
20 goog.scope(function() { | 19 goog.scope(function() { |
21 var ElementType = i18n.input.chrome.inputview.elements.ElementType; | 20 var ElementType = i18n.input.chrome.inputview.elements.ElementType; |
| 21 var util = i18n.input.chrome.inputview.layouts.util; |
22 | 22 |
23 | 23 |
24 /** | 24 /** |
25 * The id for the key. | 25 * The id for the key. |
26 * | 26 * |
27 * @type {number} | 27 * @type {number} |
28 * @private | 28 * @private |
29 */ | 29 */ |
30 i18n.input.chrome.inputview.layouts.util.keyId_ = 0; | 30 util.keyId_ = 0; |
31 | 31 |
32 | 32 |
33 /** | 33 /** |
34 * The prefix of the key id, it's overwritten by layout file. | 34 * The prefix of the key id, it's overwritten by layout file. |
35 * | 35 * |
36 * @type {string} | 36 * @type {string} |
37 */ | 37 */ |
38 i18n.input.chrome.inputview.layouts.util.keyIdPrefix = ''; | 38 util.keyIdPrefix = ''; |
| 39 |
39 | 40 |
40 /** | 41 /** |
41 * Resets id counter for keys in preparation for processing a new layout. | 42 * Resets id counter for keys in preparation for processing a new layout. |
42 * @param {string} prefix The prefix for the key id. | 43 * @param {string} prefix The prefix for the key id. |
43 */ | 44 */ |
44 i18n.input.chrome.inputview.layouts.util.setPrefix = function(prefix) { | 45 util.setPrefix = function(prefix) { |
45 i18n.input.chrome.inputview.layouts.util.keyIdPrefix = prefix; | 46 util.keyIdPrefix = prefix; |
46 i18n.input.chrome.inputview.layouts.util.keyId_ = 0; | 47 util.keyId_ = 0; |
47 }; | 48 }; |
48 | 49 |
| 50 |
49 /** | 51 /** |
50 * Creates a sequence of key with the same specification. | 52 * Creates a sequence of key with the same specification. |
51 * | 53 * |
52 * @param {!Object} spec The specification. | 54 * @param {!Object} spec The specification. |
53 * @param {number} num How many keys. | 55 * @param {number} num How many keys. |
54 * @return {!Array.<Object>} The keys. | 56 * @return {!Array.<Object>} The keys. |
55 */ | 57 */ |
56 i18n.input.chrome.inputview.layouts.util.createKeySequence = function(spec, | 58 util.createKeySequence = function(spec, |
57 num) { | 59 num) { |
58 var sequence = []; | 60 var sequence = []; |
59 for (var i = 0; i < num; i++) { | 61 for (var i = 0; i < num; i++) { |
60 sequence.push(i18n.input.chrome.inputview.layouts.util.createKey(spec)); | 62 sequence.push(util.createKey(spec)); |
61 } | 63 } |
62 return sequence; | 64 return sequence; |
63 }; | 65 }; |
64 | 66 |
65 | 67 |
66 /** | 68 /** |
67 * Creates a soft key view. | 69 * Creates a soft key view. |
68 * | 70 * |
69 * @param {!Object} spec The specification. | 71 * @param {!Object} spec The specification. |
70 * @param {string=} opt_id The id. | 72 * @param {string=} opt_id The id. |
71 * @return {!Object} The soft key view. | 73 * @return {!Object} The soft key view. |
72 */ | 74 */ |
73 i18n.input.chrome.inputview.layouts.util.createKey = function(spec, opt_id) { | 75 util.createKey = function(spec, opt_id) { |
74 var id = i18n.input.chrome.inputview.layouts.util.keyIdPrefix + | 76 var id = util.keyIdPrefix + |
75 i18n.input.chrome.inputview.layouts.util.keyId_++; | 77 util.keyId_++; |
76 return i18n.input.chrome.inputview.layouts.util.createElem( | 78 return util.createElem( |
77 ElementType.SOFT_KEY_VIEW, spec, id); | 79 ElementType.SOFT_KEY_VIEW, spec, id); |
78 }; | 80 }; |
79 | 81 |
80 | 82 |
81 /** | 83 /** |
82 * Creates a linear layout. | 84 * Creates a linear layout. |
83 * | 85 * |
84 * @param {!Object} spec The specification. | 86 * @param {!Object} spec The specification. |
85 * @param {string=} opt_id The id. | 87 * @param {string=} opt_id The id. |
86 * @return {!Object} The linear layout. | 88 * @return {!Object} The linear layout. |
87 */ | 89 */ |
88 i18n.input.chrome.inputview.layouts.util.createLinearLayout = function(spec, | 90 util.createLinearLayout = function(spec, |
89 opt_id) { | 91 opt_id) { |
90 return i18n.input.chrome.inputview.layouts.util.createElem( | 92 return util.createElem( |
91 ElementType.LINEAR_LAYOUT, spec, opt_id, spec['iconCssClass']); | 93 ElementType.LINEAR_LAYOUT, spec, opt_id, spec['iconCssClass']); |
92 }; | 94 }; |
93 | 95 |
94 | 96 |
95 /** | 97 /** |
96 * Creates an extended layout. | 98 * Creates an extended layout. |
97 * | 99 * |
98 * @param {!Object} spec The specification. | 100 * @param {!Object} spec The specification. |
99 * @param {string=} opt_id The id. | 101 * @param {string=} opt_id The id. |
100 * @return {!Object} The extended layout. | 102 * @return {!Object} The extended layout. |
101 */ | 103 */ |
102 i18n.input.chrome.inputview.layouts.util.createExtendedLayout = function(spec, | 104 util.createExtendedLayout = function(spec, |
103 opt_id) { | 105 opt_id) { |
104 return i18n.input.chrome.inputview.layouts.util.createElem( | 106 return util.createElem( |
105 ElementType.EXTENDED_LAYOUT, spec, opt_id, spec['iconCssClass']); | 107 ElementType.EXTENDED_LAYOUT, spec, opt_id, spec['iconCssClass']); |
106 }; | 108 }; |
107 | 109 |
108 | 110 |
109 /** | 111 /** |
110 * Creates a handwriting layout. | 112 * Creates a handwriting layout. |
111 * | 113 * |
112 * @param {!Object} spec The specification. | 114 * @param {!Object} spec The specification. |
113 * @param {string=} opt_id The id. | 115 * @param {string=} opt_id The id. |
114 * @return {!Object} The handwriting layout. | 116 * @return {!Object} The handwriting layout. |
115 */ | 117 */ |
116 i18n.input.chrome.inputview.layouts.util.createHandwritingLayout = | 118 util.createHandwritingLayout = |
117 function(spec, opt_id) { | 119 function(spec, opt_id) { |
118 return i18n.input.chrome.inputview.layouts.util.createElem( | 120 return util.createElem( |
119 ElementType.HANDWRITING_LAYOUT, spec, opt_id); | 121 ElementType.HANDWRITING_LAYOUT, spec, opt_id); |
120 }; | 122 }; |
121 | 123 |
122 | 124 |
123 /** | 125 /** |
124 * Creates a vertical layout. | 126 * Creates a vertical layout. |
125 * | 127 * |
126 * @param {!Object} spec The specification. | 128 * @param {!Object} spec The specification. |
127 * @param {string=} opt_id The id. | 129 * @param {string=} opt_id The id. |
128 * @return {!Object} The vertical layout. | 130 * @return {!Object} The vertical layout. |
129 */ | 131 */ |
130 i18n.input.chrome.inputview.layouts.util.createVerticalLayout = function(spec, | 132 util.createVerticalLayout = function(spec, |
131 opt_id) { | 133 opt_id) { |
132 return i18n.input.chrome.inputview.layouts.util.createElem( | 134 return util.createElem( |
133 ElementType.VERTICAL_LAYOUT, spec, opt_id); | 135 ElementType.VERTICAL_LAYOUT, spec, opt_id); |
134 }; | 136 }; |
135 | 137 |
136 | 138 |
137 /** | 139 /** |
138 * Creates a layout view. | 140 * Creates a layout view. |
139 * | 141 * |
140 * @param {!Object} spec The specification. | 142 * @param {!Object} spec The specification. |
141 * @param {string=} opt_id The id. | 143 * @param {string=} opt_id The id. |
142 * @return {!Object} The view. | 144 * @return {!Object} The view. |
143 */ | 145 */ |
144 i18n.input.chrome.inputview.layouts.util.createLayoutView = function(spec, | 146 util.createLayoutView = function(spec, |
145 opt_id) { | 147 opt_id) { |
146 return i18n.input.chrome.inputview.layouts.util.createElem( | 148 return util.createElem( |
147 ElementType.LAYOUT_VIEW, spec, opt_id); | 149 ElementType.LAYOUT_VIEW, spec, opt_id); |
148 }; | 150 }; |
149 | 151 |
150 | 152 |
151 /** | 153 /** |
152 * Creates a candidate view. | 154 * Creates a candidate view. |
153 * | 155 * |
154 * @param {!Object} spec The specification. | 156 * @param {!Object} spec The specification. |
155 * @param {string=} opt_id The id. | 157 * @param {string=} opt_id The id. |
156 * @return {!Object} The view. | 158 * @return {!Object} The view. |
157 */ | 159 */ |
158 i18n.input.chrome.inputview.layouts.util.createCandidateView = function(spec, | 160 util.createCandidateView = function(spec, |
159 opt_id) { | 161 opt_id) { |
160 return i18n.input.chrome.inputview.layouts.util.createElem( | 162 return util.createElem( |
161 ElementType.CANDIDATE_VIEW, spec, opt_id); | 163 ElementType.CANDIDATE_VIEW, spec, opt_id); |
162 }; | 164 }; |
163 | 165 |
164 | 166 |
165 /** | 167 /** |
166 * Creates a canvas view. | 168 * Creates a canvas view. |
167 * | 169 * |
168 * @param {!Object} spec The specification. | 170 * @param {!Object} spec The specification. |
169 * @param {string=} opt_id The id. | 171 * @param {string=} opt_id The id. |
170 * @return {!Object} The view. | 172 * @return {!Object} The view. |
171 */ | 173 */ |
172 i18n.input.chrome.inputview.layouts.util.createCanvasView = function(spec, | 174 util.createCanvasView = function(spec, |
173 opt_id) { | 175 opt_id) { |
174 return i18n.input.chrome.inputview.layouts.util.createElem( | 176 return util.createElem( |
175 ElementType.CANVAS_VIEW, spec, opt_id); | 177 ElementType.CANVAS_VIEW, spec, opt_id); |
176 }; | 178 }; |
177 | 179 |
178 | 180 |
179 /** | 181 /** |
180 * Creates the keyboard. | 182 * Creates the keyboard. |
181 * | 183 * |
182 * @param {Object} spec The specification. | 184 * @param {Object} spec The specification. |
183 * @param {string=} opt_id The id. | 185 * @param {string=} opt_id The id. |
184 * @return {Object} The keyboard. | 186 * @return {Object} The keyboard. |
185 */ | 187 */ |
186 i18n.input.chrome.inputview.layouts.util.createKeyboard = function(spec, | 188 util.createKeyboard = function(spec, |
187 opt_id) { | 189 opt_id) { |
188 return i18n.input.chrome.inputview.layouts.util.createElem( | 190 return util.createElem( |
189 ElementType.KEYBOARD, spec, opt_id); | 191 ElementType.KEYBOARD, spec, opt_id); |
190 }; | 192 }; |
191 | 193 |
192 | 194 |
193 /** | 195 /** |
194 * Creates an element which could be any type, such as soft key view, layout, | 196 * Creates an element which could be any type, such as soft key view, layout, |
195 * etc. | 197 * etc. |
196 * | 198 * |
197 * @param {!ElementType} type The type. | 199 * @param {!ElementType} type The type. |
198 * @param {Object} spec The specification. | 200 * @param {Object} spec The specification. |
199 * @param {string=} opt_id The id. | 201 * @param {string=} opt_id The id. |
200 * @param {i18n.input.chrome.inputview.Css=} opt_iconCssClass The Css class. | 202 * @param {string=} opt_iconCssClass The Css class. |
201 * @return {!Object} The element. | 203 * @return {!Object} The element. |
202 */ | 204 */ |
203 i18n.input.chrome.inputview.layouts.util.createElem = function(type, spec, | 205 util.createElem = function(type, spec, |
204 opt_id, opt_iconCssClass) { | 206 opt_id, opt_iconCssClass) { |
205 var newSpec = {}; | 207 var newSpec = {}; |
206 for (var key in spec) { | 208 for (var key in spec) { |
207 newSpec[key] = spec[key]; | 209 newSpec[key] = spec[key]; |
208 } | 210 } |
209 newSpec['type'] = type; | 211 newSpec['type'] = type; |
210 if (opt_id) { | 212 if (opt_id) { |
211 newSpec['id'] = opt_id; | 213 newSpec['id'] = opt_id; |
212 } | 214 } |
213 if (opt_iconCssClass) { | 215 if (opt_iconCssClass) { |
214 newSpec['iconCssClass'] = opt_iconCssClass; | 216 newSpec['iconCssClass'] = opt_iconCssClass; |
215 } | 217 } |
216 return { | 218 return { |
217 'spec': newSpec | 219 'spec': newSpec |
218 }; | 220 }; |
219 }; | 221 }; |
220 | 222 |
221 }); // goog.scope | 223 }); // goog.scope |
OLD | NEW |