Skip to content

Commit 3314930

Browse files
author
George Mount
committed
DO NOT MERGE Set the initial scroll position for RTL.
Bug 5268793 Webkit knows about the correct initial position for web pages. On initial show, scroll to the webkit position. Cherry-picked from master CL: I2537b84a External WebKit CL: I6a91b97f Change-Id: I2537b84a30a26a79a8a0f23fe62b9ed757f9c5a4
1 parent d211b48 commit 3314930

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

core/java/android/webkit/BrowserFrame.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,4 +1404,17 @@ public void stopLoading() {
14041404
native void nativeSslClientCert(int handle,
14051405
byte[] pkcs8EncodedPrivateKey,
14061406
byte[][] asn1DerEncodedCertificateChain);
1407+
1408+
/**
1409+
* Returns true when the contents of the frame is an RTL or vertical-rl
1410+
* page. This is used for determining whether a frame should be initially
1411+
* scrolled right-most as opposed to left-most.
1412+
* @return true when the frame should be initially scrolled right-most
1413+
* based on the text direction and writing mode.
1414+
*/
1415+
/* package */ boolean getShouldStartScrolledRight() {
1416+
return nativeGetShouldStartScrolledRight(mNativeFrame);
1417+
}
1418+
1419+
private native boolean nativeGetShouldStartScrolledRight(int nativeBrowserFrame);
14071420
}

core/java/android/webkit/WebView.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8716,27 +8716,6 @@ void setNewPicture(final WebViewCore.DrawData draw, boolean updateBaseLayer) {
87168716
isPictureAfterFirstLayout, registerPageSwapCallback);
87178717
}
87188718
final Point viewSize = draw.mViewSize;
8719-
if (isPictureAfterFirstLayout) {
8720-
// Reset the last sent data here since dealing with new page.
8721-
mLastWidthSent = 0;
8722-
mZoomManager.onFirstLayout(draw);
8723-
if (!mDrawHistory) {
8724-
// Do not send the scroll event for this particular
8725-
// scroll message. Note that a scroll event may
8726-
// still be fired if the user scrolls before the
8727-
// message can be handled.
8728-
mSendScrollEvent = false;
8729-
setContentScrollTo(viewState.mScrollX, viewState.mScrollY);
8730-
mSendScrollEvent = true;
8731-
8732-
// As we are on a new page, remove the WebTextView. This
8733-
// is necessary for page loads driven by webkit, and in
8734-
// particular when the user was on a password field, so
8735-
// the WebTextView was visible.
8736-
clearTextEntry();
8737-
}
8738-
}
8739-
87408719
// We update the layout (i.e. request a layout from the
87418720
// view system) if the last view size that we sent to
87428721
// WebCore matches the view size of the picture we just
@@ -8749,7 +8728,25 @@ void setNewPicture(final WebViewCore.DrawData draw, boolean updateBaseLayer) {
87498728
mSendScrollEvent = false;
87508729
recordNewContentSize(draw.mContentSize.x,
87518730
draw.mContentSize.y, updateLayout);
8731+
8732+
if (isPictureAfterFirstLayout) {
8733+
// Reset the last sent data here since dealing with new page.
8734+
mLastWidthSent = 0;
8735+
mZoomManager.onFirstLayout(draw);
8736+
int scrollX = viewState.mShouldStartScrolledRight
8737+
? getContentWidth() : viewState.mScrollX;
8738+
int scrollY = viewState.mScrollY;
8739+
setContentScrollTo(scrollX, scrollY);
8740+
if (!mDrawHistory) {
8741+
// As we are on a new page, remove the WebTextView. This
8742+
// is necessary for page loads driven by webkit, and in
8743+
// particular when the user was on a password field, so
8744+
// the WebTextView was visible.
8745+
clearTextEntry();
8746+
}
8747+
}
87528748
mSendScrollEvent = true;
8749+
87538750
if (DebugFlags.WEB_VIEW) {
87548751
Rect b = draw.mInvalRegion.getBounds();
87558752
Log.v(LOGTAG, "NEW_PICTURE_MSG_ID {" +

core/java/android/webkit/WebViewCore.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,7 @@ static class ViewState {
19821982
int mScrollY;
19831983
boolean mMobileSite;
19841984
boolean mIsRestored;
1985+
boolean mShouldStartScrolledRight;
19851986
}
19861987

19871988
static class DrawData {
@@ -2382,6 +2383,7 @@ private void setupViewport(boolean updateViewState) {
23822383
viewState.mMobileSite = false;
23832384
// for non-mobile site, we don't need minPrefWidth, set it as 0
23842385
viewState.mScrollX = 0;
2386+
viewState.mShouldStartScrolledRight = false;
23852387
Message.obtain(mWebView.mPrivateHandler,
23862388
WebView.UPDATE_ZOOM_RANGE, viewState).sendToTarget();
23872389
return;
@@ -2412,6 +2414,11 @@ private void setupViewport(boolean updateViewState) {
24122414
mInitialViewState.mDefaultScale = adjust;
24132415
mInitialViewState.mScrollX = mRestoredX;
24142416
mInitialViewState.mScrollY = mRestoredY;
2417+
mInitialViewState.mShouldStartScrolledRight = (mRestoredX == 0)
2418+
&& (mRestoredY == 0)
2419+
&& (mBrowserFrame != null)
2420+
&& mBrowserFrame.getShouldStartScrolledRight();
2421+
24152422
mInitialViewState.mMobileSite = (0 == mViewportWidth);
24162423
if (mIsRestored) {
24172424
mInitialViewState.mIsRestored = true;

0 commit comments

Comments
 (0)