From 5229200dd36f803ed11c8d10d776c5c0cdeb0d14 Mon Sep 17 00:00:00 2001 From: shepshapard Date: Mon, 25 Jun 2018 13:42:11 -0700 Subject: [PATCH] Fix invisible scroll thumb blocks clicks. The current issue is that Views that have either the horizontal or vertical scroll bars enabled will intercept mouse interactions that entire the region where the scrolling thumb would be even if the View cannot actually scroll because it's content isn't larger than it. This is fixed by only intercepting mouse interactions in the scroll thumb region if there is something to scroll. Bug: 110375792 Test: None yet Change-Id: Ib638b4ac88375f55bc80ba2a66d945a16ecd6d22 --- core/java/android/view/View.java | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 0e5527dfe39e..546ea87e23a2 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -6119,14 +6119,18 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } x += getScrollX(); y += getScrollY(); - if (isVerticalScrollBarEnabled() && !isVerticalScrollBarHidden()) { + final boolean canScrollVertically = + computeVerticalScrollRange() > computeVerticalScrollExtent(); + if (isVerticalScrollBarEnabled() && !isVerticalScrollBarHidden() && canScrollVertically) { final Rect touchBounds = mScrollCache.mScrollBarTouchBounds; getVerticalScrollBarBounds(null, touchBounds); if (touchBounds.contains((int) x, (int) y)) { return true; } } - if (isHorizontalScrollBarEnabled()) { + final boolean canScrollHorizontally = + computeHorizontalScrollRange() > computeHorizontalScrollExtent(); + if (isHorizontalScrollBarEnabled() && canScrollHorizontally) { final Rect touchBounds = mScrollCache.mScrollBarTouchBounds; getHorizontalScrollBarBounds(null, touchBounds); if (touchBounds.contains((int) x, (int) y)) { @@ -6141,18 +6145,18 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } private boolean isOnVerticalScrollbarThumb(float x, float y) { - if (mScrollCache == null) { + if (mScrollCache == null || !isVerticalScrollBarEnabled() || isVerticalScrollBarHidden()) { return false; } - if (isVerticalScrollBarEnabled() && !isVerticalScrollBarHidden()) { + final int range = computeVerticalScrollRange(); + final int extent = computeVerticalScrollExtent(); + if (range > extent) { x += getScrollX(); y += getScrollY(); final Rect bounds = mScrollCache.mScrollBarBounds; final Rect touchBounds = mScrollCache.mScrollBarTouchBounds; getVerticalScrollBarBounds(bounds, touchBounds); - final int range = computeVerticalScrollRange(); final int offset = computeVerticalScrollOffset(); - final int extent = computeVerticalScrollExtent(); final int thumbLength = ScrollBarUtils.getThumbLength(bounds.height(), bounds.width(), extent, range); final int thumbOffset = ScrollBarUtils.getThumbOffset(bounds.height(), thumbLength, @@ -6168,18 +6172,19 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } private boolean isOnHorizontalScrollbarThumb(float x, float y) { - if (mScrollCache == null) { + if (mScrollCache == null || !isHorizontalScrollBarEnabled()) { return false; } - if (isHorizontalScrollBarEnabled()) { + final int range = computeHorizontalScrollRange(); + final int extent = computeHorizontalScrollExtent(); + if (range > extent) { x += getScrollX(); y += getScrollY(); final Rect bounds = mScrollCache.mScrollBarBounds; final Rect touchBounds = mScrollCache.mScrollBarTouchBounds; getHorizontalScrollBarBounds(bounds, touchBounds); - final int range = computeHorizontalScrollRange(); final int offset = computeHorizontalScrollOffset(); - final int extent = computeHorizontalScrollExtent(); + final int thumbLength = ScrollBarUtils.getThumbLength(bounds.width(), bounds.height(), extent, range); final int thumbOffset = ScrollBarUtils.getThumbOffset(bounds.width(), thumbLength, -- 2.11.0