| 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(0, bitmaps.size()); |
| 44 DCHECK_LE(0, frame_delay_ms); |
| 45 } |
| 46 |
| 47 const gfx::Point& BitmapCursorOzone::hotspot() { |
| 48 return hotspot_; |
| 49 } |
| 50 |
| 51 const SkBitmap& BitmapCursorOzone::bitmap() { |
| 52 return bitmaps_[0]; |
| 53 } |
| 54 |
| 55 const std::vector<SkBitmap>& BitmapCursorOzone::bitmaps() { |
| 56 return bitmaps_; |
| 57 } |
| 58 |
| 59 int BitmapCursorOzone::frame_delay_ms() { |
| 60 return frame_delay_ms_; |
| 61 } |
| 62 |
| 33 BitmapCursorFactoryOzone::BitmapCursorFactoryOzone() {} | 63 BitmapCursorFactoryOzone::BitmapCursorFactoryOzone() {} |
| 34 | 64 |
| 35 BitmapCursorFactoryOzone::~BitmapCursorFactoryOzone() {} | 65 BitmapCursorFactoryOzone::~BitmapCursorFactoryOzone() {} |
| 36 | 66 |
| 37 // static | 67 // static |
| 38 scoped_refptr<BitmapCursorOzone> BitmapCursorFactoryOzone::GetBitmapCursor( | 68 scoped_refptr<BitmapCursorOzone> BitmapCursorFactoryOzone::GetBitmapCursor( |
| 39 PlatformCursor platform_cursor) { | 69 PlatformCursor platform_cursor) { |
| 40 return make_scoped_refptr(ToBitmapCursorOzone(platform_cursor)); | 70 return make_scoped_refptr(ToBitmapCursorOzone(platform_cursor)); |
| 41 } | 71 } |
| 42 | 72 |
| 43 PlatformCursor BitmapCursorFactoryOzone::GetDefaultCursor(int type) { | 73 PlatformCursor BitmapCursorFactoryOzone::GetDefaultCursor(int type) { |
| 44 return GetDefaultCursorInternal(type); | 74 return GetDefaultCursorInternal(type); |
| 45 } | 75 } |
| 46 | 76 |
| 47 PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor( | 77 PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor( |
| 48 const SkBitmap& bitmap, | 78 const SkBitmap& bitmap, |
| 49 const gfx::Point& hotspot) { | 79 const gfx::Point& hotspot) { |
| 50 BitmapCursorOzone* cursor = new BitmapCursorOzone(bitmap, hotspot); | 80 BitmapCursorOzone* cursor = new BitmapCursorOzone(bitmap, hotspot); |
| 51 cursor->AddRef(); // Balanced by UnrefImageCursor. | 81 cursor->AddRef(); // Balanced by UnrefImageCursor. |
| 52 return ToPlatformCursor(cursor); | 82 return ToPlatformCursor(cursor); |
| 53 } | 83 } |
| 54 | 84 |
| 55 PlatformCursor BitmapCursorFactoryOzone::CreateAnimatedCursor( | 85 PlatformCursor BitmapCursorFactoryOzone::CreateAnimatedCursor( |
| 56 const std::vector<SkBitmap>& bitmaps, | 86 const std::vector<SkBitmap>& bitmaps, |
| 57 const gfx::Point& hotspot, | 87 const gfx::Point& hotspot, |
| 58 int frame_delay_ms) { | 88 int frame_delay_ms) { |
| 59 DCHECK_LT(0, bitmaps.size()); | 89 DCHECK_LT(0, bitmaps.size()); |
| 60 NOTIMPLEMENTED(); | 90 BitmapCursorOzone* cursor = |
| 61 return CreateImageCursor(bitmaps[0], hotspot); | 91 new BitmapCursorOzone(bitmaps, hotspot, frame_delay_ms); |
| 92 cursor->AddRef(); // Balanced by UnrefImageCursor. |
| 93 return ToPlatformCursor(cursor); |
| 62 } | 94 } |
| 63 | 95 |
| 64 void BitmapCursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { | 96 void BitmapCursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { |
| 65 ToBitmapCursorOzone(cursor)->AddRef(); | 97 ToBitmapCursorOzone(cursor)->AddRef(); |
| 66 } | 98 } |
| 67 | 99 |
| 68 void BitmapCursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { | 100 void BitmapCursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { |
| 69 ToBitmapCursorOzone(cursor)->Release(); | 101 ToBitmapCursorOzone(cursor)->Release(); |
| 70 } | 102 } |
| 71 | 103 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 82 cursor = GetDefaultCursorInternal(kCursorPointer); | 114 cursor = GetDefaultCursorInternal(kCursorPointer); |
| 83 DCHECK(cursor) << "Failed to load default cursor bitmap"; | 115 DCHECK(cursor) << "Failed to load default cursor bitmap"; |
| 84 default_cursors_[type] = cursor; | 116 default_cursors_[type] = cursor; |
| 85 } | 117 } |
| 86 | 118 |
| 87 // Returned owned default cursor for this type. | 119 // Returned owned default cursor for this type. |
| 88 return default_cursors_[type]; | 120 return default_cursors_[type]; |
| 89 } | 121 } |
| 90 | 122 |
| 91 } // namespace ui | 123 } // namespace ui |
| OLD | NEW |