Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame^] | 1 | // Copyright 2019 The Chromium Authors |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 4 | |
[email protected] | c2809346d | 2014-03-20 00:11:03 | [diff] [blame] | 5 | #ifndef CONTENT_COMMON_CURSORS_WEBCURSOR_H_ |
6 | #define CONTENT_COMMON_CURSORS_WEBCURSOR_H_ | ||||
7 | |||||
avi | a9aa7a8 | 2015-12-25 03:06:31 | [diff] [blame] | 8 | #include "build/build_config.h" |
[email protected] | c2809346d | 2014-03-20 00:11:03 | [diff] [blame] | 9 | #include "content/common/content_export.h" |
Henrique Ferreiro | 35aa76ef | 2020-03-10 22:29:29 | [diff] [blame] | 10 | #include "ui/base/cursor/cursor.h" |
oshima | 516f03b | 2016-04-28 15:40:11 | [diff] [blame] | 11 | #include "ui/display/display.h" |
tfarina | 655f81d | 2014-12-23 02:38:50 | [diff] [blame] | 12 | #include "ui/gfx/geometry/point.h" |
tfarina | ebe974f0 | 2015-01-03 04:25:32 | [diff] [blame] | 13 | #include "ui/gfx/geometry/size.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 14 | #include "ui/gfx/native_widget_types.h" |
[email protected] | 67b2505 | 2008-10-23 21:57:51 | [diff] [blame] | 15 | |
[email protected] | 84f43c97 | 2013-09-16 23:08:19 | [diff] [blame] | 16 | #if defined(USE_AURA) |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 17 | #include "third_party/abseil-cpp/absl/types/optional.h" |
[email protected] | 84f43c97 | 2013-09-16 23:08:19 | [diff] [blame] | 18 | #include "ui/base/cursor/cursor.h" |
19 | #endif | ||||
20 | |||||
[email protected] | c2809346d | 2014-03-20 00:11:03 | [diff] [blame] | 21 | namespace content { |
22 | |||||
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 23 | // This class encapsulates a cross-platform description of a cursor. Platform |
24 | // specific methods are provided to translate the cross-platform cursor into a | ||||
25 | // platform specific cursor. It is also possible to serialize / de-serialize a | ||||
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 26 | // WebCursor. This class is highly similar to ui::Cursor. |
[email protected] | c2809346d | 2014-03-20 00:11:03 | [diff] [blame] | 27 | class CONTENT_EXPORT WebCursor { |
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 28 | public: |
Mitsuru Oshima | d15e3786 | 2020-01-14 07:55:21 | [diff] [blame] | 29 | WebCursor(); |
Henrique Ferreiro | 35aa76ef | 2020-03-10 22:29:29 | [diff] [blame] | 30 | explicit WebCursor(const ui::Cursor& info); |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 31 | explicit WebCursor(const WebCursor& other); |
[email protected] | cf4e5eb1 | 2009-01-09 01:20:38 | [diff] [blame] | 32 | ~WebCursor(); |
33 | |||||
Henrique Ferreiro | 35aa76ef | 2020-03-10 22:29:29 | [diff] [blame] | 34 | const ui::Cursor& cursor() const { return cursor_; } |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 35 | |
Henrique Ferreiro | 35aa76ef | 2020-03-10 22:29:29 | [diff] [blame] | 36 | // Sets the ui::Cursor |cursor|; returns whether it has reasonable values. |
37 | bool SetCursor(const ui::Cursor& cursor); | ||||
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 38 | |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 39 | // Equality operator; performs bitmap content comparison as needed. |
40 | bool operator==(const WebCursor& other) const; | ||||
41 | bool operator!=(const WebCursor& other) const; | ||||
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 42 | |
[email protected] | f0b6b48 | 2010-11-23 00:55:28 | [diff] [blame] | 43 | // Returns a native cursor representing the current WebCursor instance. |
44 | gfx::NativeCursor GetNativeCursor(); | ||||
45 | |||||
[email protected] | c783955 | 2012-04-03 21:14:36 | [diff] [blame] | 46 | #if defined(USE_AURA) |
[email protected] | ee37dc65 | 2013-08-06 00:33:27 | [diff] [blame] | 47 | // Updates |device_scale_factor_| and |rotation_| based on |display|. |
oshima | 516f03b | 2016-04-28 15:40:11 | [diff] [blame] | 48 | void SetDisplayInfo(const display::Display& display); |
[email protected] | ee37dc65 | 2013-08-06 00:33:27 | [diff] [blame] | 49 | |
Evan Stade | 891067b2 | 2018-11-16 01:26:33 | [diff] [blame] | 50 | void CreateScaledBitmapAndHotspotFromCustomData(SkBitmap* bitmap, |
51 | gfx::Point* hotspot, | ||||
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 52 | float* scale); |
Mitsuru Oshima | d15e3786 | 2020-01-14 07:55:21 | [diff] [blame] | 53 | |
54 | bool has_custom_cursor_for_test() const { return !!custom_cursor_; } | ||||
[email protected] | 67b2505 | 2008-10-23 21:57:51 | [diff] [blame] | 55 | #endif |
56 | |||||
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 57 | private: |
[email protected] | cf4e5eb1 | 2009-01-09 01:20:38 | [diff] [blame] | 58 | // Platform specific cleanup. |
59 | void CleanupPlatformData(); | ||||
60 | |||||
Evan Stade | 891067b2 | 2018-11-16 01:26:33 | [diff] [blame] | 61 | float GetCursorScaleFactor(SkBitmap* bitmap); |
62 | |||||
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 63 | // The basic cursor info. |
Henrique Ferreiro | 35aa76ef | 2020-03-10 22:29:29 | [diff] [blame] | 64 | ui::Cursor cursor_; |
[email protected] | 2b99be2 | 2008-11-14 18:45:26 | [diff] [blame] | 65 | |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 66 | #if defined(USE_AURA) || defined(USE_OZONE) |
[email protected] | c783955 | 2012-04-03 21:14:36 | [diff] [blame] | 67 | // Only used for custom cursors. |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 68 | float device_scale_factor_ = 1.f; |
Evan Stade | 891067b2 | 2018-11-16 01:26:33 | [diff] [blame] | 69 | display::Display::Rotation rotation_ = display::Display::ROTATE_0; |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 70 | #endif |
Evan Stade | 891067b2 | 2018-11-16 01:26:33 | [diff] [blame] | 71 | |
[email protected] | 95539f00 | 2014-08-07 16:01:20 | [diff] [blame] | 72 | #if defined(USE_OZONE) |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 73 | // This matches ozone drm_util.cc's kDefaultCursorWidth/Height. |
74 | static constexpr int kDefaultMaxSize = 64; | ||||
75 | gfx::Size maximum_cursor_size_ = {kDefaultMaxSize, kDefaultMaxSize}; | ||||
[email protected] | 95539f00 | 2014-08-07 16:01:20 | [diff] [blame] | 76 | #endif |
Mitsuru Oshima | d15e3786 | 2020-01-14 07:55:21 | [diff] [blame] | 77 | |
78 | #if defined(USE_AURA) | ||||
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 79 | absl::optional<ui::Cursor> custom_cursor_; |
Mitsuru Oshima | d15e3786 | 2020-01-14 07:55:21 | [diff] [blame] | 80 | #endif |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 81 | }; |
82 | |||||
[email protected] | c2809346d | 2014-03-20 00:11:03 | [diff] [blame] | 83 | } // namespace content |
84 | |||||
85 | #endif // CONTENT_COMMON_CURSORS_WEBCURSOR_H_ |