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

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;
19 20
20 /** 21 /**
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 if (containerView == null) return false; 93 if (containerView == null) return false;
93 94
94 ImageView imageView = new ImageView(containerView.getContext()); 95 ImageView imageView = new ImageView(containerView.getContext());
95 imageView.setImageBitmap(shadowImage); 96 imageView.setImageBitmap(shadowImage);
96 imageView.layout(0, 0, shadowImage.getWidth(), shadowImage.getHeight()); 97 imageView.layout(0, 0, shadowImage.getWidth(), shadowImage.getHeight());
97 98
98 return containerView.startDragAndDrop(ClipData.newPlainText(null, text), 99 return containerView.startDragAndDrop(ClipData.newPlainText(null, text),
99 new View.DragShadowBuilder(imageView), null, View.DRAG_FLAG_GLOB AL); 100 new View.DragShadowBuilder(imageView), null, View.DRAG_FLAG_GLOB AL);
100 } 101 }
101 102
103 @CalledByNative
104 private void onCursorChangedToCustom(Bitmap customCursorBitmap, int hotspotX , int hotspotY) {
105 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
106 getContainerView().getRootView().setPointerIcon(
107 PointerIcon.create(customCursorBitmap, hotspotX, hotspotY));
108 }
109 }
110
111 @CalledByNative
112 public void onCursorChanged(int cursorType) {
113 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
aelias_OOO_until_Jul13 2017/05/17 04:47:15 "if ( < N ) return;" to reduce indentation
Jinsuk Kim 2017/05/17 04:49:50 Do early return to avoid too long if. if (INT < N
jaebaek 2017/05/18 01:44:28 Done.
jaebaek 2017/05/18 01:44:29 Done.
114 ViewGroup containerView = getContainerView();
Jinsuk Kim 2017/05/17 04:49:50 Define variables for the root view and the context
jaebaek 2017/05/18 01:44:29 Done.
115 switch (cursorType) {
116 case CursorType.NULL:
117 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
118 containerView.getContext(), PointerIcon.TYPE_NULL));
aelias_OOO_until_Jul13 2017/05/17 04:47:15 You can avoid some boilerplate duplication here by
jaebaek 2017/05/18 01:44:29 Done.
119 break;
120 case CursorType.ARROW:
121 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
122 containerView.getContext(), PointerIcon.TYPE_ARROW)) ;
123 break;
124 case CursorType.CONTEXT_MENU:
125 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
126 containerView.getContext(), PointerIcon.TYPE_CONTEXT _MENU));
127 break;
128 case CursorType.HAND:
129 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
130 containerView.getContext(), PointerIcon.TYPE_HAND));
131 break;
132 case CursorType.HELP:
133 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
134 containerView.getContext(), PointerIcon.TYPE_HELP));
135 break;
136 case CursorType.WAIT:
137 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
138 containerView.getContext(), PointerIcon.TYPE_WAIT));
139 break;
140 case CursorType.CELL:
141 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
142 containerView.getContext(), PointerIcon.TYPE_CELL));
143 break;
144 case CursorType.CROSSHAIR:
145 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
146 containerView.getContext(), PointerIcon.TYPE_CROSSHA IR));
147 break;
148 case CursorType.TEXT:
149 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
150 containerView.getContext(), PointerIcon.TYPE_TEXT));
151 break;
152 case CursorType.VERTICAL_TEXT:
153 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
154 containerView.getContext(), PointerIcon.TYPE_VERTICA L_TEXT));
155 break;
156 case CursorType.ALIAS:
157 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
158 containerView.getContext(), PointerIcon.TYPE_ALIAS)) ;
159 break;
160 case CursorType.COPY:
161 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
162 containerView.getContext(), PointerIcon.TYPE_COPY));
163 break;
164 case CursorType.NO_DROP:
165 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
166 containerView.getContext(), PointerIcon.TYPE_NO_DROP ));
167 break;
168 case CursorType.ALL_SCROLL:
169 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
170 containerView.getContext(), PointerIcon.TYPE_ALL_SCR OLL));
171 break;
172 case CursorType.HORIZONTAL_DOUBLE_ARROW:
173 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
174 containerView.getContext(), PointerIcon.TYPE_HORIZON TAL_DOUBLE_ARROW));
175 break;
176 case CursorType.VERTICAL_DOUBLE_ARROW:
177 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
178 containerView.getContext(), PointerIcon.TYPE_VERTICA L_DOUBLE_ARROW));
179 break;
180 case CursorType.TOP_RIGHT_DIAGONAL_DOUBLE_ARROW:
181 containerView.getRootView().setPointerIcon(
182 PointerIcon.getSystemIcon(containerView.getContext() ,
183 PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_A RROW));
184 break;
185 case CursorType.TOP_LEFT_DIAGONAL_DOUBLE_ARROW:
186 containerView.getRootView().setPointerIcon(
187 PointerIcon.getSystemIcon(containerView.getContext() ,
188 PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_AR ROW));
189 break;
190 case CursorType.ZOOM_IN:
191 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
192 containerView.getContext(), PointerIcon.TYPE_ZOOM_IN ));
193 break;
194 case CursorType.ZOOM_OUT:
195 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
196 containerView.getContext(), PointerIcon.TYPE_ZOOM_OU T));
197 break;
198 case CursorType.GRAB:
199 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
200 containerView.getContext(), PointerIcon.TYPE_GRAB));
201 break;
202 case CursorType.GRABBING:
203 containerView.getRootView().setPointerIcon(PointerIcon.getSy stemIcon(
204 containerView.getContext(), PointerIcon.TYPE_GRABBIN G));
205 break;
206 default:
aelias_OOO_until_Jul13 2017/05/17 04:47:15 Please exhaustively list all remaining WebCursorIn
jaebaek 2017/05/18 01:44:29 I listed all WebCursorInfo types and default for e
207 break;
208 }
209 }
210 }
211
102 /** 212 /**
103 * Called whenever the background color of the page changes as notified by B link. 213 * 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. 214 * @param color The new ARGB color of the page background.
105 */ 215 */
106 @CalledByNative 216 @CalledByNative
107 public void onBackgroundColorChanged(int color) {} 217 public void onBackgroundColorChanged(int color) {}
108 218
109 /** 219 /**
110 * Notify the client of the position of the top controls. 220 * Notify the client of the position of the top controls.
111 * @param topControlsOffsetY The Y offset of the top controls in physical pi xels. 221 * @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; 264 return this;
155 } 265 }
156 266
157 @Override 267 @Override
158 public ViewGroup getContainerView() { 268 public ViewGroup getContainerView() {
159 return mContainerView; 269 return mContainerView;
160 } 270 }
161 }.init(containerView); 271 }.init(containerView);
162 } 272 }
163 } 273 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698