1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
#include "base/logging.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/cursor/cursors_aura.h"
namespace ui {
namespace {
BitmapCursorOzone* ToBitmapCursorOzone(PlatformCursor cursor) {
return static_cast<BitmapCursorOzone*>(cursor);
}
PlatformCursor ToPlatformCursor(BitmapCursorOzone* cursor) {
return static_cast<PlatformCursor>(cursor);
}
scoped_refptr<BitmapCursorOzone> CreateDefaultBitmapCursor(int type) {
SkBitmap bitmap;
gfx::Point hotspot;
if (GetCursorBitmap(type, &bitmap, &hotspot))
return new BitmapCursorOzone(bitmap, hotspot);
return NULL;
}
} // namespace
BitmapCursorOzone::BitmapCursorOzone(const SkBitmap& bitmap,
const gfx::Point& hotspot)
: hotspot_(hotspot), frame_delay_ms_(0) {
bitmaps_.push_back(bitmap);
}
BitmapCursorOzone::BitmapCursorOzone(const std::vector<SkBitmap>& bitmaps,
const gfx::Point& hotspot,
int frame_delay_ms)
: bitmaps_(bitmaps), hotspot_(hotspot), frame_delay_ms_(frame_delay_ms) {
DCHECK_LT(0U, bitmaps.size());
DCHECK_LE(0, frame_delay_ms);
}
BitmapCursorOzone::~BitmapCursorOzone() {
}
const gfx::Point& BitmapCursorOzone::hotspot() {
return hotspot_;
}
const SkBitmap& BitmapCursorOzone::bitmap() {
return bitmaps_[0];
}
const std::vector<SkBitmap>& BitmapCursorOzone::bitmaps() {
return bitmaps_;
}
int BitmapCursorOzone::frame_delay_ms() {
return frame_delay_ms_;
}
BitmapCursorFactoryOzone::BitmapCursorFactoryOzone() {}
BitmapCursorFactoryOzone::~BitmapCursorFactoryOzone() {}
// static
scoped_refptr<BitmapCursorOzone> BitmapCursorFactoryOzone::GetBitmapCursor(
PlatformCursor platform_cursor) {
return make_scoped_refptr(ToBitmapCursorOzone(platform_cursor));
}
PlatformCursor BitmapCursorFactoryOzone::GetDefaultCursor(int type) {
return GetDefaultCursorInternal(type).get();
}
PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor(
const SkBitmap& bitmap,
const gfx::Point& hotspot) {
BitmapCursorOzone* cursor = new BitmapCursorOzone(bitmap, hotspot);
cursor->AddRef(); // Balanced by UnrefImageCursor.
return ToPlatformCursor(cursor);
}
PlatformCursor BitmapCursorFactoryOzone::CreateAnimatedCursor(
const std::vector<SkBitmap>& bitmaps,
const gfx::Point& hotspot,
int frame_delay_ms) {
DCHECK_LT(0U, bitmaps.size());
BitmapCursorOzone* cursor =
new BitmapCursorOzone(bitmaps, hotspot, frame_delay_ms);
cursor->AddRef(); // Balanced by UnrefImageCursor.
return ToPlatformCursor(cursor);
}
void BitmapCursorFactoryOzone::RefImageCursor(PlatformCursor cursor) {
ToBitmapCursorOzone(cursor)->AddRef();
}
void BitmapCursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) {
ToBitmapCursorOzone(cursor)->Release();
}
scoped_refptr<BitmapCursorOzone>
BitmapCursorFactoryOzone::GetDefaultCursorInternal(int type) {
if (type == kCursorNone)
return NULL; // NULL is used for hidden cursor.
if (!default_cursors_.count(type)) {
// Create new image cursor from default aura bitmap for this type. We hold a
// ref forever because clients do not do refcounting for default cursors.
scoped_refptr<BitmapCursorOzone> cursor = CreateDefaultBitmapCursor(type);
if (!cursor.get() && type != kCursorPointer)
cursor = GetDefaultCursorInternal(kCursorPointer);
DCHECK(cursor.get()) << "Failed to load default cursor bitmap";
default_cursors_[type] = cursor;
}
// Returned owned default cursor for this type.
return default_cursors_[type];
}
} // namespace ui
|