Bug 1302452 - Rip out the filler view inside LayerView since we don't support older Android versions any more. r=rbarker
☠☠ backed out by cec9f17302db ☠ ☠
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 13 Sep 2016 11:13:35 -0400
changeset 355117 2b996739ade25a2d6cf3fb5ad6f2af1aa1e2fe88
parent 355116 40663c31d2d6bd122ab90dc4b76376102b75d821
child 355118 cec9f17302dbc776fa3a43c3a3c81e7fee873f0f
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker
bugs1302452
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1302452 - Rip out the filler view inside LayerView since we don't support older Android versions any more. r=rbarker MozReview-Commit-ID: 5LrWNHmnUR5
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/OverscrollEdgeEffect.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.gfx;
 
 import java.nio.ByteBuffer;
 import java.nio.IntBuffer;
 
 import org.mozilla.gecko.AndroidGamepadManager;
+import org.mozilla.gecko.animation.ViewHelper;
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.annotation.WrapForJNI;
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.AppConstants.Versions;
 import org.mozilla.gecko.EventDispatcher;
 import org.mozilla.gecko.GeckoAccessibility;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoThread;
@@ -36,41 +37,37 @@ import android.util.AttributeSet;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.SurfaceHolder;
 import android.view.SurfaceView;
 import android.view.TextureView;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.InputDevice;
-import android.widget.LinearLayout;
-import android.widget.ScrollView;
+import android.widget.FrameLayout;
 
 /**
  * A view rendered by the layer compositor.
  */
-public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener {
+public class LayerView extends FrameLayout implements Tabs.OnTabsChangedListener {
     private static final String LOGTAG = "GeckoLayerView";
 
     private GeckoLayerClient mLayerClient;
     private PanZoomController mPanZoomController;
     private DynamicToolbarAnimator mToolbarAnimator;
     private LayerRenderer mRenderer;
     /* Must be a PAINT_xxx constant */
     private int mPaintState;
     private FullScreenState mFullScreenState;
 
     private SurfaceView mSurfaceView;
     private TextureView mTextureView;
-    private View mFillerView;
 
     private Listener mListener;
 
-    private float mSurfaceTranslation;
-
     /* This should only be modified on the Java UI thread. */
     private final Overscroll mOverscroll;
 
     private boolean mServerSurfaceValid;
     private int mWidth, mHeight;
 
     private boolean onAttachedToWindowCalled;
 
@@ -239,17 +236,16 @@ public class LayerView extends ScrollVie
         }
     }
 
     @Override
     public boolean onTouchEvent(MotionEvent event) {
         if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
             requestFocus();
         }
