From c0c03af15f60e4402026c456cc55c108895a508f Mon Sep 17 00:00:00 2001 From: Grace Kloba Date: Thu, 17 Sep 2009 11:01:44 -0700 Subject: [PATCH] Fix the zoom center. Now there is a titlebar, the zoom center needs to be adjusted for it as the user really cares the spot in the document. We need to pin zoom around that spot. Fix http://b/issue?id=2126300 --- core/java/android/webkit/WebView.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index a5536dde0b5e..740c39e003ad 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -1923,7 +1923,8 @@ public class WebView extends AbsoluteLayout int oldY = mScrollY; float ratio = scale * mInvActualScale; // old inverse float sx = ratio * oldX + (ratio - 1) * mZoomCenterX; - float sy = ratio * oldY + (ratio - 1) * mZoomCenterY; + float sy = ratio * oldY + (ratio - 1) + * (mZoomCenterY - getTitleHeight()); // now update our new scale and inverse if (scale != mActualScale && !mPreviewZoomOnly) { @@ -2781,15 +2782,20 @@ public class WebView extends AbsoluteLayout } } } + // calculate the intermediate scroll position. As we need to use + // zoomScale, we can't use pinLocX/Y directly. Copy the logic here. float scale = zoomScale * mInvInitialZoomScale; int tx = Math.round(scale * (mInitialScrollX + mZoomCenterX) - mZoomCenterX); tx = -pinLoc(tx, getViewWidth(), Math.round(mContentWidth * zoomScale)) + mScrollX; - int ty = Math.round(scale * (mInitialScrollY + mZoomCenterY) - - mZoomCenterY); - ty = -pinLoc(ty, getViewHeight(), Math.round(mContentHeight - * zoomScale)) + mScrollY; + int titleHeight = getTitleHeight(); + int ty = Math.round(scale + * (mInitialScrollY + mZoomCenterY - titleHeight) + - (mZoomCenterY - titleHeight)); + ty = -(ty <= titleHeight ? Math.max(ty, 0) : pinLoc(ty + - titleHeight, getViewHeight(), Math.round(mContentHeight + * zoomScale)) + titleHeight) + mScrollY; canvas.translate(tx, ty); canvas.scale(zoomScale, zoomScale); if (inEditingMode() && !mNeedToAdjustWebTextView -- 2.11.0