Merge change 21468 into eclair

* changes:
  Couple of fixes for viewport.
This commit is contained in:
Android (Google) Code Review
2009-08-18 10:51:49 -07:00

View File

@@ -1778,12 +1778,27 @@ final class WebViewCore {
mBrowserFrame.didFirstLayout(); mBrowserFrame.didFirstLayout();
// reset the scroll position as it is a new page now if (mWebView == null) return;
mWebkitScrollX = mWebkitScrollY = 0;
// for non-standard load, we only adjust scale if mRestoredScale > 0 setupViewport(standardLoad || mRestoredScale > 0);
if (mWebView == null || (mRestoredScale == 0 && !standardLoad)) return;
// reset the scroll position, the restored offset and scales
mWebkitScrollX = mWebkitScrollY = mRestoredX = mRestoredY
= mRestoredScale = mRestoredScreenWidthScale = 0;
}
// called by JNI
private void updateViewport() {
// if updateViewport is called before first layout, wait until first
// layout to update the viewport. In the rare case, this is called after
// first layout, force an update as we have just parsed the viewport
// meta tag.
if (mBrowserFrame.firstLayoutDone()) {
setupViewport(true);
}
}
private void setupViewport(boolean updateRestoreState) {
// set the viewport settings from WebKit // set the viewport settings from WebKit
setViewportSettingsFromNative(); setViewportSettingsFromNative();
@@ -1834,6 +1849,9 @@ final class WebViewCore {
mViewportWidth = 0; mViewportWidth = 0;
} }
// if mViewportWidth is 0, it means device-width, always update.
if (mViewportWidth != 0 && !updateRestoreState) return;
// now notify webview // now notify webview
int webViewWidth = Math.round(mCurrentViewWidth * mCurrentViewScale); int webViewWidth = Math.round(mCurrentViewWidth * mCurrentViewScale);
mRestoreState = new RestoreState(); mRestoreState = new RestoreState();
@@ -1884,25 +1902,29 @@ final class WebViewCore {
data.mScale = -1.0f; data.mScale = -1.0f;
mEventHub.sendMessageAtFrontOfQueue(Message.obtain(null, mEventHub.sendMessageAtFrontOfQueue(Message.obtain(null,
EventHub.VIEW_SIZE_CHANGED, data)); EventHub.VIEW_SIZE_CHANGED, data));
} else if (mSettings.getUseWideViewPort() && mCurrentViewWidth > 0) { } else if (mSettings.getUseWideViewPort()) {
WebView.ViewSizeData data = new WebView.ViewSizeData(); if (mCurrentViewWidth == 0) {
// mViewScale as 0 means it is in zoom overview mode. So we don't // Trick to ensure VIEW_SIZE_CHANGED will be sent from WebView
// know the exact scale. If mRestoredScale is non-zero, use it; // to WebViewCore
// otherwise just use mTextWrapScale as the initial scale. mWebView.mLastWidthSent = 0;
data.mScale = mRestoreState.mViewScale == 0 } else {
? (mRestoredScale > 0 ? mRestoredScale WebView.ViewSizeData data = new WebView.ViewSizeData();
: mRestoreState.mTextWrapScale) // mViewScale as 0 means it is in zoom overview mode. So we don't
: mRestoreState.mViewScale; // know the exact scale. If mRestoredScale is non-zero, use it;
data.mWidth = Math.round(webViewWidth / data.mScale); // otherwise just use mTextWrapScale as the initial scale.
data.mHeight = mCurrentViewHeight * data.mWidth data.mScale = mRestoreState.mViewScale == 0
/ mCurrentViewWidth; ? (mRestoredScale > 0 ? mRestoredScale
data.mTextWrapWidth = Math.round(webViewWidth : mRestoreState.mTextWrapScale)
/ mRestoreState.mTextWrapScale); : mRestoreState.mViewScale;
mEventHub.sendMessageAtFrontOfQueue(Message.obtain(null, data.mWidth = Math.round(webViewWidth / data.mScale);
EventHub.VIEW_SIZE_CHANGED, data)); data.mHeight = mCurrentViewHeight * data.mWidth
/ mCurrentViewWidth;
data.mTextWrapWidth = Math.round(webViewWidth
/ mRestoreState.mTextWrapScale);
mEventHub.sendMessageAtFrontOfQueue(Message.obtain(null,
EventHub.VIEW_SIZE_CHANGED, data));
}
} }
// reset restored offset, scale
mRestoredX = mRestoredY = mRestoredScale = mRestoredScreenWidthScale = 0;
} }
// called by JNI // called by JNI