Skip to content

Commit a60a189

Browse files
committed
Remove code preventing scrollTo(0,0)
Bug: 5677901 Also remove a bunch of unnecessary logic around delaying the scroll until the page load has completed, as Browser will keep the URL bar visible itself Change-Id: I4b175f4ff1d741b7027a4c98f676764707f57342
1 parent 9687433 commit a60a189

File tree

1 file changed

+6
-99
lines changed

1 file changed

+6
-99
lines changed

core/java/android/webkit/WebViewClassic.java

Lines changed: 6 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,6 @@ public void onTrimMemory(int level) {
10741074
private static final int STD_SPEED = 480; // pixels per second
10751075
// time for the longest scroll animation
10761076
private static final int MAX_DURATION = 750; // milliseconds
1077-
private static final int SLIDE_TITLE_DURATION = 500; // milliseconds
10781077

10791078
// Used by OverScrollGlow
10801079
OverScroller mScroller;
@@ -4013,17 +4012,6 @@ private boolean setContentScrollBy(int cx, int cy, boolean animate) {
40134012
* @param url The URL of the page which has finished loading.
40144013
*/
40154014
/* package */ void onPageFinished(String url) {
4016-
if (mPageThatNeedsToSlideTitleBarOffScreen != null) {
4017-
// If the user is now on a different page, or has scrolled the page
4018-
// past the point where the title bar is offscreen, ignore the
4019-
// scroll request.
4020-
if (mPageThatNeedsToSlideTitleBarOffScreen.equals(url)
4021-
&& getScrollX() == 0 && getScrollY() == 0) {
4022-
pinScrollTo(0, mYDistanceToSlideTitleOffScreen, true,
4023-
SLIDE_TITLE_DURATION);
4024-
}
4025-
mPageThatNeedsToSlideTitleBarOffScreen = null;
4026-
}
40274015
mZoomManager.onPageFinished(url);
40284016
injectAccessibilityForUrl(url);
40294017
}
@@ -4135,93 +4123,16 @@ private int getAxsUrlParameterValue(String url) {
41354123
return -1;
41364124
}
41374125

4138-
/**
4139-
* The URL of a page that sent a message to scroll the title bar off screen.
4140-
*
4141-
* Many mobile sites tell the page to scroll to (0,1) in order to scroll the
4142-
* title bar off the screen. Sometimes, the scroll position is set before
4143-
* the page finishes loading. Rather than scrolling while the page is still
4144-
* loading, keep track of the URL and new scroll position so we can perform
4145-
* the scroll once the page finishes loading.
4146-
*/
4147-
private String mPageThatNeedsToSlideTitleBarOffScreen;
4148-
4149-
/**
4150-
* The destination Y scroll position to be used when the page finishes
4151-
* loading. See mPageThatNeedsToSlideTitleBarOffScreen.
4152-
*/
4153-
private int mYDistanceToSlideTitleOffScreen;
4154-
4155-
// scale from content to view coordinates, and pin
4156-
// return true if pin caused the final x/y different than the request cx/cy,
4157-
// and a future scroll may reach the request cx/cy after our size has
4158-
// changed
4159-
// return false if the view scroll to the exact position as it is requested,
4160-
// where negative numbers are taken to mean 0
4161-
private boolean setContentScrollTo(int cx, int cy) {
4162-
if (mDrawHistory) {
4163-
// disallow WebView to change the scroll position as History Picture
4164-
// is used in the view system.
4165-
// One known case where this is called is that WebCore tries to
4166-
// restore the scroll position. As history Picture already uses the
4167-
// saved scroll position, it is ok to skip this.
4168-
return false;
4169-
}
4170-
int vx;
4171-
int vy;
4172-
if ((cx | cy) == 0) {
4173-
// If the page is being scrolled to (0,0), do not add in the title
4174-
// bar's height, and simply scroll to (0,0). (The only other work
4175-
// in contentToView_ is to multiply, so this would not change 0.)
4176-
vx = 0;
4177-
vy = 0;
4178-
} else {
4179-
vx = contentToViewX(cx);
4180-
vy = contentToViewY(cy);
4181-
}
4182-
// Log.d(LOGTAG, "content scrollTo [" + cx + " " + cy + "] view=[" +
4183-
// vx + " " + vy + "]");
4184-
// Some mobile sites attempt to scroll the title bar off the page by
4185-
// scrolling to (0,1). If we are at the top left corner of the
4186-
// page, assume this is an attempt to scroll off the title bar, and
4187-
// animate the title bar off screen slowly enough that the user can see
4188-
// it.
4189-
if (cx == 0 && cy == 1 && getScrollX() == 0 && getScrollY() == 0
4190-
&& getTitleHeight() > 0) {
4191-
// FIXME: 100 should be defined somewhere as our max progress.
4192-
if (getProgress() < 100) {
4193-
// Wait to scroll the title bar off screen until the page has
4194-
// finished loading. Keep track of the URL and the destination
4195-
// Y position
4196-
mPageThatNeedsToSlideTitleBarOffScreen = getUrl();
4197-
mYDistanceToSlideTitleOffScreen = vy;
4198-
} else {
4199-
pinScrollTo(vx, vy, true, SLIDE_TITLE_DURATION);
4200-
}
4201-
// Since we are animating, we have not yet reached the desired
4202-
// scroll position. Do not return true to request another attempt
4203-
return false;
4204-
}
4205-
pinScrollTo(vx, vy, false, 0);
4206-
// If the request was to scroll to a negative coordinate, treat it as if
4207-
// it was a request to scroll to 0
4208-
if ((getScrollX() != vx && cx >= 0) || (getScrollY() != vy && cy >= 0)) {
4209-
return true;
4210-
} else {
4211-
return false;
4212-
}
4213-
}
4214-
42154126
// scale from content to view coordinates, and pin
4216-
private void spawnContentScrollTo(int cx, int cy) {
4127+
private void contentScrollTo(int cx, int cy, boolean animate) {
42174128
if (mDrawHistory) {
42184129
// disallow WebView to change the scroll position as History Picture
42194130
// is used in the view system.
42204131
return;
42214132
}
4222-
int vx = contentToViewDimension(cx - mScrollOffset.x);
4223-
int vy = contentToViewDimension(cy - mScrollOffset.y);
4224-
pinScrollBy(vx, vy, true, 0);
4133+
int vx = contentToViewX(cx);
4134+
int vy = contentToViewY(cy);
4135+
pinScrollTo(vx, vy, animate, 0);
42254136
}
42264137

42274138
/**
@@ -7428,11 +7339,7 @@ public void handleMessage(Message msg) {
74287339
}
74297340
}
74307341
final Point p = (Point) msg.obj;
7431-
if (msg.arg1 == 1) {
7432-
spawnContentScrollTo(p.x, p.y);
7433-
} else {
7434-
setContentScrollTo(p.x, p.y);
7435-
}
7342+
contentScrollTo(p.x, p.y, msg.arg1 == 1);
74367343
break;
74377344
}
74387345
case UPDATE_ZOOM_RANGE: {
@@ -8073,7 +7980,7 @@ void setNewPicture(final WebViewCore.DrawData draw, boolean updateBaseLayer) {
80737980
int scrollX = viewState.mShouldStartScrolledRight
80747981
? getContentWidth() : viewState.mScrollX;
80757982
int scrollY = viewState.mScrollY;
8076-
setContentScrollTo(scrollX, scrollY);
7983+
contentScrollTo(scrollX, scrollY, false);
80777984
if (!mDrawHistory) {
80787985
// As we are on a new page, hide the keyboard
80797986
hideSoftKeyboard();

0 commit comments

Comments
 (0)