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/image_cursors.h"
9 #include "base/logging.h"
10 #include "base/strings/string16.h"
11 #include "ui/base/cursor/cursor.h"
12 #include "ui/base/cursor/cursor_loader.h"
13 #include "ui/base/cursor/cursors_aura.h"
14 #include "ui/gfx/display.h"
15 #include "ui/gfx/geometry/point.h"
21 const int kImageCursorIds
[] = {
29 kCursorNorthEastResize
,
30 kCursorSouthWestResize
,
31 kCursorSouthEastResize
,
32 kCursorNorthWestResize
,
48 kCursorEastWestResize
,
49 kCursorNorthSouthResize
,
50 kCursorNorthEastSouthWestResize
,
51 kCursorNorthWestSouthEastResize
,
56 const int kAnimatedCursorIds
[] = {
63 ImageCursors::ImageCursors() : cursor_set_(CURSOR_SET_NORMAL
) {
66 ImageCursors::~ImageCursors() {
69 float ImageCursors::GetScale() const {
70 if (!cursor_loader_
) {
72 // Returning default on release build as it's not serious enough to crash
73 // even if this ever happens.
76 return cursor_loader_
->scale();
79 gfx::Display::Rotation
ImageCursors::GetRotation() const {
80 if (!cursor_loader_
) {
82 // Returning default on release build as it's not serious enough to crash
83 // even if this ever happens.
84 return gfx::Display::ROTATE_0
;
86 return cursor_loader_
->rotation();
89 bool ImageCursors::SetDisplay(const gfx::Display
& display
,
91 if (!cursor_loader_
) {
92 cursor_loader_
.reset(CursorLoader::Create());
93 } else if (cursor_loader_
->rotation() == display
.rotation() &&
94 cursor_loader_
->scale() == scale_factor
) {
98 cursor_loader_
->set_rotation(display
.rotation());
99 cursor_loader_
->set_scale(scale_factor
);
104 void ImageCursors::ReloadCursors() {
105 float device_scale_factor
= cursor_loader_
->scale();
107 cursor_loader_
->UnloadAll();
109 for (size_t i
= 0; i
< arraysize(kImageCursorIds
); ++i
) {
110 int resource_id
= -1;
111 gfx::Point hot_point
;
112 bool success
= GetCursorDataFor(cursor_set_
,
118 cursor_loader_
->LoadImageCursor(kImageCursorIds
[i
], resource_id
, hot_point
);
120 for (size_t i
= 0; i
< arraysize(kAnimatedCursorIds
); ++i
) {
121 int resource_id
= -1;
122 gfx::Point hot_point
;
123 bool success
= GetAnimatedCursorDataFor(cursor_set_
,
124 kAnimatedCursorIds
[i
],
129 cursor_loader_
->LoadAnimatedCursor(kAnimatedCursorIds
[i
],
132 kAnimatedCursorFrameDelayMs
);
136 void ImageCursors::SetCursorSet(CursorSetType cursor_set
) {
137 if (cursor_set_
== cursor_set
)
140 cursor_set_
= cursor_set
;
142 if (cursor_loader_
.get())
146 void ImageCursors::SetPlatformCursor(gfx::NativeCursor
* cursor
) {
147 cursor_loader_
->SetPlatformCursor(cursor
);