Loading core/java/android/webkit/WebView.java +36 −28 Original line number Original line Diff line number Diff line Loading @@ -6724,50 +6724,59 @@ public class WebView extends AbsoluteLayout } } /** /** * Returns true if x/y in content coordinates corresponds to a plugin. * Returns plugin bounds if x/y in content coordinates corresponds to a * plugin. Otherwise a NULL rectangle is returned. */ */ boolean isPluginAt(int x, int y) { Rect getPluginBounds(int x, int y) { return nativePointInNavCache(x, y, mNavSlop) && if (nativePointInNavCache(x, y, mNavSlop) && nativeCacheHitIsPlugin()) { nativeCacheHitIsPlugin(); return nativeCacheHitNodeBounds(); } else { return null; } } } /* /* * Return true if the view (Plugin) is fully visible and maximized inside * Return true if the rect (e.g. plugin) is fully visible and maximized * the WebView. * inside the WebView. */ */ boolean isPluginFitOnScreen(ViewManager.ChildView view) { boolean isRectFitOnScreen(Rect rect) { final int rectWidth = rect.width(); final int rectHeight = rect.height(); final int viewWidth = getViewWidth(); final int viewWidth = getViewWidth(); final int viewHeight = getViewHeightWithTitle(); final int viewHeight = getViewHeightWithTitle(); float scale = Math.min((float) viewWidth / view.width, (float) viewHeight / view.height); float scale = Math.min((float) viewWidth / rectWidth, (float) viewHeight / rectHeight); scale = mZoomManager.computeScaleWithLimits(scale); scale = mZoomManager.computeScaleWithLimits(scale); return !mZoomManager.willScaleTriggerZoom(scale) return !mZoomManager.willScaleTriggerZoom(scale) && contentToViewX(view.x) >= mScrollX && contentToViewX(rect.left) >= mScrollX && contentToViewX(view.x + view.width) <= mScrollX + viewWidth && contentToViewX(rect.right) <= mScrollX + viewWidth && contentToViewY(view.y) >= mScrollY && contentToViewY(rect.top) >= mScrollY && contentToViewY(view.y + view.height) <= mScrollY + viewHeight; && contentToViewY(rect.bottom) <= mScrollY + viewHeight; } } /* /* * Maximize and center the rectangle, specified in the document coordinate * Maximize and center the rectangle, specified in the document coordinate * space, inside the WebView. If the zoom doesn't need to be changed, do an * space, inside the WebView. If the zoom doesn't need to be changed, do an * animated scroll to center it. If the zoom needs to be changed, find the * animated scroll to center it. If the zoom needs to be changed, find the * zoom center and do a smooth zoom transition. * zoom center and do a smooth zoom transition. The rect is in document * coordinates */ */ void centerFitRect(int docX, int docY, int docWidth, int docHeight) { void centerFitRect(Rect rect) { int viewWidth = getViewWidth(); final int rectWidth = rect.width(); int viewHeight = getViewHeightWithTitle(); final int rectHeight = rect.height(); float scale = Math.min((float) viewWidth / docWidth, (float) viewHeight final int viewWidth = getViewWidth(); / docHeight); final int viewHeight = getViewHeightWithTitle(); float scale = Math.min((float) viewWidth / rectWidth, (float) viewHeight / rectHeight); scale = mZoomManager.computeScaleWithLimits(scale); scale = mZoomManager.computeScaleWithLimits(scale); if (!mZoomManager.willScaleTriggerZoom(scale)) { if (!mZoomManager.willScaleTriggerZoom(scale)) { pinScrollTo(contentToViewX(docX + docWidth / 2) - viewWidth / 2, pinScrollTo(contentToViewX(rect.left + rectWidth / 2) - viewWidth / 2, contentToViewY(docY + docHeight / 2) - viewHeight / 2, contentToViewY(rect.top + rectHeight / 2) - viewHeight / 2, true, 0); true, 0); } else { } else { float actualScale = mZoomManager.getScale(); float actualScale = mZoomManager.getScale(); float oldScreenX = docX * actualScale - mScrollX; float oldScreenX = rect.left * actualScale - mScrollX; float rectViewX = docX * scale; float rectViewX = rect.left * scale; float rectViewWidth = docWidth * scale; float rectViewWidth = rectWidth * scale; float newMaxWidth = mContentWidth * scale; float newMaxWidth = mContentWidth * scale; float newScreenX = (viewWidth - rectViewWidth) / 2; float newScreenX = (viewWidth - rectViewWidth) / 2; // pin the newX to the WebView // pin the newX to the WebView Loading @@ -6778,10 +6787,10 @@ public class WebView extends AbsoluteLayout } } float zoomCenterX = (oldScreenX * scale - newScreenX * actualScale) float zoomCenterX = (oldScreenX * scale - newScreenX * actualScale) / (scale - actualScale); / (scale - actualScale); float oldScreenY = docY * actualScale + getTitleHeight() float oldScreenY = rect.top * actualScale + getTitleHeight() - mScrollY; - mScrollY; float rectViewY = docY * scale + getTitleHeight(); float rectViewY = rect.top * scale + getTitleHeight(); float rectViewHeight = docHeight * scale; float rectViewHeight = rectHeight * scale; float newMaxHeight = mContentHeight * scale + getTitleHeight(); float newMaxHeight = mContentHeight * scale + getTitleHeight(); float newScreenY = (viewHeight - rectViewHeight) / 2; float newScreenY = (viewHeight - rectViewHeight) / 2; // pin the newY to the WebView // pin the newY to the WebView Loading Loading @@ -7514,8 +7523,7 @@ public class WebView extends AbsoluteLayout break; break; case CENTER_FIT_RECT: case CENTER_FIT_RECT: Rect r = (Rect)msg.obj; centerFitRect((Rect)msg.obj); centerFitRect(r.left, r.top, r.width(), r.height()); break; break; case SET_SCROLLBAR_MODES: case SET_SCROLLBAR_MODES: Loading core/java/android/webkit/ZoomManager.java +5 −4 Original line number Original line Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.PackageManager; import android.graphics.Canvas; import android.graphics.Canvas; import android.graphics.Point; import android.graphics.Point; import android.graphics.Rect; import android.os.Bundle; import android.os.Bundle; import android.os.SystemClock; import android.os.SystemClock; import android.util.Log; import android.util.Log; Loading Loading @@ -551,12 +552,12 @@ class ZoomManager { * If the double tap was on a plugin then either zoom to maximize the * If the double tap was on a plugin then either zoom to maximize the * plugin on the screen or scale to overview mode. * plugin on the screen or scale to overview mode. */ */ ViewManager.ChildView plugin = mWebView.mViewManager.hitTest(mAnchorX, mAnchorY); Rect pluginBounds = mWebView.getPluginBounds(mAnchorX, mAnchorY); if (plugin != null) { if (pluginBounds != null) { if (mWebView.isPluginFitOnScreen(plugin)) { if (mWebView.isRectFitOnScreen(pluginBounds)) { zoomToOverview(); zoomToOverview(); } else { } else { mWebView.centerFitRect(plugin.x, plugin.y, plugin.width, plugin.height); mWebView.centerFitRect(pluginBounds); } } return; return; } } Loading Loading
core/java/android/webkit/WebView.java +36 −28 Original line number Original line Diff line number Diff line Loading @@ -6724,50 +6724,59 @@ public class WebView extends AbsoluteLayout } } /** /** * Returns true if x/y in content coordinates corresponds to a plugin. * Returns plugin bounds if x/y in content coordinates corresponds to a * plugin. Otherwise a NULL rectangle is returned. */ */ boolean isPluginAt(int x, int y) { Rect getPluginBounds(int x, int y) { return nativePointInNavCache(x, y, mNavSlop) && if (nativePointInNavCache(x, y, mNavSlop) && nativeCacheHitIsPlugin()) { nativeCacheHitIsPlugin(); return nativeCacheHitNodeBounds(); } else { return null; } } } /* /* * Return true if the view (Plugin) is fully visible and maximized inside * Return true if the rect (e.g. plugin) is fully visible and maximized * the WebView. * inside the WebView. */ */ boolean isPluginFitOnScreen(ViewManager.ChildView view) { boolean isRectFitOnScreen(Rect rect) { final int rectWidth = rect.width(); final int rectHeight = rect.height(); final int viewWidth = getViewWidth(); final int viewWidth = getViewWidth(); final int viewHeight = getViewHeightWithTitle(); final int viewHeight = getViewHeightWithTitle(); float scale = Math.min((float) viewWidth / view.width, (float) viewHeight / view.height); float scale = Math.min((float) viewWidth / rectWidth, (float) viewHeight / rectHeight); scale = mZoomManager.computeScaleWithLimits(scale); scale = mZoomManager.computeScaleWithLimits(scale); return !mZoomManager.willScaleTriggerZoom(scale) return !mZoomManager.willScaleTriggerZoom(scale) && contentToViewX(view.x) >= mScrollX && contentToViewX(rect.left) >= mScrollX && contentToViewX(view.x + view.width) <= mScrollX + viewWidth && contentToViewX(rect.right) <= mScrollX + viewWidth && contentToViewY(view.y) >= mScrollY && contentToViewY(rect.top) >= mScrollY && contentToViewY(view.y + view.height) <= mScrollY + viewHeight; && contentToViewY(rect.bottom) <= mScrollY + viewHeight; } } /* /* * Maximize and center the rectangle, specified in the document coordinate * Maximize and center the rectangle, specified in the document coordinate * space, inside the WebView. If the zoom doesn't need to be changed, do an * space, inside the WebView. If the zoom doesn't need to be changed, do an * animated scroll to center it. If the zoom needs to be changed, find the * animated scroll to center it. If the zoom needs to be changed, find the * zoom center and do a smooth zoom transition. * zoom center and do a smooth zoom transition. The rect is in document * coordinates */ */ void centerFitRect(int docX, int docY, int docWidth, int docHeight) { void centerFitRect(Rect rect) { int viewWidth = getViewWidth(); final int rectWidth = rect.width(); int viewHeight = getViewHeightWithTitle(); final int rectHeight = rect.height(); float scale = Math.min((float) viewWidth / docWidth, (float) viewHeight final int viewWidth = getViewWidth(); / docHeight); final int viewHeight = getViewHeightWithTitle(); float scale = Math.min((float) viewWidth / rectWidth, (float) viewHeight / rectHeight); scale = mZoomManager.computeScaleWithLimits(scale); scale = mZoomManager.computeScaleWithLimits(scale); if (!mZoomManager.willScaleTriggerZoom(scale)) { if (!mZoomManager.willScaleTriggerZoom(scale)) { pinScrollTo(contentToViewX(docX + docWidth / 2) - viewWidth / 2, pinScrollTo(contentToViewX(rect.left + rectWidth / 2) - viewWidth / 2, contentToViewY(docY + docHeight / 2) - viewHeight / 2, contentToViewY(rect.top + rectHeight / 2) - viewHeight / 2, true, 0); true, 0); } else { } else { float actualScale = mZoomManager.getScale(); float actualScale = mZoomManager.getScale(); float oldScreenX = docX * actualScale - mScrollX; float oldScreenX = rect.left * actualScale - mScrollX; float rectViewX = docX * scale; float rectViewX = rect.left * scale; float rectViewWidth = docWidth * scale; float rectViewWidth = rectWidth * scale; float newMaxWidth = mContentWidth * scale; float newMaxWidth = mContentWidth * scale; float newScreenX = (viewWidth - rectViewWidth) / 2; float newScreenX = (viewWidth - rectViewWidth) / 2; // pin the newX to the WebView // pin the newX to the WebView Loading @@ -6778,10 +6787,10 @@ public class WebView extends AbsoluteLayout } } float zoomCenterX = (oldScreenX * scale - newScreenX * actualScale) float zoomCenterX = (oldScreenX * scale - newScreenX * actualScale) / (scale - actualScale); / (scale - actualScale); float oldScreenY = docY * actualScale + getTitleHeight() float oldScreenY = rect.top * actualScale + getTitleHeight() - mScrollY; - mScrollY; float rectViewY = docY * scale + getTitleHeight(); float rectViewY = rect.top * scale + getTitleHeight(); float rectViewHeight = docHeight * scale; float rectViewHeight = rectHeight * scale; float newMaxHeight = mContentHeight * scale + getTitleHeight(); float newMaxHeight = mContentHeight * scale + getTitleHeight(); float newScreenY = (viewHeight - rectViewHeight) / 2; float newScreenY = (viewHeight - rectViewHeight) / 2; // pin the newY to the WebView // pin the newY to the WebView Loading Loading @@ -7514,8 +7523,7 @@ public class WebView extends AbsoluteLayout break; break; case CENTER_FIT_RECT: case CENTER_FIT_RECT: Rect r = (Rect)msg.obj; centerFitRect((Rect)msg.obj); centerFitRect(r.left, r.top, r.width(), r.height()); break; break; case SET_SCROLLBAR_MODES: case SET_SCROLLBAR_MODES: Loading
core/java/android/webkit/ZoomManager.java +5 −4 Original line number Original line Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.PackageManager; import android.graphics.Canvas; import android.graphics.Canvas; import android.graphics.Point; import android.graphics.Point; import android.graphics.Rect; import android.os.Bundle; import android.os.Bundle; import android.os.SystemClock; import android.os.SystemClock; import android.util.Log; import android.util.Log; Loading Loading @@ -551,12 +552,12 @@ class ZoomManager { * If the double tap was on a plugin then either zoom to maximize the * If the double tap was on a plugin then either zoom to maximize the * plugin on the screen or scale to overview mode. * plugin on the screen or scale to overview mode. */ */ ViewManager.ChildView plugin = mWebView.mViewManager.hitTest(mAnchorX, mAnchorY); Rect pluginBounds = mWebView.getPluginBounds(mAnchorX, mAnchorY); if (plugin != null) { if (pluginBounds != null) { if (mWebView.isPluginFitOnScreen(plugin)) { if (mWebView.isRectFitOnScreen(pluginBounds)) { zoomToOverview(); zoomToOverview(); } else { } else { mWebView.centerFitRect(plugin.x, plugin.y, plugin.width, plugin.height); mWebView.centerFitRect(pluginBounds); } } return; return; } } Loading