Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: services/ui/public/interfaces/cursor/cursor_struct_traits.cc

Issue 2833163002: Change ui cursor identifiers to an enum class. (Closed)
Patch Set: Remove extranious ::ui:: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "services/ui/public/interfaces/cursor/cursor_struct_traits.h" 5 #include "services/ui/public/interfaces/cursor/cursor_struct_traits.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "mojo/common/common_custom_types_struct_traits.h" 8 #include "mojo/common/common_custom_types_struct_traits.h"
9 #include "services/ui/public/interfaces/cursor/cursor.mojom.h"
9 #include "skia/public/interfaces/bitmap_array_struct_traits.h" 10 #include "skia/public/interfaces/bitmap_array_struct_traits.h"
10 #include "skia/public/interfaces/bitmap_skbitmap_struct_traits.h" 11 #include "skia/public/interfaces/bitmap_skbitmap_struct_traits.h"
11 #include "third_party/skia/include/core/SkBitmap.h" 12 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "ui/base/cursor/cursor.h" 13 #include "ui/base/cursor/cursor.h"
13 #include "ui/gfx/geometry/mojo/geometry_struct_traits.h" 14 #include "ui/gfx/geometry/mojo/geometry_struct_traits.h"
14 15
15 namespace mojo { 16 namespace mojo {
16 17
17 // static 18 // static
19 ui::mojom::CursorType
20 EnumTraits<ui::mojom::CursorType, ui::CursorType>::ToMojom(
21 ui::CursorType input) {
22 switch (input) {
23 case ui::CursorType::CURSOR_NULL:
24 return ui::mojom::CursorType::CURSOR_NULL;
25 case ui::CursorType::POINTER:
26 return ui::mojom::CursorType::POINTER;
27 case ui::CursorType::CROSS:
28 return ui::mojom::CursorType::CROSS;
29 case ui::CursorType::HAND:
30 return ui::mojom::CursorType::HAND;
31 case ui::CursorType::IBEAM:
32 return ui::mojom::CursorType::IBEAM;
33 case ui::CursorType::WAIT:
34 return ui::mojom::CursorType::WAIT;
35 case ui::CursorType::HELP:
36 return ui::mojom::CursorType::HELP;
37 case ui::CursorType::EAST_RESIZE:
38 return ui::mojom::CursorType::EAST_RESIZE;
39 case ui::CursorType::NORTH_RESIZE:
40 return ui::mojom::CursorType::NORTH_RESIZE;
41 case ui::CursorType::NORTH_EAST_RESIZE:
42 return ui::mojom::CursorType::NORTH_EAST_RESIZE;
43 case ui::CursorType::NORTH_WEST_RESIZE:
44 return ui::mojom::CursorType::NORTH_WEST_RESIZE;
45 case ui::CursorType::SOUTH_RESIZE:
46 return ui::mojom::CursorType::SOUTH_RESIZE;
47 case ui::CursorType::SOUTH_EAST_RESIZE:
48 return ui::mojom::CursorType::SOUTH_EAST_RESIZE;
49 case ui::CursorType::SOUTH_WEST_RESIZE:
50 return ui::mojom::CursorType::SOUTH_WEST_RESIZE;
51 case ui::CursorType::WEST_RESIZE:
52 return ui::mojom::CursorType::WEST_RESIZE;
53 case ui::CursorType::NORTH_SOUTH_RESIZE:
54 return ui::mojom::CursorType::NORTH_SOUTH_RESIZE;
55 case ui::CursorType::EAST_WEST_RESIZE:
56 return ui::mojom::CursorType::EAST_WEST_RESIZE;
57 case ui::CursorType::NORTH_EAST_SOUTH_WEST_RESIZE:
58 return ui::mojom::CursorType::NORTH_EAST_SOUTH_WEST_RESIZE;
59 case ui::CursorType::NORTH_WEST_SOUTH_EAST_RESIZE:
60 return ui::mojom::CursorType::NORTH_WEST_SOUTH_EAST_RESIZE;
61 case ui::CursorType::COLUMN_RESIZE:
62 return ui::mojom::CursorType::COLUMN_RESIZE;
63 case ui::CursorType::ROW_RESIZE:
64 return ui::mojom::CursorType::ROW_RESIZE;
65 case ui::CursorType::MIDDLE_PANNING:
66 return ui::mojom::CursorType::MIDDLE_PANNING;
67 case ui::CursorType::EAST_PANNING:
68 return ui::mojom::CursorType::EAST_PANNING;
69 case ui::CursorType::NORTH_PANNING:
70 return ui::mojom::CursorType::NORTH_PANNING;
71 case ui::CursorType::NORTH_EAST_PANNING:
72 return ui::mojom::CursorType::NORTH_EAST_PANNING;
73 case ui::CursorType::NORTH_WEST_PANNING:
74 return ui::mojom::CursorType::NORTH_WEST_PANNING;
75 case ui::CursorType::SOUTH_PANNING:
76 return ui::mojom::CursorType::SOUTH_PANNING;
77 case ui::CursorType::SOUTH_EAST_PANNING:
78 return ui::mojom::CursorType::SOUTH_EAST_PANNING;
79 case ui::CursorType::SOUTH_WEST_PANNING:
80 return ui::mojom::CursorType::SOUTH_WEST_PANNING;
81 case ui::CursorType::WEST_PANNING:
82 return ui::mojom::CursorType::WEST_PANNING;
83 case ui::CursorType::MOVE:
84 return ui::mojom::CursorType::MOVE;
85 case ui::CursorType::VERTICAL_TEXT:
86 return ui::mojom::CursorType::VERTICAL_TEXT;
87 case ui::CursorType::CELL:
88 return ui::mojom::CursorType::CELL;
89 case ui::CursorType::CONTEXT_MENU:
90 return ui::mojom::CursorType::CONTEXT_MENU;
91 case ui::CursorType::ALIAS:
92 return ui::mojom::CursorType::ALIAS;
93 case ui::CursorType::PROGRESS:
94 return ui::mojom::CursorType::PROGRESS;
95 case ui::CursorType::NO_DROP:
96 return ui::mojom::CursorType::NO_DROP;
97 case ui::CursorType::COPY:
98 return ui::mojom::CursorType::COPY;
99 case ui::CursorType::NONE:
100 return ui::mojom::CursorType::NONE;
101 case ui::CursorType::NOT_ALLOWED:
102 return ui::mojom::CursorType::NOT_ALLOWED;
103 case ui::CursorType::ZOOM_IN:
104 return ui::mojom::CursorType::ZOOM_IN;
105 case ui::CursorType::ZOOM_OUT:
106 return ui::mojom::CursorType::ZOOM_OUT;
107 case ui::CursorType::GRAB:
108 return ui::mojom::CursorType::GRAB;
109 case ui::CursorType::GRABBING:
110 return ui::mojom::CursorType::GRABBING;
111 case ui::CursorType::CUSTOM:
112 return ui::mojom::CursorType::CUSTOM;
113 case ui::CursorType::DND_NONE:
114 case ui::CursorType::DND_MOVE:
115 case ui::CursorType::DND_COPY:
116 case ui::CursorType::DND_LINK:
117 // The mojom version is the same as the restricted Webcursor constants;
118 // don't allow system cursors to be transmitted.
119 NOTREACHED();
120 return ui::mojom::CursorType::CURSOR_NULL;
121 }
122 NOTREACHED();
123 return ui::mojom::CursorType::CURSOR_NULL;
124 }
125
126 // static
127 bool EnumTraits<ui::mojom::CursorType, ui::CursorType>::FromMojom(
128 ui::mojom::CursorType input,
129 ui::CursorType* out) {
130 switch (input) {
131 case ui::mojom::CursorType::CURSOR_NULL:
132 *out = ui::CursorType::CURSOR_NULL;
133 return true;
134 case ui::mojom::CursorType::POINTER:
135 *out = ui::CursorType::POINTER;
136 return true;
137 case ui::mojom::CursorType::CROSS:
138 *out = ui::CursorType::CROSS;
139 return true;
140 case ui::mojom::CursorType::HAND:
141 *out = ui::CursorType::HAND;
142 return true;
143 case ui::mojom::CursorType::IBEAM:
144 *out = ui::CursorType::IBEAM;
145 return true;
146 case ui::mojom::CursorType::WAIT:
147 *out = ui::CursorType::WAIT;
148 return true;
149 case ui::mojom::CursorType::HELP:
150 *out = ui::CursorType::HELP;
151 return true;
152 case ui::mojom::CursorType::EAST_RESIZE:
153 *out = ui::CursorType::EAST_RESIZE;
154 return true;
155 case ui::mojom::CursorType::NORTH_RESIZE:
156 *out = ui::CursorType::NORTH_RESIZE;
157 return true;
158 case ui::mojom::CursorType::NORTH_EAST_RESIZE:
159 *out = ui::CursorType::NORTH_EAST_RESIZE;
160 return true;
161 case ui::mojom::CursorType::NORTH_WEST_RESIZE:
162 *out = ui::CursorType::NORTH_WEST_RESIZE;
163 return true;
164 case ui::mojom::CursorType::SOUTH_RESIZE:
165 *out = ui::CursorType::SOUTH_RESIZE;
166 return true;
167 case ui::mojom::CursorType::SOUTH_EAST_RESIZE:
168 *out = ui::CursorType::SOUTH_EAST_RESIZE;
169 return true;
170 case ui::mojom::CursorType::SOUTH_WEST_RESIZE:
171 *out = ui::CursorType::SOUTH_WEST_RESIZE;
172 return true;
173 case ui::mojom::CursorType::WEST_RESIZE:
174 *out = ui::CursorType::WEST_RESIZE;
175 return true;
176 case ui::mojom::CursorType::NORTH_SOUTH_RESIZE:
177 *out = ui::CursorType::NORTH_SOUTH_RESIZE;
178 return true;
179 case ui::mojom::CursorType::EAST_WEST_RESIZE:
180 *out = ui::CursorType::EAST_WEST_RESIZE;
181 return true;
182 case ui::mojom::CursorType::NORTH_EAST_SOUTH_WEST_RESIZE:
183 *out = ui::CursorType::NORTH_EAST_SOUTH_WEST_RESIZE;
184 return true;
185 case ui::mojom::CursorType::NORTH_WEST_SOUTH_EAST_RESIZE:
186 *out = ui::CursorType::NORTH_WEST_SOUTH_EAST_RESIZE;
187 return true;
188 case ui::mojom::CursorType::COLUMN_RESIZE:
189 *out = ui::CursorType::COLUMN_RESIZE;
190 return true;
191 case ui::mojom::CursorType::ROW_RESIZE:
192 *out = ui::CursorType::ROW_RESIZE;
193 return true;
194 case ui::mojom::CursorType::MIDDLE_PANNING:
195 *out = ui::CursorType::MIDDLE_PANNING;
196 return true;
197 case ui::mojom::CursorType::EAST_PANNING:
198 *out = ui::CursorType::EAST_PANNING;
199 return true;
200 case ui::mojom::CursorType::NORTH_PANNING:
201 *out = ui::CursorType::NORTH_PANNING;
202 return true;
203 case ui::mojom::CursorType::NORTH_EAST_PANNING:
204 *out = ui::CursorType::NORTH_EAST_PANNING;
205 return true;
206 case ui::mojom::CursorType::NORTH_WEST_PANNING:
207 *out = ui::CursorType::NORTH_WEST_PANNING;
208 return true;
209 case ui::mojom::CursorType::SOUTH_PANNING:
210 *out = ui::CursorType::SOUTH_PANNING;
211 return true;
212 case ui::mojom::CursorType::SOUTH_EAST_PANNING:
213 *out = ui::CursorType::SOUTH_EAST_PANNING;
214 return true;
215 case ui::mojom::CursorType::SOUTH_WEST_PANNING:
216 *out = ui::CursorType::SOUTH_WEST_PANNING;
217 return true;
218 case ui::mojom::CursorType::WEST_PANNING:
219 *out = ui::CursorType::WEST_PANNING;
220 return true;
221 case ui::mojom::CursorType::MOVE:
222 *out = ui::CursorType::MOVE;
223 return true;
224 case ui::mojom::CursorType::VERTICAL_TEXT:
225 *out = ui::CursorType::VERTICAL_TEXT;
226 return true;
227 case ui::mojom::CursorType::CELL:
228 *out = ui::CursorType::CELL;
229 return true;
230 case ui::mojom::CursorType::CONTEXT_MENU:
231 *out = ui::CursorType::CONTEXT_MENU;
232 return true;
233 case ui::mojom::CursorType::ALIAS:
234 *out = ui::CursorType::ALIAS;
235 return true;
236 case ui::mojom::CursorType::PROGRESS:
237 *out = ui::CursorType::PROGRESS;
238 return true;
239 case ui::mojom::CursorType::NO_DROP:
240 *out = ui::CursorType::NO_DROP;
241 return true;
242 case ui::mojom::CursorType::COPY:
243 *out = ui::CursorType::COPY;
244 return true;
245 case ui::mojom::CursorType::NONE:
246 *out = ui::CursorType::NONE;
247 return true;
248 case ui::mojom::CursorType::NOT_ALLOWED:
249 *out = ui::CursorType::NOT_ALLOWED;
250 return true;
251 case ui::mojom::CursorType::ZOOM_IN:
252 *out = ui::CursorType::ZOOM_IN;
253 return true;
254 case ui::mojom::CursorType::ZOOM_OUT:
255 *out = ui::CursorType::ZOOM_OUT;
256 return true;
257 case ui::mojom::CursorType::GRAB:
258 *out = ui::CursorType::GRAB;
259 return true;
260 case ui::mojom::CursorType::GRABBING:
261 *out = ui::CursorType::GRABBING;
262 return true;
263 case ui::mojom::CursorType::CUSTOM:
264 *out = ui::CursorType::CUSTOM;
265 return true;
266 }
267
268 NOTREACHED();
269 return false;
270 }
271
272 // static
18 const base::TimeDelta& 273 const base::TimeDelta&
19 StructTraits<ui::mojom::CursorDataDataView, ui::CursorData>::frame_delay( 274 StructTraits<ui::mojom::CursorDataDataView, ui::CursorData>::frame_delay(
20 const ui::CursorData& c) { 275 const ui::CursorData& c) {
21 return c.frame_delay(); 276 return c.frame_delay();
22 } 277 }
23 278
24 // static 279 // static
25 const gfx::Point& 280 const gfx::Point&
26 StructTraits<ui::mojom::CursorDataDataView, ui::CursorData>::hotspot_in_pixels( 281 StructTraits<ui::mojom::CursorDataDataView, ui::CursorData>::hotspot_in_pixels(
27 const ui::CursorData& c) { 282 const ui::CursorData& c) {
28 return c.hotspot_in_pixels(); 283 return c.hotspot_in_pixels();
29 } 284 }
30 285
31 // static 286 // static
32 const std::vector<SkBitmap>& 287 const std::vector<SkBitmap>&
33 StructTraits<ui::mojom::CursorDataDataView, ui::CursorData>::cursor_frames( 288 StructTraits<ui::mojom::CursorDataDataView, ui::CursorData>::cursor_frames(
34 const ui::CursorData& c) { 289 const ui::CursorData& c) {
35 return c.cursor_frames(); 290 return c.cursor_frames();
36 } 291 }
37 292
38 // static 293 // static
39 bool StructTraits<ui::mojom::CursorDataDataView, ui::CursorData>::Read( 294 bool StructTraits<ui::mojom::CursorDataDataView, ui::CursorData>::Read(
40 ui::mojom::CursorDataDataView data, 295 ui::mojom::CursorDataDataView data,
41 ui::CursorData* out) { 296 ui::CursorData* out) {
42 ui::mojom::CursorType type = data.cursor_type(); 297 ui::CursorType type;
43 if (type != ui::mojom::CursorType::CUSTOM) { 298 if (!data.ReadCursorType(&type))
44 *out = ui::CursorData(static_cast<int>(type)); 299 return false;
300
301 if (type != ui::CursorType::CUSTOM) {
302 *out = ui::CursorData(type);
45 return true; 303 return true;
46 } 304 }
47 305
48 gfx::Point hotspot_in_pixels; 306 gfx::Point hotspot_in_pixels;
49 std::vector<SkBitmap> cursor_frames; 307 std::vector<SkBitmap> cursor_frames;
50 float scale_factor = data.scale_factor(); 308 float scale_factor = data.scale_factor();
51 base::TimeDelta frame_delay; 309 base::TimeDelta frame_delay;
52 310
53 if (!data.ReadHotspotInPixels(&hotspot_in_pixels) || 311 if (!data.ReadHotspotInPixels(&hotspot_in_pixels) ||
54 !data.ReadCursorFrames(&cursor_frames) || 312 !data.ReadCursorFrames(&cursor_frames) ||
55 !data.ReadFrameDelay(&frame_delay)) { 313 !data.ReadFrameDelay(&frame_delay)) {
56 return false; 314 return false;
57 } 315 }
58 316
59 *out = ui::CursorData(hotspot_in_pixels, cursor_frames, scale_factor, 317 *out = ui::CursorData(hotspot_in_pixels, cursor_frames, scale_factor,
60 frame_delay); 318 frame_delay);
61 return true; 319 return true;
62 } 320 }
63 321
64 } // namespace mojo 322 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698