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.handler.Util'); | 14 goog.provide('i18n.input.chrome.inputview.handler.Util'); |
15 | 15 |
16 goog.require('goog.dom'); | 16 goog.require('goog.dom'); |
17 | 17 goog.require('goog.events.EventType'); |
18 | 18 |
19 goog.scope(function() { | 19 goog.scope(function() { |
20 var Util = i18n.input.chrome.inputview.handler.Util; | 20 var Util = i18n.input.chrome.inputview.handler.Util; |
21 | 21 |
22 | 22 |
| 23 /** |
| 24 * The mouse event identifier. |
| 25 * |
| 26 * @type {number} |
| 27 */ |
| 28 Util.MOUSE_EVENT_IDENTIFIER = -1; |
| 29 |
| 30 |
| 31 /** |
| 32 * Represents invalid event identifier. |
| 33 * |
| 34 * @type {number} |
| 35 */ |
| 36 Util.INVALID_EVENT_IDENTIFIER = -2; |
| 37 |
23 | 38 |
24 /** | 39 /** |
25 * Gets the view. | 40 * Gets the view. |
26 * | 41 * |
27 * @param {Node} target . | 42 * @param {Node} target . |
28 * @return {i18n.input.chrome.inputview.elements.Element} . | 43 * @return {i18n.input.chrome.inputview.elements.Element} . |
29 */ | 44 */ |
30 Util.getView = function(target) { | 45 Util.getView = function(target) { |
31 if (!target) { | 46 if (!target) { |
32 return null; | 47 return null; |
33 } | 48 } |
34 var element = /** @type {!Element} */ (target); | 49 var element = /** @type {!Element} */ (target); |
35 var view = element['view']; | 50 var view = element['view']; |
36 while (!view && element) { | 51 while (!view && element) { |
37 view = element['view']; | 52 view = element['view']; |
38 element = goog.dom.getParentElement(element); | 53 element = goog.dom.getParentElement(element); |
39 } | 54 } |
40 return view; | 55 return view; |
41 }; | 56 }; |
42 | 57 |
| 58 |
| 59 /** |
| 60 * Gets the identifier from |e|. If |e| is a MouseEvent, returns -1. |
| 61 * |
| 62 * @param {!Event|!Touch|!goog.events.BrowserEvent} e The event. |
| 63 * @return {number} . |
| 64 * |
| 65 */ |
| 66 Util.getEventIdentifier = function(e) { |
| 67 var nativeEvt = e.getBrowserEvent ? e.getBrowserEvent() : e; |
| 68 if (nativeEvt.changedTouches) { |
| 69 if (e.type == goog.events.EventType.TOUCHMOVE) { |
| 70 console.error('TouchMove is not expected.'); |
| 71 } |
| 72 // TouchStart and TouchEnd should only contains one Touch in changedTouches. |
| 73 // The spec didn't have this restriction but it is safe to assume it in |
| 74 // Chrome. |
| 75 nativeEvt = nativeEvt.changedTouches[0]; |
| 76 } |
| 77 return nativeEvt.identifier === undefined ? |
| 78 Util.MOUSE_EVENT_IDENTIFIER : nativeEvt.identifier; |
| 79 }; |
| 80 |
| 81 |
43 }); // goog.scope | 82 }); // goog.scope |
OLD | NEW |