From 405d785f86c1f32feaf1f0f93d1cd8df5cbcd151 Mon Sep 17 00:00:00 2001 From: Leon Scroggins Date: Mon, 2 Nov 2009 14:50:54 -0800 Subject: [PATCH] Do not scroll the title bar off screen until the page finishes loading. Fix http://b/issue?id=2139418 --- core/java/android/webkit/CallbackProxy.java | 9 ++-- core/java/android/webkit/WebView.java | 49 ++++++++++++++++++++- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/core/java/android/webkit/CallbackProxy.java b/core/java/android/webkit/CallbackProxy.java index f9dec7f30aaff..e405cf2b1c1a1 100644 --- a/core/java/android/webkit/CallbackProxy.java +++ b/core/java/android/webkit/CallbackProxy.java @@ -251,8 +251,10 @@ class CallbackProxy extends Handler { break; case PAGE_FINISHED: + String finishedUrl = (String) msg.obj; + mWebView.onPageFinished(finishedUrl); if (mWebViewClient != null) { - mWebViewClient.onPageFinished(mWebView, (String) msg.obj); + mWebViewClient.onPageFinished(mWebView, finishedUrl); } break; @@ -777,11 +779,6 @@ class CallbackProxy extends Handler { } public void onPageFinished(String url) { - // Do an unsynchronized quick check to avoid posting if no callback has - // been set. - if (mWebViewClient == null) { - return; - } // Performance probe if (PERF_PROBE) { // un-comment this if PERF_PROBE is true diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 98a6c2c244162..630450db5c3e8 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -2548,6 +2548,41 @@ public class WebView extends AbsoluteLayout } } + /** + * Called by CallbackProxy when the page finishes loading. + * @param url The URL of the page which has finished loading. + */ + /* package */ void onPageFinished(String url) { + if (mPageThatNeedsToSlideTitleBarOffScreen != null) { + // If the user is now on a different page, or has scrolled the page + // past the point where the title bar is offscreen, ignore the + // scroll request. + if (mPageThatNeedsToSlideTitleBarOffScreen.equals(url) + && mScrollX == 0 && mScrollY == 0) { + pinScrollTo(0, mYDistanceToSlideTitleOffScreen, true, + SLIDE_TITLE_DURATION); + } + mPageThatNeedsToSlideTitleBarOffScreen = null; + } + } + + /** + * The URL of a page that sent a message to scroll the title bar off screen. + * + * Many mobile sites tell the page to scroll to (0,1) in order to scroll the + * title bar off the screen. Sometimes, the scroll position is set before + * the page finishes loading. Rather than scrolling while the page is still + * loading, keep track of the URL and new scroll position so we can perform + * the scroll once the page finishes loading. + */ + private String mPageThatNeedsToSlideTitleBarOffScreen; + + /** + * The destination Y scroll position to be used when the page finishes + * loading. See mPageThatNeedsToSlideTitleBarOffScreen. + */ + private int mYDistanceToSlideTitleOffScreen; + // scale from content to view coordinates, and pin // return true if pin caused the final x/y different than the request cx/cy, // and a future scroll may reach the request cx/cy after our size has @@ -2582,8 +2617,18 @@ public class WebView extends AbsoluteLayout // page, assume this is an attempt to scroll off the title bar, and // animate the title bar off screen slowly enough that the user can see // it. - if (cx == 0 && cy == 1 && mScrollX == 0 && mScrollY == 0) { - pinScrollTo(vx, vy, true, SLIDE_TITLE_DURATION); + if (cx == 0 && cy == 1 && mScrollX == 0 && mScrollY == 0 + && mTitleBar != null) { + // FIXME: 100 should be defined somewhere as our max progress. + if (getProgress() < 100) { + // Wait to scroll the title bar off screen until the page has + // finished loading. Keep track of the URL and the destination + // Y position + mPageThatNeedsToSlideTitleBarOffScreen = getUrl(); + mYDistanceToSlideTitleOffScreen = vy; + } else { + pinScrollTo(vx, vy, true, SLIDE_TITLE_DURATION); + } // Since we are animating, we have not yet reached the desired // scroll position. Do not return true to request another attempt return false;