Kaydet (Commit) 7f0dfb3a authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Miklos Vajna

android: tune the viewport moving to cursor position on key input

Change-Id: Ie420307f28cc05ca03fabe47f46712f67c6f18fa
üst 20714274
......@@ -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;
}
......@@ -164,6 +167,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
*
......
......@@ -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) {
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment