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