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.
5 #include "ui/base/cursor/cursor_loader_ozone.h"
7 #include "ui/base/cursor/cursor.h"
8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/image/image_skia.h"
10 #include "ui/ozone/public/cursor_factory_ozone.h"
14 CursorLoaderOzone::CursorLoaderOzone() {}
16 CursorLoaderOzone::~CursorLoaderOzone() {}
18 void CursorLoaderOzone::LoadImageCursor(int id
,
20 const gfx::Point
& hot
) {
21 const gfx::ImageSkia
* image
=
22 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id
);
23 const gfx::ImageSkiaRep
& image_rep
=
24 image
->GetRepresentation(scale());
25 SkBitmap bitmap
= image_rep
.sk_bitmap();
27 CursorFactoryOzone::GetInstance()->CreateImageCursor(bitmap
, hot
);
30 void CursorLoaderOzone::LoadAnimatedCursor(int id
,
32 const gfx::Point
& hot
,
34 // TODO(dnicoara) Add support: crbug.com/343245
38 void CursorLoaderOzone::UnloadAll() {
39 for (ImageCursorMap::const_iterator it
= cursors_
.begin();
42 CursorFactoryOzone::GetInstance()->UnrefImageCursor(it
->second
);
46 void CursorLoaderOzone::SetPlatformCursor(gfx::NativeCursor
* cursor
) {
47 int native_type
= cursor
->native_type();
48 PlatformCursor platform
;
50 if (cursors_
.count(native_type
)) {
51 // An image cursor is loaded for this type.
52 platform
= cursors_
[native_type
];
53 } else if (native_type
== kCursorCustom
) {
54 // The platform cursor was already set via WebCursor::GetPlatformCursor.
55 platform
= cursor
->platform();
57 // Use default cursor of this type.
58 platform
= CursorFactoryOzone::GetInstance()->GetDefaultCursor(native_type
);
61 cursor
->SetPlatformCursor(platform
);
64 CursorLoader
* CursorLoader::Create() {
65 return new CursorLoaderOzone();