| 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 |
| 11 namespace ui { | 11 namespace ui { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 BitmapCursorOzone* ToBitmapCursorOzone(PlatformCursor cursor) { | 15 BitmapCursorOzone* ToBitmapCursorOzone(PlatformCursor cursor) { |
| 16 return static_cast<BitmapCursorOzone*>(cursor); | 16 return static_cast<BitmapCursorOzone*>(cursor); |
| 17 } | 17 } |
| 18 | 18 |
| 19 PlatformCursor ToPlatformCursor(BitmapCursorOzone* cursor) { | 19 PlatformCursor ToPlatformCursor(BitmapCursorOzone* cursor) { |
| 20 return static_cast<PlatformCursor>(cursor); | 20 return static_cast<PlatformCursor>(cursor); |
| 21 } | 21 } |
| 22 | 22 |
| 23 scoped_refptr<BitmapCursorOzone> CreateDefaultBitmapCursor(int type) { | 23 scoped_refptr<BitmapCursorOzone> CreateDefaultBitmapCursor(CursorType 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, | 33 BitmapCursorOzone::BitmapCursorOzone(const SkBitmap& bitmap, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 BitmapCursorFactoryOzone::BitmapCursorFactoryOzone() {} | 66 BitmapCursorFactoryOzone::BitmapCursorFactoryOzone() {} |
| 67 | 67 |
| 68 BitmapCursorFactoryOzone::~BitmapCursorFactoryOzone() {} | 68 BitmapCursorFactoryOzone::~BitmapCursorFactoryOzone() {} |
| 69 | 69 |
| 70 // static | 70 // static |
| 71 scoped_refptr<BitmapCursorOzone> BitmapCursorFactoryOzone::GetBitmapCursor( | 71 scoped_refptr<BitmapCursorOzone> BitmapCursorFactoryOzone::GetBitmapCursor( |
| 72 PlatformCursor platform_cursor) { | 72 PlatformCursor platform_cursor) { |
| 73 return make_scoped_refptr(ToBitmapCursorOzone(platform_cursor)); | 73 return make_scoped_refptr(ToBitmapCursorOzone(platform_cursor)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 PlatformCursor BitmapCursorFactoryOzone::GetDefaultCursor(int type) { | 76 PlatformCursor BitmapCursorFactoryOzone::GetDefaultCursor(CursorType type) { |
| 77 return GetDefaultCursorInternal(type).get(); | 77 return GetDefaultCursorInternal(type).get(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor( | 80 PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor( |
| 81 const SkBitmap& bitmap, | 81 const SkBitmap& bitmap, |
| 82 const gfx::Point& hotspot, | 82 const gfx::Point& hotspot, |
| 83 float bitmap_dpi) { | 83 float bitmap_dpi) { |
| 84 BitmapCursorOzone* cursor = new BitmapCursorOzone(bitmap, hotspot); | 84 BitmapCursorOzone* cursor = new BitmapCursorOzone(bitmap, hotspot); |
| 85 cursor->AddRef(); // Balanced by UnrefImageCursor. | 85 cursor->AddRef(); // Balanced by UnrefImageCursor. |
| 86 return ToPlatformCursor(cursor); | 86 return ToPlatformCursor(cursor); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 100 | 100 |
| 101 void BitmapCursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { | 101 void BitmapCursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { |
| 102 ToBitmapCursorOzone(cursor)->AddRef(); | 102 ToBitmapCursorOzone(cursor)->AddRef(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void BitmapCursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { | 105 void BitmapCursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { |
| 106 ToBitmapCursorOzone(cursor)->Release(); | 106 ToBitmapCursorOzone(cursor)->Release(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 scoped_refptr<BitmapCursorOzone> | 109 scoped_refptr<BitmapCursorOzone> |
| 110 BitmapCursorFactoryOzone::GetDefaultCursorInternal(int type) { | 110 BitmapCursorFactoryOzone::GetDefaultCursorInternal(CursorType type) { |
| 111 if (type == kCursorNone) | 111 if (type == CursorType::kNone) |
| 112 return NULL; // NULL is used for hidden cursor. | 112 return NULL; // NULL is used for hidden cursor. |
| 113 | 113 |
| 114 if (!default_cursors_.count(type)) { | 114 if (!default_cursors_.count(type)) { |
| 115 // Create new image cursor from default aura bitmap for this type. We hold a | 115 // Create new image cursor from default aura bitmap for this type. We hold a |
| 116 // ref forever because clients do not do refcounting for default cursors. | 116 // ref forever because clients do not do refcounting for default cursors. |
| 117 scoped_refptr<BitmapCursorOzone> cursor = CreateDefaultBitmapCursor(type); | 117 scoped_refptr<BitmapCursorOzone> cursor = CreateDefaultBitmapCursor(type); |
| 118 if (!cursor.get() && type != kCursorPointer) | 118 if (!cursor.get() && type != CursorType::kPointer) |
| 119 cursor = GetDefaultCursorInternal(kCursorPointer); | 119 cursor = GetDefaultCursorInternal(CursorType::kPointer); |
| 120 DCHECK(cursor.get()) << "Failed to load default cursor bitmap"; | 120 DCHECK(cursor.get()) << "Failed to load default cursor bitmap"; |
| 121 default_cursors_[type] = cursor; | 121 default_cursors_[type] = cursor; |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Returned owned default cursor for this type. | 124 // Returned owned default cursor for this type. |
| 125 return default_cursors_[type]; | 125 return default_cursors_[type]; |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace ui | 128 } // namespace ui |
| OLD | NEW |