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

Side by Side Diff: android_webview/java/src/org/chromium/android_webview/PopupTouchHandleDrawable.java

Issue 2410223003: Hide the PopupTouchHandlerDrawable if it is occluded. (Closed)
Patch Set: address comments 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.android_webview; 5 package org.chromium.android_webview;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.content.Context; 8 import android.content.Context;
9 import android.graphics.Canvas; 9 import android.graphics.Canvas;
10 import android.graphics.drawable.Drawable; 10 import android.graphics.drawable.Drawable;
11 import android.os.Build; 11 import android.os.Build;
12 import android.os.SystemClock; 12 import android.os.SystemClock;
13 import android.view.Gravity;
13 import android.view.MotionEvent; 14 import android.view.MotionEvent;
14 import android.view.View; 15 import android.view.View;
15 import android.view.ViewGroup; 16 import android.view.ViewGroup;
17 import android.view.ViewParent;
16 import android.view.WindowManager; 18 import android.view.WindowManager;
17 import android.view.animation.AnimationUtils; 19 import android.view.animation.AnimationUtils;
18 import android.widget.PopupWindow; 20 import android.widget.PopupWindow;
19 21
20 import org.chromium.base.ObserverList; 22 import org.chromium.base.ObserverList;
21 import org.chromium.base.annotations.CalledByNative; 23 import org.chromium.base.annotations.CalledByNative;
22 import org.chromium.base.annotations.JNINamespace; 24 import org.chromium.base.annotations.JNINamespace;
23 import org.chromium.content.browser.ContentViewCore; 25 import org.chromium.content.browser.ContentViewCore;
24 import org.chromium.content.browser.PositionObserver; 26 import org.chromium.content.browser.PositionObserver;
25 import org.chromium.content.browser.ViewPositionObserver; 27 import org.chromium.content.browser.ViewPositionObserver;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 final float deviceScale = mContentViewCore.getDeviceScaleFactor(); 267 final float deviceScale = mContentViewCore.getDeviceScaleFactor();
266 return mParentPositionY + (int) (mOriginYDip * deviceScale); 268 return mParentPositionY + (int) (mOriginYDip * deviceScale);
267 } 269 }
268 270
269 private void updatePosition() { 271 private void updatePosition() {
270 mContainer.update(getContainerPositionX(), getContainerPositionY(), 272 mContainer.update(getContainerPositionX(), getContainerPositionY(),
271 getRight() - getLeft(), getBottom() - getTop()); 273 getRight() - getLeft(), getBottom() - getTop());
272 } 274 }
273 275
274 private boolean isShowingAllowed() { 276 private boolean isShowingAllowed() {
275 return mAttachedToWindow && mVisible && mFocused && !mScrolling && !mTem porarilyHidden; 277 final float deviceScale = mContentViewCore.getDeviceScaleFactor();
278 // mOriginX/YDip * deviceScale is the distance of the handler drawable f rom the top left of
279 // the containerView (the WebView).
280 return mAttachedToWindow && mVisible && mFocused && !mScrolling && !mTem porarilyHidden
281 && isPositionVisible(mOriginXDip * deviceScale, mOriginYDip * de viceScale);
282 }
283
284 // Adapted from android.widget.Editor#isPositionVisible.
285 private boolean isPositionVisible(final float positionX, final float positio nY) {
286 final float[] position = new float[2];
287 position[0] = positionX;
288 position[1] = positionY;
289 View view = mContentViewCore.getContainerView();
290
291 while (view != null) {
292 if (view != mContentViewCore.getContainerView()) {
293 // Local scroll is already taken into account in positionX/Y
294 position[0] -= view.getScrollX();
295 position[1] -= view.getScrollY();
296 }
297
298 final float drawableWidth = mDrawable.getIntrinsicWidth();
299 final float drawableHeight = mDrawable.getIntrinsicHeight();
300
301 if (position[0] + drawableWidth < 0 || position[1] + drawableHeight < 0
302 || position[0] > view.getWidth() || position[1] > view.getHe ight()) {
303 return false;
304 }
305
306 if (!view.getMatrix().isIdentity()) {
307 view.getMatrix().mapPoints(position);
308 }
309
310 position[0] += view.getLeft();
311 position[1] += view.getTop();
312
313 final ViewParent parent = view.getParent();
314 if (parent instanceof View) {
315 view = (View) parent;
316 } else {
317 // We've reached the ViewRoot, stop iterating
318 view = null;
319 }
320 }
321
322 // We've been able to walk up the view hierarchy and the position was ne ver clipped
323 return true;
276 } 324 }
277 325
278 private void updateVisibility() { 326 private void updateVisibility() {
279 int newVisibility = isShowingAllowed() ? VISIBLE : INVISIBLE; 327 int newVisibility = isShowingAllowed() ? VISIBLE : INVISIBLE;
280 328
281 // When regaining visibility, delay the visibility update by one frame 329 // When regaining visibility, delay the visibility update by one frame
282 // to ensure the PopupWindow has first been positioned properly. 330 // to ensure the PopupWindow has first been positioned properly.
283 if (newVisibility == VISIBLE && getVisibility() != VISIBLE) { 331 if (newVisibility == VISIBLE && getVisibility() != VISIBLE) {
284 if (!mDelayVisibilityUpdateWAR) { 332 if (!mDelayVisibilityUpdateWAR) {
285 mDelayVisibilityUpdateWAR = true; 333 mDelayVisibilityUpdateWAR = true;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 if (mContentViewCore == null) return; 498 if (mContentViewCore == null) return;
451 if (mContainer.isShowing()) return; 499 if (mContainer.isShowing()) return;
452 500
453 // While hidden, the parent position may have become stale. It must be u pdated before 501 // While hidden, the parent position may have become stale. It must be u pdated before
454 // checking isPositionVisible(). 502 // checking isPositionVisible().
455 updateParentPosition(mParentPositionObserver.getPositionX(), 503 updateParentPosition(mParentPositionObserver.getPositionX(),
456 mParentPositionObserver.getPositionY()); 504 mParentPositionObserver.getPositionY());
457 mParentPositionObserver.addListener(mParentPositionListener); 505 mParentPositionObserver.addListener(mParentPositionListener);
458 mContainer.setContentView(this); 506 mContainer.setContentView(this);
459 try { 507 try {
460 mContainer.showAtLocation(mContentViewCore.getContainerView(), 0, 508 mContainer.showAtLocation(mContentViewCore.getContainerView(), Gravi ty.NO_GRAVITY,
461 getContainerPositionX(), getContainerPositionY()); 509 getContainerPositionX(), getContainerPositionY());
462 } catch (WindowManager.BadTokenException e) { 510 } catch (WindowManager.BadTokenException e) {
463 hide(); 511 hide();
464 } 512 }
465 } 513 }
466 514
467 @CalledByNative 515 @CalledByNative
468 private void hide() { 516 private void hide() {
469 mTemporarilyHiddenExpireTime = 0; 517 mTemporarilyHiddenExpireTime = 0;
470 setTemporarilyHidden(false); 518 setTemporarilyHidden(false);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 // must be updated accordingly. 571 // must be updated accordingly.
524 mParentPositionObserver.clearListener(); 572 mParentPositionObserver.clearListener();
525 mParentPositionObserver = new ViewPositionObserver(newContainerView); 573 mParentPositionObserver = new ViewPositionObserver(newContainerView);
526 if (mContainer.isShowing()) { 574 if (mContainer.isShowing()) {
527 mParentPositionObserver.addListener(mParentPositionListener); 575 mParentPositionObserver.addListener(mParentPositionListener);
528 } 576 }
529 } 577 }
530 578
531 private native long nativeInit(float horizontalPaddingRatio); 579 private native long nativeInit(float horizontalPaddingRatio);
532 } 580 }
OLDNEW
« 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