Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: third_party/google_input_tools/src/chrome/os/inputview/handler/pointerhandler.js

Issue 674153004: Add third_party/google-input-tools: Take 2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@google_input_tools
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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");
13 //
14 goog.provide('i18n.input.chrome.inputview.handler.PointerHandler');
15
16 goog.require('goog.Timer');
17 goog.require('goog.events.EventHandler');
18 goog.require('goog.events.EventTarget');
19 goog.require('goog.events.EventType');
20 goog.require('goog.math.Coordinate');
21 goog.require('i18n.input.chrome.inputview.handler.PointerActionBundle');
22
23 goog.scope(function() {
24
25
26
27 /**
28 * The pointer controller.
29 *
30 * @param {!Element=} opt_target .
31 * @constructor
32 * @extends {goog.events.EventTarget}
33 */
34 i18n.input.chrome.inputview.handler.PointerHandler = function(opt_target) {
35 goog.base(this);
36
37 /**
38 * The pointer handlers.
39 *
40 * @type {!Object.<number, !i18n.input.chrome.inputview.handler.PointerActionB undle>}
41 * @private
42 */
43 this.pointerActionBundles_ = {};
44
45 /**
46 * The event handler.
47 *
48 * @type {!goog.events.EventHandler}
49 * @private
50 */
51 this.eventHandler_ = new goog.events.EventHandler(this);
52
53 var target = opt_target || document;
54 this.eventHandler_.
55 listen(target, [goog.events.EventType.MOUSEDOWN,
56 goog.events.EventType.TOUCHSTART], this.onPointerDown_, true).
57 listen(target, [goog.events.EventType.MOUSEUP,
58 goog.events.EventType.TOUCHEND], this.onPointerUp_, true).
59 listen(target, goog.events.EventType.TOUCHMOVE, this.onTouchMove_,
60 true);
61 };
62 goog.inherits(i18n.input.chrome.inputview.handler.PointerHandler,
63 goog.events.EventTarget);
64 var PointerHandler = i18n.input.chrome.inputview.handler.PointerHandler;
65
66
67 /**
68 * The canvas class name.
69 * @const {string}
70 * @private
71 */
72 PointerHandler.CANVAS_CLASS_NAME_ = 'ita-hwt-canvas';
73
74
75 /**
76 * Mouse down tick, which is for delayed pointer up for tap action on touchpad.
77 *
78 * @private {Date}
79 */
80 PointerHandler.prototype.mouseDownTick_ = null;
81
82
83 /**
84 * Event handler for previous mousedown or touchstart target.
85 *
86 * @private {i18n.input.chrome.inputview.handler.PointerActionBundle}
87 */
88 PointerHandler.prototype.previousPointerActionBundle_ = null;
89
90
91 /**
92 * Creates a new pointer handler.
93 *
94 * @param {!Node} target .
95 * @return {!i18n.input.chrome.inputview.handler.PointerActionBundle} .
96 * @private
97 */
98 PointerHandler.prototype.createPointerActionBundle_ = function(target) {
99 var uid = goog.getUid(target);
100 if (!this.pointerActionBundles_[uid]) {
101 this.pointerActionBundles_[uid] = new i18n.input.chrome.inputview.handler.
102 PointerActionBundle(target, this);
103 }
104 return this.pointerActionBundles_[uid];
105 };
106
107
108 /**
109 * Callback for mouse/touch down on the target.
110 *
111 * @param {!goog.events.BrowserEvent} e The event.
112 * @private
113 */
114 PointerHandler.prototype.onPointerDown_ = function(e) {
115 var pointerActionBundle = this.createPointerActionBundle_(
116 /** @type {!Node} */ (e.target));
117 if (this.previousPointerActionBundle_ &&
118 this.previousPointerActionBundle_ != pointerActionBundle) {
119 this.previousPointerActionBundle_.cancelDoubleClick();
120 }
121 this.previousPointerActionBundle_ = pointerActionBundle;
122 pointerActionBundle.handlePointerDown(e);
123 if (e.type == goog.events.EventType.MOUSEDOWN) {
124 this.mouseDownTick_ = new Date();
125 }
126 };
127
128
129 /**
130 * Callback for pointer out.
131 *
132 * @param {!goog.events.BrowserEvent} e The event.
133 * @private
134 */
135 PointerHandler.prototype.onPointerUp_ = function(e) {
136 if (e.type == goog.events.EventType.MOUSEUP) {
137 // If mouseup happens too fast after mousedown, it may be a tap action on
138 // touchpad, so delay the pointer up action so user can see the visual
139 // flash.
140 if (this.mouseDownTick_ && new Date() - this.mouseDownTick_ < 10) {
141 goog.Timer.callOnce(this.onPointerUp_.bind(this, e), 50);
142 return;
143 }
144 }
145 var uid = goog.getUid(e.target);
146 var pointerActionBundle = this.pointerActionBundles_[uid];
147 if (pointerActionBundle) {
148 pointerActionBundle.handlePointerUp(e);
149 }
150 };
151
152
153 /**
154 * Callback for touchmove.
155 *
156 * @param {!goog.events.BrowserEvent} e The event.
157 * @private
158 */
159 PointerHandler.prototype.onTouchMove_ = function(e) {
160 var touches = e.getBrowserEvent()['touches'];
161 if (!touches || touches.length == 0) {
162 return;
163 }
164 for (var i = 0; i < touches.length; i++) {
165 var uid = goog.getUid(touches[i].target);
166 var pointerActionBundle = this.pointerActionBundles_[uid];
167 if (pointerActionBundle) {
168 pointerActionBundle.handleTouchMove(touches[i]);
169 }
170 }
171 };
172
173
174 /** @override */
175 PointerHandler.prototype.disposeInternal = function() {
176 for (var bundle in this.pointerActionBundles_) {
177 goog.dispose(bundle);
178 }
179 goog.dispose(this.eventHandler_);
180
181 goog.base(this, 'disposeInternal');
182 };
183
184 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698