Use fixed viewpport for tablet device.
This makes the zoom animation much more smooth. With previous dynamic viewport, the animation jumps because of viewport adjustment and big screen. Also the viewport width is changed from 800 to 1040 to better suit the tablet device. It's the middle point of 1280 and 800. The text reflow re-alignment for non-double-tap zoom is disabled for tablet, since most of the time the reflow has no effect. issue: 2919307 Change-Id: I74493df6408291c24ef8511512d7ed0b81bf507a
This commit is contained in:
@@ -22,6 +22,7 @@ import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.EventLog;
|
||||
|
||||
import java.util.Locale;
|
||||
@@ -176,6 +177,7 @@ public class WebSettings {
|
||||
private boolean mJavaScriptCanOpenWindowsAutomatically = false;
|
||||
private boolean mUseDoubleTree = false;
|
||||
private boolean mUseWideViewport = false;
|
||||
private boolean mUseFixedViewport = false;
|
||||
private boolean mSupportMultipleWindows = false;
|
||||
private boolean mShrinksStandaloneImagesToFit = false;
|
||||
private long mMaximumDecodedImageSize = 0; // 0 means default
|
||||
@@ -318,6 +320,11 @@ public class WebSettings {
|
||||
mDefaultTextEncoding = context.getString(com.android.internal.
|
||||
R.string.default_text_encoding);
|
||||
|
||||
// Detect tablet device for fixed viewport mode.
|
||||
final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
mUseFixedViewport = (metrics.density == 1.0f
|
||||
&& (metrics.widthPixels >= 800 ||metrics.heightPixels >= 800));
|
||||
|
||||
if (sLockForLocaleSettings == null) {
|
||||
sLockForLocaleSettings = new Object();
|
||||
sLocale = Locale.getDefault();
|
||||
@@ -1469,6 +1476,13 @@ public class WebSettings {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether to use fixed viewport.
|
||||
*/
|
||||
/* package */ boolean getUseFixedViewport() {
|
||||
return mUseFixedViewport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether private browsing is enabled.
|
||||
*/
|
||||
|
||||
@@ -651,7 +651,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 = 800;
|
||||
static final int DEFAULT_VIEWPORT_WIDTH = 1040;
|
||||
|
||||
// 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
|
||||
|
||||
@@ -1686,7 +1686,7 @@ final class WebViewCore {
|
||||
if (mSettings.getUseWideViewPort()) {
|
||||
if (mViewportWidth == -1) {
|
||||
if (mSettings.getLayoutAlgorithm() ==
|
||||
WebSettings.LayoutAlgorithm.NORMAL) {
|
||||
WebSettings.LayoutAlgorithm.NORMAL || mSettings.getUseFixedViewport()) {
|
||||
width = WebView.DEFAULT_VIEWPORT_WIDTH;
|
||||
} else {
|
||||
/*
|
||||
|
||||
@@ -541,7 +541,9 @@ class ZoomManager {
|
||||
}
|
||||
|
||||
if (settings.getLayoutAlgorithm() == WebSettings.LayoutAlgorithm.NARROW_COLUMNS
|
||||
&& willScaleTriggerZoom(mTextWrapScale)) {
|
||||
&& willScaleTriggerZoom(mTextWrapScale)
|
||||
// For tablet, not much need to reflow text w/o double tapping.
|
||||
&& !settings.getUseFixedViewport()) {
|
||||
refreshZoomScale(true);
|
||||
} else if (!mInZoomOverview) {
|
||||
zoomToOverview();
|
||||
@@ -765,7 +767,8 @@ class ZoomManager {
|
||||
public void onNewPicture(WebViewCore.DrawData drawData) {
|
||||
final int viewWidth = mWebView.getViewWidth();
|
||||
|
||||
if (mWebView.getSettings().getUseWideViewPort()) {
|
||||
if (!mWebView.getSettings().getUseFixedViewport()
|
||||
&& mWebView.getSettings().getUseWideViewPort()) {
|
||||
// limit mZoomOverviewWidth upper bound to
|
||||
// sMaxViewportWidth so that if the page doesn't behave
|
||||
// well, the WebView won't go insane. limit the lower
|
||||
@@ -819,7 +822,8 @@ class ZoomManager {
|
||||
reflowText = false;
|
||||
} else {
|
||||
WebSettings settings = mWebView.getSettings();
|
||||
if (settings.getUseWideViewPort() && settings.getLoadWithOverviewMode()) {
|
||||
if (settings.getUseWideViewPort()
|
||||
&& (settings.getLoadWithOverviewMode() || settings.getUseFixedViewport())) {
|
||||
mInitialZoomOverview = true;
|
||||
scale = (float) mWebView.getViewWidth() / WebView.DEFAULT_VIEWPORT_WIDTH;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user