OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/base/cursor/cursor_loader_ozone.h" | |
6 | |
7 #include "ui/base/cursor/cursor.h" | |
8 #include "ui/base/resource/resource_bundle.h" | |
9 #include "ui/gfx/image/image_skia.h" | |
10 | |
11 namespace ui { | |
12 | |
13 namespace { | |
14 | |
15 // Creates a 1x1 cursor which will be fully transparent. | |
16 SkBitmap CreateInvisibleCursor() { | |
17 SkBitmap cursor; | |
18 cursor.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | |
19 cursor.allocPixels(); | |
20 | |
21 cursor.lockPixels(); | |
22 cursor.eraseARGB(0, 0, 0, 0); | |
23 cursor.unlockPixels(); | |
24 | |
25 return cursor; | |
26 } | |
27 | |
28 } // namespace | |
29 | |
30 CursorLoaderOzone::CursorLoaderOzone() | |
31 : invisible_cursor_(CreateInvisibleCursor()) {} | |
32 | |
33 CursorLoaderOzone::~CursorLoaderOzone() {} | |
34 | |
35 void CursorLoaderOzone::LoadImageCursor(int id, | |
36 int resource_id, | |
37 const gfx::Point& hot) { | |
38 const gfx::ImageSkia* image = ResourceBundle::GetSharedInstance() | |
rjkroege
2014/02/12 18:03:17
Perhaps the point of maintaining the cursors_ cach
dnicoara
2014/02/12 20:44:57
GetImageSkiaName may not be as cheap since it need
| |
39 .GetImageSkiaNamed(resource_id); | |
40 | |
41 cursors_[id] = image; | |
42 } | |
43 | |
44 void CursorLoaderOzone::LoadAnimatedCursor(int id, | |
45 int resource_id, | |
46 const gfx::Point& hot, | |
47 int frame_delay_ms) { | |
48 NOTIMPLEMENTED(); | |
49 } | |
50 | |
51 void CursorLoaderOzone::UnloadAll() { | |
52 cursors_.clear(); | |
53 } | |
54 | |
55 void CursorLoaderOzone::SetPlatformCursor(gfx::NativeCursor* cursor) { | |
56 if (cursors_.find(cursor->native_type()) != cursors_.end()) { | |
57 const gfx::ImageSkiaRep& image_rep = | |
58 cursors_[cursor->native_type()]->GetRepresentation( | |
59 display().device_scale_factor()); | |
60 | |
61 cursor->SetPlatformCursor(&image_rep.sk_bitmap()); | |
62 } else if (*cursor == kCursorNone) { | |
63 cursor->SetPlatformCursor(&invisible_cursor_); | |
64 } else if (*cursor == kCursorCustom) { | |
65 cursor->SetPlatformCursor(cursor->platform()); | |
dnicoara
2014/02/12 16:18:20
This is where the custom webkit cursors are being
rjkroege
2014/02/12 18:03:17
nit: can you add a TODO listing the bug. And add a
dnicoara
2014/02/12 20:44:57
Done.
| |
66 } else { | |
67 const gfx::ImageSkiaRep& image_rep = | |
68 cursors_[kCursorPointer]->GetRepresentation( | |
69 display().device_scale_factor()); | |
70 | |
71 cursor->SetPlatformCursor(&image_rep.sk_bitmap()); | |
72 } | |
73 } | |
74 | |
75 CursorLoader* CursorLoader::Create() { | |
76 return new CursorLoaderOzone(); | |
77 } | |
78 | |
79 } // namespace ui | |
OLD | NEW |