-        event.offsetLocation(0, -mSurfaceTranslation);
 
         if (mToolbarAnimator != null && mToolbarAnimator.onInterceptTouchEvent(event)) {
             if (mPanZoomController != null) {
                 mPanZoomController.onMotionEventVelocity(event.getEventTime(), mToolbarAnimator.getVelocity());
             }
             return true;
         }
         if (!mLayerClient.isGeckoReady()) {
@@ -267,33 +263,29 @@ public class LayerView extends ScrollVie
     public boolean onHoverEvent(MotionEvent event) {
         // If we get a touchscreen hover event, and accessibility is not enabled,
         // don't send it to gecko.
         if (event.getSource() == InputDevice.SOURCE_TOUCHSCREEN &&
             !GeckoAccessibility.isEnabled()) {
             return false;
         }
 
-        event.offsetLocation(0, -mSurfaceTranslation);
-
         if (!mLayerClient.isGeckoReady()) {
             // If gecko isn't loaded yet, don't try sending events to the
             // native code because it's just going to crash
             return true;
         } else if (mPanZoomController != null && mPanZoomController.onMotionEvent(event)) {
             return true;
         }
 
         return false;
     }
 
     @Override
     public boolean onGenericMotionEvent(MotionEvent event) {
-        event.offsetLocation(0, -mSurfaceTranslation);
-
         if (AndroidGamepadManager.handleMotionEvent(event)) {
             return true;
         }
         if (!mLayerClient.isGeckoReady()) {
             // If gecko isn't loaded yet, don't try sending events to the
             // native code because it's just going to crash
             return true;
         }
@@ -335,35 +327,17 @@ public class LayerView extends ScrollVie
             addView(mTextureView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
         } else {
             // This will stop PropertyAnimator from creating a drawing cache (i.e. a bitmap)
             // from a SurfaceView, which is just not possible (the bitmap will be transparent).
             setWillNotCacheDrawing(false);
 
             mSurfaceView = new LayerSurfaceView(getContext(), this);
             mSurfaceView.setBackgroundColor(Color.WHITE);
-
-            // The "filler" view sits behind the URL bar and should never be
-            // visible. It exists solely to make this LayerView actually
-            // scrollable so that we can shift the surface around on the screen.
-            // Once we drop support for pre-Honeycomb Android versions this
-            // should not be needed; we can just turn LayerView back into a
-            // FrameLayout that holds mSurfaceView and nothing else.
-            mFillerView = new View(getContext()) {
-                @Override protected void onMeasure(int aWidthSpec, int aHeightSpec) {
-                    setMeasuredDimension(0, Math.round(mToolbarAnimator.getMaxTranslation()));
-                }
-            };
-            mFillerView.setBackgroundColor(Color.RED);
-
-            LinearLayout container = new LinearLayout(getContext());
-            container.setOrientation(LinearLayout.VERTICAL);
-            container.addView(mFillerView);
-            container.addView(mSurfaceView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
-            addView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+            addView(mSurfaceView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
 
             SurfaceHolder holder = mSurfaceView.getHolder();
             holder.addCallback(new SurfaceListener());
         }
 
         attachCompositor();
 
         onAttachedToWindowCalled = true;
@@ -619,55 +593,27 @@ public class LayerView extends ScrollVie
         }
 
         @Override
         public void surfaceDestroyed(SurfaceHolder holder) {
             onDestroyed();
         }
     }
 
-    @Override
-    protected void onMeasure(int aWidthSpec, int aHeightSpec) {
-        super.onMeasure(aWidthSpec, aHeightSpec);
-        if (mSurfaceView != null) {
-            // Because of the crazy setup where this LayerView is a ScrollView
-            // and the SurfaceView is inside a LinearLayout, the SurfaceView
-            // doesn't get the right information to size itself the way we want.
-            // We always want it to be the same size as this LayerView, so we
-            // use a hack to make sure it sizes itself that way.
-            ((LayerSurfaceView)mSurfaceView).overrideSize(getMeasuredWidth(), getMeasuredHeight());
-        }
-    }
-
     /* A subclass of SurfaceView to listen to layout changes, as
      * View.OnLayoutChangeListener requires API level 11.
      */
     private class LayerSurfaceView extends SurfaceView {
         private LayerView mParent;
-        private int mForcedWidth;
-        private int mForcedHeight;
 
         public LayerSurfaceView(Context aContext, LayerView aParent) {
             super(aContext);
             mParent = aParent;
         }
 
-        void overrideSize(int aWidth, int aHeight) {
-            if (mForcedWidth != aWidth || mForcedHeight != aHeight) {
-                mForcedWidth = aWidth;
-                mForcedHeight = aHeight;
-                requestLayout();
-            }
-        }
-
-        @Override
-        protected void onMeasure(int aWidthSpec, int aHeightSpec) {
-            setMeasuredDimension(mForcedWidth, mForcedHeight);
-        }
-
         @Override
         protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
             super.onLayout(changed, left, top, right, bottom);
             if (changed && mParent.mServerSurfaceValid) {
                 mParent.surfaceChanged(right - left, bottom - top);
             }
         }
     }
@@ -741,32 +687,24 @@ public class LayerView extends ScrollVie
     }
 
     public FullScreenState getFullScreenState() {
         return mFullScreenState;
     }
 
     public void setMaxTranslation(float aMaxTranslation) {
         mToolbarAnimator.setMaxTranslation(aMaxTranslation);
-        if (mFillerView != null) {
-            mFillerView.requestLayout();
-        }
     }
 
     public void setSurfaceTranslation(float translation) {
-        // Once we drop support for pre-Honeycomb Android versions, we can
-        // revert bug 1197811 and just use ViewHelper here.
-        if (mSurfaceTranslation != translation) {
-            mSurfaceTranslation = translation;
-            scrollTo(0, Math.round(mToolbarAnimator.getMaxTranslation() - translation));
-        }
+        ViewHelper.setTranslationY(this, translation);
     }
 
     public float getSurfaceTranslation() {
-        return mSurfaceTranslation;
+        return ViewHelper.getTranslationY(this);
     }
 
     @Override
     public void onTabChanged(Tab tab, Tabs.TabEvents msg, String data) {
         if (msg == Tabs.TabEvents.VIEWPORT_CHANGE && Tabs.getInstance().isSelectedTab(tab) && mLayerClient != null) {
             setIsRTL(tab.getIsRTL());
         }
     }
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/OverscrollEdgeEffect.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/OverscrollEdgeEffect.java
@@ -119,35 +119,34 @@ public class OverscrollEdgeEffect implem
     }
 
     @Override
     public void draw(final Canvas canvas, final ImmutableViewportMetrics metrics) {
         if (metrics == null) {
             return;
         }
 
-        float fillerSize = mView.getDynamicToolbarAnimator().getMaxTranslation();
         PointF visibleEnd = mView.getDynamicToolbarAnimator().getVisibleEndOfLayerView();
 
         // If we're pulling an edge, or fading it out, draw!
         boolean invalidate = false;
         if (!mEdges[TOP].isFinished()) {
-            invalidate |= draw(mEdges[TOP], canvas, 0, fillerSize, 0);
+            invalidate |= draw(mEdges[TOP], canvas, 0, 0, 0);
         }
 
         if (!mEdges[BOTTOM].isFinished()) {
-            invalidate |= draw(mEdges[BOTTOM], canvas, visibleEnd.x, fillerSize + visibleEnd.y, 180);
+            invalidate |= draw(mEdges[BOTTOM], canvas, visibleEnd.x, visibleEnd.y, 180);
         }
 
         if (!mEdges[LEFT].isFinished()) {
-            invalidate |= draw(mEdges[LEFT], canvas, 0, fillerSize + visibleEnd.y, 270);
+            invalidate |= draw(mEdges[LEFT], canvas, 0, visibleEnd.y, 270);
         }
 
         if (!mEdges[RIGHT].isFinished()) {
-            invalidate |= draw(mEdges[RIGHT], canvas, visibleEnd.x, fillerSize, 90);
+            invalidate |= draw(mEdges[RIGHT], canvas, visibleEnd.x, 0, 90);
         }
 
         // If the edge effect is animating off screen, invalidate.
         if (invalidate) {
             invalidate();
         }
     }