OLD | NEW |
---|---|
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 Loading... | |
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 PointerIcon icon = PointerIcon.create(customCursorBitmap, hotspotX, hotspotY); | |
108 updatePointerIcon(icon); | |
109 } | |
110 } | |
111 | |
112 @CalledByNative | |
113 private void onCursorChanged(int cursorType) { | |
114 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return; | |
115 | |
116 int pointerIconType = PointerIcon.TYPE_ARROW; | |
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_COLUMN_RESIZE: | |
158 pointerIconType = PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW; | |
159 break; | |
160 case WebCursorInfoType.TYPE_ROW_RESIZE: | |
161 pointerIconType = PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW; | |
162 break; | |
163 case WebCursorInfoType.TYPE_NORTH_EAST_SOUTH_WEST_RESIZE: | |
164 pointerIconType = PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARR OW; | |
165 break; | |
166 case WebCursorInfoType.TYPE_NORTH_WEST_SOUTH_EAST_RESIZE: | |
167 pointerIconType = PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARRO W; | |
168 break; | |
169 case WebCursorInfoType.TYPE_ZOOM_IN: | |
170 pointerIconType = PointerIcon.TYPE_ZOOM_IN; | |
171 break; | |
172 case WebCursorInfoType.TYPE_ZOOM_OUT: | |
173 pointerIconType = PointerIcon.TYPE_ZOOM_OUT; | |
174 break; | |
175 case WebCursorInfoType.TYPE_GRAB: | |
176 pointerIconType = PointerIcon.TYPE_GRAB; | |
177 break; | |
178 case WebCursorInfoType.TYPE_GRABBING: | |
179 pointerIconType = PointerIcon.TYPE_GRABBING; | |
180 break; | |
181 // TODO(jaebaek): set types correctly | |
182 // after fixing http://crbug.com/584424. | |
183 case WebCursorInfoType.TYPE_EAST_WEST_RESIZE: | |
184 pointerIconType = PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW; | |
185 break; | |
186 case WebCursorInfoType.TYPE_NORTH_SOUTH_RESIZE: | |
187 pointerIconType = PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW; | |
188 break; | |
189 case WebCursorInfoType.TYPE_EAST_RESIZE: | |
190 pointerIconType = PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW; | |
191 break; | |
192 case WebCursorInfoType.TYPE_NORTH_RESIZE: | |
193 pointerIconType = PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW; | |
194 break; | |
195 case WebCursorInfoType.TYPE_NORTH_EAST_RESIZE: | |
196 pointerIconType = PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARR OW; | |
197 break; | |
198 case WebCursorInfoType.TYPE_NORTH_WEST_RESIZE: | |
199 pointerIconType = PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARRO W; | |
200 break; | |
201 case WebCursorInfoType.TYPE_SOUTH_RESIZE: | |
202 pointerIconType = PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW; | |
203 break; | |
204 case WebCursorInfoType.TYPE_SOUTH_EAST_RESIZE: | |
205 pointerIconType = PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARRO W; | |
206 break; | |
207 case WebCursorInfoType.TYPE_SOUTH_WEST_RESIZE: | |
208 pointerIconType = PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARR OW; | |
209 break; | |
210 case WebCursorInfoType.TYPE_WEST_RESIZE: | |
211 pointerIconType = PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW; | |
212 break; | |
213 case WebCursorInfoType.TYPE_PROGRESS: | |
214 pointerIconType = PointerIcon.TYPE_WAIT; | |
215 break; | |
216 case WebCursorInfoType.TYPE_NOT_ALLOWED: | |
217 pointerIconType = PointerIcon.TYPE_NO_DROP; | |
218 break; | |
219 case WebCursorInfoType.TYPE_MOVE: | |
220 case WebCursorInfoType.TYPE_MIDDLE_PANNING: | |
221 pointerIconType = PointerIcon.TYPE_ALL_SCROLL; | |
222 break; | |
223 case WebCursorInfoType.TYPE_EAST_PANNING: | |
224 case WebCursorInfoType.TYPE_NORTH_PANNING: | |
225 case WebCursorInfoType.TYPE_NORTH_EAST_PANNING: | |
226 case WebCursorInfoType.TYPE_NORTH_WEST_PANNING: | |
227 case WebCursorInfoType.TYPE_SOUTH_PANNING: | |
228 case WebCursorInfoType.TYPE_SOUTH_EAST_PANNING: | |
229 case WebCursorInfoType.TYPE_SOUTH_WEST_PANNING: | |
230 case WebCursorInfoType.TYPE_WEST_PANNING: | |
231 assert false : "These pointer icon types are not supported"; | |
232 break; | |
233 case WebCursorInfoType.TYPE_CUSTOM: | |
234 assert false : "onCursorChangedToCustom must be called instead"; | |
235 break; | |
236 } | |
237 ViewGroup containerView = getContainerView(); | |
238 PointerIcon icon = PointerIcon.getSystemIcon(containerView.getContext(), pointerIconType); | |
239 updatePointerIcon(icon); | |
240 } | |
241 | |
242 /** | |
243 * Set mouse cursor type for Android N or upper version of Android. | |
244 * @param icon The type of mouse cursor to be updated. | |
245 */ | |
246 public void updatePointerIcon(PointerIcon icon) {} | |
aelias_OOO_until_Jul13
2017/05/30 23:26:35
Please use "abstract" instead of default implement
jaebaek
2017/05/31 13:29:08
Done.
| |
247 | |
102 /** | 248 /** |
103 * Called whenever the background color of the page changes as notified by B link. | 249 * 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. | 250 * @param color The new ARGB color of the page background. |
105 */ | 251 */ |
106 @CalledByNative | 252 @CalledByNative |
107 public void onBackgroundColorChanged(int color) {} | 253 public void onBackgroundColorChanged(int color) {} |
108 | 254 |
109 /** | 255 /** |
110 * Notify the client of the position of the top controls. | 256 * Notify the client of the position of the top controls. |
111 * @param topControlsOffsetY The Y offset of the top controls in physical pi xels. | 257 * @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 Loading... | |
154 return this; | 300 return this; |
155 } | 301 } |
156 | 302 |
157 @Override | 303 @Override |
158 public ViewGroup getContainerView() { | 304 public ViewGroup getContainerView() { |
159 return mContainerView; | 305 return mContainerView; |
160 } | 306 } |
161 }.init(containerView); | 307 }.init(containerView); |
162 } | 308 } |
163 } | 309 } |
OLD | NEW |