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

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

Issue 1537183002: Refactor Chromoting JNI code to use jni/Client (Java changes only). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Suppress FindBugs warning Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.graphics.Point; 7 import android.graphics.Point;
8 import android.view.MotionEvent; 8 import android.view.MotionEvent;
9 9
10 import org.chromium.chromoting.jni.JniInterface; 10 import org.chromium.chromoting.jni.Client;
11 11
12 /** 12 /**
13 * Defines a set of behavior and methods to simulate trackpad behavior when resp onding to 13 * Defines a set of behavior and methods to simulate trackpad behavior when resp onding to
14 * local input event data. This class is also responsible for forwarding input event data 14 * local input event data. This class is also responsible for forwarding input event data
15 * to the remote host for injection there. 15 * to the remote host for injection there.
16 */ 16 */
17 public class TrackpadInputStrategy implements InputStrategyInterface { 17 public class TrackpadInputStrategy implements InputStrategyInterface {
18 private final RenderData mRenderData; 18 private final RenderData mRenderData;
19 private final Client mClient;
19 20
20 /** Mouse-button currently held down, or BUTTON_UNDEFINED otherwise. */ 21 /** Mouse-button currently held down, or BUTTON_UNDEFINED otherwise. */
21 private int mHeldButton = TouchInputHandlerInterface.BUTTON_UNDEFINED; 22 private int mHeldButton = TouchInputHandlerInterface.BUTTON_UNDEFINED;
22 23
23 public TrackpadInputStrategy(RenderData renderData) { 24 public TrackpadInputStrategy(RenderData renderData, Client client) {
24 mRenderData = renderData; 25 mRenderData = renderData;
26 mClient = client;
25 27
26 synchronized (mRenderData) { 28 synchronized (mRenderData) {
27 mRenderData.drawCursor = true; 29 mRenderData.drawCursor = true;
28 } 30 }
29 } 31 }
30 32
31 @Override 33 @Override
32 public boolean onTap(int button) { 34 public boolean onTap(int button) {
33 injectMouseButtonEvent(button, true); 35 injectMouseButtonEvent(button, true);
34 injectMouseButtonEvent(button, false); 36 injectMouseButtonEvent(button, false);
35 return true; 37 return true;
36 } 38 }
37 39
38 @Override 40 @Override
39 public boolean onPressAndHold(int button) { 41 public boolean onPressAndHold(int button) {
40 injectMouseButtonEvent(button, true); 42 injectMouseButtonEvent(button, true);
41 mHeldButton = button; 43 mHeldButton = button;
42 return true; 44 return true;
43 } 45 }
44 46
45 @Override 47 @Override
46 public void onScroll(float distanceX, float distanceY) { 48 public void onScroll(float distanceX, float distanceY) {
47 JniInterface.sendMouseWheelEvent((int) -distanceX, (int) -distanceY); 49 mClient.sendMouseWheelEvent((int) -distanceX, (int) -distanceY);
48 } 50 }
49 51
50 @Override 52 @Override
51 public void onMotionEvent(MotionEvent event) { 53 public void onMotionEvent(MotionEvent event) {
52 if (event.getActionMasked() == MotionEvent.ACTION_UP 54 if (event.getActionMasked() == MotionEvent.ACTION_UP
53 && mHeldButton != TouchInputHandlerInterface.BUTTON_UNDEFINED) { 55 && mHeldButton != TouchInputHandlerInterface.BUTTON_UNDEFINED) {
54 injectMouseButtonEvent(mHeldButton, false); 56 injectMouseButtonEvent(mHeldButton, false);
55 mHeldButton = TouchInputHandlerInterface.BUTTON_UNDEFINED; 57 mHeldButton = TouchInputHandlerInterface.BUTTON_UNDEFINED;
56 } 58 }
57 } 59 }
58 60
59 @Override 61 @Override
60 public void injectCursorMoveEvent(int x, int y) { 62 public void injectCursorMoveEvent(int x, int y) {
61 JniInterface.sendMouseEvent(x, y, TouchInputHandlerInterface.BUTTON_UNDE FINED, false); 63 mClient.sendMouseEvent(x, y, TouchInputHandlerInterface.BUTTON_UNDEFINED , false);
62 } 64 }
63 65
64 @Override 66 @Override
65 public DesktopView.InputFeedbackType getShortPressFeedbackType() { 67 public DesktopView.InputFeedbackType getShortPressFeedbackType() {
66 return DesktopView.InputFeedbackType.NONE; 68 return DesktopView.InputFeedbackType.NONE;
67 } 69 }
68 70
69 @Override 71 @Override
70 public DesktopView.InputFeedbackType getLongPressFeedbackType() { 72 public DesktopView.InputFeedbackType getLongPressFeedbackType() {
71 return DesktopView.InputFeedbackType.SMALL_ANIMATION; 73 return DesktopView.InputFeedbackType.SMALL_ANIMATION;
72 } 74 }
73 75
74 @Override 76 @Override
75 public boolean isIndirectInputMode() { 77 public boolean isIndirectInputMode() {
76 return true; 78 return true;
77 } 79 }
78 80
79 private void injectMouseButtonEvent(int button, boolean pressed) { 81 private void injectMouseButtonEvent(int button, boolean pressed) {
80 Point cursorPosition; 82 Point cursorPosition;
81 synchronized (mRenderData) { 83 synchronized (mRenderData) {
82 cursorPosition = mRenderData.getCursorPosition(); 84 cursorPosition = mRenderData.getCursorPosition();
83 } 85 }
84 JniInterface.sendMouseEvent(cursorPosition.x, cursorPosition.y, button, pressed); 86 mClient.sendMouseEvent(cursorPosition.x, cursorPosition.y, button, press ed);
85 } 87 }
86 } 88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698