[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - android/experimental

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Thu Apr 9 01:32:40 PDT 2015


 android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java         |   38 +++++++++-
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java                  |    2 
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java |   13 +--
 3 files changed, 43 insertions(+), 10 deletions(-)

New commits:
commit 47bf36924c5f156cee40aa31f341015c66765c6a
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Thu Apr 9 17:27:31 2015 +0900

    android: tune the viewport moving to cursor position on key input
    
    Change-Id: Ie420307f28cc05ca03fabe47f46712f67c6f18fa

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
index 9f83006..1fdc681 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 99f9948..d9a20d8 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 f758681..f8b39b4 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);


More information about the Libreoffice-commits mailing list