summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Derek Sollenberger <djsollen@google.com> 2011-01-18 10:38:34 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2011-01-18 10:38:34 -0800
commit788c51852a559f17188f60c40f0c0d83abbafab2 (patch)
treef7f7db629db02867bb8b4c38383b8f8ce2db208b
parent8d74f7f560498966d06a1fb5f490d182ade6c3c2 (diff)
parentdd1173bc9be22a2bb5054a760a74d3d5e49161ed (diff)
Merge "Fix smart zoom for plugins that use OpenGL." into honeycomb
-rw-r--r--core/java/android/webkit/WebView.java64
-rw-r--r--core/java/android/webkit/ZoomManager.java9
2 files changed, 41 insertions, 32 deletions
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 0a32c9e69a7b..78d4cd2f5e3e 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -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) {
- return nativePointInNavCache(x, y, mNavSlop) &&
- nativeCacheHitIsPlugin();
+ Rect getPluginBounds(int x, int y) {
+ if (nativePointInNavCache(x, y, mNavSlop) && nativeCacheHitIsPlugin()) {
+ return nativeCacheHitNodeBounds();
+ } else {
+ return null;
+ }
}
/*
- * Return true if the view (Plugin) is fully visible and maximized inside
- * the WebView.
+ * Return true if the rect (e.g. plugin) is fully visible and maximized
+ * 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 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);
return !mZoomManager.willScaleTriggerZoom(scale)
- && contentToViewX(view.x) >= mScrollX
- && contentToViewX(view.x + view.width) <= mScrollX + viewWidth
- && contentToViewY(view.y) >= mScrollY
- && contentToViewY(view.y + view.height) <= mScrollY + viewHeight;
+ && contentToViewX(rect.left) >= mScrollX
+ && contentToViewX(rect.right) <= mScrollX + viewWidth
+ && contentToViewY(rect.top) >= mScrollY
+ && contentToViewY(rect.bottom) <= mScrollY + viewHeight;
}
/*
* 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
* 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) {
- int viewWidth = getViewWidth();
- int viewHeight = getViewHeightWithTitle();
- float scale = Math.min((float) viewWidth / docWidth, (float) viewHeight
- / docHeight);
+ void centerFitRect(Rect rect) {
+ final int rectWidth = rect.width();
+ final int rectHeight = rect.height();
+ final int viewWidth = getViewWidth();
+ final int viewHeight = getViewHeightWithTitle();
+ float scale = Math.min((float) viewWidth / rectWidth, (float) viewHeight
+ / rectHeight);
scale = mZoomManager.computeScaleWithLimits(scale);
if (!mZoomManager.willScaleTriggerZoom(scale)) {
- pinScrollTo(contentToViewX(docX + docWidth / 2) - viewWidth / 2,
- contentToViewY(docY + docHeight / 2) - viewHeight / 2,
+ pinScrollTo(contentToViewX(rect.left + rectWidth / 2) - viewWidth / 2,
+ contentToViewY(rect.top + rectHeight / 2) - viewHeight / 2,
true, 0);
} else {
float actualScale = mZoomManager.getScale();
- float oldScreenX = docX * actualScale - mScrollX;
- float rectViewX = docX * scale;
- float rectViewWidth = docWidth * scale;
+ float oldScreenX = rect.left * actualScale - mScrollX;
+ float rectViewX = rect.left * scale;
+ float rectViewWidth = rectWidth * scale;
float newMaxWidth = mContentWidth * scale;
float newScreenX = (viewWidth - rectViewWidth) / 2;
// pin the newX to the WebView
@@ -6778,10 +6787,10 @@ public class WebView extends AbsoluteLayout
}
float zoomCenterX = (oldScreenX * scale - newScreenX * actualScale)
/ (scale - actualScale);
- float oldScreenY = docY * actualScale + getTitleHeight()
+ float oldScreenY = rect.top * actualScale + getTitleHeight()
- mScrollY;
- float rectViewY = docY * scale + getTitleHeight();
- float rectViewHeight = docHeight * scale;
+ float rectViewY = rect.top * scale + getTitleHeight();
+ float rectViewHeight = rectHeight * scale;
float newMaxHeight = mContentHeight * scale + getTitleHeight();
float newScreenY = (viewHeight - rectViewHeight) / 2;
// pin the newY to the WebView
@@ -7514,8 +7523,7 @@ public class WebView extends AbsoluteLayout
break;
case CENTER_FIT_RECT:
- Rect r = (Rect)msg.obj;
- centerFitRect(r.left, r.top, r.width(), r.height());
+ centerFitRect((Rect)msg.obj);
break;
case SET_SCROLLBAR_MODES:
diff --git a/core/java/android/webkit/ZoomManager.java b/core/java/android/webkit/ZoomManager.java
index b4a33de232c3..88a54ea06d70 100644
--- a/core/java/android/webkit/ZoomManager.java
+++ b/core/java/android/webkit/ZoomManager.java
@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Canvas;
import android.graphics.Point;
+import android.graphics.Rect;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
@@ -551,12 +552,12 @@ class ZoomManager {
* If the double tap was on a plugin then either zoom to maximize the
* plugin on the screen or scale to overview mode.
*/
- ViewManager.ChildView plugin = mWebView.mViewManager.hitTest(mAnchorX, mAnchorY);
- if (plugin != null) {
- if (mWebView.isPluginFitOnScreen(plugin)) {
+ Rect pluginBounds = mWebView.getPluginBounds(mAnchorX, mAnchorY);
+ if (pluginBounds != null) {
+ if (mWebView.isRectFitOnScreen(pluginBounds)) {
zoomToOverview();
} else {
- mWebView.centerFitRect(plugin.x, plugin.y, plugin.width, plugin.height);
+ mWebView.centerFitRect(pluginBounds);
}
return;
}