OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview A handwriting virtual keyboard implementation. | 6 * @fileoverview A handwriting virtual keyboard implementation. |
7 */ | 7 */ |
8 | 8 |
9 /** | 9 /** |
10 * Const variables | 10 * Const variables |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 }; | 89 }; |
90 canvas.ontouchmove = canvas.onmousemove; | 90 canvas.ontouchmove = canvas.onmousemove; |
91 | 91 |
92 canvas.onmouseup = function(e) { | 92 canvas.onmouseup = function(e) { |
93 var coords = canvas.getEventCoordinates(e); | 93 var coords = canvas.getEventCoordinates(e); |
94 if (canvas.stroke_.length > 0) { | 94 if (canvas.stroke_.length > 0) { |
95 context.lineTo(coords.x, coords.y); | 95 context.lineTo(coords.x, coords.y); |
96 context.stroke(); | 96 context.stroke(); |
97 canvas.addStroke(coords.x, coords.y); | 97 canvas.addStroke(coords.x, coords.y); |
98 if (chrome.experimental) { | 98 if (chrome.experimental) { |
99 chrome.experimental.input.sendHandwritingStroke(canvas.stroke_); | 99 chrome.experimental.input.virtualKeyboard.sendHandwritingStroke( |
| 100 canvas.stroke_); |
100 } | 101 } |
101 canvas.stroke_ = []; | 102 canvas.stroke_ = []; |
102 } | 103 } |
103 }; | 104 }; |
104 canvas.onmouseout = canvas.onmouseup; | 105 canvas.onmouseout = canvas.onmouseup; |
105 | 106 |
106 canvas.ontouchstart = canvas.onmousedown; | 107 canvas.ontouchstart = canvas.onmousedown; |
107 canvas.ontouchenter = canvas.onmousedown; | 108 canvas.ontouchenter = canvas.onmousedown; |
108 canvas.ontouchend = canvas.onmouseup; | 109 canvas.ontouchend = canvas.onmouseup; |
109 canvas.ontouchleave = canvas.onmouseup; | 110 canvas.ontouchleave = canvas.onmouseup; |
110 canvas.ontouchcancel = canvas.onmouseup; | 111 canvas.ontouchcancel = canvas.onmouseup; |
111 | 112 |
112 // Clear the canvas when an IME hides the lookup table. | 113 // Clear the canvas when an IME hides the lookup table. |
113 if (chrome.experimental && chrome.experimental.inputUI) { | 114 if (chrome.experimental && chrome.experimental.input.ui) { |
114 chrome.experimental.inputUI.onUpdateLookupTable.addListener( | 115 chrome.experimental.input.ui.onUpdateLookupTable.addListener( |
115 function(table) { | 116 function(table) { |
116 if (!table.visible) { | 117 if (!table.visible) { |
117 canvas.clear(); | 118 canvas.clear(); |
118 } | 119 } |
119 }); | 120 }); |
120 } | 121 } |
121 return canvas; | 122 return canvas; |
122 }, | 123 }, |
123 | 124 |
124 /** | 125 /** |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 }, | 180 }, |
180 | 181 |
181 /** | 182 /** |
182 * Clears the canvas. | 183 * Clears the canvas. |
183 * @return {void} | 184 * @return {void} |
184 */ | 185 */ |
185 clear: function() { | 186 clear: function() { |
186 var context = this.getContext('2d'); | 187 var context = this.getContext('2d'); |
187 context.clearRect(0, 0, this.width, this.height); | 188 context.clearRect(0, 0, this.width, this.height); |
188 if (chrome.experimental) { | 189 if (chrome.experimental) { |
189 chrome.experimental.input.cancelHandwritingStrokes(); | 190 chrome.experimental.input.virtualKeyboard.cancelHandwritingStrokes(); |
190 } | 191 } |
191 }, | 192 }, |
192 | 193 |
193 /** | 194 /** |
194 * Set the visibility of the canvas. | 195 * Set the visibility of the canvas. |
195 * @param {boolean} visible True if the canvas should be visible. | 196 * @param {boolean} visible True if the canvas should be visible. |
196 * @return {void} | 197 * @return {void} |
197 */ | 198 */ |
198 set visible(visible) { | 199 set visible(visible) { |
199 this.hidden = !visible; | 200 this.hidden = !visible; |
(...skipping 23 matching lines...) Expand all Loading... |
223 ]; | 224 ]; |
224 | 225 |
225 // Add the layout to KEYBOARDS, which is defined in common.js | 226 // Add the layout to KEYBOARDS, which is defined in common.js |
226 KEYBOARDS['handwriting-vk'] = { | 227 KEYBOARDS['handwriting-vk'] = { |
227 'definition': KEYS_HANDWRITING_VK, | 228 'definition': KEYS_HANDWRITING_VK, |
228 'aspect': 2.1, | 229 'aspect': 2.1, |
229 // TODO(yusukes): Stop special-casing canvas when mazda's i18n keyboard | 230 // TODO(yusukes): Stop special-casing canvas when mazda's i18n keyboard |
230 // code is ready. | 231 // code is ready. |
231 'canvas': null | 232 'canvas': null |
232 }; | 233 }; |
OLD | NEW |