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

Side by Side Diff: ui/base/cursor/cursor_data.h

Issue 2833163002: Change ui cursor identifiers to an enum class. (Closed)
Patch Set: OK, it can't be explicit for mac. 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
« no previous file with comments | « ui/base/cursor/cursor.cc ('k') | ui/base/cursor/cursor_data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef UI_BASE_CURSOR_CURSOR_DATA_H_ 5 #ifndef UI_BASE_CURSOR_CURSOR_DATA_H_
6 #define UI_BASE_CURSOR_CURSOR_DATA_H_ 6 #define UI_BASE_CURSOR_CURSOR_DATA_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "ui/base/ui_base_export.h" 12 #include "ui/base/ui_base_export.h"
13 #include "ui/gfx/geometry/point.h" 13 #include "ui/gfx/geometry/point.h"
14 14
15 class SkBitmap; 15 class SkBitmap;
16 16
17 namespace ui { 17 namespace ui {
18 enum class CursorType;
18 19
19 // The new Cursor class. (aka, Cursor2) 20 // The new Cursor class. (aka, Cursor2)
20 // 21 //
21 // Contains all data for a cursor. Its type, along with any custom bitmap 22 // Contains all data for a cursor. Its type, along with any custom bitmap
22 // images, hotspot data, scaling factors, etc. 23 // images, hotspot data, scaling factors, etc.
23 // 24 //
24 // Why a new class? ui::Cursor currently wraps a PlatformCursor, which is a 25 // Why a new class? ui::Cursor currently wraps a PlatformCursor, which is a
25 // platform specific representation, which is generated in //content/. This 26 // platform specific representation, which is generated in //content/. This
26 // previously was OK, as a WebCursor was sent over chrome IPC from the renderer 27 // previously was OK, as a WebCursor was sent over chrome IPC from the renderer
27 // to the browser process, and then the data in WebCursor was turned into the 28 // to the browser process, and then the data in WebCursor was turned into the
28 // an opaque platform specific structure, stuffed inside ui::Cursor, and then 29 // an opaque platform specific structure, stuffed inside ui::Cursor, and then
29 // read by win32 or x11. Now, the windowing server can be in a separate 30 // read by win32 or x11. Now, the windowing server can be in a separate
30 // process, so this doesn't work. 31 // process, so this doesn't work.
31 // 32 //
32 // Using a raw mojo struct is not convenient; we want to have copyable classes 33 // Using a raw mojo struct is not convenient; we want to have copyable classes
33 // which are internally copy-on-write for large data, like the internally used 34 // which are internally copy-on-write for large data, like the internally used
34 // SkBitmap, as we cache this data at multiple layers. 35 // SkBitmap, as we cache this data at multiple layers.
35 // 36 //
36 // TODO(erg): Rename this to ui::Cursor once we've mojoified the entire chain 37 // TODO(erg): Rename this to ui::Cursor once we've mojoified the entire chain
37 // from the renderer to the window server. 38 // from the renderer to the window server.
38 class UI_BASE_EXPORT CursorData { 39 class UI_BASE_EXPORT CursorData {
39 public: 40 public:
40 CursorData(); 41 CursorData();
41 explicit CursorData(int type); 42 explicit CursorData(CursorType type);
42 CursorData(const gfx::Point& hostpot_point, 43 CursorData(const gfx::Point& hostpot_point,
43 const std::vector<SkBitmap>& cursor_frames, 44 const std::vector<SkBitmap>& cursor_frames,
44 float scale_factor, 45 float scale_factor,
45 const base::TimeDelta& frame_delay); 46 const base::TimeDelta& frame_delay);
46 CursorData(const CursorData& cursor); 47 CursorData(const CursorData& cursor);
47 ~CursorData(); 48 ~CursorData();
48 49
49 CursorData& operator=(const CursorData& cursor); 50 CursorData& operator=(const CursorData& cursor);
50 51
51 int cursor_type() const { return cursor_type_; } 52 CursorType cursor_type() const { return cursor_type_; }
52 const base::TimeDelta& frame_delay() const { return frame_delay_; } 53 const base::TimeDelta& frame_delay() const { return frame_delay_; }
53 float scale_factor() const { return scale_factor_; } 54 float scale_factor() const { return scale_factor_; }
54 const gfx::Point& hotspot_in_pixels() const { return hotspot_; } 55 const gfx::Point& hotspot_in_pixels() const { return hotspot_; }
55 const std::vector<SkBitmap>& cursor_frames() const { return cursor_frames_; } 56 const std::vector<SkBitmap>& cursor_frames() const { return cursor_frames_; }
56 57
57 // Returns true if this CursorData instance is of |cursor_type|. 58 // Returns true if this CursorData instance is of |cursor_type|.
58 bool IsType(int cursor_type) const; 59 bool IsType(CursorType cursor_type) const;
59 60
60 // Checks if the data in |rhs| was created from the same input data. 61 // Checks if the data in |rhs| was created from the same input data.
61 // 62 //
62 // This is subtly different from operator==, as we need this to be a 63 // This is subtly different from operator==, as we need this to be a
63 // lightweight operation instead of performing pixel equality checks on 64 // lightweight operation instead of performing pixel equality checks on
64 // arbitrary sized SkBitmaps. So we check the internal SkBitmap generation 65 // arbitrary sized SkBitmaps. So we check the internal SkBitmap generation
65 // IDs, which are per-process, monotonically increasing ids which get changed 66 // IDs, which are per-process, monotonically increasing ids which get changed
66 // whenever there's a modification to the pixel data. This means that this 67 // whenever there's a modification to the pixel data. This means that this
67 // method can have false negatives: two SkBitmap instances made with the same 68 // method can have false negatives: two SkBitmap instances made with the same
68 // input data (but which weren't copied from each other) can have equal pixel 69 // input data (but which weren't copied from each other) can have equal pixel
69 // data, but different generation ids. 70 // data, but different generation ids.
70 bool IsSameAs(const CursorData& rhs) const; 71 bool IsSameAs(const CursorData& rhs) const;
71 72
72 private: 73 private:
73 // A native type constant from cursor.h. 74 // A native type constant from cursor.h.
74 int cursor_type_; 75 CursorType cursor_type_;
75 76
76 // The delay between cursor frames. 77 // The delay between cursor frames.
77 base::TimeDelta frame_delay_; 78 base::TimeDelta frame_delay_;
78 79
79 // The scale factor of the images in |cursor_frames_|. 80 // The scale factor of the images in |cursor_frames_|.
80 float scale_factor_; 81 float scale_factor_;
81 82
82 // The hotspot in cursor frames. 83 // The hotspot in cursor frames.
83 gfx::Point hotspot_; 84 gfx::Point hotspot_;
84 85
85 // The frames of a cursor. 86 // The frames of a cursor.
86 std::vector<SkBitmap> cursor_frames_; 87 std::vector<SkBitmap> cursor_frames_;
87 88
88 // Generator IDs. The size of |generator_ids_| must be equal to the size of 89 // Generator IDs. The size of |generator_ids_| must be equal to the size of
89 // cursor_frames_, and is generated when we set the bitmaps. We produce these 90 // cursor_frames_, and is generated when we set the bitmaps. We produce these
90 // unique IDs so we can do quick equality checks. 91 // unique IDs so we can do quick equality checks.
91 std::vector<uint32_t> generator_ids_; 92 std::vector<uint32_t> generator_ids_;
92 }; 93 };
93 94
94 } // namespace ui 95 } // namespace ui
95 96
96 #endif // UI_BASE_CURSOR_CURSOR_DATA_H_ 97 #endif // UI_BASE_CURSOR_CURSOR_DATA_H_
OLDNEW
« no previous file with comments | « ui/base/cursor/cursor.cc ('k') | ui/base/cursor/cursor_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698