OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "ui/base/cursor/cursors_aura.h" | 5 #include "ui/base/cursor/cursors_aura.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 int y; | 26 int y; |
27 }; | 27 }; |
28 | 28 |
29 struct CursorData { | 29 struct CursorData { |
30 CursorType id; | 30 CursorType id; |
31 int resource_id; | 31 int resource_id; |
32 HotPoint hot_1x; | 32 HotPoint hot_1x; |
33 HotPoint hot_2x; | 33 HotPoint hot_2x; |
34 }; | 34 }; |
35 | 35 |
36 struct CursorSet { | 36 struct CursorSizeData { |
37 const CursorSetType id; | 37 const CursorSize id; |
38 const CursorData* cursors; | 38 const CursorData* cursors; |
39 const int length; | 39 const int length; |
40 const CursorData* animated_cursors; | 40 const CursorData* animated_cursors; |
41 const int animated_length; | 41 const int animated_length; |
42 }; | 42 }; |
43 | 43 |
44 const CursorData kNormalCursors[] = { | 44 const CursorData kNormalCursors[] = { |
45 {CursorType::kNull, IDR_AURA_CURSOR_PTR, {4, 4}, {7, 7}}, | 45 {CursorType::kNull, IDR_AURA_CURSOR_PTR, {4, 4}, {7, 7}}, |
46 {CursorType::kPointer, IDR_AURA_CURSOR_PTR, {4, 4}, {7, 7}}, | 46 {CursorType::kPointer, IDR_AURA_CURSOR_PTR, {4, 4}, {7, 7}}, |
47 {CursorType::kNoDrop, IDR_AURA_CURSOR_NO_DROP, {9, 9}, {18, 18}}, | 47 {CursorType::kNoDrop, IDR_AURA_CURSOR_NO_DROP, {9, 9}, {18, 18}}, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 {64, 62}}, | 195 {64, 62}}, |
196 {CursorType::kGrab, IDR_AURA_CURSOR_BIG_GRAB, {21, 11}, {42, 22}}, | 196 {CursorType::kGrab, IDR_AURA_CURSOR_BIG_GRAB, {21, 11}, {42, 22}}, |
197 {CursorType::kGrabbing, IDR_AURA_CURSOR_BIG_GRABBING, {20, 12}, {40, 24}}, | 197 {CursorType::kGrabbing, IDR_AURA_CURSOR_BIG_GRABBING, {20, 12}, {40, 24}}, |
198 }; | 198 }; |
199 | 199 |
200 const CursorData kAnimatedCursors[] = { | 200 const CursorData kAnimatedCursors[] = { |
201 {CursorType::kWait, IDR_AURA_CURSOR_THROBBER, {7, 7}, {14, 14}}, | 201 {CursorType::kWait, IDR_AURA_CURSOR_THROBBER, {7, 7}, {14, 14}}, |
202 {CursorType::kProgress, IDR_AURA_CURSOR_THROBBER, {7, 7}, {14, 14}}, | 202 {CursorType::kProgress, IDR_AURA_CURSOR_THROBBER, {7, 7}, {14, 14}}, |
203 }; | 203 }; |
204 | 204 |
205 const CursorSet kCursorSets[] = { | 205 const CursorSizeData kCursorSizes[] = { |
206 { | 206 {CursorSize::kNormal, kNormalCursors, arraysize(kNormalCursors), |
207 CURSOR_SET_NORMAL, | 207 kAnimatedCursors, arraysize(kAnimatedCursors)}, |
208 kNormalCursors, arraysize(kNormalCursors), | 208 {CursorSize::kLarge, kLargeCursors, arraysize(kLargeCursors), |
209 kAnimatedCursors, arraysize(kAnimatedCursors) | 209 // TODO(yoshiki): Replace animated cursors with big assets. |
210 }, | 210 // crbug.com/247254 |
211 { | 211 kAnimatedCursors, arraysize(kAnimatedCursors)}, |
212 CURSOR_SET_LARGE, | |
213 kLargeCursors, arraysize(kLargeCursors), | |
214 // TODO(yoshiki): Replace animated cursors with big assets. crbug.com/247254 | |
215 kAnimatedCursors, arraysize(kAnimatedCursors) | |
216 }, | |
217 }; | 212 }; |
218 | 213 |
219 const CursorSet* GetCursorSetByType(CursorSetType cursor_set_id) { | 214 const CursorSizeData* GetCursorSizeByType(CursorSize cursor_size) { |
220 for (size_t i = 0; i < arraysize(kCursorSets); ++i) { | 215 for (size_t i = 0; i < arraysize(kCursorSizes); ++i) { |
221 if (kCursorSets[i].id == cursor_set_id) | 216 if (kCursorSizes[i].id == cursor_size) |
222 return &kCursorSets[i]; | 217 return &kCursorSizes[i]; |
223 } | 218 } |
224 | 219 |
225 return NULL; | 220 return NULL; |
226 } | 221 } |
227 | 222 |
228 bool SearchTable(const CursorData* table, | 223 bool SearchTable(const CursorData* table, |
229 size_t table_length, | 224 size_t table_length, |
230 CursorType id, | 225 CursorType id, |
231 float scale_factor, | 226 float scale_factor, |
232 int* resource_id, | 227 int* resource_id, |
233 gfx::Point* point) { | 228 gfx::Point* point) { |
234 bool resource_2x_available = | 229 bool resource_2x_available = |
235 ResourceBundle::GetSharedInstance().GetMaxScaleFactor() == | 230 ResourceBundle::GetSharedInstance().GetMaxScaleFactor() == |
236 SCALE_FACTOR_200P; | 231 SCALE_FACTOR_200P; |
237 for (size_t i = 0; i < table_length; ++i) { | 232 for (size_t i = 0; i < table_length; ++i) { |
238 if (table[i].id == id) { | 233 if (table[i].id == id) { |
239 *resource_id = table[i].resource_id; | 234 *resource_id = table[i].resource_id; |
240 *point = scale_factor == 1.0f || !resource_2x_available ? | 235 *point = scale_factor == 1.0f || !resource_2x_available ? |
241 gfx::Point(table[i].hot_1x.x, table[i].hot_1x.y) : | 236 gfx::Point(table[i].hot_1x.x, table[i].hot_1x.y) : |
242 gfx::Point(table[i].hot_2x.x, table[i].hot_2x.y); | 237 gfx::Point(table[i].hot_2x.x, table[i].hot_2x.y); |
243 return true; | 238 return true; |
244 } | 239 } |
245 } | 240 } |
246 | 241 |
247 return false; | 242 return false; |
248 } | 243 } |
249 | 244 |
250 } // namespace | 245 } // namespace |
251 | 246 |
252 bool GetCursorDataFor(CursorSetType cursor_set_id, | 247 bool GetCursorDataFor(CursorSize cursor_size, |
253 CursorType id, | 248 CursorType id, |
254 float scale_factor, | 249 float scale_factor, |
255 int* resource_id, | 250 int* resource_id, |
256 gfx::Point* point) { | 251 gfx::Point* point) { |
257 const CursorSet* cursor_set = GetCursorSetByType(cursor_set_id); | 252 const CursorSizeData* cursor_set = GetCursorSizeByType(cursor_size); |
258 if (cursor_set && | 253 if (cursor_set && |
259 SearchTable(cursor_set->cursors, | 254 SearchTable(cursor_set->cursors, |
260 cursor_set->length, | 255 cursor_set->length, |
261 id, scale_factor, resource_id, point)) { | 256 id, scale_factor, resource_id, point)) { |
262 return true; | 257 return true; |
263 } | 258 } |
264 | 259 |
265 // Falls back to the default cursor set. | 260 // Falls back to the default cursor set. |
266 cursor_set = GetCursorSetByType(ui::CURSOR_SET_NORMAL); | 261 cursor_set = GetCursorSizeByType(ui::CursorSize::kNormal); |
267 DCHECK(cursor_set); | 262 DCHECK(cursor_set); |
268 return SearchTable(cursor_set->cursors, | 263 return SearchTable(cursor_set->cursors, |
269 cursor_set->length, | 264 cursor_set->length, |
270 id, scale_factor, resource_id, point); | 265 id, scale_factor, resource_id, point); |
271 } | 266 } |
272 | 267 |
273 bool GetAnimatedCursorDataFor(CursorSetType cursor_set_id, | 268 bool GetAnimatedCursorDataFor(CursorSize cursor_size, |
274 CursorType id, | 269 CursorType id, |
275 float scale_factor, | 270 float scale_factor, |
276 int* resource_id, | 271 int* resource_id, |
277 gfx::Point* point) { | 272 gfx::Point* point) { |
278 const CursorSet* cursor_set = GetCursorSetByType(cursor_set_id); | 273 const CursorSizeData* cursor_set = GetCursorSizeByType(cursor_size); |
279 if (cursor_set && | 274 if (cursor_set && |
280 SearchTable(cursor_set->animated_cursors, | 275 SearchTable(cursor_set->animated_cursors, |
281 cursor_set->animated_length, | 276 cursor_set->animated_length, |
282 id, scale_factor, resource_id, point)) { | 277 id, scale_factor, resource_id, point)) { |
283 return true; | 278 return true; |
284 } | 279 } |
285 | 280 |
286 // Falls back to the default cursor set. | 281 // Falls back to the default cursor set. |
287 cursor_set = GetCursorSetByType(ui::CURSOR_SET_NORMAL); | 282 cursor_set = GetCursorSizeByType(ui::CursorSize::kNormal); |
288 DCHECK(cursor_set); | 283 DCHECK(cursor_set); |
289 return SearchTable(cursor_set->animated_cursors, | 284 return SearchTable(cursor_set->animated_cursors, |
290 cursor_set->animated_length, | 285 cursor_set->animated_length, |
291 id, scale_factor, resource_id, point); | 286 id, scale_factor, resource_id, point); |
292 } | 287 } |
293 | 288 |
294 bool GetCursorBitmap(const Cursor& cursor, | 289 bool GetCursorBitmap(const Cursor& cursor, |
295 SkBitmap* bitmap, | 290 SkBitmap* bitmap, |
296 gfx::Point* point) { | 291 gfx::Point* point) { |
297 DCHECK(bitmap && point); | 292 DCHECK(bitmap && point); |
298 #if defined(OS_WIN) | 293 #if defined(OS_WIN) |
299 Cursor cursor_copy = cursor; | 294 Cursor cursor_copy = cursor; |
300 ui::CursorLoaderWin cursor_loader; | 295 ui::CursorLoaderWin cursor_loader; |
301 cursor_loader.SetPlatformCursor(&cursor_copy); | 296 cursor_loader.SetPlatformCursor(&cursor_copy); |
302 const std::unique_ptr<SkBitmap> cursor_bitmap( | 297 const std::unique_ptr<SkBitmap> cursor_bitmap( |
303 IconUtil::CreateSkBitmapFromHICON(cursor_copy.platform())); | 298 IconUtil::CreateSkBitmapFromHICON(cursor_copy.platform())); |
304 *point = IconUtil::GetHotSpotFromHICON(cursor_copy.platform()); | 299 *point = IconUtil::GetHotSpotFromHICON(cursor_copy.platform()); |
305 #else | 300 #else |
306 int resource_id; | 301 int resource_id; |
307 if (!GetCursorDataFor(ui::CURSOR_SET_NORMAL, | 302 if (!GetCursorDataFor(ui::CursorSize::kNormal, cursor.native_type(), |
308 cursor.native_type(), | 303 cursor.device_scale_factor(), &resource_id, point)) { |
309 cursor.device_scale_factor(), | |
310 &resource_id, | |
311 point)) { | |
312 return false; | 304 return false; |
313 } | 305 } |
314 | 306 |
315 const SkBitmap* cursor_bitmap = ResourceBundle::GetSharedInstance(). | 307 const SkBitmap* cursor_bitmap = ResourceBundle::GetSharedInstance(). |
316 GetImageSkiaNamed(resource_id)->bitmap(); | 308 GetImageSkiaNamed(resource_id)->bitmap(); |
317 #endif | 309 #endif |
318 if (!cursor_bitmap) | 310 if (!cursor_bitmap) |
319 return false; | 311 return false; |
320 *bitmap = *cursor_bitmap; | 312 *bitmap = *cursor_bitmap; |
321 return true; | 313 return true; |
322 } | 314 } |
323 | 315 |
324 } // namespace ui | 316 } // namespace ui |
OLD | NEW |