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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/coordinator/CoordinatorLayoutForPointer.java

Issue 2878403002: Support setting mouse cursor icon in Android N. (Closed)
Patch Set: Support setting mouse cursor icon in Android N Created 3 years, 4 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.coordinator;
6
7 import android.content.Context;
8 import android.os.Build;
9 import android.support.design.widget.CoordinatorLayout;
10 import android.util.AttributeSet;
11 import android.view.MotionEvent;
12 import android.view.PointerIcon;
13 import android.view.View;
14
15 /**
16 * This class overrides {@link onResolvePointerIcon} method to correctly determi ne the pointer icon
17 * from a mouse motion event. This is needed because the default android impl do es not consider
18 * view visibility.
19 */
20 public class CoordinatorLayoutForPointer extends CoordinatorLayout {
21 public CoordinatorLayoutForPointer(Context context, AttributeSet attrs) {
22 super(context, attrs);
23 }
24
25 private boolean isWithinBoundOfView(int x, int y, View view) {
26 return ((x >= view.getLeft() && x <= view.getRight())
27 && (y >= view.getTop() && y <= view.getBottom()));
28 }
29
30 @Override
31 public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
32 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return null;
33
34 final int x = (int) event.getX(pointerIndex);
35 final int y = (int) event.getY(pointerIndex);
36 final int childrenCount = getChildCount();
37 for (int i = childrenCount - 1; i >= 0; --i) {
38 if (getChildAt(i).getVisibility() != VISIBLE) continue;
39 if (isWithinBoundOfView(x, y, getChildAt(i))) {
40 return getChildAt(i).onResolvePointerIcon(event, pointerIndex);
41 }
42 }
43 return super.onResolvePointerIcon(event, pointerIndex);
44 }
45 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698