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

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

Issue 2035303002: [Chromoting] Decouple DesktopView and TouchInputHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java
diff --git a/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java b/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java
index e31c2a3d83236669f74ad20ea4ffee1dbf5b65be..91fa6a776ff1c604601d1b3eed22a9b886bbb446 100644
--- a/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java
+++ b/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java
@@ -14,6 +14,8 @@ import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ViewConfiguration;
+import org.chromium.chromoting.jni.Client;
+
/**
* This class is responsible for handling Touch input from the user. Touch events which manipulate
* the local canvas are handled in this class and any input which should be sent to the remote host
@@ -21,6 +23,7 @@ import android.view.ViewConfiguration;
*/
public class TouchInputHandler implements TouchInputHandlerInterface {
private final DesktopViewInterface mViewer;
+ private final Context mContext;
private final RenderData mRenderData;
private final DesktopCanvas mDesktopCanvas;
private InputStrategyInterface mInputStrategy;
@@ -180,6 +183,7 @@ public class TouchInputHandler implements TouchInputHandlerInterface {
public TouchInputHandler(DesktopViewInterface viewer, Context context, RenderData renderData) {
mViewer = viewer;
+ mContext = context;
mRenderData = renderData;
mDesktopCanvas = new DesktopCanvas(mViewer, mRenderData);
@@ -257,20 +261,6 @@ public class TouchInputHandler implements TouchInputHandlerInterface {
}
@Override
- public void onSoftInputMethodVisibilityChanged(boolean inputMethodVisible, Rect bounds) {
- synchronized (mRenderData) {
- if (inputMethodVisible) {
- mDesktopCanvas.setInputMethodOffsetValues(mRenderData.screenWidth - bounds.right,
- mRenderData.screenHeight - bounds.bottom);
- } else {
- mDesktopCanvas.setInputMethodOffsetValues(0, 0);
- }
- }
-
- mDesktopCanvas.repositionImage(true);
- }
-
- @Override
public void processAnimation() {
boolean active = mCursorAnimationJob.processAnimation();
active |= mScrollAnimationJob.processAnimation();
@@ -281,7 +271,67 @@ public class TouchInputHandler implements TouchInputHandlerInterface {
}
@Override
- public void setInputStrategy(InputStrategyInterface inputStrategy) {
+ public void init(Desktop desktop, final Client client) {
+ desktop.onInputModeChanged().add(
+ new Event.ParameterRunnable<InputModeChangedEventParameter>() {
+ @Override
+ public void run(InputModeChangedEventParameter parameter) {
+ final Desktop.InputMode inputMode = parameter.inputMode;
Lambros 2016/06/06 22:11:34 I think this would be more readable if you pull th
Hzj_jie 2016/06/07 01:26:13 Done.
+ final CapabilityManager.HostCapability hostTouchCapability =
+ parameter.hostCapability;
+ // We need both input mode and host input capabilities to select the input
+ // strategy.
+ if (!inputMode.isSet() || !hostTouchCapability.isSet()) {
+ return;
+ }
+
+ switch (inputMode) {
+ case TRACKPAD:
+ setInputStrategy(new TrackpadInputStrategy(mRenderData, client));
+ break;
+
+ case TOUCH:
+ if (hostTouchCapability.isSupported()) {
+ setInputStrategy(new TouchInputStrategy(mRenderData, client));
+ } else {
+ setInputStrategy(new SimulatedTouchInputStrategy(
+ mRenderData, client, mContext));
+ }
+ break;
+
+ default:
+ // Unreachable, but required by Google Java style and findbugs.
+ assert false : "Unreached";
+ }
+
+ // Ensure the cursor state is updated appropriately.
+ // TODO (zijiehe): Move repaint control out of DesktopView.
+ if (mViewer instanceof DesktopView) {
+ ((DesktopView) mViewer).requestRepaint();
+ }
+ }
+ });
+
+ desktop.onSoftInputMethodVisibilityChanged().add(
+ new Event.ParameterRunnable<SoftInputMethodVisibilityChangedEventParameter>() {
+ @Override
+ public void run(SoftInputMethodVisibilityChangedEventParameter parameter) {
+ synchronized (mRenderData) {
Lambros 2016/06/06 22:11:34 And this.
Hzj_jie 2016/06/07 01:26:13 Done.
+ if (parameter.visible) {
+ mDesktopCanvas.setInputMethodOffsetValues(
+ mRenderData.screenWidth - parameter.right,
+ mRenderData.screenHeight - parameter.bottom);
+ } else {
+ mDesktopCanvas.setInputMethodOffsetValues(0, 0);
+ }
+ }
+
+ mDesktopCanvas.repositionImage(true);
+ }
+ });
+ }
+
+ private void setInputStrategy(InputStrategyInterface inputStrategy) {
// Since the rules for flinging differ between input modes, we want to stop running the
// current fling animation when the mode changes to prevent a wonky experience.
mCursorAnimationJob.abortAnimation();

Powered by Google App Engine
This is Rietveld 408576698