| Index: remoting/android/java/src/org/chromium/chromoting/DesktopCanvas.java
|
| diff --git a/remoting/android/java/src/org/chromium/chromoting/DesktopCanvas.java b/remoting/android/java/src/org/chromium/chromoting/DesktopCanvas.java
|
| index 874697800986af858b459db23e285607a52b3cd1..60a92231dc0b3552cbae1c6dbd0bd6edee0bdd9e 100644
|
| --- a/remoting/android/java/src/org/chromium/chromoting/DesktopCanvas.java
|
| +++ b/remoting/android/java/src/org/chromium/chromoting/DesktopCanvas.java
|
| @@ -4,7 +4,9 @@
|
|
|
| package org.chromium.chromoting;
|
|
|
| +import android.graphics.Matrix;
|
| import android.graphics.PointF;
|
| +import android.graphics.Rect;
|
| import android.graphics.RectF;
|
|
|
| /**
|
| @@ -28,16 +30,9 @@ public class DesktopCanvas {
|
| private PointF mViewportPosition = new PointF();
|
|
|
| /**
|
| - * Represents the amount of vertical space in pixels used by the soft input device and
|
| - * accompanying system UI.
|
| + * Represents the amount of space, in pixels, used by system UI.
|
| */
|
| - private int mInputMethodOffsetY = 0;
|
| -
|
| - /**
|
| - * Represents the amount of horizontal space in pixels used by the soft input device and
|
| - * accompanying system UI.
|
| - */
|
| - private int mInputMethodOffsetX = 0;
|
| + private Rect mSystemUiOffsetPx = new Rect();
|
|
|
| public DesktopCanvas(DesktopViewInterface viewer, RenderData renderData) {
|
| mViewer = viewer;
|
| @@ -45,52 +40,100 @@ public class DesktopCanvas {
|
| }
|
|
|
| /**
|
| - * Returns the desired center position of the viewport. Note that this may not represent the
|
| - * true center of the viewport as other calculations are done to maximize the viewable area.
|
| + * Returns the true center position of the viewport in image coordinates.
|
| *
|
| - * @return A point representing the desired position of the viewport.
|
| + * @return A point representing the true center position of the viewport.
|
| */
|
| - public PointF getViewportPosition() {
|
| - return new PointF(mViewportPosition.x, mViewportPosition.y);
|
| + private PointF getTrueViewportCenter() {
|
| + synchronized (mRenderData) {
|
| + PointF viewportSize = getViewportSize();
|
| + // Find the center point of the viewport on the screen.
|
| + float[] viewportPosition = {((float) viewportSize.x / 2) + mSystemUiOffsetPx.left,
|
| + ((float) viewportSize.y / 2) + mSystemUiOffsetPx.top};
|
| + // Convert the screen position to an image position.
|
| + Matrix inverted = new Matrix();
|
| + mRenderData.transform.invert(inverted);
|
| + inverted.mapPoints(viewportPosition);
|
| + return new PointF(viewportPosition[0], viewportPosition[1]);
|
| + }
|
| }
|
|
|
| /**
|
| - * Sets the desired center position of the viewport.
|
| + * Shifts the viewport by the passed in deltas (in image coordinates).
|
| *
|
| - * @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) {
|
| - mViewportPosition.set(newX, newY);
|
| - }
|
| -
|
| - /**
|
| - * Sets the offset values used to calculate the space used by the current soft input method.
|
| *
|
| - * @param offsetX The space used by the soft input method UI on the right edge of the screen.
|
| - * @param offsetY The space used by the soft input method UI on the bottom edge of the screen.
|
| + * @return A point representing the desired center position of the viewport.
|
| */
|
| - public void setInputMethodOffsetValues(int offsetX, int offsetY) {
|
| - mInputMethodOffsetX = offsetX;
|
| - mInputMethodOffsetY = offsetY;
|
| + public PointF moveViewportCenter(boolean useScreenCenter, float deltaX, float deltaY) {
|
| + PointF viewportCenter;
|
| + synchronized (mRenderData) {
|
| + RectF bounds;
|
| + if (useScreenCenter) {
|
| + viewportCenter = getTrueViewportCenter();
|
| + float[] mappedValues = {
|
| + (float) mRenderData.screenWidth / 2, (float) mRenderData.screenHeight / 2};
|
| + Matrix canvasToImage = new Matrix();
|
| + mRenderData.transform.invert(canvasToImage);
|
| + canvasToImage.mapVectors(mappedValues);
|
| + bounds = new RectF(mappedValues[0], mappedValues[1],
|
| + mRenderData.imageWidth - mappedValues[0],
|
| + mRenderData.imageHeight - mappedValues[1]);
|
| + } else {
|
| + viewportCenter = new PointF(mViewportPosition.x, mViewportPosition.y);
|
| + bounds = new RectF(0, 0, mRenderData.imageWidth, mRenderData.imageHeight);
|
| + }
|
| +
|
| + viewportCenter.set(viewportCenter.x + deltaX, viewportCenter.y + deltaY);
|
| + if (viewportCenter.x < bounds.left) {
|
| + viewportCenter.x = bounds.left;
|
| + } else if (viewportCenter.x > bounds.right) {
|
| + viewportCenter.x = bounds.right;
|
| + }
|
| +
|
| + if (viewportCenter.y < bounds.top) {
|
| + viewportCenter.y = bounds.top;
|
| + } else if (viewportCenter.y > bounds.bottom) {
|
| + viewportCenter.y = bounds.bottom;
|
| + }
|
| +
|
| + mViewportPosition.set(viewportCenter);
|
| + }
|
| +
|
| + return viewportCenter;
|
| }
|
|
|
| /**
|
| * Returns the current size of the viewport. This size includes the offset calculations for
|
| - * any visible Input Method UI.
|
| + * any visible system UI.
|
| *
|
| * @return A point representing the current size of the viewport.
|
| */
|
| - public PointF getViewportSize() {
|
| + private PointF getViewportSize() {
|
| float adjustedScreenWidth, adjustedScreenHeight;
|
| synchronized (mRenderData) {
|
| - adjustedScreenWidth = mRenderData.screenWidth - mInputMethodOffsetX;
|
| - adjustedScreenHeight = mRenderData.screenHeight - mInputMethodOffsetY;
|
| + adjustedScreenWidth =
|
| + mRenderData.screenWidth - mSystemUiOffsetPx.right - mSystemUiOffsetPx.left;
|
| + adjustedScreenHeight =
|
| + mRenderData.screenHeight - mSystemUiOffsetPx.top - mSystemUiOffsetPx.bottom;
|
| }
|
|
|
| return new PointF(adjustedScreenWidth, adjustedScreenHeight);
|
| }
|
|
|
| + /**
|
| + * Sets the offset values used to calculate the space used by system UI.
|
| + *
|
| + * @param left The space used by system UI on the left edge of the screen.
|
| + * @param top The space used by system UI on the top edge of the screen.
|
| + * @param right The space used by system UI on the right edge of the screen.
|
| + * @param bottom The space used by system UI on the bottom edge of the screen.
|
| + */
|
| + public void setSystemUiOffsetValues(int left, int top, int right, int bottom) {
|
| + synchronized (mRenderData) {
|
| + mSystemUiOffsetPx.set(left, top, right, bottom);
|
| + }
|
| + }
|
| +
|
| /** Repositions the image by zooming it such that the image is displayed without borders. */
|
| public void resizeImageToFitScreen() {
|
| synchronized (mRenderData) {
|
| @@ -120,7 +163,7 @@ public class DesktopCanvas {
|
| * center position before being adjusted to fit the screen boundaries.
|
| */
|
| public void repositionImage(boolean centerViewport) {
|
| - PointF adjustedViewportSize = getViewportSize();
|
| + PointF viewportSize = getViewportSize();
|
| synchronized (mRenderData) {
|
| // 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.
|
| @@ -133,8 +176,8 @@ public class DesktopCanvas {
|
|
|
| // 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]);
|
| + ((float) viewportSize.x / 2) + mSystemUiOffsetPx.left - viewportPosition[0],
|
| + ((float) viewportSize.y / 2) + mSystemUiOffsetPx.top - viewportPosition[1]);
|
| }
|
|
|
| // Get the coordinates of the desktop rectangle (top-left/bottom-right corners) in
|
| @@ -142,14 +185,15 @@ public class DesktopCanvas {
|
| RectF rectScreen = new RectF(0, 0, mRenderData.imageWidth, mRenderData.imageHeight);
|
| mRenderData.transform.mapRect(rectScreen);
|
|
|
| - float leftDelta = rectScreen.left;
|
| - float rightDelta = rectScreen.right - mRenderData.screenWidth + mInputMethodOffsetX;
|
| - float topDelta = rectScreen.top;
|
| - float bottomDelta = rectScreen.bottom - mRenderData.screenHeight + mInputMethodOffsetY;
|
| + float leftDelta = rectScreen.left - mSystemUiOffsetPx.left;
|
| + float rightDelta = rectScreen.right - mRenderData.screenWidth + mSystemUiOffsetPx.right;
|
| + float topDelta = rectScreen.top - mSystemUiOffsetPx.top;
|
| + float bottomDelta =
|
| + rectScreen.bottom - mRenderData.screenHeight + mSystemUiOffsetPx.bottom;
|
| float xAdjust = 0;
|
| float yAdjust = 0;
|
|
|
| - if (rectScreen.right - rectScreen.left < adjustedViewportSize.x) {
|
| + if (rectScreen.right - rectScreen.left < viewportSize.x) {
|
| // Image is narrower than the screen, so center it.
|
| xAdjust = -(rightDelta + leftDelta) / 2;
|
| } else if (leftDelta > 0 && rightDelta > 0) {
|
| @@ -161,7 +205,7 @@ public class DesktopCanvas {
|
| }
|
|
|
| // Apply similar logic for yAdjust.
|
| - if (rectScreen.bottom - rectScreen.top < adjustedViewportSize.y) {
|
| + if (rectScreen.bottom - rectScreen.top < viewportSize.y) {
|
| yAdjust = -(bottomDelta + topDelta) / 2;
|
| } else if (topDelta > 0 && bottomDelta > 0) {
|
| yAdjust = -Math.min(topDelta, bottomDelta);
|
|
|