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.Accents'); | 14 goog.provide('i18n.input.chrome.inputview.Accents'); |
15 | 15 |
16 goog.require('goog.dom'); | 16 goog.require('goog.dom'); |
17 goog.require('goog.math.Coordinate'); | 17 goog.require('goog.math.Coordinate'); |
18 goog.require('goog.style'); | 18 goog.require('goog.style'); |
| 19 goog.require('i18n.input.chrome.inputview.util'); |
19 | 20 |
20 | 21 |
21 goog.scope(function() { | 22 goog.scope(function() { |
22 var Accents = i18n.input.chrome.inputview.Accents; | 23 var Accents = i18n.input.chrome.inputview.Accents; |
23 | 24 |
24 | 25 |
25 /** | 26 /** |
26 * The highlighted element. | 27 * The highlighted element. |
27 * | 28 * |
28 * @type {Element} | 29 * @type {Element} |
29 * @private | 30 * @private |
30 */ | 31 */ |
31 Accents.highlightedItem_ = null; | 32 Accents.highlightedItem_ = null; |
32 | 33 |
33 | 34 |
34 /** | 35 /** |
35 * Gets the highlighted character. | 36 * Gets the highlighted character. |
36 * | 37 * |
37 * @return {string} The character. | 38 * @return {string} The character. |
38 * @private | 39 * @private |
39 */ | 40 */ |
40 Accents.getHighlightedAccent_ = function() { | 41 Accents.getHighlightedAccent_ = function() { |
41 return Accents.highlightedItem_ ? Accents.highlightedItem_.textContent : ''; | 42 return Accents.highlightedItem_ ? |
| 43 Accents.highlightedItem_.textContent.trim() : ''; |
42 }; | 44 }; |
43 | 45 |
44 | 46 |
45 /** | 47 /** |
46 * Highlights the item according to the current coordinate of the finger. | 48 * Highlights the item according to the current coordinate of the finger. |
47 * | 49 * |
48 * @param {number} x The x position of finger in screen coordinate system. | 50 * @param {number} x The x position of finger in screen coordinate system. |
49 * @param {number} y The y position of finger in screen coordinate system. | 51 * @param {number} y The y position of finger in screen coordinate system. |
50 * @param {number} offset The offset to cancel highlight. | 52 * @param {number} offset The offset to cancel highlight. |
51 * @private | 53 * @private |
52 */ | 54 */ |
53 Accents.highlightItem_ = function(x, y, offset) { | 55 Accents.highlightItem_ = function(x, y, offset) { |
54 var highlightedItem = Accents.getHighlightedItem_(x, y, offset); | 56 var highlightedItem = Accents.getHighlightedItem_(x, y, offset); |
55 if (Accents.highlightedItem_ != highlightedItem) { | 57 if (Accents.highlightedItem_ != highlightedItem) { |
56 if (Accents.highlightedItem_) { | 58 if (Accents.highlightedItem_) { |
57 Accents.highlightedItem_.classList.remove('highlight'); | 59 Accents.highlightedItem_.classList.remove('highlight'); |
58 } | 60 } |
59 Accents.highlightedItem_ = highlightedItem; | 61 Accents.highlightedItem_ = highlightedItem; |
60 if (Accents.highlightedItem_) { | 62 if (Accents.highlightedItem_ && |
| 63 Accents.highlightedItem_.textContent.trim()) { |
61 Accents.highlightedItem_.classList.add('highlight'); | 64 Accents.highlightedItem_.classList.add('highlight'); |
62 } | 65 } |
63 } | 66 } |
64 }; | 67 }; |
65 | 68 |
66 | 69 |
67 /** | 70 /** |
68 * Gets the higlighted item from |x| and |y| position. | 71 * Gets the higlighted item from |x| and |y| position. |
69 * @param {number} x The x position of finger in screen coordinate system. | 72 * @param {number} x The x position of finger in screen coordinate system. |
70 * @param {number} y The y position of finger in screen coordinate system. | 73 * @param {number} y The y position of finger in screen coordinate system. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 container.classList.add('accent-container'); | 126 container.classList.add('accent-container'); |
124 | 127 |
125 var orderedAccents = Accents.reorderAccents_(accents, numOfColumns, numOfRows, | 128 var orderedAccents = Accents.reorderAccents_(accents, numOfColumns, numOfRows, |
126 startKeyIndex); | 129 startKeyIndex); |
127 var row = null; | 130 var row = null; |
128 for (var i = 0; i < orderedAccents.length; i++) { | 131 for (var i = 0; i < orderedAccents.length; i++) { |
129 var keyElem = document.createElement('div'); | 132 var keyElem = document.createElement('div'); |
130 // Even if this is an empty key, we still need to add textDiv. Otherwise, | 133 // Even if this is an empty key, we still need to add textDiv. Otherwise, |
131 // the keys have layout issues. | 134 // the keys have layout issues. |
132 var textDiv = document.createElement('div'); | 135 var textDiv = document.createElement('div'); |
133 textDiv.textContent = orderedAccents[i]; | 136 textDiv.textContent = |
| 137 i18n.input.chrome.inputview.util.getVisibleCharacter( |
| 138 orderedAccents[i]); |
| 139 textDiv.style.lineHeight = height + 'px'; |
134 keyElem.appendChild(textDiv); | 140 keyElem.appendChild(textDiv); |
135 if (!orderedAccents[i]) { | 141 if (!orderedAccents[i]) { |
136 keyElem.classList.add('empty-key'); | 142 keyElem.classList.add('empty-key'); |
137 } | 143 } |
138 keyElem.style.width = width; | 144 keyElem.style.width = width + 'px'; |
139 keyElem.style.height = height; | 145 keyElem.style.height = height + 'px'; |
140 if (i % numOfColumns == 0) { | 146 if (i % numOfColumns == 0) { |
141 if (row) { | 147 if (row) { |
142 container.appendChild(row); | 148 container.appendChild(row); |
143 } | 149 } |
144 row = document.createElement('div'); | 150 row = document.createElement('div'); |
145 row.classList.add('accent-row'); | 151 row.classList.add('accent-row'); |
146 } | 152 } |
147 row.appendChild(keyElem); | 153 row.appendChild(keyElem); |
148 } | 154 } |
149 container.appendChild(row); | 155 container.appendChild(row); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 201 } |
196 | 202 |
197 return orderedAccents; | 203 return orderedAccents; |
198 }; | 204 }; |
199 | 205 |
200 goog.exportSymbol('accents.highlightedAccent', Accents.getHighlightedAccent_); | 206 goog.exportSymbol('accents.highlightedAccent', Accents.getHighlightedAccent_); |
201 goog.exportSymbol('accents.highlightItem', Accents.highlightItem_); | 207 goog.exportSymbol('accents.highlightItem', Accents.highlightItem_); |
202 goog.exportSymbol('accents.setAccents', Accents.setAccents_); | 208 goog.exportSymbol('accents.setAccents', Accents.setAccents_); |
203 | 209 |
204 }); // goog.scope | 210 }); // goog.scope |
OLD | NEW |