Chromium Code Reviews| 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 4cbd35ed60803a8945067e13135d52748f44e497..14674fe5269f20fe881c4b3a68a732eb22e5199e 100644 |
| --- a/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java |
| +++ b/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java |
| @@ -361,8 +361,12 @@ public class TouchInputHandler { |
| synchronized (mRenderData) { |
| screenCenterX = (float) mRenderData.screenWidth / 2; |
| screenCenterY = (float) mRenderData.screenHeight / 2; |
| + |
| + float[] imagePoint = mapScreenPointToImagePoint(screenCenterX, screenCenterY); |
| + mDesktopCanvas.setViewportPosition(imagePoint[0], imagePoint[1]); |
| } |
| moveCursorToScreenPoint(screenCenterX, screenCenterY); |
| + mDesktopCanvas.repositionImage(true); |
| } |
| private void setInputStrategy(InputStrategyInterface inputStrategy) { |
| @@ -399,13 +403,8 @@ public class TouchInputHandler { |
| /** Moves the cursor to the specified position on the screen. */ |
| private void moveCursorToScreenPoint(float screenX, float screenY) { |
| - float[] mappedValues = {screenX, screenY}; |
| - synchronized (mRenderData) { |
| - Matrix canvasToImage = new Matrix(); |
| - mRenderData.transform.invert(canvasToImage); |
| - canvasToImage.mapPoints(mappedValues); |
| - } |
| - moveCursor((int) mappedValues[0], (int) mappedValues[1]); |
| + float[] imagePoint = mapScreenPointToImagePoint(screenX, screenY); |
| + moveCursor((int) imagePoint[0], (int) imagePoint[1]); |
| } |
| /** Moves the cursor to the specified position on the remote host. */ |
| @@ -437,6 +436,18 @@ public class TouchInputHandler { |
| return true; |
| } |
| + /** Translates a point in screen coordinates to a location on the desktop image. */ |
| + private float[] mapScreenPointToImagePoint(float screenX, float screenY) { |
| + float[] mappedPoints = {screenX, screenY}; |
| + Matrix screenToImage = new Matrix(); |
| + synchronized (mRenderData) { |
| + mRenderData.transform.invert(screenToImage); |
| + } |
| + screenToImage.mapPoints(mappedPoints); |
| + |
| + return mappedPoints; |
| + } |
| + |
| /** Responds to touch events filtered by the gesture detectors. */ |
| private class GestureListener extends GestureDetector.SimpleOnGestureListener |
| implements ScaleGestureDetector.OnScaleGestureListener, |
| @@ -570,7 +581,7 @@ public class TouchInputHandler { |
| } |
| if (!mInputStrategy.isIndirectInputMode()) { |
| - if (!mapScreenPointToImage(x, y)) { |
| + if (screenPointLiesOutsideImageBoundary(x, y)) { |
| return false; |
| } |
| moveCursorToScreenPoint(x, y); |
| @@ -595,7 +606,7 @@ public class TouchInputHandler { |
| } |
| if (!mInputStrategy.isIndirectInputMode()) { |
| - if (!mapScreenPointToImage(x, y)) { |
| + if (screenPointLiesOutsideImageBoundary(x, y)) { |
| return; |
| } |
| moveCursorToScreenPoint(x, y); |
| @@ -626,21 +637,18 @@ public class TouchInputHandler { |
| } |
| } |
| - /** Verifies the given point maps to a valid location within the desktop image. */ |
| - private boolean mapScreenPointToImage(float screenX, float screenY) { |
| - float[] mappedPoints = {screenX, screenY}; |
| + /** Determines whether the given screen point lies outside the desktop image. */ |
| + private boolean screenPointLiesOutsideImageBoundary(float screenX, float screenY) { |
| + float[] mappedPoints = mapScreenPointToImagePoint(screenX, screenY); |
| int imageWidth; |
| int imageHeight; |
| - Matrix screenToImage = new Matrix(); |
| synchronized (mRenderData) { |
| - mRenderData.transform.invert(screenToImage); |
| imageWidth = mRenderData.imageWidth; |
| imageHeight = mRenderData.imageHeight; |
| } |
| - screenToImage.mapPoints(mappedPoints); |
| - return (mappedPoints[0] >= 0 && mappedPoints[0] <= imageWidth) |
| - && (mappedPoints[1] >= 0 && mappedPoints[1] <= imageHeight); |
| + return (mappedPoints[0] < 0 && mappedPoints[0] > imageWidth) |
|
Lambros
2016/07/14 21:11:08
The '&&'s should be ||, and the parentheses are no
joedow
2016/07/14 21:47:36
Oh geez, not sure why I didn't catch this in my te
|
| + || (mappedPoints[1] < 0 && mappedPoints[1] > imageHeight); |
| } |
| } |
| } |