forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcursor_factory.cc
209 lines (186 loc) · 6.99 KB
/
cursor_factory.cc
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// 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/cursor_factory.h"
#include <ostream>
#include "base/check.h"
#include "base/check_op.h"
#include "base/memory/scoped_refptr.h"
#include "base/notreached.h"
#include "base/observer_list.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
#include "ui/base/cursor/platform_cursor.h"
namespace ui {
namespace {
CursorFactory* g_instance = nullptr;
} // namespace
CursorFactoryObserver::~CursorFactoryObserver() = default;
CursorFactory::CursorFactory() {
DCHECK(!g_instance) << "There should only be a single CursorFactory.";
g_instance = this;
}
CursorFactory::~CursorFactory() {
DCHECK_EQ(g_instance, this);
g_instance = nullptr;
}
CursorFactory* CursorFactory::GetInstance() {
DCHECK(g_instance);
return g_instance;
}
void CursorFactory::AddObserver(CursorFactoryObserver* observer) {
observers_.AddObserver(observer);
}
void CursorFactory::RemoveObserver(CursorFactoryObserver* observer) {
observers_.RemoveObserver(observer);
}
void CursorFactory::NotifyObserversOnThemeLoaded() {
for (auto& observer : observers_)
observer.OnThemeLoaded();
}
scoped_refptr<PlatformCursor> CursorFactory::GetDefaultCursor(
mojom::CursorType type) {
NOTIMPLEMENTED();
return nullptr;
}
scoped_refptr<PlatformCursor> CursorFactory::CreateImageCursor(
mojom::CursorType type,
const SkBitmap& bitmap,
const gfx::Point& hotspot) {
NOTIMPLEMENTED();
return nullptr;
}
scoped_refptr<PlatformCursor> CursorFactory::CreateAnimatedCursor(
mojom::CursorType type,
const std::vector<SkBitmap>& bitmaps,
const gfx::Point& hotspot,
base::TimeDelta frame_delay) {
NOTIMPLEMENTED();
return nullptr;
}
void CursorFactory::ObserveThemeChanges() {
NOTIMPLEMENTED();
}
void CursorFactory::SetDeviceScaleFactor(float scale) {}
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// Returns a cursor name compatible with either X11 or the FreeDesktop.org
// cursor spec ([1] and [2]), followed by fallbacks that can work as
// replacements in some environments where the original may not be available
// (e.g. desktop environments other than GNOME and KDE).
//
// TODO(hferreiro): each list starts with the FreeDesktop.org icon name but
// "ns-resize", "ew-resize", "nesw-resize", "nwse-resize", "grab", "grabbing",
// which were not available in older versions of Breeze, the default KDE theme.
//
// [1]
// https://www.x.org/releases/current/doc/libX11/libX11/libX11.html#x_font_cursors
// [2] https://www.freedesktop.org/wiki/Specifications/cursor-spec/
std::vector<std::string> CursorNamesFromType(mojom::CursorType type) {
switch (type) {
case mojom::CursorType::kMove:
// Returning "move" is the correct thing here, but Blink doesn't make a
// distinction between move and all-scroll. Other platforms use a cursor
// more consistent with all-scroll, so use that.
case mojom::CursorType::kMiddlePanning:
case mojom::CursorType::kMiddlePanningVertical:
case mojom::CursorType::kMiddlePanningHorizontal:
return {"all-scroll", "fleur"};
case mojom::CursorType::kEastPanning:
case mojom::CursorType::kEastResize:
return {"e-resize", "right_side"};
case mojom::CursorType::kNorthPanning:
case mojom::CursorType::kNorthResize:
return {"n-resize", "top_side"};
case mojom::CursorType::kNorthEastPanning:
case mojom::CursorType::kNorthEastResize:
return {"ne-resize", "top_right_corner"};
case mojom::CursorType::kNorthWestPanning:
case mojom::CursorType::kNorthWestResize:
return {"nw-resize", "top_left_corner"};
case mojom::CursorType::kSouthPanning:
case mojom::CursorType::kSouthResize:
return {"s-resize", "bottom_side"};
case mojom::CursorType::kSouthEastPanning:
case mojom::CursorType::kSouthEastResize:
return {"se-resize", "bottom_right_corner"};
case mojom::CursorType::kSouthWestPanning:
case mojom::CursorType::kSouthWestResize:
return {"sw-resize", "bottom_left_corner"};
case mojom::CursorType::kWestPanning:
case mojom::CursorType::kWestResize:
return {"w-resize", "left_side"};
case mojom::CursorType::kNone:
return {};
case mojom::CursorType::kGrab:
return {"openhand", "grab"};
case mojom::CursorType::kGrabbing:
return {"closedhand", "grabbing", "hand2"};
case mojom::CursorType::kCross:
return {"crosshair", "cross"};
case mojom::CursorType::kHand:
return {"pointer", "hand", "hand2"};
case mojom::CursorType::kIBeam:
return {"text", "xterm"};
case mojom::CursorType::kProgress:
return {"progress", "left_ptr_watch", "watch"};
case mojom::CursorType::kWait:
return {"wait", "watch"};
case mojom::CursorType::kHelp:
return {"help"};
case mojom::CursorType::kNorthSouthResize:
return {"sb_v_double_arrow", "ns-resize"};
case mojom::CursorType::kEastWestResize:
return {"sb_h_double_arrow", "ew-resize"};
case mojom::CursorType::kColumnResize:
return {"col-resize", "sb_h_double_arrow"};
case mojom::CursorType::kRowResize:
return {"row-resize", "sb_v_double_arrow"};
case mojom::CursorType::kNorthEastSouthWestResize:
return {"size_bdiag", "nesw-resize", "fd_double_arrow"};
case mojom::CursorType::kNorthWestSouthEastResize:
return {"size_fdiag", "nwse-resize", "bd_double_arrow"};
case mojom::CursorType::kVerticalText:
return {"vertical-text"};
case mojom::CursorType::kZoomIn:
return {"zoom-in"};
case mojom::CursorType::kZoomOut:
return {"zoom-out"};
case mojom::CursorType::kCell:
return {"cell", "plus"};
case mojom::CursorType::kContextMenu:
return {"context-menu"};
case mojom::CursorType::kAlias:
return {"alias"};
case mojom::CursorType::kNoDrop:
return {"no-drop"};
case mojom::CursorType::kCopy:
return {"copy"};
case mojom::CursorType::kNotAllowed:
case mojom::CursorType::kNorthSouthNoResize:
case mojom::CursorType::kEastWestNoResize:
case mojom::CursorType::kNorthEastSouthWestNoResize:
case mojom::CursorType::kNorthWestSouthEastNoResize:
return {"not-allowed", "crossed_circle"};
case mojom::CursorType::kDndNone:
return {"dnd-none", "hand2"};
case mojom::CursorType::kDndMove:
return {"dnd-move", "hand2"};
case mojom::CursorType::kDndCopy:
return {"dnd-copy", "hand2"};
case mojom::CursorType::kDndLink:
return {"dnd-link", "hand2"};
case mojom::CursorType::kCustom:
// kCustom is for custom image cursors. The platform cursor will be set
// at WebCursor::GetNativeCursor().
NOTREACHED();
[[fallthrough]];
case mojom::CursorType::kNull:
case mojom::CursorType::kPointer:
return {"left_ptr"};
}
NOTREACHED();
return {"left_ptr"};
}
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
} // namespace ui