Commit 1bbf9d22 authored by joedow's avatar joedow Committed by Commit bot

Fixing a cursor position initialization problem

This issue was caused during a recent refactoring.  This CL adds the
initialization code for Trackpad mode back.

BUG=628034

Review-Url: https://codereview.chromium.org/2146303002
Cr-Commit-Position: refs/heads/master@{#405610}
parent 6573f1ea
......@@ -77,6 +77,18 @@ public class DesktopCanvas {
return viewportCenter;
}
/**
* Sets the desired center position of the viewport.
*
* @param newX The new x coordinate value for the desired center position.
* @param newY The new y coordinate value for the desired center position.
*/
public void setViewportPosition(float newX, float newY) {
synchronized (mRenderData) {
mViewportPosition.set(newX, newY);
}
}
/**
* Returns the current size of the viewport. This size includes the offset calculations for
* any visible system UI.
......
......@@ -20,6 +20,8 @@ import android.view.ViewConfiguration;
* are passed to the InputStrategyInterface implementation set by the DesktopView.
*/
public class TouchInputHandler {
private static final float EPSILON = 0.001f;
private final AbstractDesktopView mViewer;
private final Context mContext;
private final RenderData mRenderData;
......@@ -361,8 +363,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 +405,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 +438,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 +583,7 @@ public class TouchInputHandler {
}
if (!mInputStrategy.isIndirectInputMode()) {
if (!mapScreenPointToImage(x, y)) {
if (screenPointLiesOutsideImageBoundary(x, y)) {
return false;
}
moveCursorToScreenPoint(x, y);
......@@ -595,7 +608,7 @@ public class TouchInputHandler {
}
if (!mInputStrategy.isIndirectInputMode()) {
if (!mapScreenPointToImage(x, y)) {
if (screenPointLiesOutsideImageBoundary(x, y)) {
return;
}
moveCursorToScreenPoint(x, y);
......@@ -626,21 +639,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};
int imageWidth;
int imageHeight;
Matrix screenToImage = new Matrix();
/** Determines whether the given screen point lies outside the desktop image. */
private boolean screenPointLiesOutsideImageBoundary(float screenX, float screenY) {
float[] mappedPoints = mapScreenPointToImagePoint(screenX, screenY);
float imageWidth;
float imageHeight;
synchronized (mRenderData) {
mRenderData.transform.invert(screenToImage);
imageWidth = mRenderData.imageWidth;
imageHeight = mRenderData.imageHeight;
imageWidth = (float) mRenderData.imageWidth + EPSILON;
imageHeight = (float) mRenderData.imageHeight + EPSILON;
}
screenToImage.mapPoints(mappedPoints);
return (mappedPoints[0] >= 0 && mappedPoints[0] <= imageWidth)
&& (mappedPoints[1] >= 0 && mappedPoints[1] <= imageHeight);
return mappedPoints[0] < -EPSILON || mappedPoints[0] > imageWidth
|| mappedPoints[1] < -EPSILON || mappedPoints[1] > imageHeight;
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment