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

Side by Side Diff: third_party/google_input_tools/src/chrome/os/inputview/m17nmodel.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 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.M17nModel');
15
16 goog.require('goog.events.EventHandler');
17 goog.require('goog.events.EventTarget');
18 goog.require('i18n.input.chrome.inputview.SpecNodeName');
19 goog.require('i18n.input.chrome.inputview.content.util');
20 goog.require('i18n.input.chrome.vk.KeyCode');
21 goog.require('i18n.input.chrome.vk.Model');
22
23
24
25 /**
26 * The model to legacy cloud vk configuration.
27 *
28 * @constructor
29 * @extends {goog.events.EventTarget}
30 */
31 i18n.input.chrome.inputview.M17nModel = function() {
32 goog.base(this);
33
34 /**
35 * The event handler.
36 *
37 * @type {!goog.events.EventHandler}
38 * @private
39 */
40 this.handler_ = new goog.events.EventHandler(this);
41
42 /**
43 * The model for cloud vk.
44 *
45 * @type {!i18n.input.chrome.vk.Model}
46 * @private
47 */
48 this.model_ = new i18n.input.chrome.vk.Model();
49 this.handler_.listen(this.model_,
50 i18n.input.chrome.vk.EventType.LAYOUT_LOADED,
51 this.onLayoutLoaded_);
52 };
53 goog.inherits(i18n.input.chrome.inputview.M17nModel,
54 goog.events.EventTarget);
55
56
57 /**
58 * The active layout view.
59 *
60 * @type {!i18n.input.chrome.vk.ParsedLayout}
61 * @private
62 */
63 i18n.input.chrome.inputview.M17nModel.prototype.layoutView_;
64
65
66 /**
67 * Loads the configuration.
68 *
69 * @param {string} lang The m17n keyboard layout code (with 'm17n:' prefix).
70 */
71 i18n.input.chrome.inputview.M17nModel.prototype.loadConfig = function(lang) {
72 var m17nMatches = lang.match(/^m17n:(.*)/);
73 if (m17nMatches && m17nMatches[1]) {
74 this.model_.loadLayout(m17nMatches[1]);
75 }
76 };
77
78
79 /**
80 * Callback when legacy model is loaded.
81 *
82 * @param {!i18n.input.chrome.vk.LayoutEvent} e The event.
83 * @private
84 */
85 i18n.input.chrome.inputview.M17nModel.prototype.onLayoutLoaded_ = function(
86 e) {
87 var layoutView = /** @type {!i18n.input.chrome.vk.ParsedLayout} */
88 (e.layoutView);
89 this.layoutView_ = layoutView;
90 var is102 = layoutView.view.is102;
91 var codes = is102 ? i18n.input.chrome.vk.KeyCode.CODES102 :
92 i18n.input.chrome.vk.KeyCode.CODES101;
93 var keyCount = is102 ? 48 : 47;
94 var keyCharacters = [];
95 for (var i = 0; i < keyCount; i++) {
96 var characters = this.findCharacters_(layoutView.view.mappings,
97 codes[i]);
98 keyCharacters.push(characters);
99 }
100 keyCharacters.push(['\u0020', '\u0020']);
101 var hasAltGrKey = !!layoutView.view.mappings['c'] &&
102 layoutView.view.mappings['c'] != layoutView.view.mappings[''];
103 var skvPrefix = is102 ? '102kbd-k-' : '101kbd-k-';
104 var skPrefix = layoutView.view.id + '-k-';
105 var data = i18n.input.chrome.inputview.content.util.createData(keyCharacters,
106 skvPrefix, is102, hasAltGrKey);
107 if (data) {
108 data[i18n.input.chrome.inputview.SpecNodeName.TITLE] =
109 layoutView.view.title;
110 data[i18n.input.chrome.inputview.SpecNodeName.ID] =
111 'm17n:' + e.layoutCode;
112 this.dispatchEvent(new i18n.input.chrome.inputview.events.
113 ConfigLoadedEvent(data));
114 }
115 };
116
117
118 /**
119 * Finds out the characters for the key.
120 *
121 * @param {!Object} mappings The mappings.
122 * @param {string} code The code.
123 * @return {!Array.<string>} The characters for the code.
124 * @private
125 */
126 i18n.input.chrome.inputview.M17nModel.prototype.findCharacters_ = function(
127 mappings, code) {
128 var characters = [];
129 var states = [
130 '',
131 's',
132 'c',
133 'sc',
134 'l',
135 'sl',
136 'cl',
137 'scl'
138 ];
139 for (var i = 0; i < states.length; i++) {
140 if (mappings[states[i]] && mappings[states[i]][code]) {
141 characters[i] = mappings[states[i]][code][1];
142 } else if (code == '\u0020') {
143 characters[i] = '\u0020';
144 } else {
145 characters[i] = '';
146 }
147 }
148 return characters;
149 };
150
151
152 /** @override */
153 i18n.input.chrome.inputview.M17nModel.prototype.disposeInternal = function() {
154 goog.dispose(this.handler_);
155
156 goog.base(this, 'disposeInternal');
157 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698