Bug 1416319 - 5. Update DynamicToolbarAnimator usage in other classes; r=rbarker

Use DynamicToolbarAnimator through the session in places where we need
to interact with the toolbar or get the current toolbar height.

MozReview-Commit-ID: PdGX4FEHp5

--HG--
extra : rebase_source : 825fc70b584eb4b75f0ce9bd21a36c68f700c8c2
This commit is contained in:
Jim Chen 2017-11-22 14:12:22 -05:00
parent 5686bed431
commit dc678eed57
9 changed files with 39 additions and 23 deletions

View File

@ -1738,7 +1738,7 @@ public class BrowserApp extends GeckoApp
if (mLayerView != null && height != mToolbarHeight) {
mToolbarHeight = height;
mLayerView.setMaxToolbarHeight(height);
mLayerView.getDynamicToolbarAnimator().setMaxToolbarHeight(height);
mDynamicToolbar.setVisible(true, VisibilityTransition.IMMEDIATE);
}
}

View File

@ -2,7 +2,6 @@ package org.mozilla.gecko;
import org.mozilla.gecko.PrefsHelper.PrefHandlerBase;
import org.mozilla.gecko.gfx.DynamicToolbarAnimator.PinReason;
import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.util.ThreadUtils;
import android.os.Build;
@ -25,7 +24,7 @@ public class DynamicToolbar {
private final boolean forceDisabled;
private final PrefsHelper.PrefHandler prefObserver;
private LayerView layerView;
private GeckoView layerView;
private OnEnabledChangedListener enabledChangedListener;
private boolean temporarilyVisible;
@ -77,7 +76,7 @@ public class DynamicToolbar {
PrefsHelper.removeObserver(prefObserver);
}
public void setLayerView(LayerView layerView) {
public void setLayerView(GeckoView layerView) {
ThreadUtils.assertOnUiThread();
this.layerView = layerView;

View File

@ -254,7 +254,7 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
}
private void positionAndShowPopup() {
positionAndShowPopup(mGeckoView.getViewportMetrics());
positionAndShowPopup(mGeckoView.getSession().getViewportMetrics());
}
private void positionAndShowPopup(ImmutableViewportMetrics aMetrics) {
@ -288,7 +288,7 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
// display the FormAssistPopup.
int left = (int) (mX * zoom - aMetrics.viewportRectLeft);
int top = (int) (mY * zoom - aMetrics.viewportRectTop + mGeckoView.getTop() +
mGeckoView.getCurrentToolbarHeight());
mGeckoView.getDynamicToolbarAnimator().getCurrentToolbarHeight());
int width = (int) (mW * zoom);
int height = (int) (mH * zoom);

View File

@ -176,7 +176,7 @@ public class GeckoAccessibility {
sVirtualCursorNode.setBoundsInParent(relativeBounds);
int[] locationOnScreen = new int[2];
view.getLocationOnScreen(locationOnScreen);
locationOnScreen[1] += view.getCurrentToolbarHeight();
locationOnScreen[1] += view.getDynamicToolbarAnimator().getCurrentToolbarHeight();
Rect screenBounds = new Rect(relativeBounds);
screenBounds.offset(locationOnScreen[0], locationOnScreen[1]);
sVirtualCursorNode.setBoundsInScreen(screenBounds);

View File

@ -173,8 +173,8 @@ public class FloatingToolbarTextSelection implements TextSelection, BundleEventL
final double width = (int) message.getDouble("width");
final double height = (int) message.getDouble("height");
final float toolbarOffset = geckoView.getCurrentToolbarHeight();
final float zoomFactor = geckoView.getZoomFactor();
final float toolbarOffset = geckoView.getDynamicToolbarAnimator().getCurrentToolbarHeight();
final float zoomFactor = geckoView.getSession().getViewportMetrics().zoomFactor;
geckoView.getLocationInWindow(locationInWindow);
contentRect = new Rect(

View File

@ -235,7 +235,7 @@ class GeckoInputConnection
v.requestFocus();
}
final GeckoView view = getView();
if (view != null) {
if (view != null && view.getSession() != null) {
if (showToolbar) {
view.getDynamicToolbarAnimator().showToolbar(/*immediately*/ true);
}
@ -364,12 +364,12 @@ class GeckoInputConnection
// Calculate Gecko logical coords to screen coords
final GeckoView view = getView();
if (view == null) {
if (view == null || view.getSession() == null) {
return;
}
// First aRects element is the widget bounds in device units.
final float zoom = view.getZoomFactor();
final float zoom = view.getSession().getViewportMetrics().zoomFactor;
final Matrix matrix = new Matrix();
matrix.postScale(zoom, zoom);
matrix.postTranslate(aRects[0].left, aRects[0].top);

View File

@ -155,6 +155,7 @@ public class LayerView extends FrameLayout {
mCompositor.enableLayerUpdateNotifications(!mDrawListeners.isEmpty());
}
/* protected */ LayerSession mSession;
private LayerSession.Compositor mCompositor;
public LayerView(Context context, AttributeSet attrs) {
@ -213,7 +214,7 @@ public class LayerView extends FrameLayout {
// We must have a layer client to get valid viewport metrics
if (mOverscroll != null) {
mOverscroll.draw(canvas, getViewportMetrics());
mOverscroll.draw(canvas, mSession.getViewportMetrics());
}
}
@ -321,6 +322,7 @@ public class LayerView extends FrameLayout {
}
protected void attachCompositor(final LayerSession session) {
mSession = session;
mCompositor = session.mCompositor;
mCompositor.layerView = this;

View File

@ -112,7 +112,9 @@ class NativePanZoomController extends JNIObject implements PanZoomController {
event.getPointerCoords(0, coords);
final float x = coords.x;
// Scroll events are not adjusted by the AndroidDyanmicToolbarAnimator so adjust the offset here.
final float y = coords.y - mView.getCurrentToolbarHeight();
final int toolbarHeight = (mView.mSession != null) ?
mView.mSession.getDynamicToolbarAnimator().getCurrentToolbarHeight() : 0;
final float y = coords.y - toolbarHeight;
final float hScroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL) *
mPointerScrollFactor;
@ -138,7 +140,9 @@ class NativePanZoomController extends JNIObject implements PanZoomController {
final float x = coords.x;
// Mouse events are not adjusted by the AndroidDyanmicToolbarAnimator so adjust the offset
// here.
final float y = coords.y - mView.getCurrentToolbarHeight();
final int toolbarHeight = (mView.mSession != null) ?
mView.mSession.getDynamicToolbarAnimator().getCurrentToolbarHeight() : 0;
final float y = coords.y - toolbarHeight;
return handleMouseEvent(event.getActionMasked(), event.getEventTime(), event.getMetaState(), x, y, event.getButtonState());
}
@ -260,8 +264,17 @@ class NativePanZoomController extends JNIObject implements PanZoomController {
* to avoid unwanted scroll interactions.
*/
@WrapForJNI(calledFrom = "gecko")
private void onSelectionDragState(boolean state) {
mView.getDynamicToolbarAnimator().setPinned(state, PinReason.CARET_DRAG);
private void onSelectionDragState(final boolean state) {
final LayerView view = mView;
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {
if (view.mSession != null) {
view.mSession.getDynamicToolbarAnimator()
.setPinned(state, PinReason.CARET_DRAG);
}
}
});
}
private static class PointerInfo {

View File

@ -119,12 +119,14 @@ public class OverscrollEdgeEffect implements Overscroll {
@Override
public void draw(final Canvas canvas, final ImmutableViewportMetrics metrics) {
if (metrics == null) {
if (metrics == null || mView.mSession == null) {
return;
}
PointF visibleEnd = mView.getDynamicToolbarAnimator().getVisibleEndOfLayerView();
float toolbarEnd = (float)mView.getDynamicToolbarAnimator().getCurrentToolbarHeight();
final float width = mView.getWidth();
final float height = mView.getHeight();
final float toolbarEnd = mView.mSession.getDynamicToolbarAnimator()
.getCurrentToolbarHeight();
// If we're pulling an edge, or fading it out, draw!
boolean invalidate = false;
@ -133,15 +135,15 @@ public class OverscrollEdgeEffect implements Overscroll {
}
if (!mEdges[BOTTOM].isFinished()) {
invalidate |= draw(mEdges[BOTTOM], canvas, visibleEnd.x, visibleEnd.y, 180);
invalidate |= draw(mEdges[BOTTOM], canvas, width, height, 180);
}
if (!mEdges[LEFT].isFinished()) {
invalidate |= draw(mEdges[LEFT], canvas, 0, visibleEnd.y, 270);
invalidate |= draw(mEdges[LEFT], canvas, 0, height, 270);
}
if (!mEdges[RIGHT].isFinished()) {
invalidate |= draw(mEdges[RIGHT], canvas, visibleEnd.x, 0, 90);
invalidate |= draw(mEdges[RIGHT], canvas, width, 0, 90);
}
// If the edge effect is animating off screen, invalidate.