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.dom.TagName'); | 17 goog.require('goog.dom.TagName'); |
18 goog.require('goog.dom.classlist'); | 18 goog.require('goog.dom.classlist'); |
19 goog.require('goog.math.Coordinate'); | |
20 goog.require('goog.style'); | 19 goog.require('goog.style'); |
21 goog.require('i18n.input.chrome.inputview.Css'); | 20 goog.require('i18n.input.chrome.inputview.Css'); |
22 goog.require('i18n.input.chrome.inputview.util'); | 21 goog.require('i18n.input.chrome.inputview.util'); |
23 | 22 |
24 | 23 |
25 goog.scope(function() { | 24 goog.scope(function() { |
26 var Accents = i18n.input.chrome.inputview.Accents; | 25 var Accents = i18n.input.chrome.inputview.Accents; |
27 var Css = i18n.input.chrome.inputview.Css; | 26 var Css = i18n.input.chrome.inputview.Css; |
28 | 27 |
29 | 28 |
(...skipping 24 matching lines...) Expand all Loading... |
54 * @param {number} x The x position of finger in screen coordinate system. | 53 * @param {number} x The x position of finger in screen coordinate system. |
55 * @param {number} y The y position of finger in screen coordinate system. | 54 * @param {number} y The y position of finger in screen coordinate system. |
56 * @param {number} offset The offset to cancel highlight. | 55 * @param {number} offset The offset to cancel highlight. |
57 * @private | 56 * @private |
58 */ | 57 */ |
59 Accents.highlightItem_ = function(x, y, offset) { | 58 Accents.highlightItem_ = function(x, y, offset) { |
60 var highlightedItem = Accents.getHighlightedItem_(x, y, offset); | 59 var highlightedItem = Accents.getHighlightedItem_(x, y, offset); |
61 if (Accents.highlightedItem_ != highlightedItem) { | 60 if (Accents.highlightedItem_ != highlightedItem) { |
62 if (Accents.highlightedItem_) { | 61 if (Accents.highlightedItem_) { |
63 goog.dom.classlist.remove(Accents.highlightedItem_, | 62 goog.dom.classlist.remove(Accents.highlightedItem_, |
64 i18n.input.chrome.inputview.Css.ELEMENT_HIGHLIGHT); | 63 i18n.input.chrome.inputview.Css.ELEMENT_HIGHLIGHT); |
65 } | 64 } |
66 Accents.highlightedItem_ = highlightedItem; | 65 Accents.highlightedItem_ = highlightedItem; |
67 if (Accents.highlightedItem_ && | 66 if (Accents.highlightedItem_ && |
68 Accents.highlightedItem_.textContent.trim()) { | 67 Accents.highlightedItem_.textContent.trim()) { |
69 goog.dom.classlist.add(Accents.highlightedItem_, | 68 goog.dom.classlist.add(Accents.highlightedItem_, |
70 i18n.input.chrome.inputview.Css.ELEMENT_HIGHLIGHT); | 69 i18n.input.chrome.inputview.Css.ELEMENT_HIGHLIGHT); |
71 } | 70 } |
72 } | 71 } |
73 }; | 72 }; |
74 | 73 |
75 | 74 |
76 /** | 75 /** |
77 * Gets the higlighted item from |x| and |y| position. | 76 * Gets the higlighted item from |x| and |y| position. |
78 * @param {number} x The x position of finger in screen coordinate system. | 77 * @param {number} x The x position of finger in screen coordinate system. |
79 * @param {number} y The y position of finger in screen coordinate system. | 78 * @param {number} y The y position of finger in screen coordinate system. |
80 * @param {number} offset The offset to cancel highlight. | 79 * @param {number} offset The offset to cancel highlight. |
| 80 * @return {Element} . |
81 * @private | 81 * @private |
82 */ | 82 */ |
83 Accents.getHighlightedItem_ = function(x, y, offset) { | 83 Accents.getHighlightedItem_ = function(x, y, offset) { |
84 var dom = goog.dom.getDomHelper(); | 84 var dom = goog.dom.getDomHelper(); |
85 var row = null; | 85 var row = null; |
86 var rows = dom.getElementsByClass(i18n.input.chrome.inputview.Css.ACCENT_ROW); | 86 var rows = dom.getElementsByClass(i18n.input.chrome.inputview.Css.ACCENT_ROW); |
87 for (var i = 0; i < rows.length; i++) { | 87 for (var i = 0; i < rows.length; i++) { |
88 var coordinate = goog.style.getClientPosition(rows[i]); | 88 var coordinate = goog.style.getClientPosition(rows[i]); |
89 var size = goog.style.getSize(rows[i]); | 89 var size = goog.style.getSize(rows[i]); |
90 var screenYStart = coordinate.y + window.screenY; | 90 var screenYStart = coordinate.y + window.screenY; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 * @param {number} width The width of accent key. | 123 * @param {number} width The width of accent key. |
124 * @param {number} height The height of accent key. | 124 * @param {number} height The height of accent key. |
125 * @param {number} startKeyIndex The index of the start key in bottom row. | 125 * @param {number} startKeyIndex The index of the start key in bottom row. |
126 * @private | 126 * @private |
127 */ | 127 */ |
128 Accents.setAccents_ = function(accents, numOfColumns, numOfRows, width, | 128 Accents.setAccents_ = function(accents, numOfColumns, numOfRows, width, |
129 height, startKeyIndex) { | 129 height, startKeyIndex) { |
130 var TagName = goog.dom.TagName; | 130 var TagName = goog.dom.TagName; |
131 var dom = goog.dom.getDomHelper(); | 131 var dom = goog.dom.getDomHelper(); |
132 var container = dom.createDom(TagName.DIV, Css.ACCENT_CONTAINER); | 132 var container = dom.createDom(TagName.DIV, Css.ACCENT_CONTAINER); |
133 goog.dom.setProperties(container, { | |
134 'id' : 'container' | |
135 }); | |
136 container.id = 'container'; | 133 container.id = 'container'; |
137 | 134 |
138 var orderedAccents = Accents.reorderAccents_(accents, numOfColumns, numOfRows, | 135 var orderedAccents = Accents.reorderAccents_(accents, numOfColumns, numOfRows, |
139 startKeyIndex); | 136 startKeyIndex); |
140 var row = null; | 137 var row = null; |
141 for (var i = 0; i < orderedAccents.length; i++) { | 138 for (var i = 0; i < orderedAccents.length; i++) { |
142 var keyElem = dom.createDom(TagName.DIV, Css.ACCENT_KEY); | 139 var keyElem = dom.createDom(TagName.DIV, Css.ACCENT_KEY); |
143 // Even if this is an empty key, we still need to add textDiv. Otherwise, | 140 // Even if this is an empty key, we still need to add textDiv. Otherwise, |
144 // the keys have layout issues. | 141 // the keys have layout issues. |
145 var textDiv = dom.createElement(TagName.DIV); | 142 var textDiv = dom.createElement(TagName.DIV); |
(...skipping 26 matching lines...) Expand all Loading... |
172 /** | 169 /** |
173 * Generates the reordered accents which is optimized for creating accent key | 170 * Generates the reordered accents which is optimized for creating accent key |
174 * elements sequentially(from top to bottom, left to right). | 171 * elements sequentially(from top to bottom, left to right). |
175 * Accent in |accents| is ordered according to its frequency(more frequently | 172 * Accent in |accents| is ordered according to its frequency(more frequently |
176 * used appears first). Once reordered, the more frequently used accents will be | 173 * used appears first). Once reordered, the more frequently used accents will be |
177 * positioned closer to the parent key. See tests for example. | 174 * positioned closer to the parent key. See tests for example. |
178 * @param {!Array.<string>} accents The accents to display. | 175 * @param {!Array.<string>} accents The accents to display. |
179 * @param {!number} numOfColumns The number of colums of this accents window. | 176 * @param {!number} numOfColumns The number of colums of this accents window. |
180 * @param {!number} numOfRows The number of rows of this accents window. | 177 * @param {!number} numOfRows The number of rows of this accents window. |
181 * @param {number} startKeyIndex The index of the start key in bottom row. | 178 * @param {number} startKeyIndex The index of the start key in bottom row. |
| 179 * @return {!Array.<string>} . |
182 * @private | 180 * @private |
183 */ | 181 */ |
184 Accents.reorderAccents_ = function(accents, numOfColumns, numOfRows, | 182 Accents.reorderAccents_ = function(accents, numOfColumns, numOfRows, |
185 startKeyIndex) { | 183 startKeyIndex) { |
186 var orderedAccents = new Array(numOfColumns * numOfRows); | 184 var orderedAccents = new Array(numOfColumns * numOfRows); |
187 | 185 |
188 var index = 0; | 186 var index = 0; |
189 // Generates the order to fill keys in a row. Start with startKeyIndex, we try | 187 // Generates the order to fill keys in a row. Start with startKeyIndex, we try |
190 // to fill keys on both side(right side first) of the start key. | 188 // to fill keys on both side(right side first) of the start key. |
191 var rowOrder = new Array(numOfColumns); | 189 var rowOrder = new Array(numOfColumns); |
(...skipping 21 matching lines...) Expand all Loading... |
213 } | 211 } |
214 | 212 |
215 return orderedAccents; | 213 return orderedAccents; |
216 }; | 214 }; |
217 | 215 |
218 goog.exportSymbol('accents.highlightedAccent', Accents.getHighlightedAccent_); | 216 goog.exportSymbol('accents.highlightedAccent', Accents.getHighlightedAccent_); |
219 goog.exportSymbol('accents.highlightItem', Accents.highlightItem_); | 217 goog.exportSymbol('accents.highlightItem', Accents.highlightItem_); |
220 goog.exportSymbol('accents.setAccents', Accents.setAccents_); | 218 goog.exportSymbol('accents.setAccents', Accents.setAccents_); |
221 | 219 |
222 }); // goog.scope | 220 }); // goog.scope |
OLD | NEW |