Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / google_input_tools / src / chrome / os / inputview / handler / util.js
blob9902944bd32f38aa69f8d47ccdd56b4390fdb95b
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
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
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;
23 /**
24 * The mouse event identifier.
26 * @type {number}
28 Util.MOUSE_EVENT_IDENTIFIER = -1;
31 /**
32 * Represents invalid event identifier.
34 * @type {number}
36 Util.INVALID_EVENT_IDENTIFIER = -2;
39 /**
40 * Gets the view.
42 * @param {Node} target .
43 * @return {i18n.input.chrome.inputview.elements.Element} .
45 Util.getView = function(target) {
46 if (!target) {
47 return null;
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);
55 return view;
59 /**
60 * Gets the identifier from |e|. If |e| is a MouseEvent, returns -1.
62 * @param {!Event|!Touch|!goog.events.BrowserEvent} e The event.
63 * @return {number} .
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
74 // Chrome.
75 nativeEvt = nativeEvt.changedTouches[0];
77 return nativeEvt.identifier === undefined ?
78 Util.MOUSE_EVENT_IDENTIFIER : nativeEvt.identifier;
82 }); // goog.scope