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
8 // http://www.apache.org/licenses/LICENSE-2.0
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");
14 goog
.provide('i18n.input.chrome.inputview.handler.Util');
16 goog
.require('goog.dom');
17 goog
.require('goog.events.EventType');
19 goog
.scope(function() {
20 var Util
= i18n
.input
.chrome
.inputview
.handler
.Util
;
24 * The mouse event identifier.
28 Util
.MOUSE_EVENT_IDENTIFIER
= -1;
32 * Represents invalid event identifier.
36 Util
.INVALID_EVENT_IDENTIFIER
= -2;
42 * @param {Node} target .
43 * @return {i18n.input.chrome.inputview.elements.Element} .
45 Util
.getView = function(target
) {
49 var element
= /** @type {!Element} */ (target
);
50 var view
= element
['view'];
51 while (!view
&& element
) {
52 view
= element
['view'];
53 element
= goog
.dom
.getParentElement(element
);
60 * Gets the identifier from |e|. If |e| is a MouseEvent, returns -1.
62 * @param {!Event|!Touch|!goog.events.BrowserEvent} e The event.
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.');
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
75 nativeEvt
= nativeEvt
.changedTouches
[0];
77 return nativeEvt
.identifier
=== undefined ?
78 Util
.MOUSE_EVENT_IDENTIFIER
: nativeEvt
.identifier
;