Set reading level scale to display density instead of a fixed minimum.
On a double tap, zoom to either reading level scale or 0.5f more than
current (overview) scale, whichever is greater. This addresses the
scenario for large screen devices where overview and reading level scale
are the same.
Bug: 5165527
Change-Id: I50216d60f98b2904f06742336b9c8c7c512328a6
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 4748522..6274895 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -2343,6 +2343,14 @@
}
/**
+ * Return the reading level scale of the WebView
+ * @return The reading level scale.
+ */
+ /*package*/ float getReadingLevelScale() {
+ return mZoomManager.getReadingLevelScale();
+ }
+
+ /**
* Set the initial scale for the WebView. 0 means default. If
* {@link WebSettings#getUseWideViewPort()} is true, it zooms out all the
* way. Otherwise it starts with 100%. If initial scale is greater than 0,
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 3ca3eaa..b24dcb0 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -2445,7 +2445,7 @@
if (mSettings.isNarrowColumnLayout()) {
// In case of automatic text reflow in fixed view port mode.
mInitialViewState.mTextWrapScale =
- ZoomManager.computeReadingLevelScale(data.mScale);
+ mWebView.getReadingLevelScale();
}
} else {
// Scale is given such as when page is restored, use it.
diff --git a/core/java/android/webkit/ZoomManager.java b/core/java/android/webkit/ZoomManager.java
index 2bcb020..0bfb668 100644
--- a/core/java/android/webkit/ZoomManager.java
+++ b/core/java/android/webkit/ZoomManager.java
@@ -58,13 +58,6 @@
private ZoomControlExternal mExternalZoomControl;
/*
- * For large screen devices, the defaultScale usually set to 1.0 and
- * equal to the overview scale, to differentiate the zoom level for double tapping,
- * a default reading level scale is used.
- */
- private static final float DEFAULT_READING_LEVEL_SCALE = 1.5f;
-
- /*
* The scale factors that determine the upper and lower bounds for the
* default zoom scale.
*/
@@ -151,6 +144,19 @@
private float mDefaultScale;
private float mInvDefaultScale;
+ /*
+ * The scale factor that is used to determine the zoom level for reading text.
+ * The value is initially set to equal the display density.
+ * TODO: Support changing this in WebSettings
+ */
+ private float mReadingLevelScale;
+
+ /*
+ * The scale factor that is used as the minimum increment when going from
+ * overview to reading level on a double tap.
+ */
+ private static float MIN_DOUBLE_TAP_SCALE_INCREMENT = 0.5f;
+
// the current computed zoom scale and its inverse.
private float mActualScale;
private float mInvActualScale;
@@ -230,6 +236,7 @@
setDefaultZoomScale(density);
mActualScale = density;
mInvActualScale = 1 / density;
+ mReadingLevelScale = density;
mTextWrapScale = density;
}
@@ -304,13 +311,7 @@
}
public final float getReadingLevelScale() {
- return computeScaleWithLimits(computeReadingLevelScale(getZoomOverviewScale()));
- }
-
- /* package */ final static float computeReadingLevelScale(float scale) {
- // The reading scale is at least 0.5f apart from the input scale.
- final float MIN_SCALE_DIFF = 0.5f;
- return Math.max(scale + MIN_SCALE_DIFF, DEFAULT_READING_LEVEL_SCALE);
+ return mReadingLevelScale;
}
public final float getInvDefaultScale() {
@@ -652,7 +653,7 @@
} else if (!mInZoomOverview && willScaleTriggerZoom(getZoomOverviewScale())) {
zoomToOverview();
} else {
- zoomToReadingLevel();
+ zoomToReadingLevelOrMore();
}
}
@@ -683,8 +684,10 @@
!mWebView.getSettings().getUseFixedViewport());
}
- private void zoomToReadingLevel() {
- final float readingScale = getReadingLevelScale();
+ private void zoomToReadingLevelOrMore() {
+ final float zoomScale = Math.max(getReadingLevelScale(),
+ mActualScale + MIN_DOUBLE_TAP_SCALE_INCREMENT);
+
int left = mWebView.nativeGetBlockLeftEdge(mAnchorX, mAnchorY, mActualScale);
if (left != WebView.NO_LEFTEDGE) {
// add a 5pt padding to the left edge.
@@ -693,13 +696,13 @@
// Re-calculate the zoom center so that the new scroll x will be
// on the left edge.
if (viewLeft > 0) {
- mZoomCenterX = viewLeft * readingScale / (readingScale - mActualScale);
+ mZoomCenterX = viewLeft * zoomScale / (zoomScale - mActualScale);
} else {
mWebView.scrollBy(viewLeft, 0);
mZoomCenterX = 0;
}
}
- startZoomAnimation(readingScale,
+ startZoomAnimation(zoomScale,
!mWebView.getSettings().getUseFixedViewport());
}