diff options
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/webkit/WebView.java | 27 | ||||
-rw-r--r-- | core/java/android/webkit/WebViewCore.java | 13 |
2 files changed, 29 insertions, 11 deletions
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 8b67162..5f7fdda 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -504,6 +504,16 @@ public class WebView extends AbsoluteLayout "REQUEST_KEYBOARD" // = 27; }; + // If the site doesn't use the viewport meta tag to specify the viewport, + // use DEFAULT_VIEWPORT_WIDTH as the default viewport width + static final int DEFAULT_VIEWPORT_WIDTH = 800; + + // normally we try to fit the content to the minimum preferred width + // calculated by the Webkit. To avoid the bad behavior when some site's + // minimum preferred width keeps growing when changing the viewport width or + // the minimum preferred width is huge, an upper limit is needed. + static int sMaxViewportWidth = DEFAULT_VIEWPORT_WIDTH; + // default scale limit. Depending on the display density private static float DEFAULT_MAX_ZOOM_SCALE; private static float DEFAULT_MIN_ZOOM_SCALE; @@ -523,7 +533,7 @@ public class WebView extends AbsoluteLayout // ideally mZoomOverviewWidth should be mContentWidth. But sites like espn, // engadget always have wider mContentWidth no matter what viewport size is. - int mZoomOverviewWidth = WebViewCore.DEFAULT_VIEWPORT_WIDTH; + int mZoomOverviewWidth = DEFAULT_VIEWPORT_WIDTH; float mLastScale; // default scale. Depending on the display density. @@ -3732,6 +3742,14 @@ public class WebView extends AbsoluteLayout mZoomCenterY = getViewHeight() * .5f; } + // adjust the max viewport width depending on the view dimensions. This + // is to ensure the scaling is not going insane. So do not shrink it if + // the view size is temporarily smaller, e.g. when soft keyboard is up. + int newMaxViewportWidth = (int) (Math.max(w, h) / DEFAULT_MIN_ZOOM_SCALE); + if (newMaxViewportWidth > sMaxViewportWidth) { + sMaxViewportWidth = newMaxViewportWidth; + } + // update mMinZoomScale if the minimum zoom scale is not fixed if (!mMinZoomScaleFixed) { // when change from narrow screen to wide screen, the new viewWidth @@ -5165,8 +5183,11 @@ public class WebView extends AbsoluteLayout mPictureListener.onNewPicture(WebView.this, capturePicture()); } if (useWideViewport) { - mZoomOverviewWidth = Math.max(draw.mMinPrefWidth, - draw.mViewPoint.x); + // limit mZoomOverviewWidth to sMaxViewportWidth so that + // if the page doesn't behave well, the WebView won't go + // insane. + mZoomOverviewWidth = Math.min(sMaxViewportWidth, Math + .max(draw.mMinPrefWidth, draw.mViewPoint.x)); } if (!mMinZoomScaleFixed) { mMinZoomScale = (float) viewWidth / mZoomOverviewWidth; diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index 5460a47..e0e7897 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -124,10 +124,6 @@ final class WebViewCore { private int mWebkitScrollX = 0; private int mWebkitScrollY = 0; - // If the site doesn't use viewport meta tag to specify the viewport, use - // DEFAULT_VIEWPORT_WIDTH as default viewport width - static final int DEFAULT_VIEWPORT_WIDTH = 800; - // The thread name used to identify the WebCore thread and for use in // debugging other classes that require operation within the WebCore thread. /* package */ static final String THREAD_NAME = "WebViewCoreThread"; @@ -1522,7 +1518,7 @@ final class WebViewCore { if (mViewportWidth == -1) { if (mSettings.getLayoutAlgorithm() == WebSettings.LayoutAlgorithm.NORMAL) { - width = DEFAULT_VIEWPORT_WIDTH; + width = WebView.DEFAULT_VIEWPORT_WIDTH; } else { /* * if a page's minimum preferred width is wider than the @@ -1536,8 +1532,9 @@ final class WebViewCore { * In the worse case, the native width will be adjusted when * next zoom or screen orientation change happens. */ - width = Math.max(w, Math.max(DEFAULT_VIEWPORT_WIDTH, - nativeGetContentMinPrefWidth())); + width = Math.min(WebView.sMaxViewportWidth, Math.max(w, + Math.max(WebView.DEFAULT_VIEWPORT_WIDTH, + nativeGetContentMinPrefWidth()))); } } else { width = Math.max(w, mViewportWidth); @@ -1637,7 +1634,7 @@ final class WebViewCore { draw.mViewPoint = new Point(mCurrentViewWidth, mCurrentViewHeight); if (mSettings.getUseWideViewPort()) { draw.mMinPrefWidth = Math.max( - mViewportWidth == -1 ? DEFAULT_VIEWPORT_WIDTH + mViewportWidth == -1 ? WebView.DEFAULT_VIEWPORT_WIDTH : (mViewportWidth == 0 ? mCurrentViewWidth : mViewportWidth), nativeGetContentMinPrefWidth()); |