Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2859)

Unified Diff: android_webview/java/src/org/chromium/android_webview/PopupTouchHandleDrawable.java

Issue 2413113002: Hide the PopupTouchHandlerDrawable if it is occluded. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/java/src/org/chromium/android_webview/PopupTouchHandleDrawable.java
diff --git a/android_webview/java/src/org/chromium/android_webview/PopupTouchHandleDrawable.java b/android_webview/java/src/org/chromium/android_webview/PopupTouchHandleDrawable.java
index 06ed10e2c76f6a47d751627a2763834a4c7d6fa3..3ff98343cea2b2c478152fda964b7dad672b6edb 100644
--- a/android_webview/java/src/org/chromium/android_webview/PopupTouchHandleDrawable.java
+++ b/android_webview/java/src/org/chromium/android_webview/PopupTouchHandleDrawable.java
@@ -10,9 +10,11 @@ import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.SystemClock;
+import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewParent;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.PopupWindow;
@@ -272,7 +274,53 @@ public class PopupTouchHandleDrawable extends View {
}
private boolean isShowingAllowed() {
- return mAttachedToWindow && mVisible && mFocused && !mScrolling && !mTemporarilyHidden;
+ final float deviceScale = mContentViewCore.getDeviceScaleFactor();
+ // mOriginX/YDip * deviceScale is the distance of the handler drawable from the top left of
+ // the containerView (the WebView).
+ return mAttachedToWindow && mVisible && mFocused && !mScrolling && !mTemporarilyHidden
+ && isPositionVisible(mOriginXDip * deviceScale, mOriginYDip * deviceScale);
+ }
+
+ // Adapted from android.widget.Editor#isPositionVisible.
+ private boolean isPositionVisible(final float positionX, final float positionY) {
+ final float[] position = new float[2];
+ position[0] = positionX;
+ position[1] = positionY;
+ View view = mContentViewCore.getContainerView();
+
+ while (view != null) {
+ if (view != mContentViewCore.getContainerView()) {
+ // Local scroll is already taken into account in positionX/Y
+ position[0] -= view.getScrollX();
+ position[1] -= view.getScrollY();
+ }
+
+ final float drawableWidth = mDrawable.getIntrinsicWidth();
+ final float drawableHeight = mDrawable.getIntrinsicHeight();
+
+ if (position[0] + drawableWidth < 0 || position[1] + drawableHeight < 0
+ || position[0] > view.getWidth() || position[1] > view.getHeight()) {
+ return false;
+ }
+
+ if (!view.getMatrix().isIdentity()) {
+ view.getMatrix().mapPoints(position);
+ }
+
+ position[0] += view.getLeft();
+ position[1] += view.getTop();
+
+ final ViewParent parent = view.getParent();
+ if (parent instanceof View) {
+ view = (View) parent;
+ } else {
+ // We've reached the ViewRoot, stop iterating
+ view = null;
+ }
+ }
+
+ // We've been able to walk up the view hierarchy and the position was never clipped
+ return true;
}
private void updateVisibility() {
@@ -457,7 +505,7 @@ public class PopupTouchHandleDrawable extends View {
mParentPositionObserver.addListener(mParentPositionListener);
mContainer.setContentView(this);
try {
- mContainer.showAtLocation(mContentViewCore.getContainerView(), 0,
+ mContainer.showAtLocation(mContentViewCore.getContainerView(), Gravity.NO_GRAVITY,
getContainerPositionX(), getContainerPositionY());
} catch (WindowManager.BadTokenException e) {
hide();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698