summaryrefslogtreecommitdiffstats
path: root/remoting/android
diff options
context:
space:
mode:
authorjoedow <joedow@chromium.org>2015-12-15 05:34:40 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-15 13:35:35 +0000
commitea6c50b06b9056613348cb215c9fc940a47ee088 (patch)
treef07ff132d80ef5162a51063b36fc5fd04acd2205 /remoting/android
parent44b25c4e530267d55f5cfc8acc82f07eb7b0dd18 (diff)
downloadchromium_src-ea6c50b06b9056613348cb215c9fc940a47ee088.zip
chromium_src-ea6c50b06b9056613348cb215c9fc940a47ee088.tar.gz
chromium_src-ea6c50b06b9056613348cb215c9fc940a47ee088.tar.bz2
Fixing two viewport positioning bugs in touch mode.
This change addresses two problems I have experienced with the viewport in touch mode. The first is that panning did not work correctly when the soft keyboard is present. This is addressed by have the DesktopCanvas class expose a property which provides its size (adjusted to account for the space taken up by the soft input method UI). The second bug was related to zooming the canvas. For indirect input modes we want to zoom in at the location of the cursor, rather than the focal point of the gesture, however for direct modes, we expect the latter behavior and should use the focal point of the gesture to zoom. Currently touch modes use the cursor point which is not correct. BUG= Review URL: https://codereview.chromium.org/1528763002 Cr-Commit-Position: refs/heads/master@{#365237}
Diffstat (limited to 'remoting/android')
-rw-r--r--remoting/android/java/src/org/chromium/chromoting/DesktopCanvas.java60
-rw-r--r--remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java15
2 files changed, 49 insertions, 26 deletions
diff --git a/remoting/android/java/src/org/chromium/chromoting/DesktopCanvas.java b/remoting/android/java/src/org/chromium/chromoting/DesktopCanvas.java
index 83a0be3..986745e 100644
--- a/remoting/android/java/src/org/chromium/chromoting/DesktopCanvas.java
+++ b/remoting/android/java/src/org/chromium/chromoting/DesktopCanvas.java
@@ -75,6 +75,22 @@ public class DesktopCanvas {
mInputMethodOffsetY = offsetY;
}
+ /**
+ * Returns the current size of the viewport. This size includes the offset calculations for
+ * any visible Input Method UI.
+ *
+ * @return A point representing the current size of the viewport.
+ */
+ public PointF getViewportSize() {
+ float adjustedScreenWidth, adjustedScreenHeight;
+ synchronized (mRenderData) {
+ adjustedScreenWidth = mRenderData.screenWidth - mInputMethodOffsetX;
+ adjustedScreenHeight = mRenderData.screenHeight - mInputMethodOffsetY;
+ }
+
+ return new PointF(adjustedScreenWidth, adjustedScreenHeight);
+ }
+
/** Repositions the image by zooming it such that the complete image fits on the screen. */
public void resizeImageToFitScreen() {
synchronized (mRenderData) {
@@ -107,31 +123,32 @@ public class DesktopCanvas {
}
}
- repositionImage();
+ repositionImage(true);
}
/**
- * Repositions the image by translating it (without affecting the zoom level) to place the
- * viewport close to the center of the screen.
+ * Repositions the image by translating it (without affecting the zoom level).
+ *
+ * @param centerViewport Determines whether the viewport will be translated to the desired
+ * center position before being adjusted to fit the screen boundaries.
*/
- public void repositionImage() {
+ public void repositionImage(boolean centerViewport) {
+ PointF adjustedViewportSize = getViewportSize();
synchronized (mRenderData) {
- float adjustedScreenWidth = mRenderData.screenWidth - mInputMethodOffsetX;
- float adjustedScreenHeight = mRenderData.screenHeight - mInputMethodOffsetY;
-
// The goal of the code below is to position the viewport as close to the desired center
// position as possible whilst keeping as much of the desktop in view as possible.
// To achieve these goals, we first position the desktop image at the desired center
// point and then re-position it to maximize the viewable area.
-
- // Map the current viewport position to screen coordinates.
- float[] viewportPosition = {mViewportPosition.x, mViewportPosition.y};
- mRenderData.transform.mapPoints(viewportPosition);
-
- // Translate so the viewport is displayed in the middle of the screen.
- mRenderData.transform.postTranslate(
- (float) adjustedScreenWidth / 2 - viewportPosition[0],
- (float) adjustedScreenHeight / 2 - viewportPosition[1]);
+ if (centerViewport) {
+ // Map the current viewport position to screen coordinates.
+ float[] viewportPosition = {mViewportPosition.x, mViewportPosition.y};
+ mRenderData.transform.mapPoints(viewportPosition);
+
+ // Translate so the viewport is displayed in the middle of the screen.
+ mRenderData.transform.postTranslate(
+ (float) adjustedViewportSize.x / 2 - viewportPosition[0],
+ (float) adjustedViewportSize.y / 2 - viewportPosition[1]);
+ }
// Get the coordinates of the desktop rectangle (top-left/bottom-right corners) in
// screen coordinates. Order is: left, top, right, bottom.
@@ -145,7 +162,7 @@ public class DesktopCanvas {
float xAdjust = 0;
float yAdjust = 0;
- if (rectScreen.right - rectScreen.left < adjustedScreenWidth) {
+ if (rectScreen.right - rectScreen.left < adjustedViewportSize.x) {
// Image is narrower than the screen, so center it.
xAdjust = -(rightDelta + leftDelta) / 2;
} else if (leftDelta > 0 && rightDelta > 0) {
@@ -157,7 +174,7 @@ public class DesktopCanvas {
}
// Apply similar logic for yAdjust.
- if (rectScreen.bottom - rectScreen.top < adjustedScreenHeight) {
+ if (rectScreen.bottom - rectScreen.top < adjustedViewportSize.y) {
yAdjust = -(bottomDelta + topDelta) / 2;
} else if (topDelta > 0 && bottomDelta > 0) {
yAdjust = -Math.min(topDelta, bottomDelta);
@@ -176,8 +193,11 @@ public class DesktopCanvas {
* limits. The minimum zoom level is chosen to avoid black space around all 4 sides. The
* maximum zoom level is set arbitrarily, so that the user can zoom out again in a reasonable
* time, and to prevent arithmetic overflow problems from displaying the image.
+ *
+ * @param centerViewport Determines whether the viewport will be translated to the desired
+ * center position before being adjusted to fit the screen boundaries.
*/
- public void repositionImageWithZoom() {
+ public void repositionImageWithZoom(boolean centerViewport) {
synchronized (mRenderData) {
// Avoid division by zero in case this gets called before the image size is initialized.
if (mRenderData.imageWidth == 0 || mRenderData.imageHeight == 0) {
@@ -203,6 +223,6 @@ public class DesktopCanvas {
}
}
- repositionImage();
+ repositionImage(centerViewport);
}
}
diff --git a/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java b/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java
index 940fc82..d7f5e11 100644
--- a/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java
+++ b/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java
@@ -154,7 +154,7 @@ public class TouchInputHandler implements TouchInputHandlerInterface {
public void onClientSizeChanged(int width, int height) {
mPanGestureBounds = new Rect(
mEdgeSlopInPx, mEdgeSlopInPx, width - mEdgeSlopInPx, height - mEdgeSlopInPx);
- mDesktopCanvas.repositionImageWithZoom();
+ mDesktopCanvas.repositionImageWithZoom(true);
}
@Override
@@ -174,7 +174,7 @@ public class TouchInputHandler implements TouchInputHandlerInterface {
}
}
- mDesktopCanvas.repositionImageWithZoom();
+ mDesktopCanvas.repositionImage(true);
}
@Override
@@ -224,9 +224,10 @@ public class TouchInputHandler implements TouchInputHandlerInterface {
if (mInputStrategy.isIndirectInputMode() || mIsDragging) {
viewportPoint = mDesktopCanvas.getViewportPosition();
} else {
+ PointF adjustedViewportSize = mDesktopCanvas.getViewportSize();
synchronized (mRenderData) {
- float[] viewportPosition = new float[] {(float) mRenderData.screenWidth / 2,
- (float) mRenderData.screenHeight / 2};
+ float[] viewportPosition = new float[] {(float) adjustedViewportSize.x / 2,
+ (float) adjustedViewportSize.y / 2};
Matrix inverted = new Matrix();
mRenderData.transform.invert(inverted);
inverted.mapPoints(viewportPosition);
@@ -265,7 +266,7 @@ public class TouchInputHandler implements TouchInputHandlerInterface {
moveCursor((int) newX, (int) newY);
}
- mDesktopCanvas.repositionImage();
+ mDesktopCanvas.repositionImage(true);
}
/** Moves the cursor to the specified position on the screen. */
@@ -402,7 +403,9 @@ public class TouchInputHandler implements TouchInputHandlerInterface {
mRenderData.transform.postScale(
scaleFactor, scaleFactor, detector.getFocusX(), detector.getFocusY());
}
- mDesktopCanvas.repositionImageWithZoom();
+ // For indirect input modes we want to zoom using the cursor as the focal point, for
+ // direct modes we use the actual focal point of the gesture.
+ mDesktopCanvas.repositionImageWithZoom(mInputStrategy.isIndirectInputMode());
return true;
}