OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/ozone/bitmap_cursor_factory_ozone.h" | 5 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
9 #include "ui/base/cursor/cursors_aura.h" | 9 #include "ui/base/cursor/cursors_aura.h" |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 scoped_refptr<BitmapCursorOzone> CreateDefaultBitmapCursor(int type) { | 23 scoped_refptr<BitmapCursorOzone> CreateDefaultBitmapCursor(int type) { |
24 SkBitmap bitmap; | 24 SkBitmap bitmap; |
25 gfx::Point hotspot; | 25 gfx::Point hotspot; |
26 if (GetCursorBitmap(type, &bitmap, &hotspot)) | 26 if (GetCursorBitmap(type, &bitmap, &hotspot)) |
27 return new BitmapCursorOzone(bitmap, hotspot); | 27 return new BitmapCursorOzone(bitmap, hotspot); |
28 return NULL; | 28 return NULL; |
29 } | 29 } |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
| 33 BitmapCursorOzone::BitmapCursorOzone(const SkBitmap& bitmap, |
| 34 const gfx::Point& hotspot) |
| 35 : hotspot_(hotspot), frame_delay_ms_(0) { |
| 36 bitmaps_.push_back(bitmap); |
| 37 } |
| 38 |
| 39 BitmapCursorOzone::BitmapCursorOzone(const std::vector<SkBitmap>& bitmaps, |
| 40 const gfx::Point& hotspot, |
| 41 int frame_delay_ms) |
| 42 : bitmaps_(bitmaps), hotspot_(hotspot), frame_delay_ms_(frame_delay_ms) { |
| 43 DCHECK_LT(0U, bitmaps.size()); |
| 44 DCHECK_LE(0, frame_delay_ms); |
| 45 } |
| 46 |
| 47 BitmapCursorOzone::~BitmapCursorOzone() { |
| 48 } |
| 49 |
| 50 const gfx::Point& BitmapCursorOzone::hotspot() { |
| 51 return hotspot_; |
| 52 } |
| 53 |
| 54 const SkBitmap& BitmapCursorOzone::bitmap() { |
| 55 return bitmaps_[0]; |
| 56 } |
| 57 |
| 58 const std::vector<SkBitmap>& BitmapCursorOzone::bitmaps() { |
| 59 return bitmaps_; |
| 60 } |
| 61 |
| 62 int BitmapCursorOzone::frame_delay_ms() { |
| 63 return frame_delay_ms_; |
| 64 } |
| 65 |
33 BitmapCursorFactoryOzone::BitmapCursorFactoryOzone() {} | 66 BitmapCursorFactoryOzone::BitmapCursorFactoryOzone() {} |
34 | 67 |
35 BitmapCursorFactoryOzone::~BitmapCursorFactoryOzone() {} | 68 BitmapCursorFactoryOzone::~BitmapCursorFactoryOzone() {} |
36 | 69 |
37 // static | 70 // static |
38 scoped_refptr<BitmapCursorOzone> BitmapCursorFactoryOzone::GetBitmapCursor( | 71 scoped_refptr<BitmapCursorOzone> BitmapCursorFactoryOzone::GetBitmapCursor( |
39 PlatformCursor platform_cursor) { | 72 PlatformCursor platform_cursor) { |
40 return make_scoped_refptr(ToBitmapCursorOzone(platform_cursor)); | 73 return make_scoped_refptr(ToBitmapCursorOzone(platform_cursor)); |
41 } | 74 } |
42 | 75 |
43 PlatformCursor BitmapCursorFactoryOzone::GetDefaultCursor(int type) { | 76 PlatformCursor BitmapCursorFactoryOzone::GetDefaultCursor(int type) { |
44 return GetDefaultCursorInternal(type).get(); | 77 return GetDefaultCursorInternal(type).get(); |
45 } | 78 } |
46 | 79 |
47 PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor( | 80 PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor( |
48 const SkBitmap& bitmap, | 81 const SkBitmap& bitmap, |
49 const gfx::Point& hotspot) { | 82 const gfx::Point& hotspot) { |
50 BitmapCursorOzone* cursor = new BitmapCursorOzone(bitmap, hotspot); | 83 BitmapCursorOzone* cursor = new BitmapCursorOzone(bitmap, hotspot); |
51 cursor->AddRef(); // Balanced by UnrefImageCursor. | 84 cursor->AddRef(); // Balanced by UnrefImageCursor. |
52 return ToPlatformCursor(cursor); | 85 return ToPlatformCursor(cursor); |
53 } | 86 } |
54 | 87 |
55 PlatformCursor BitmapCursorFactoryOzone::CreateAnimatedCursor( | 88 PlatformCursor BitmapCursorFactoryOzone::CreateAnimatedCursor( |
56 const std::vector<SkBitmap>& bitmaps, | 89 const std::vector<SkBitmap>& bitmaps, |
57 const gfx::Point& hotspot, | 90 const gfx::Point& hotspot, |
58 int frame_delay_ms) { | 91 int frame_delay_ms) { |
59 DCHECK_LT(0U, bitmaps.size()); | 92 DCHECK_LT(0U, bitmaps.size()); |
60 NOTIMPLEMENTED(); | 93 BitmapCursorOzone* cursor = |
61 return CreateImageCursor(bitmaps[0], hotspot); | 94 new BitmapCursorOzone(bitmaps, hotspot, frame_delay_ms); |
| 95 cursor->AddRef(); // Balanced by UnrefImageCursor. |
| 96 return ToPlatformCursor(cursor); |
62 } | 97 } |
63 | 98 |
64 void BitmapCursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { | 99 void BitmapCursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { |
65 ToBitmapCursorOzone(cursor)->AddRef(); | 100 ToBitmapCursorOzone(cursor)->AddRef(); |
66 } | 101 } |
67 | 102 |
68 void BitmapCursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { | 103 void BitmapCursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { |
69 ToBitmapCursorOzone(cursor)->Release(); | 104 ToBitmapCursorOzone(cursor)->Release(); |
70 } | 105 } |
71 | 106 |
(...skipping 10 matching lines...) Expand all Loading... |
82 cursor = GetDefaultCursorInternal(kCursorPointer); | 117 cursor = GetDefaultCursorInternal(kCursorPointer); |
83 DCHECK(cursor.get()) << "Failed to load default cursor bitmap"; | 118 DCHECK(cursor.get()) << "Failed to load default cursor bitmap"; |
84 default_cursors_[type] = cursor; | 119 default_cursors_[type] = cursor; |
85 } | 120 } |
86 | 121 |
87 // Returned owned default cursor for this type. | 122 // Returned owned default cursor for this type. |
88 return default_cursors_[type]; | 123 return default_cursors_[type]; |
89 } | 124 } |
90 | 125 |
91 } // namespace ui | 126 } // namespace ui |
OLD | NEW |