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

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java

Issue 2066683003: [Chromoting] Add InputInjector and InputInjectorWrapper for easy unittesting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Suppress FindBugs warning of FE_FLOATING_POINT_EQUALITY Created 4 years, 6 months 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 package org.chromium.chromoting; 5 package org.chromium.chromoting;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.graphics.Matrix; 8 import android.graphics.Matrix;
9 import android.graphics.Point; 9 import android.graphics.Point;
10 import android.graphics.PointF; 10 import android.graphics.PointF;
11 import android.graphics.Rect; 11 import android.graphics.Rect;
12 import android.view.GestureDetector; 12 import android.view.GestureDetector;
13 import android.view.MotionEvent; 13 import android.view.MotionEvent;
14 import android.view.ScaleGestureDetector; 14 import android.view.ScaleGestureDetector;
15 import android.view.ViewConfiguration; 15 import android.view.ViewConfiguration;
16 16
17 import org.chromium.chromoting.jni.Client;
18
19 /** 17 /**
20 * This class is responsible for handling Touch input from the user. Touch even ts which manipulate 18 * This class is responsible for handling Touch input from the user. Touch even ts which manipulate
21 * the local canvas are handled in this class and any input which should be sent to the remote host 19 * the local canvas are handled in this class and any input which should be sent to the remote host
22 * are passed to the InputStrategyInterface implementation set by the DesktopVie w. 20 * are passed to the InputStrategyInterface implementation set by the DesktopVie w.
23 */ 21 */
24 public class TouchInputHandler implements TouchInputHandlerInterface { 22 public class TouchInputHandler {
23 // These constants must match those in the generated struct protocol::MouseE vent_MouseButton.
Sergey Ulanov 2016/06/22 06:39:02 Maybe make these be part of the InputInjector inte
Hzj_jie 2016/06/22 23:18:54 Done.
24 public static final int BUTTON_UNDEFINED = 0;
25 public static final int BUTTON_LEFT = 1;
26 public static final int BUTTON_MIDDLE = 2;
27 public static final int BUTTON_RIGHT = 3;
28
25 private final DesktopViewInterface mViewer; 29 private final DesktopViewInterface mViewer;
26 private final Context mContext; 30 private final Context mContext;
27 private final RenderData mRenderData; 31 private final RenderData mRenderData;
28 private final DesktopCanvas mDesktopCanvas; 32 private final DesktopCanvas mDesktopCanvas;
29 private InputStrategyInterface mInputStrategy; 33 private InputStrategyInterface mInputStrategy;
30 34
31 private GestureDetector mScroller; 35 private GestureDetector mScroller;
32 private ScaleGestureDetector mZoomer; 36 private ScaleGestureDetector mZoomer;
33 private TapGestureDetector mTapDetector; 37 private TapGestureDetector mTapDetector;
34 38
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 mEdgeSlopInPx = ViewConfiguration.get(context).getScaledEdgeSlop(); 213 mEdgeSlopInPx = ViewConfiguration.get(context).getScaledEdgeSlop();
210 214
211 mInputStrategy = new NullInputStrategy(); 215 mInputStrategy = new NullInputStrategy();
212 216
213 mCursorAnimationJob = new CursorAnimationJob(context); 217 mCursorAnimationJob = new CursorAnimationJob(context);
214 mScrollAnimationJob = new ScrollAnimationJob(context); 218 mScrollAnimationJob = new ScrollAnimationJob(context);
215 219
216 attachViewEvents(viewer); 220 attachViewEvents(viewer);
217 } 221 }
218 222
219 @Override
220 public void processAnimation() { 223 public void processAnimation() {
221 boolean active = mCursorAnimationJob.processAnimation(); 224 boolean active = mCursorAnimationJob.processAnimation();
222 active |= mScrollAnimationJob.processAnimation(); 225 active |= mScrollAnimationJob.processAnimation();
223 226
224 if (!active) { 227 if (!active) {
225 mViewer.setAnimationEnabled(false); 228 mViewer.setAnimationEnabled(false);
226 } 229 }
227 } 230 }
228 231
229 @Override 232 public void init(Desktop desktop, final InputInjectorWrapper injector) {
230 public void init(Desktop desktop, final Client client) { 233 Preconditions.notNull(injector);
231 Preconditions.notNull(client);
232 desktop.onInputModeChanged().add( 234 desktop.onInputModeChanged().add(
233 new Event.ParameterRunnable<InputModeChangedEventParameter>() { 235 new Event.ParameterRunnable<InputModeChangedEventParameter>() {
234 @Override 236 @Override
235 public void run(InputModeChangedEventParameter parameter) { 237 public void run(InputModeChangedEventParameter parameter) {
236 handleInputModeChanged(parameter, client); 238 handleInputModeChanged(parameter, injector);
237 } 239 }
238 }); 240 });
239 241
240 desktop.onSoftInputMethodVisibilityChanged().add( 242 desktop.onSoftInputMethodVisibilityChanged().add(
241 new Event.ParameterRunnable<SoftInputMethodVisibilityChangedEven tParameter>() { 243 new Event.ParameterRunnable<SoftInputMethodVisibilityChangedEven tParameter>() {
242 @Override 244 @Override
243 public void run(SoftInputMethodVisibilityChangedEventParamet er parameter) { 245 public void run(SoftInputMethodVisibilityChangedEventParamet er parameter) {
244 handleSoftInputMethodVisibilityChanged(parameter); 246 handleSoftInputMethodVisibilityChanged(parameter);
245 } 247 }
246 }); 248 });
(...skipping 13 matching lines...) Expand all
260 } 262 }
261 }); 263 });
262 viewer.onHostSizeChanged().add(new Event.ParameterRunnable<SizeChangedEv entParameter>() { 264 viewer.onHostSizeChanged().add(new Event.ParameterRunnable<SizeChangedEv entParameter>() {
263 @Override 265 @Override
264 public void run(SizeChangedEventParameter parameter) { 266 public void run(SizeChangedEventParameter parameter) {
265 handleHostSizeChanged(parameter.width, parameter.height); 267 handleHostSizeChanged(parameter.width, parameter.height);
266 } 268 }
267 }); 269 });
268 } 270 }
269 271
270 private void handleInputModeChanged(InputModeChangedEventParameter parameter , 272 private void handleInputModeChanged(
271 Client client) { 273 InputModeChangedEventParameter parameter, InputInjectorWrapper injec tor) {
272 final Desktop.InputMode inputMode = parameter.inputMode; 274 final Desktop.InputMode inputMode = parameter.inputMode;
273 final CapabilityManager.HostCapability hostTouchCapability = 275 final CapabilityManager.HostCapability hostTouchCapability =
274 parameter.hostCapability; 276 parameter.hostCapability;
275 // We need both input mode and host input capabilities to select the inp ut 277 // We need both input mode and host input capabilities to select the inp ut
276 // strategy. 278 // strategy.
277 if (!inputMode.isSet() || !hostTouchCapability.isSet()) { 279 if (!inputMode.isSet() || !hostTouchCapability.isSet()) {
278 return; 280 return;
279 } 281 }
280 282
281 switch (inputMode) { 283 switch (inputMode) {
282 case TRACKPAD: 284 case TRACKPAD:
283 setInputStrategy(new TrackpadInputStrategy(mRenderData, client)) ; 285 setInputStrategy(new TrackpadInputStrategy(mRenderData, injector ));
284 break; 286 break;
285 287
286 case TOUCH: 288 case TOUCH:
287 if (hostTouchCapability.isSupported()) { 289 if (hostTouchCapability.isSupported()) {
288 setInputStrategy(new TouchInputStrategy(mRenderData, client) ); 290 setInputStrategy(new TouchInputStrategy(mRenderData, injecto r));
289 } else { 291 } else {
290 setInputStrategy(new SimulatedTouchInputStrategy( 292 setInputStrategy(
291 mRenderData, client, mContext)); 293 new SimulatedTouchInputStrategy(mRenderData, injecto r, mContext));
292 } 294 }
293 break; 295 break;
294 296
295 default: 297 default:
296 // Unreachable, but required by Google Java style and findbugs. 298 // Unreachable, but required by Google Java style and findbugs.
297 assert false : "Unreached"; 299 assert false : "Unreached";
298 } 300 }
299 301
300 // Ensure the cursor state is updated appropriately. 302 // Ensure the cursor state is updated appropriately.
301 // TODO (zijiehe): Move repaint control out of DesktopView. 303 // TODO (zijiehe): Move repaint control out of DesktopView.
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 case 2: 650 case 2:
649 return BUTTON_RIGHT; 651 return BUTTON_RIGHT;
650 case 3: 652 case 3:
651 return BUTTON_MIDDLE; 653 return BUTTON_MIDDLE;
652 default: 654 default:
653 return BUTTON_UNDEFINED; 655 return BUTTON_UNDEFINED;
654 } 656 }
655 } 657 }
656 } 658 }
657 } 659 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698