am a4fa107f: Do not grow the viewport width to infinite to fit the content. Limit the overview viewport width to a level that if a site behaves badly, the WebView still does reasonably.

Merge commit 'a4fa107f97933a81c42ee3cd9ca3984c08e5ab25' into eclair-mr2-plus-aosp

* commit 'a4fa107f97933a81c42ee3cd9ca3984c08e5ab25':
  Do not grow the viewport width to infinite to fit
This commit is contained in:
Grace Kloba
2009-11-18 11:48:08 -08:00
committed by Android Git Automerger
2 changed files with 29 additions and 11 deletions

View File

@@ -504,6 +504,16 @@ public class WebView extends AbsoluteLayout
"REQUEST_KEYBOARD" // = 27; "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 // default scale limit. Depending on the display density
private static float DEFAULT_MAX_ZOOM_SCALE; private static float DEFAULT_MAX_ZOOM_SCALE;
private static float DEFAULT_MIN_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, // ideally mZoomOverviewWidth should be mContentWidth. But sites like espn,
// engadget always have wider mContentWidth no matter what viewport size is. // engadget always have wider mContentWidth no matter what viewport size is.
int mZoomOverviewWidth = WebViewCore.DEFAULT_VIEWPORT_WIDTH; int mZoomOverviewWidth = DEFAULT_VIEWPORT_WIDTH;
float mLastScale; float mLastScale;
// default scale. Depending on the display density. // default scale. Depending on the display density.
@@ -3732,6 +3742,14 @@ public class WebView extends AbsoluteLayout
mZoomCenterY = getViewHeight() * .5f; 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 // update mMinZoomScale if the minimum zoom scale is not fixed
if (!mMinZoomScaleFixed) { if (!mMinZoomScaleFixed) {
// when change from narrow screen to wide screen, the new viewWidth // 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()); mPictureListener.onNewPicture(WebView.this, capturePicture());
} }
if (useWideViewport) { if (useWideViewport) {
mZoomOverviewWidth = Math.max(draw.mMinPrefWidth, // limit mZoomOverviewWidth to sMaxViewportWidth so that
draw.mViewPoint.x); // 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) { if (!mMinZoomScaleFixed) {
mMinZoomScale = (float) viewWidth / mZoomOverviewWidth; mMinZoomScale = (float) viewWidth / mZoomOverviewWidth;

View File

@@ -124,10 +124,6 @@ final class WebViewCore {
private int mWebkitScrollX = 0; private int mWebkitScrollX = 0;
private int mWebkitScrollY = 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 // The thread name used to identify the WebCore thread and for use in
// debugging other classes that require operation within the WebCore thread. // debugging other classes that require operation within the WebCore thread.
/* package */ static final String THREAD_NAME = "WebViewCoreThread"; /* package */ static final String THREAD_NAME = "WebViewCoreThread";
@@ -1522,7 +1518,7 @@ final class WebViewCore {
if (mViewportWidth == -1) { if (mViewportWidth == -1) {
if (mSettings.getLayoutAlgorithm() == if (mSettings.getLayoutAlgorithm() ==
WebSettings.LayoutAlgorithm.NORMAL) { WebSettings.LayoutAlgorithm.NORMAL) {
width = DEFAULT_VIEWPORT_WIDTH; width = WebView.DEFAULT_VIEWPORT_WIDTH;
} else { } else {
/* /*
* if a page's minimum preferred width is wider than the * 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 * In the worse case, the native width will be adjusted when
* next zoom or screen orientation change happens. * next zoom or screen orientation change happens.
*/ */
width = Math.max(w, Math.max(DEFAULT_VIEWPORT_WIDTH, width = Math.min(WebView.sMaxViewportWidth, Math.max(w,
nativeGetContentMinPrefWidth())); Math.max(WebView.DEFAULT_VIEWPORT_WIDTH,
nativeGetContentMinPrefWidth())));
} }
} else { } else {
width = Math.max(w, mViewportWidth); width = Math.max(w, mViewportWidth);
@@ -1637,7 +1634,7 @@ final class WebViewCore {
draw.mViewPoint = new Point(mCurrentViewWidth, mCurrentViewHeight); draw.mViewPoint = new Point(mCurrentViewWidth, mCurrentViewHeight);
if (mSettings.getUseWideViewPort()) { if (mSettings.getUseWideViewPort()) {
draw.mMinPrefWidth = Math.max( draw.mMinPrefWidth = Math.max(
mViewportWidth == -1 ? DEFAULT_VIEWPORT_WIDTH mViewportWidth == -1 ? WebView.DEFAULT_VIEWPORT_WIDTH
: (mViewportWidth == 0 ? mCurrentViewWidth : (mViewportWidth == 0 ? mCurrentViewWidth
: mViewportWidth), : mViewportWidth),
nativeGetContentMinPrefWidth()); nativeGetContentMinPrefWidth());