Merge "Use website preferred width as the fixed viewport."

This commit is contained in:
Shimeng (Simon) Wang
2010-09-17 11:31:45 -07:00
committed by Android (Google) Code Review
3 changed files with 20 additions and 4 deletions

View File

@@ -178,6 +178,7 @@ public class WebSettings {
private boolean mUseDoubleTree = false;
private boolean mUseWideViewport = false;
private boolean mUseFixedViewport = false;
private int mMaxFixedViewportWidth = WebView.DEFAULT_VIEWPORT_WIDTH;
private boolean mSupportMultipleWindows = false;
private boolean mShrinksStandaloneImagesToFit = false;
private long mMaximumDecodedImageSize = 0; // 0 means default
@@ -324,8 +325,9 @@ public class WebSettings {
// Detect tablet device for fixed viewport mode.
final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
mUseFixedViewport = (metrics.density == 1.0f
&& (metrics.widthPixels >= 800 ||metrics.heightPixels >= 800));
final int landscapeWidth = Math.max(metrics.widthPixels, metrics.heightPixels);
mUseFixedViewport = (metrics.density == 1.0f && landscapeWidth >= 800);
mMaxFixedViewportWidth = (int) (landscapeWidth * 1.25);
if (sLockForLocaleSettings == null) {
sLockForLocaleSettings = new Object();
@@ -1515,6 +1517,13 @@ public class WebSettings {
return mUseFixedViewport;
}
/**
* Returns maximum fixed viewport width.
*/
/* package */ int getMaxFixedViewportWidth() {
return mMaxFixedViewportWidth;
}
/**
* Returns whether private browsing is enabled.
*/

View File

@@ -667,7 +667,7 @@ public class WebView extends AbsoluteLayout
// 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 = 1040;
static final int DEFAULT_VIEWPORT_WIDTH = 980;
// 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

View File

@@ -1706,7 +1706,7 @@ final class WebViewCore {
}
} else if (mViewportWidth > 0) {
if (mSettings.getUseFixedViewport()) {
// Use website specified viewport width.
// Use website specified or desired fixed viewport width.
width = mViewportWidth;
} else {
width = Math.max(w, mViewportWidth);
@@ -1827,6 +1827,13 @@ final class WebViewCore {
}
if (mInitialViewState != null) {
draw.mViewState = mInitialViewState;
if (mViewportWidth == -1 && mSettings.getUseFixedViewport() &&
mSettings.getUseWideViewPort()) {
// Use website's initial preferred width as the fixed viewport width.
mViewportWidth = Math.min(mSettings.getMaxFixedViewportWidth(),
draw.mMinPrefWidth);
draw.mViewState.mViewportWidth = mViewportWidth;
}
mInitialViewState = null;
}
if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "webkitDraw NEW_PICTURE_MSG_ID");