diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-04-09 17:27:31 +0900 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-04-13 09:07:03 +0200 |
commit | 7f0dfb3ae67bd8ce64fbbea3b418071faee1a6a0 (patch) | |
tree | a334d710e402d07b561e012039f10fa17fe6cc79 /android | |
parent | 207142748b095252f5c9bfd1b418a892823304d0 (diff) |
android: tune the viewport moving to cursor position on key input
Change-Id: Ie420307f28cc05ca03fabe47f46712f67c6f18fa
Diffstat (limited to 'android')
3 files changed, 43 insertions, 10 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java index 9f83006bc785..1fdc681e11ca 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java @@ -8,6 +8,8 @@ import android.net.Uri; import org.libreoffice.canvas.SelectionHandle; import org.libreoffice.kit.Document; import org.libreoffice.overlay.DocumentOverlay; +import org.mozilla.gecko.gfx.GeckoLayerClient; +import org.mozilla.gecko.gfx.ImmutableViewportMetrics; import java.util.ArrayList; import java.util.Collections; @@ -19,11 +21,13 @@ import java.util.List; public class InvalidationHandler implements Document.MessageCallback { private static String LOGTAG = InvalidationHandler.class.getSimpleName(); private final DocumentOverlay mDocumentOverlay; + private final GeckoLayerClient mLayerClient; private OverlayState mState; private boolean mKeyEvent = false; public InvalidationHandler(LibreOfficeMainActivity mainActivity) { mDocumentOverlay = mainActivity.getDocumentOverlay(); + mLayerClient = mainActivity.getLayerClient(); mState = OverlayState.NONE; } @@ -153,8 +157,7 @@ public class InvalidationHandler implements Document.MessageCallback { mDocumentOverlay.positionHandle(SelectionHandle.HandleType.MIDDLE, cursorRectangle); if (mKeyEvent) { - PointF point = new PointF(cursorRectangle.centerX(), cursorRectangle.centerY()); - LOKitShell.moveViewportTo(point, null); + moveViewportToMakeCursorVisible(cursorRectangle); mKeyEvent = false; } @@ -165,6 +168,37 @@ public class InvalidationHandler implements Document.MessageCallback { } /** + * Move the viewport to show the cursor. The cursor will appear at the + * viewport position depending on where the cursor is relative to the + * viewport (either cursor is above, below, on left or right). + * + * @param cursorRectangle - cursor position on the document + */ + public void moveViewportToMakeCursorVisible(RectF cursorRectangle) { + RectF moveToRect = mLayerClient.getViewportMetrics().getCssViewport(); + if (moveToRect.contains(cursorRectangle)) { + return; + } + + float newLeft = moveToRect.left; + float newTop = moveToRect.top; + + if (cursorRectangle.right < moveToRect.left || cursorRectangle.left < moveToRect.left) { + newLeft = cursorRectangle.left - (moveToRect.width() * 0.1f); + } else if (cursorRectangle.right > moveToRect.right || cursorRectangle.left > moveToRect.right) { + newLeft = cursorRectangle.right - (moveToRect.width() * 0.9f); + } + + if (cursorRectangle.top < moveToRect.top || cursorRectangle.bottom < moveToRect.top) { + newTop = cursorRectangle.top - (moveToRect.height() * 0.1f); + } else if (cursorRectangle.bottom > moveToRect.bottom || cursorRectangle.top > moveToRect.bottom) { + newTop = cursorRectangle.bottom - (moveToRect.height() / 2.0f); + } + + LOKitShell.moveViewportTo(new PointF(newLeft, newTop), null); + } + + /** * Handles the text selection start message * * @param payload diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java index 99f994864234..d9a20d8acf35 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java @@ -158,7 +158,7 @@ public class LOKitShell { } /** - * Move the viewport to the desired point, and change the zoom level. + * Move the viewport to the desired point (top-left), and change the zoom level. * Ensure this runs on the UI thread. */ public static void moveViewportTo(final PointF position, final Float zoom) { diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java index f758681a4515..f8b39b4f1453 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java @@ -418,7 +418,7 @@ public class JavaPanZoomController } else { setState(PanZoomState.PANNING); } - LibreOfficeMainActivity.mAppContext.hideSoftKeyboard(); + //LibreOfficeMainActivity.mAppContext.hideSoftKeyboard(); } private float panDistance(MotionEvent move) { @@ -1023,16 +1023,15 @@ public class JavaPanZoomController } /** - * Move to centerPosition and zoom to the desired input zoom factor. Input zoom - * factor can be null, in this case leave the zoom unchanged. + * Move the viewport to the top-left point to and zoom to the desired + * zoom factor. Input zoom factor can be null, in this case leave the zoom unchanged. */ - public boolean animatedMove(PointF centerPoint, Float zoom) { + public boolean animatedMove(PointF topLeft, Float zoom) { RectF moveToRect = getMetrics().getCssViewport(); - moveToRect.offsetTo( - centerPoint.x - moveToRect.width() / 2.0f, - centerPoint.y - moveToRect.height() / 2.0f); + moveToRect.offsetTo(topLeft.x, topLeft.y); ImmutableViewportMetrics finalMetrics = getMetrics(); + finalMetrics = finalMetrics.setViewportOrigin( moveToRect.left * finalMetrics.zoomFactor, moveToRect.top * finalMetrics.zoomFactor); |