summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToma┼ż Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-04-08 18:21:11 +0900
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-04-13 09:07:02 +0200
commit20382895558479a7a89a9893c2379b5dbdb0a64f (patch)
treea32c1b049a71754039e96be3b3cf365f1a4d41a8
parent6cbcde026784ab279e2ea2e03d65e992fb7cb110 (diff)
android: add possibility to move the viewport and zoom + animation
Change-Id: I294ad30b1fdd7f1a3d5099304cc4f077034567b7
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java13
-rw-r--r--android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java9
-rw-r--r--android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java24
3 files changed, 46 insertions, 0 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
index 38c13ca345f6..99f994864234 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
@@ -156,6 +156,19 @@ public class LOKitShell {
public static void sendNavigationClickEvent() {
LOKitShell.sendEvent(new LOEvent(LOEvent.NAVIGATION_CLICK));
}
+
+ /**
+ * Move the viewport to the desired point, and change the zoom level.
+ * Ensure this runs on the UI thread.
+ */
+ public static void moveViewportTo(final PointF position, final Float zoom) {
+ getLayerView().getLayerClient().post(new Runnable() {
+ @Override
+ public void run() {
+ getLayerView().getLayerClient().moveTo(position, zoom);
+ }
+ });
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
index 40fb8bb9c926..bb6e3d04e4fb 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
@@ -324,6 +324,15 @@ public class GeckoLayerClient implements PanZoomTarget {
}
}
+ /**
+ * Move the viewport to the desired point, and change the zoom level.
+ */
+ public void moveTo(PointF point, Float zoom) {
+ if (mPanZoomController instanceof JavaPanZoomController) {
+ ((JavaPanZoomController) mPanZoomController).animatedMove(point, zoom);
+ }
+ }
+
public void zoomTo(float pageWidth, float pageHeight) {
zoomTo(new RectF(0, 0, pageWidth, pageHeight));
}
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 adae23a428fe..0811c26105a1 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
@@ -1021,6 +1021,30 @@ public class JavaPanZoomController
return true;
}
+ /**
+ * Move to centerPosition and zoom to the desired input zoom factor. Input zoom
+ * factor can be null, in this case leave the zoom unchanged.
+ */
+ public boolean animatedMove(PointF centerPoint, Float zoom) {
+ RectF moveToRect = getMetrics().getCssViewport();
+ moveToRect.offsetTo(
+ centerPoint.x - moveToRect.width() / 2.0f,
+ centerPoint.y - moveToRect.height() / 2.0f);
+
+ ImmutableViewportMetrics finalMetrics = getMetrics();
+ finalMetrics = finalMetrics.setViewportOrigin(
+ moveToRect.left * finalMetrics.zoomFactor,
+ moveToRect.top * finalMetrics.zoomFactor);
+
+ if (zoom != null) {
+ finalMetrics = finalMetrics.scaleTo(zoom, new PointF(0.0f, 0.0f));
+ }
+ finalMetrics = getValidViewportMetrics(finalMetrics);
+
+ bounce(finalMetrics, PanZoomState.ANIMATED_ZOOM);
+ return true;
+ }
+
/** This function must be called from the UI thread. */
public void abortPanning() {
checkMainThread();