Skip to content

Commit edb528e

Browse files
committed
Add setting for configuring zoom level on double-tap.
In overview mode, text wrap is done at reading level scale. If user changes double-tap zoom in overview mode, reflow text at the new scale. In any other mode, a double-tap will take user to overview mode, at which point, the text will be reflowed at the updated reading level scale. Bug: 5312461 Change-Id: I29be34a32246019101a9a875e1758e22b5af2bd3
1 parent c351ab4 commit edb528e

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

core/java/android/webkit/WebSettings.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public enum PluginState {
211211
private ZoomDensity mDefaultZoom = ZoomDensity.MEDIUM;
212212
private RenderPriority mRenderPriority = RenderPriority.NORMAL;
213213
private int mOverrideCacheMode = LOAD_DEFAULT;
214+
private int mDoubleTapZoom = 100;
214215
private boolean mSaveFormData = true;
215216
private boolean mAutoFillEnabled = false;
216217
private boolean mSavePassword = true;
@@ -768,6 +769,27 @@ public synchronized TextSize getTextSize() {
768769
return closestSize != null ? closestSize : TextSize.NORMAL;
769770
}
770771

772+
/**
773+
* Set the double-tap zoom of the page in percent. Default is 100.
774+
* @param doubleTapZoom A percent value for increasing or decreasing the double-tap zoom.
775+
* @hide
776+
*/
777+
public void setDoubleTapZoom(int doubleTapZoom) {
778+
if (mDoubleTapZoom != doubleTapZoom) {
779+
mDoubleTapZoom = doubleTapZoom;
780+
mWebView.updateDoubleTapZoom();
781+
}
782+
}
783+
784+
/**
785+
* Get the double-tap zoom of the page in percent.
786+
* @return A percent value describing the double-tap zoom.
787+
* @hide
788+
*/
789+
public int getDoubleTapZoom() {
790+
return mDoubleTapZoom;
791+
}
792+
771793
/**
772794
* Set the default zoom density of the page. This should be called from UI
773795
* thread.

core/java/android/webkit/WebView.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,6 +2986,13 @@ boolean sendViewSizeZoom(boolean force) {
29862986
return false;
29872987
}
29882988

2989+
/**
2990+
* Update the double-tap zoom.
2991+
*/
2992+
/* package */ void updateDoubleTapZoom() {
2993+
mZoomManager.updateDoubleTapZoom();
2994+
}
2995+
29892996
private int computeRealHorizontalScrollRange() {
29902997
if (mDrawHistory) {
29912998
return mHistoryWidth;

core/java/android/webkit/ZoomManager.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ class ZoomManager {
145145
private float mInvDefaultScale;
146146

147147
/*
148-
* The scale factor that is used to determine the zoom level for reading text.
149-
* The value is initially set to equal the display density.
150-
* TODO: Support changing this in WebSettings
148+
* The logical density of the display. This is a scaling factor for the
149+
* Density Independent Pixel unit, where one DIP is one pixel on an
150+
* approximately 160 dpi screen (see android.util.DisplayMetrics.density)
151151
*/
152-
private float mReadingLevelScale;
152+
private float mDisplayDensity;
153153

154154
/*
155155
* The scale factor that is used as the minimum increment when going from
@@ -233,11 +233,11 @@ public ZoomManager(WebView webView, CallbackProxy callbackProxy) {
233233
public void init(float density) {
234234
assert density > 0;
235235

236+
mDisplayDensity = density;
236237
setDefaultZoomScale(density);
237238
mActualScale = density;
238239
mInvActualScale = 1 / density;
239-
mReadingLevelScale = density;
240-
mTextWrapScale = density;
240+
mTextWrapScale = getReadingLevelScale();
241241
}
242242

243243
/**
@@ -310,8 +310,11 @@ public final float getDefaultScale() {
310310
return mInitialScale > 0 ? mInitialScale : mDefaultScale;
311311
}
312312

313+
/**
314+
* Returns the zoom scale used for reading text on a double-tap.
315+
*/
313316
public final float getReadingLevelScale() {
314-
return mReadingLevelScale;
317+
return mDisplayDensity * mWebView.getSettings().getDoubleTapZoom() / 100.0f;
315318
}
316319

317320
public final float getInvDefaultScale() {
@@ -510,6 +513,13 @@ public boolean isFixedLengthAnimationInProgress() {
510513
return mZoomScale != 0 || mInHWAcceleratedZoom;
511514
}
512515

516+
public void updateDoubleTapZoom() {
517+
if (mInZoomOverview) {
518+
mTextWrapScale = getReadingLevelScale();
519+
refreshZoomScale(true);
520+
}
521+
}
522+
513523
public void refreshZoomScale(boolean reflowText) {
514524
setZoomScale(mActualScale, reflowText, true);
515525
}

0 commit comments

Comments
 (0)