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

Side by Side Diff: third_party/google_input_tools/src/chrome/os/inputview/util.js

Issue 1576613002: Update Google Input Tools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing APIs, remove bade dependencies. Created 4 years, 10 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 unified diff | Download patch
OLDNEW
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
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 '\u0327' : '\u00B8', 45 '\u0327' : '\u00B8',
46 '\u0328' : '\u02DB', 46 '\u0328' : '\u02DB',
47 '\u0345' : '\u037A', 47 '\u0345' : '\u037A',
48 '\u030F' : '\u030F\u0020', 48 '\u030F' : '\u030F\u0020',
49 '\u031B' : '\u031B\u0020', 49 '\u031B' : '\u031B\u0020',
50 '\u0323' : '\u0323\u0020' 50 '\u0323' : '\u0323\u0020'
51 }; 51 };
52 52
53 53
54 /** 54 /**
55 * Special lower to upper case mapping.
56 *
57 * @private {!Object.<string, string>}
58 */
59 util.CASE_LOWER_TO_UPPER_MAPPING_ = {
60 '\u00b5': '\u00b5',
61 // Korean characters.
62 '\u3142': '\u3143',
63 '\u3148': '\u3149',
64 '\u3137': '\u3138',
65 '\u3131': '\u3132',
66 '\u3145': '\u3146',
67 '\u1162': '\u1164',
68 '\u1166': '\u1168'
69 };
70
71
72 /**
73 * Special upper to lower case mapping.
74 *
75 * @private {!Object.<string, string>}
76 */
77 util.CASE_UPPER_TO_LOWER_MAPPING_ = {
78 '\u0049': '\u0131'
79 };
80
81
82 /**
55 * The keysets using US keyboard layouts. 83 * The keysets using US keyboard layouts.
56 * 84 *
57 * @type {!Array.<string>} 85 * @type {!Array.<string>}
58 */ 86 */
59 util.KEYSETS_USE_US = [ 87 util.KEYSETS_USE_US = [
60 'array', 88 'array',
61 'cangjie', 89 'cangjie',
62 'dayi', 90 'dayi',
63 'jp_us', 91 'jp_us',
64 'pinyin-zh-CN', 92 'pinyin-zh-CN',
65 'pinyin-zh-TW', 93 'pinyin-zh-TW',
66 'quick', 94 'quick',
67 't13n', 95 't13n',
68 'wubi' 96 'wubi',
97 'zhuyin.us',
98 'ko.set2.us',
99 'ko.set390.us',
100 'ko.set3final.us',
101 'ko.set3sun.us',
102 'ko.romaja.us',
103 'ko.ahn.us',
104 'ko.set2y.us',
105 'ko.set3yet.us',
106 'ko.set32.us'
69 ]; 107 ];
70 108
71 109
72 /** 110 /**
73 * The keysets that have en switcher key. 111 * The keysets that have en switcher key.
74 * 112 *
75 * @type {!Array.<string>} 113 * @type {!Array.<string>}
76 */ 114 */
77 util.KEYSETS_HAVE_EN_SWTICHER = [ 115 util.KEYSETS_HAVE_EN_SWTICHER = [
78 // When other keysets that use us add the enswitcher key, 116 // When other keysets that use us add the enswitcher key,
79 // should move them to this array. 117 // should move them to this array.
80 'array', 118 'array',
81 'cangjie', 119 'cangjie',
82 'dayi', 120 'dayi',
83 'pinyin-zh-CN', 121 'pinyin-zh-CN',
84 'pinyin-zh-TW', 122 'pinyin-zh-TW',
85 'quick', 123 'quick',
86 'wubi', 124 'wubi',
87 'zhuyin' 125 'zhuyin',
126 'zhuyin.us'
88 ]; 127 ];
89 128
90 129
130 /**
131 * The keysets that can switch with US keyboard layouts.
132 *
133 * @type {!Array.<string>}
134 */
135 util.KEYSETS_SWITCH_WITH_US = [
136 'zhuyin',
137 'ko.set2',
138 'ko.set390',
139 'ko.set3final',
140 'ko.set3sun',
141 'ko.romaja',
142 'ko.ahn',
143 'ko.set2y',
144 'ko.set3yet',
145 'ko.set32'
146 ];
147
148
91 /** 149 /**
92 * The keysets that have compact keyset. 150 * The keysets that have compact keyset.
93 * 151 *
94 * @type {!Array.<string>} 152 * @type {!Array.<string>}
95 */ 153 */
96 util.KEYSETS_HAVE_COMPACT = [ 154 util.KEYSETS_HAVE_COMPACT = [
97 'ca', 155 'ca',
98 'ca-eng', 156 'ca-eng',
99 'de', 157 'de',
100 'dk', 158 'dk',
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 }; 265 };
208 266
209 267
210 /** 268 /**
211 * To upper case. 269 * To upper case.
212 * 270 *
213 * @param {string} character The character. 271 * @param {string} character The character.
214 * @return {string} The uppercase of the character. 272 * @return {string} The uppercase of the character.
215 */ 273 */
216 util.toUpper = function(character) { 274 util.toUpper = function(character) {
217 if (character == '\u00b5') { 275 var upper = util.CASE_LOWER_TO_UPPER_MAPPING_[character];
218 return '\u00b5'; 276 if (upper) {
219 } else { 277 return upper;
220 return character.toUpperCase();
221 } 278 }
279 return character.toUpperCase();
222 }; 280 };
223 281
224 282
225 /** 283 /**
226 * To lower case. 284 * To lower case.
227 * 285 *
228 * @param {string} character The character. 286 * @param {string} character The character.
229 * @return {string} The lower case of the character. 287 * @return {string} The lower case of the character.
230 */ 288 */
231 util.toLower = function(character) { 289 util.toLower = function(character) {
232 if (character == '\u0049') { 290 var lower = util.CASE_UPPER_TO_LOWER_MAPPING_[character];
233 return '\u0131'; 291 if (lower) {
292 return lower;
234 } 293 }
235 return character.toLowerCase(); 294 return character.toLowerCase();
236 }; 295 };
237 296
238 297
239 /** 298 /**
240 * Is this character trigger commit. 299 * Is this character trigger commit.
241 * 300 *
242 * @param {string} character The character. 301 * @param {string} character The character.
243 * @return {boolean} True to trigger commit. 302 * @return {boolean} True to trigger commit.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 /** 379 /**
321 * Returns the configuration file name from the keyboard code. 380 * Returns the configuration file name from the keyboard code.
322 * 381 *
323 * @param {string} keyboardCode The keyboard code. 382 * @param {string} keyboardCode The keyboard code.
324 * @return {string} The config file name which contains the keyset. 383 * @return {string} The config file name which contains the keyset.
325 */ 384 */
326 util.getConfigName = function(keyboardCode) { 385 util.getConfigName = function(keyboardCode) {
327 // Strips out all the suffixes in the keyboard code. 386 // Strips out all the suffixes in the keyboard code.
328 return keyboardCode.replace(/\..*$/, ''); 387 return keyboardCode.replace(/\..*$/, '');
329 }; 388 };
330
331
332 /**
333 * Checks that the word is a valid delete from the old to new context.
334 *
335 * @param {string} oldContext The old context.
336 * @param {string} newContext The new context.
337 * @param {string} deletionCandidate A possible word deletion.
338 *
339 * @return {boolean} Whether the deletion was valid.
340 */
341 util.isPossibleDelete = function(
342 oldContext, newContext, deletionCandidate) {
343 // Check that deletionCandidate exists in oldContext. We don't check if it's a
344 // tail since our heuristic may have trimmed whitespace.
345 var rootEnd = oldContext.lastIndexOf(deletionCandidate);
346 if (rootEnd != -1) {
347 // Check that remaining text in root persisted in newContext.
348 var root = oldContext.slice(0, rootEnd);
349 return root == newContext.slice(-rootEnd);
350 }
351 return false;
352 };
353
354
355 /**
356 * Checks whether a letter deletion would cause the observed context transform.
357 *
358 * @param {string} oldContext The old context.
359 * @param {string} newContext The new context.
360 *
361 * @return {boolean} Whether the transform is valid.
362 */
363 util.isLetterDelete = function(oldContext, newContext) {
364 if (oldContext == '') {
365 return false;
366 }
367 // Handle buffer overflow.
368 if (oldContext.length == newContext.length) {
369 return util.isLetterDelete(oldContext, newContext.slice(1));
370 }
371 return oldContext.length == newContext.length + 1 &&
372 oldContext.indexOf(newContext) == 0;
373 };
374
375
376 /**
377 * Checks whether a letter restoration would cause the observed context
378 * transform.
379 *
380 * @param {string} oldContext The old context.
381 * @param {string} newContext The new context.
382 *
383 * @return {boolean} Whether the transform is valid.
384 */
385 util.isLetterRestore = function(oldContext, newContext) {
386 return util.isLetterDelete(newContext, oldContext);
387 };
388
389 }); // goog.scope 389 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698