Don't scroll the title bar off screen while loading.
Though the user can still manually scroll the title bar off screen, we do not want it to happen automatically. When we load a new page, its scroll position can be set to (0,0). Make sure that we simply set it to the top without adding in the title bar's height. Also, prevent javascript which attempts to scroll the page to (0,0) or (0,1) from removing the title bar. Fixes http://b/issue?id=2113398 and http://b/issue?id=2123079 Change-Id: Ida64d8c94be6744c7b0b4d60af1c229b2cc83673
This commit is contained in:
@ -420,7 +420,6 @@ public class WebView extends AbsoluteLayout
|
||||
private static final int STD_SPEED = 480; // pixels per second
|
||||
// time for the longest scroll animation
|
||||
private static final int MAX_DURATION = 750; // milliseconds
|
||||
private static final int SLIDE_TITLE_DURATION = 300; // milliseconds
|
||||
private Scroller mScroller;
|
||||
|
||||
private boolean mWrapContent;
|
||||
@ -2418,18 +2417,17 @@ public class WebView extends AbsoluteLayout
|
||||
if ((dx | dy) == 0) {
|
||||
return false;
|
||||
}
|
||||
// By this point we have added in the title bar's height. If the site
|
||||
// is trying to scroll to the top of the page, scroll it to the top
|
||||
// of the WebView including showing the title bar.
|
||||
// mobile sites prefer to scroll to (0, 1), thus the + 1 below
|
||||
boolean slideTitle = getVisibleTitleHeight() > 0
|
||||
&& y <= getTitleHeight() + 1;
|
||||
if (DebugFlags.WEB_VIEW) {
|
||||
Log.v(LOGTAG, "pinScrollTo slideTitle=" + slideTitle
|
||||
+ " getVisibleTitleHeight()=" + getVisibleTitleHeight()
|
||||
+ " animationDuration=" + animationDuration + " y=" + y);
|
||||
if (getVisibleTitleHeight() > 0 && x == 0
|
||||
&& y <= getTitleHeight() + 1) {
|
||||
y = 0;
|
||||
animate = false;
|
||||
}
|
||||
if (slideTitle || animate) {
|
||||
if (animate) {
|
||||
// Log.d(LOGTAG, "startScroll: " + dx + " " + dy);
|
||||
if (slideTitle && animationDuration < SLIDE_TITLE_DURATION)
|
||||
animationDuration = SLIDE_TITLE_DURATION;
|
||||
mScroller.startScroll(mScrollX, mScrollY, dx, dy,
|
||||
animationDuration > 0 ? animationDuration : computeDuration(dx, dy));
|
||||
invalidate();
|
||||
@ -4809,8 +4807,14 @@ public class WebView extends AbsoluteLayout
|
||||
mMaxZoomScale = restoreState.mMaxScale;
|
||||
}
|
||||
setNewZoomScale(mLastScale, false);
|
||||
if (getVisibleTitleHeight() == 0
|
||||
|| restoreState.mScrollY != 0) {
|
||||
if (getTitleHeight() != 0 && restoreState.mScrollX == 0
|
||||
&& restoreState.mScrollY == 0) {
|
||||
// If there is a title bar, and the page is being
|
||||
// restored to (0,0), do not scroll the title bar
|
||||
// off the page.
|
||||
abortAnimation();
|
||||
scrollTo(0,0);
|
||||
} else {
|
||||
setContentScrollTo(restoreState.mScrollX,
|
||||
restoreState.mScrollY);
|
||||
}
|
||||
|
Reference in New Issue
Block a user