From 5fe6f951ac0b013be76f2b34b8e87ca6d11010b3 Mon Sep 17 00:00:00 2001 From: Mangesh Ghiware Date: Thu, 2 Feb 2012 16:19:54 -0800 Subject: Use WebKit hit testing result for centering on double-tap zoom. Iterate over the bounding boxes and find one large enough to fit the screen width at reading scale. Align to left edge of said box. Bug: 5175030 Bug: 5768421 Change-Id: Iac01e145336918b0a2b21d2864f46ba532aaf18f --- core/java/android/webkit/WebView.java | 28 ++++++++++++++++++++++++++++ core/java/android/webkit/WebViewCore.java | 1 + core/java/android/webkit/ZoomManager.java | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 4a42e92..86ae7db 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -2781,6 +2781,34 @@ public class WebView extends AbsoluteLayout return result; } + int getBlockLeftEdge(int x, int y, float readingScale) { + if (!sDisableNavcache) { + return nativeGetBlockLeftEdge(x, y, readingScale); + } + + float invReadingScale = 1.0f / readingScale; + int readingWidth = (int) (getViewWidth() * invReadingScale); + int left = NO_LEFTEDGE; + if (mFocusedNode != null) { + final int length = mFocusedNode.mEnclosingParentRects.length; + for (int i = 0; i < length; i++) { + Rect rect = mFocusedNode.mEnclosingParentRects[i]; + if (rect.width() < mFocusedNode.mHitTestSlop) { + // ignore bounding boxes that are too small + continue; + } else if (left != NO_LEFTEDGE && rect.width() > readingWidth) { + // stop when bounding box doesn't fit the screen width + // at reading scale + break; + } + + left = rect.left; + } + } + + return left; + } + // Called by JNI when the DOM has changed the focus. Clear the focus so // that new keys will go to the newly focused field private void domChangedFocus() { diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index 395a638..abfeb79 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -872,6 +872,7 @@ public final class WebViewCore { Rect[] mTouchRects; boolean mEditable; int mTapHighlightColor = WebView.HIGHLIGHT_COLOR; + Rect[] mEnclosingParentRects; // These are the input values that produced this hit test int mHitTestX; diff --git a/core/java/android/webkit/ZoomManager.java b/core/java/android/webkit/ZoomManager.java index 8ffba64..ae2d617 100644 --- a/core/java/android/webkit/ZoomManager.java +++ b/core/java/android/webkit/ZoomManager.java @@ -717,7 +717,7 @@ class ZoomManager { private void zoomToReadingLevel() { final float readingScale = getReadingLevelScale(); - int left = mWebView.nativeGetBlockLeftEdge(mAnchorX, mAnchorY, mActualScale); + int left = mWebView.getBlockLeftEdge(mAnchorX, mAnchorY, readingScale); if (left != WebView.NO_LEFTEDGE) { // add a 5pt padding to the left edge. int viewLeft = mWebView.contentToViewX(left < 5 ? 0 : (left - 5)) -- cgit v1.1