--- a/mobile/android/base/java/org/mozilla/gecko/ZoomedView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/ZoomedView.java
@@ -2,16 +2,17 @@
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
import org.mozilla.gecko.animation.ViewHelper;
import org.mozilla.gecko.annotation.WrapForJNI;
+import org.mozilla.gecko.gfx.DynamicToolbarAnimator;
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.gfx.PanZoomController;
import org.mozilla.gecko.gfx.PointUtils;
import org.mozilla.gecko.mozglue.DirectBufferAllocator;
import org.mozilla.gecko.PrefsHelper;
import org.mozilla.gecko.util.BundleEventListener;
import org.mozilla.gecko.util.EventCallback;
@@ -44,17 +45,17 @@ import android.view.animation.ScaleAnima
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.nio.ByteBuffer;
import java.text.DecimalFormat;
-public class ZoomedView extends FrameLayout implements LayerView.DynamicToolbarListener,
+public class ZoomedView extends FrameLayout implements DynamicToolbarAnimator.MetricsListener,
LayerView.ZoomedViewListener, BundleEventListener {
private static final String LOGTAG = "Gecko" + ZoomedView.class.getSimpleName();
private static final float[] ZOOM_FACTORS_LIST = {2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 1.5f};
private static final int W_CAPTURED_VIEW_IN_PERCENT = 50;
private static final int H_CAPTURED_VIEW_IN_PERCENT = 50;
private static final int MINIMUM_DELAY_BETWEEN_TWO_RENDER_CALLS_NS = 1000000;
private static final int DELAY_BEFORE_NEXT_RENDER_REQUEST_MS = 2000;
@@ -161,34 +162,34 @@ public class ZoomedView extends FrameLay
} else {
if (isClickInZoomedView(event.getY())) {
GeckoAppShell.notifyObservers("Gesture:ClickInZoomedView", "");
layerView.dispatchTouchEvent(actionDownEvent);
actionDownEvent.recycle();
PointF convertedPosition = getUnzoomedPositionFromPointInZoomedView(event.getX(), event.getY());
// the LayerView expects the coordinates relative to the window, not the surface, so we need
// to adjust that here.
- convertedPosition.y += layerView.getSurfaceTranslation();
+ convertedPosition.y += layerView.getCurrentToolbarHeight();
MotionEvent e = MotionEvent.obtain(event.getDownTime(), event.getEventTime(),
MotionEvent.ACTION_UP, convertedPosition.x, convertedPosition.y,
event.getMetaState());
layerView.dispatchTouchEvent(e);
e.recycle();
}
}
break;
case MotionEvent.ACTION_DOWN:
dragged = false;
originRawX = event.getRawX();
originRawY = event.getRawY();
PointF convertedPosition = getUnzoomedPositionFromPointInZoomedView(event.getX(), event.getY());
// the LayerView expects the coordinates relative to the window, not the surface, so we need
// to adjust that here.
- convertedPosition.y += layerView.getSurfaceTranslation();
+ convertedPosition.y += layerView.getCurrentToolbarHeight();
actionDownEvent = MotionEvent.obtain(event.getDownTime(), event.getEventTime(),
MotionEvent.ACTION_DOWN, convertedPosition.x, convertedPosition.y,
event.getMetaState());
break;
}
return true;
}
@@ -353,17 +354,17 @@ public class ZoomedView extends FrameLay
// edge.
float zoomedContentOffset = ((float)params.leftMargin) * maxContentOffset / maxZoomedViewOffset;
returnValue.x = (int)(zoomedContentOffset + (x / zoomFactor));
// Same comments here vertically
visibleContentPixels = viewHeight / zoomFactor;
maxContentOffset = parentHeight - visibleContentPixels;
maxZoomedViewOffset = parentHeight - (viewContainerHeight - toolbarHeight);
- float zoomedAreaOffset = (float)params.topMargin + offsetDueToToolBarPosition - layerView.getSurfaceTranslation();
+ float zoomedAreaOffset = (float)params.topMargin + offsetDueToToolBarPosition - layerView.getCurrentToolbarHeight();
zoomedContentOffset = zoomedAreaOffset * maxContentOffset / maxZoomedViewOffset;
returnValue.y = (int)(zoomedContentOffset + ((y - offsetDueToToolBarPosition) / zoomFactor));
return returnValue;
}
/*
* A touch point (x,y) occurs in LayerView, this point should be displayed
@@ -383,28 +384,28 @@ public class ZoomedView extends FrameLay
float maxZoomedViewOffset = parentWidth - viewContainerWidth;
float contentPixelOffset = x - (visibleContentPixels / 2.0f);
returnValue.x = (int)(contentPixelOffset * (maxZoomedViewOffset / maxContentOffset));
visibleContentPixels = viewHeight / zoomFactor;
maxContentOffset = parentHeight - visibleContentPixels;
maxZoomedViewOffset = parentHeight - (viewContainerHeight - toolbarHeight);
contentPixelOffset = y - (visibleContentPixels / 2.0f);
- float unscaledViewOffset = layerView.getSurfaceTranslation() - offsetDueToToolBarPosition;
+ float unscaledViewOffset = layerView.getCurrentToolbarHeight() - offsetDueToToolBarPosition;
returnValue.y = (int)((contentPixelOffset * (maxZoomedViewOffset / maxContentOffset)) + unscaledViewOffset);
return returnValue;
}
private void moveZoomedView(ImmutableViewportMetrics metrics, float newLeftMargin, float newTopMargin,
StartPointUpdate animateStartPoint) {
RelativeLayout.LayoutParams newLayoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
newLayoutParams.leftMargin = (int) newLeftMargin;
newLayoutParams.topMargin = (int) newTopMargin;
- int topMarginMin = (int)(layerView.getSurfaceTranslation() + dynamicToolbarOverlap);
+ int topMarginMin = (int)(layerView.getCurrentToolbarHeight() + dynamicToolbarOverlap);
int topMarginMax = layerView.getHeight() - viewContainerHeight;
int leftMarginMin = 0;
int leftMarginMax = layerView.getWidth() - viewContainerWidth;
if (newTopMargin < topMarginMin) {
newLayoutParams.topMargin = topMarginMin;
} else if (newTopMargin > topMarginMax) {
newLayoutParams.topMargin = topMarginMax;
@@ -562,45 +563,45 @@ public class ZoomedView extends FrameLay
private void startZoomDisplay(LayerView aLayerView, final int leftFromGecko, final int topFromGecko) {
if (isBlockedFromAppearing) {
return;
}
if (layerView == null) {
layerView = aLayerView;
layerView.addZoomedViewListener(this);
- layerView.getDynamicToolbarAnimator().addTranslationListener(this);
+ layerView.getDynamicToolbarAnimator().addMetricsListener(this);
ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
setCapturedSize(metrics);
}
startTimeReRender = 0;
shouldSetVisibleOnUpdate = true;
ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
// At this point, the start point is relative to the layerView.
// Later, it will be converted relative to the zoomed view as soon as
// the position of the zoomed view will be calculated.
animationStart.x = (float) leftFromGecko * metrics.zoomFactor;
- animationStart.y = (float) topFromGecko * metrics.zoomFactor + layerView.getSurfaceTranslation();
+ animationStart.y = (float) topFromGecko * metrics.zoomFactor + layerView.getCurrentToolbarHeight();
moveUsingGeckoPosition(leftFromGecko, topFromGecko);
}
public void stopZoomDisplay(boolean withAnimation) {
// If "startZoomDisplay" is running and not totally completed (Gecko thread is still
// running and "showZoomedView" has not yet been called), the zoomed view will be
// displayed after this call and it should not.
// Force the stop of the zoomed view, changing the shouldSetVisibleOnUpdate flag
// before the test of the visibility.
shouldSetVisibleOnUpdate = false;
if (getVisibility() == View.VISIBLE) {
hideZoomedView(withAnimation);
ThreadUtils.removeCallbacksFromUiThread(requestRenderRunnable);
if (layerView != null) {
- layerView.getDynamicToolbarAnimator().removeTranslationListener(this);
+ layerView.getDynamicToolbarAnimator().removeMetricsListener(this);
layerView.removeZoomedViewListener(this);
layerView = null;
}
}
}
private void changeZoomFactor(boolean zoomIn) {
if (zoomIn && currentZoomFactorIndex < ZOOM_FACTORS_LIST.length - 1) {
@@ -656,43 +657,30 @@ public class ZoomedView extends FrameLay
// correctly center vertically the zoomed area
moveToolbar((topFromGecko * metrics.zoomFactor > parentHeight / 2));
PointF convertedPosition = getZoomedViewTopLeftPositionFromTouchPosition((leftFromGecko * metrics.zoomFactor),
(topFromGecko * metrics.zoomFactor));
moveZoomedView(metrics, convertedPosition.x, convertedPosition.y, StartPointUpdate.GECKO_POSITION);
}
@Override
- public void onTranslationChanged(float aToolbarTranslation, float aLayerViewTranslation) {
- ThreadUtils.assertOnUiThread();
- if (layerView != null) {
- dynamicToolbarOverlap = aLayerViewTranslation - aToolbarTranslation;
- refreshZoomedViewSize(layerView.getViewportMetrics());
- }
- }
-
- @Override
public void onMetricsChanged(final ImmutableViewportMetrics viewport) {
// It can be called from a Gecko thread (forceViewportMetrics in GeckoLayerClient).
// Post to UI Thread to avoid Exception:
// "Only the original thread that created a view hierarchy can touch its views."
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {
shouldBlockUpdate(false);
refreshZoomedViewSize(viewport);
}
});
}
@Override
- public void onPanZoomStopped() {
- }
-
- @Override
public void updateView(ByteBuffer data) {
final Bitmap sb3 = Bitmap.createBitmap(viewWidth, viewHeight, getBitmapConfig());
if (sb3 != null) {
data.rewind();
try {
sb3.copyPixelsFromBuffer(data);
} catch (Exception iae) {
Log.w(LOGTAG, iae.toString());