Bug 708687 - Snap the page when the page size changes and pushes it into overscroll. r=pcwalton
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 30 Jan 2012 23:43:36 -0500
changeset 87027 d935729476d9a41eb926ae75d834aaa050343081
parent 87026 e7a004ba490e15b9b83ae24a98bef66e67c56ef0
child 87028 2fdade6a758224c989211700fa2ab5733cb9f90d
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspcwalton
bugs708687
milestone12.0a1
Bug 708687 - Snap the page when the page size changes and pushes it into overscroll. r=pcwalton
mobile/android/base/gfx/LayerController.java
mobile/android/base/ui/PanZoomController.java
--- a/mobile/android/base/gfx/LayerController.java
+++ b/mobile/android/base/gfx/LayerController.java
@@ -239,17 +239,23 @@ public class LayerController {
         if (mViewportMetrics.getPageSize().fuzzyEquals(size))
             return;
 
         mViewportMetrics.setPageSize(size);
         Log.d(LOGTAG, "setPageSize: " + mViewportMetrics);
 
         // Page size is owned by the LayerClient, so no need to notify it of
         // this change.
-        mView.requestRender();
+
+        mView.post(new Runnable() {
+            public void run() {
+                mPanZoomController.pageSizeUpdated();
+                mView.requestRender();
+            }
+        });
     }
 
     /**
      * Sets the entire viewport metrics at once. This function does not notify the layer client or
      * the pan/zoom controller, so you will need to call notifyLayerClientOfGeometryChange() or
      * notifyPanZoomControllerOfGeometryChange() after calling this. You must hold the monitor
      * while calling this.
      */
--- a/mobile/android/base/ui/PanZoomController.java
+++ b/mobile/android/base/ui/PanZoomController.java
@@ -229,16 +229,29 @@ public class PanZoomController
             // Don't do animations here; they're distracting and can cause flashes on page
             // transitions.
             mController.setViewportMetrics(getValidViewportMetrics());
             mController.notifyLayerClientOfGeometryChange();
             break;
         }
     }
 
+    /** This must be called on the UI thread. */
+    public void pageSizeUpdated() {
+        if (mState == PanZoomState.NOTHING) {
+            ViewportMetrics validated = getValidViewportMetrics();
+            if (! mController.getViewportMetrics().fuzzyEquals(validated)) {
+                // page size changed such that we are now in overscroll. snap to the
+                // the nearest valid viewport
+                mController.setViewportMetrics(validated);
+                mController.notifyLayerClientOfGeometryChange();
+            }
+        }
+    }
+
     /*
      * Panning/scrolling
      */
 
     private boolean onTouchStart(MotionEvent event) {
         Log.d(LOGTAG, "onTouchStart in state " + mState);
         // user is taking control of movement, so stop
         // any auto-movement we have going