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; |
| 18 import org.chromium.base.VisibleForTesting; |
17 import org.chromium.base.annotations.CalledByNative; | 19 import org.chromium.base.annotations.CalledByNative; |
18 import org.chromium.base.annotations.JNINamespace; | 20 import org.chromium.base.annotations.JNINamespace; |
| 21 import org.chromium.blink_public.web.WebCursorInfoType; |
19 | 22 |
20 /** | 23 /** |
21 * Class to acquire, position, and remove anchor views from the implementing Vie
w. | 24 * Class to acquire, position, and remove anchor views from the implementing Vie
w. |
22 */ | 25 */ |
23 @JNINamespace("ui") | 26 @JNINamespace("ui") |
24 public abstract class ViewAndroidDelegate { | 27 public abstract class ViewAndroidDelegate { |
25 // Temporary storage for use as a parameter of getLocationOnScreen(). | 28 // Temporary storage for use as a parameter of getLocationOnScreen(). |
26 private int[] mTemporaryContainerLocation = new int[2]; | 29 private int[] mTemporaryContainerLocation = new int[2]; |
27 | 30 |
28 /** | 31 /** |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 if (containerView == null) return false; | 98 if (containerView == null) return false; |
96 | 99 |
97 ImageView imageView = new ImageView(containerView.getContext()); | 100 ImageView imageView = new ImageView(containerView.getContext()); |
98 imageView.setImageBitmap(shadowImage); | 101 imageView.setImageBitmap(shadowImage); |
99 imageView.layout(0, 0, shadowImage.getWidth(), shadowImage.getHeight()); | 102 imageView.layout(0, 0, shadowImage.getWidth(), shadowImage.getHeight()); |
100 | 103 |
101 return containerView.startDragAndDrop(ClipData.newPlainText(null, text), | 104 return containerView.startDragAndDrop(ClipData.newPlainText(null, text), |
102 new View.DragShadowBuilder(imageView), null, View.DRAG_FLAG_GLOB
AL); | 105 new View.DragShadowBuilder(imageView), null, View.DRAG_FLAG_GLOB
AL); |
103 } | 106 } |
104 | 107 |
| 108 @VisibleForTesting |
| 109 @CalledByNative |
| 110 public void onCursorChangedToCustom(Bitmap customCursorBitmap, int hotspotX,
int hotspotY) { |
| 111 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| 112 PointerIcon icon = PointerIcon.create(customCursorBitmap, hotspotX,
hotspotY); |
| 113 getContainerView().setPointerIcon(icon); |
| 114 } |
| 115 } |
| 116 |
| 117 @VisibleForTesting |
| 118 @CalledByNative |
| 119 public void onCursorChanged(int cursorType) { |
| 120 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return; |
| 121 |
| 122 int pointerIconType = PointerIcon.TYPE_ARROW; |
| 123 switch (cursorType) { |
| 124 case WebCursorInfoType.TYPE_NONE: |
| 125 pointerIconType = PointerIcon.TYPE_NULL; |
| 126 break; |
| 127 case WebCursorInfoType.TYPE_POINTER: |
| 128 pointerIconType = PointerIcon.TYPE_ARROW; |
| 129 break; |
| 130 case WebCursorInfoType.TYPE_CONTEXT_MENU: |
| 131 pointerIconType = PointerIcon.TYPE_CONTEXT_MENU; |
| 132 break; |
| 133 case WebCursorInfoType.TYPE_HAND: |
| 134 pointerIconType = PointerIcon.TYPE_HAND; |
| 135 break; |
| 136 case WebCursorInfoType.TYPE_HELP: |
| 137 pointerIconType = PointerIcon.TYPE_HELP; |
| 138 break; |
| 139 case WebCursorInfoType.TYPE_WAIT: |
| 140 pointerIconType = PointerIcon.TYPE_WAIT; |
| 141 break; |
| 142 case WebCursorInfoType.TYPE_CELL: |
| 143 pointerIconType = PointerIcon.TYPE_CELL; |
| 144 break; |
| 145 case WebCursorInfoType.TYPE_CROSS: |
| 146 pointerIconType = PointerIcon.TYPE_CROSSHAIR; |
| 147 break; |
| 148 case WebCursorInfoType.TYPE_I_BEAM: |
| 149 pointerIconType = PointerIcon.TYPE_TEXT; |
| 150 break; |
| 151 case WebCursorInfoType.TYPE_VERTICAL_TEXT: |
| 152 pointerIconType = PointerIcon.TYPE_VERTICAL_TEXT; |
| 153 break; |
| 154 case WebCursorInfoType.TYPE_ALIAS: |
| 155 pointerIconType = PointerIcon.TYPE_ALIAS; |
| 156 break; |
| 157 case WebCursorInfoType.TYPE_COPY: |
| 158 pointerIconType = PointerIcon.TYPE_COPY; |
| 159 break; |
| 160 case WebCursorInfoType.TYPE_NO_DROP: |
| 161 pointerIconType = PointerIcon.TYPE_NO_DROP; |
| 162 break; |
| 163 case WebCursorInfoType.TYPE_COLUMN_RESIZE: |
| 164 pointerIconType = PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW; |
| 165 break; |
| 166 case WebCursorInfoType.TYPE_ROW_RESIZE: |
| 167 pointerIconType = PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW; |
| 168 break; |
| 169 case WebCursorInfoType.TYPE_NORTH_EAST_SOUTH_WEST_RESIZE: |
| 170 pointerIconType = PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARR
OW; |
| 171 break; |
| 172 case WebCursorInfoType.TYPE_NORTH_WEST_SOUTH_EAST_RESIZE: |
| 173 pointerIconType = PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARRO
W; |
| 174 break; |
| 175 case WebCursorInfoType.TYPE_ZOOM_IN: |
| 176 pointerIconType = PointerIcon.TYPE_ZOOM_IN; |
| 177 break; |
| 178 case WebCursorInfoType.TYPE_ZOOM_OUT: |
| 179 pointerIconType = PointerIcon.TYPE_ZOOM_OUT; |
| 180 break; |
| 181 case WebCursorInfoType.TYPE_GRAB: |
| 182 pointerIconType = PointerIcon.TYPE_GRAB; |
| 183 break; |
| 184 case WebCursorInfoType.TYPE_GRABBING: |
| 185 pointerIconType = PointerIcon.TYPE_GRABBING; |
| 186 break; |
| 187 // TODO(jaebaek): set types correctly |
| 188 // after fixing http://crbug.com/584424. |
| 189 case WebCursorInfoType.TYPE_EAST_WEST_RESIZE: |
| 190 pointerIconType = PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW; |
| 191 break; |
| 192 case WebCursorInfoType.TYPE_NORTH_SOUTH_RESIZE: |
| 193 pointerIconType = PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW; |
| 194 break; |
| 195 case WebCursorInfoType.TYPE_EAST_RESIZE: |
| 196 pointerIconType = PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW; |
| 197 break; |
| 198 case WebCursorInfoType.TYPE_NORTH_RESIZE: |
| 199 pointerIconType = PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW; |
| 200 break; |
| 201 case WebCursorInfoType.TYPE_NORTH_EAST_RESIZE: |
| 202 pointerIconType = PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARR
OW; |
| 203 break; |
| 204 case WebCursorInfoType.TYPE_NORTH_WEST_RESIZE: |
| 205 pointerIconType = PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARRO
W; |
| 206 break; |
| 207 case WebCursorInfoType.TYPE_SOUTH_RESIZE: |
| 208 pointerIconType = PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW; |
| 209 break; |
| 210 case WebCursorInfoType.TYPE_SOUTH_EAST_RESIZE: |
| 211 pointerIconType = PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARRO
W; |
| 212 break; |
| 213 case WebCursorInfoType.TYPE_SOUTH_WEST_RESIZE: |
| 214 pointerIconType = PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARR
OW; |
| 215 break; |
| 216 case WebCursorInfoType.TYPE_WEST_RESIZE: |
| 217 pointerIconType = PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW; |
| 218 break; |
| 219 case WebCursorInfoType.TYPE_PROGRESS: |
| 220 pointerIconType = PointerIcon.TYPE_WAIT; |
| 221 break; |
| 222 case WebCursorInfoType.TYPE_NOT_ALLOWED: |
| 223 pointerIconType = PointerIcon.TYPE_NO_DROP; |
| 224 break; |
| 225 case WebCursorInfoType.TYPE_MOVE: |
| 226 case WebCursorInfoType.TYPE_MIDDLE_PANNING: |
| 227 pointerIconType = PointerIcon.TYPE_ALL_SCROLL; |
| 228 break; |
| 229 case WebCursorInfoType.TYPE_EAST_PANNING: |
| 230 case WebCursorInfoType.TYPE_NORTH_PANNING: |
| 231 case WebCursorInfoType.TYPE_NORTH_EAST_PANNING: |
| 232 case WebCursorInfoType.TYPE_NORTH_WEST_PANNING: |
| 233 case WebCursorInfoType.TYPE_SOUTH_PANNING: |
| 234 case WebCursorInfoType.TYPE_SOUTH_EAST_PANNING: |
| 235 case WebCursorInfoType.TYPE_SOUTH_WEST_PANNING: |
| 236 case WebCursorInfoType.TYPE_WEST_PANNING: |
| 237 assert false : "These pointer icon types are not supported"; |
| 238 break; |
| 239 case WebCursorInfoType.TYPE_CUSTOM: |
| 240 assert false : "onCursorChangedToCustom must be called instead"; |
| 241 break; |
| 242 } |
| 243 ViewGroup containerView = getContainerView(); |
| 244 PointerIcon icon = PointerIcon.getSystemIcon(containerView.getContext(),
pointerIconType); |
| 245 containerView.setPointerIcon(icon); |
| 246 } |
| 247 |
105 /** | 248 /** |
106 * 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. |
107 * @param color The new ARGB color of the page background. | 250 * @param color The new ARGB color of the page background. |
108 */ | 251 */ |
109 @CalledByNative | 252 @CalledByNative |
110 public void onBackgroundColorChanged(int color) {} | 253 public void onBackgroundColorChanged(int color) {} |
111 | 254 |
112 /** | 255 /** |
113 * Notify the client of the position of the top controls. | 256 * Notify the client of the position of the top controls. |
114 * @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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 return this; | 336 return this; |
194 } | 337 } |
195 | 338 |
196 @Override | 339 @Override |
197 public ViewGroup getContainerView() { | 340 public ViewGroup getContainerView() { |
198 return mContainerView; | 341 return mContainerView; |
199 } | 342 } |
200 }.init(containerView); | 343 }.init(containerView); |
201 } | 344 } |
202 } | 345 } |
OLD | NEW |