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

Side by Side Diff: ui/android/java/src/org/chromium/ui/base/ViewAndroidDelegate.java

Issue 2878403002: Support setting mouse cursor icon in Android N. (Closed)
Patch Set: Support setting pointer icon in Android N Created 3 years, 7 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
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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.ui.base; 5 package org.chromium.ui.base;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.content.ClipData; 8 import android.content.ClipData;
9 import android.graphics.Bitmap; 9 import android.graphics.Bitmap;
10 import android.os.Build; 10 import android.os.Build;
11 import android.view.PointerIcon;
11 import android.view.View; 12 import android.view.View;
12 import android.view.ViewGroup; 13 import android.view.ViewGroup;
13 import android.widget.FrameLayout.LayoutParams; 14 import android.widget.FrameLayout.LayoutParams;
14 import android.widget.ImageView; 15 import android.widget.ImageView;
15 16
16 import org.chromium.base.ApiCompatibilityUtils; 17 import org.chromium.base.ApiCompatibilityUtils;
17 import org.chromium.base.annotations.CalledByNative; 18 import org.chromium.base.annotations.CalledByNative;
18 import org.chromium.base.annotations.JNINamespace; 19 import org.chromium.base.annotations.JNINamespace;
20 import org.chromium.blink_public.web.WebCursorInfoType;
19 21
20 /** 22 /**
21 * Class to acquire, position, and remove anchor views from the implementing Vie w. 23 * Class to acquire, position, and remove anchor views from the implementing Vie w.
22 */ 24 */
23 @JNINamespace("ui") 25 @JNINamespace("ui")
24 public abstract class ViewAndroidDelegate { 26 public abstract class ViewAndroidDelegate {
25 /** 27 /**
26 * @return An anchor view that can be used to anchor decoration views like A utofill popup. 28 * @return An anchor view that can be used to anchor decoration views like A utofill popup.
27 */ 29 */
28 @CalledByNative 30 @CalledByNative
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 if (containerView == null) return false; 94 if (containerView == null) return false;
93 95
94 ImageView imageView = new ImageView(containerView.getContext()); 96 ImageView imageView = new ImageView(containerView.getContext());
95 imageView.setImageBitmap(shadowImage); 97 imageView.setImageBitmap(shadowImage);
96 imageView.layout(0, 0, shadowImage.getWidth(), shadowImage.getHeight()); 98 imageView.layout(0, 0, shadowImage.getWidth(), shadowImage.getHeight());
97 99
98 return containerView.startDragAndDrop(ClipData.newPlainText(null, text), 100 return containerView.startDragAndDrop(ClipData.newPlainText(null, text),
99 new View.DragShadowBuilder(imageView), null, View.DRAG_FLAG_GLOB AL); 101 new View.DragShadowBuilder(imageView), null, View.DRAG_FLAG_GLOB AL);
100 } 102 }
101 103
104 @CalledByNative
105 private void onCursorChangedToCustom(Bitmap customCursorBitmap, int hotspotX , int hotspotY) {
106 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
107 getContainerView().getRootView().setPointerIcon(
108 PointerIcon.create(customCursorBitmap, hotspotX, hotspotY));
109 }
110 }
111
112 @CalledByNative
113 public void onCursorChanged(int cursorType) {
114 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
115
116 int pointerIconType;
117 switch (cursorType) {
118 case WebCursorInfoType.TYPE_NONE:
119 pointerIconType = PointerIcon.TYPE_NULL;
120 break;
121 case WebCursorInfoType.TYPE_POINTER:
122 pointerIconType = PointerIcon.TYPE_ARROW;
123 break;
124 case WebCursorInfoType.TYPE_CONTEXT_MENU:
125 pointerIconType = PointerIcon.TYPE_CONTEXT_MENU;
126 break;
127 case WebCursorInfoType.TYPE_HAND:
128 pointerIconType = PointerIcon.TYPE_HAND;
129 break;
130 case WebCursorInfoType.TYPE_HELP:
131 pointerIconType = PointerIcon.TYPE_HELP;
132 break;
133 case WebCursorInfoType.TYPE_WAIT:
134 pointerIconType = PointerIcon.TYPE_WAIT;
135 break;
136 case WebCursorInfoType.TYPE_CELL:
137 pointerIconType = PointerIcon.TYPE_CELL;
138 break;
139 case WebCursorInfoType.TYPE_CROSS:
140 pointerIconType = PointerIcon.TYPE_CROSSHAIR;
141 break;
142 case WebCursorInfoType.TYPE_I_BEAM:
143 pointerIconType = PointerIcon.TYPE_TEXT;
144 break;
145 case WebCursorInfoType.TYPE_VERTICAL_TEXT:
146 pointerIconType = PointerIcon.TYPE_VERTICAL_TEXT;
147 break;
148 case WebCursorInfoType.TYPE_ALIAS:
149 pointerIconType = PointerIcon.TYPE_ALIAS;
150 break;
151 case WebCursorInfoType.TYPE_COPY:
152 pointerIconType = PointerIcon.TYPE_COPY;
153 break;
154 case WebCursorInfoType.TYPE_NO_DROP:
155 pointerIconType = PointerIcon.TYPE_NO_DROP;
156 break;
157 case WebCursorInfoType.TYPE_EAST_WEST_RESIZE:
158 case WebCursorInfoType.TYPE_COLUMN_RESIZE:
159 pointerIconType = PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW;
160 break;
161 case WebCursorInfoType.TYPE_NORTH_SOUTH_RESIZE:
162 case WebCursorInfoType.TYPE_ROW_RESIZE:
163 pointerIconType = PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW;
164 break;
165 case WebCursorInfoType.TYPE_NORTH_EAST_SOUTH_WEST_RESIZE:
166 pointerIconType = PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARR OW;
167 break;
168 case WebCursorInfoType.TYPE_NORTH_WEST_SOUTH_EAST_RESIZE:
169 pointerIconType = PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARRO W;
170 break;
171 case WebCursorInfoType.TYPE_ZOOM_IN:
172 pointerIconType = PointerIcon.TYPE_ZOOM_IN;
173 break;
174 case WebCursorInfoType.TYPE_ZOOM_OUT:
175 pointerIconType = PointerIcon.TYPE_ZOOM_OUT;
176 break;
177 case WebCursorInfoType.TYPE_GRAB:
178 pointerIconType = PointerIcon.TYPE_GRAB;
179 break;
180 case WebCursorInfoType.TYPE_GRABBING:
181 pointerIconType = PointerIcon.TYPE_GRABBING;
182 break;
183 case WebCursorInfoType.TYPE_EAST_RESIZE:
Jinsuk Kim 2017/05/18 02:19:51 default: will be enough. No need to have other cas
aelias_OOO_until_Jul13 2017/05/18 18:57:34 I would prefer the reverse, please remove "default
jaebaek 2017/05/22 12:08:34 This is for letting others know all enums specifie
184 case WebCursorInfoType.TYPE_NORTH_RESIZE:
185 case WebCursorInfoType.TYPE_NORTH_EAST_RESIZE:
186 case WebCursorInfoType.TYPE_NORTH_WEST_RESIZE:
187 case WebCursorInfoType.TYPE_SOUTH_RESIZE:
188 case WebCursorInfoType.TYPE_SOUTH_EAST_RESIZE:
189 case WebCursorInfoType.TYPE_SOUTH_WEST_RESIZE:
190 case WebCursorInfoType.TYPE_WEST_RESIZE:
191 case WebCursorInfoType.TYPE_MIDDLE_PANNING:
192 case WebCursorInfoType.TYPE_EAST_PANNING:
193 case WebCursorInfoType.TYPE_NORTH_PANNING:
194 case WebCursorInfoType.TYPE_NORTH_EAST_PANNING:
195 case WebCursorInfoType.TYPE_NORTH_WEST_PANNING:
196 case WebCursorInfoType.TYPE_SOUTH_PANNING:
197 case WebCursorInfoType.TYPE_SOUTH_EAST_PANNING:
198 case WebCursorInfoType.TYPE_SOUTH_WEST_PANNING:
199 case WebCursorInfoType.TYPE_WEST_PANNING:
200 case WebCursorInfoType.TYPE_MOVE:
201 case WebCursorInfoType.TYPE_PROGRESS:
202 case WebCursorInfoType.TYPE_NOT_ALLOWED:
203 case WebCursorInfoType.TYPE_CUSTOM:
204 default:
205 pointerIconType = PointerIcon.TYPE_ARROW;
206 break;
207 }
208 ViewGroup containerView = getContainerView();
209 containerView.getRootView().setPointerIcon(
210 PointerIcon.getSystemIcon(containerView.getContext(), pointerIco nType));
211 }
212
102 /** 213 /**
103 * Called whenever the background color of the page changes as notified by B link. 214 * Called whenever the background color of the page changes as notified by B link.
104 * @param color The new ARGB color of the page background. 215 * @param color The new ARGB color of the page background.
105 */ 216 */
106 @CalledByNative 217 @CalledByNative
107 public void onBackgroundColorChanged(int color) {} 218 public void onBackgroundColorChanged(int color) {}
108 219
109 /** 220 /**
110 * Notify the client of the position of the top controls. 221 * Notify the client of the position of the top controls.
111 * @param topControlsOffsetY The Y offset of the top controls in physical pi xels. 222 * @param topControlsOffsetY The Y offset of the top controls in physical pi xels.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return this; 265 return this;
155 } 266 }
156 267
157 @Override 268 @Override
158 public ViewGroup getContainerView() { 269 public ViewGroup getContainerView() {
159 return mContainerView; 270 return mContainerView;
160 } 271 }
161 }.init(containerView); 272 }.init(containerView);
162 } 273 }
163 } 274 }
OLDNEW
« ui/android/BUILD.gn ('K') | « ui/android/BUILD.gn ('k') | ui/android/view_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698