Chromium Code Reviews| Index: ui/base/cursor/cursor_data.h |
| diff --git a/ui/base/cursor/cursor_data.h b/ui/base/cursor/cursor_data.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0ea71c7b207eedb0a3b75dd2cc2f4f0fcca75697 |
| --- /dev/null |
| +++ b/ui/base/cursor/cursor_data.h |
| @@ -0,0 +1,90 @@ |
| +// Copyright 2017 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. |
| + |
| +#ifndef UI_BASE_CURSOR_CURSOR_DATA_H_ |
| +#define UI_BASE_CURSOR_CURSOR_DATA_H_ |
| + |
| +#include <vector> |
| + |
| +#include "build/build_config.h" |
| +#include "ui/base/ui_base_export.h" |
| +#include "ui/gfx/geometry/point.h" |
| + |
| +class SkBitmap; |
| + |
| +namespace ui { |
| + |
| +// The new Cursor class. (aka, Cursor2) |
| +// |
| +// Contains all data for a cursor. Its type, along with any custom bitmap |
| +// images, hotspot data, scaling factors, etc. |
| +// |
| +// Why a new class? ui::Cursor currently wraps a PlatformCursor, which is a |
| +// platform specific representation, which is generated in //content/. This |
| +// previously was OK, as a WebCursor was sent over chrome IPC from the renderer |
| +// to the browser process, and then the data in WebCursor was turned into the |
| +// an opaque platform specific structure, stuffed inside ui::Cursor, and then |
| +// read by win32 or x11. Now, the windowing server can be in a separate |
| +// process, so this doesn't work. |
| +// |
| +// Using a raw mojo struct is not convenient; we want to have copyable classes |
| +// which are internally copy-on-write for large data, like the internally used |
| +// SkBitmap, as we cache this data at multiple layers. |
| +// |
| +// TODO(erg): Rename this to ui::Cursor once we've mojoified the entire chain |
| +// from the renderer to the window server. |
| +class UI_BASE_EXPORT CursorData { |
| + public: |
| + CursorData(); |
| + CursorData(int type); |
|
sky
2017/03/31 04:57:58
explicit
Elliot Glaysher
2017/03/31 21:18:15
Done.
|
| + CursorData(const gfx::Point& hostpot_point, |
| + const std::vector<SkBitmap>& cursor_frames, |
| + int frame_delay_ms); |
| + CursorData(const CursorData& cursor); |
| + ~CursorData(); |
| + |
| + CursorData& operator=(const CursorData& cursor); |
| + |
| + int native_type() const { return native_type_; } |
| + 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.)
|
| + 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.
|
| + const std::vector<SkBitmap>& cursor_frames() const { return cursor_frames_; } |
| + |
| + // Returns true if this CursorData instance is of |native_type|. |
| + bool IsType(int native_type) const; |
| + |
| + // Checks if the data in |rhs| was created from the same input data. |
| + // |
| + // This is subtly different from operator==, as we need this to be a |
| + // lightweight operation instead of performing pixel equality checks on |
| + // arbitrary sized SkBitmaps. So we check the internal SkBitmap generation |
| + // IDs, which are per-process, monotonically increasing ids which get changed |
| + // whenever there's a modification to the pixel data. This means that this |
| + // method can have false negatives: two SkBitmap instances made with the same |
| + // input data (but which weren't copied from each other) can have equal pixel |
| + // data, but different generation ids. |
| + bool IsSameAs(const CursorData& rhs) const; |
| + |
| + private: |
| + // A native type constant from cursor.h. |
| + int native_type_; |
| + |
| + // The delay between cursor frames in milliseconds. |
| + uint32_t frame_delay_ms_; |
| + |
| + // The hotspot in cursor frames. |
| + gfx::Point hotspot_; |
| + |
| + // The frames of a cursor. |
| + std::vector<SkBitmap> cursor_frames_; |
| + |
| + // Generator IDs. The size of |generator_ids_| must be equal to the size of |
| + // cursor_frames_, and is generated when we set the bitmaps. We produce these |
| + // unique IDs so we can do quick equality checks. |
| + std::vector<uint32_t> generator_ids_; |
| +}; |
| + |
| +} // namespace ui |
| + |
| +#endif // UI_BASE_CURSOR_CURSOR_DATA_H_ |