Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
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 | |||||
8 | #include <vector> | ||||
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 9 | |
avi | a9aa7a8 | 2015-12-25 03:06:31 | [diff] [blame] | 10 | #include "build/build_config.h" |
[email protected] | c2809346d | 2014-03-20 00:11:03 | [diff] [blame] | 11 | #include "content/common/content_export.h" |
dgozman | 9adbfb9 | 2017-04-14 00:52:37 | [diff] [blame] | 12 | #include "content/public/common/cursor_info.h" |
oshima | 516f03b | 2016-04-28 15:40:11 | [diff] [blame] | 13 | #include "ui/display/display.h" |
tfarina | 655f81d | 2014-12-23 02:38:50 | [diff] [blame] | 14 | #include "ui/gfx/geometry/point.h" |
tfarina | ebe974f0 | 2015-01-03 04:25:32 | [diff] [blame] | 15 | #include "ui/gfx/geometry/size.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 16 | #include "ui/gfx/native_widget_types.h" |
[email protected] | 67b2505 | 2008-10-23 21:57:51 | [diff] [blame] | 17 | |
[email protected] | 84f43c97 | 2013-09-16 23:08:19 | [diff] [blame] | 18 | #if defined(USE_AURA) |
19 | #include "ui/base/cursor/cursor.h" | ||||
20 | #endif | ||||
21 | |||||
brettw | 05cfd8ddb | 2015-06-02 07:02:47 | [diff] [blame] | 22 | namespace base { |
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 23 | class Pickle; |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 24 | class PickleIterator; |
brettw | 05cfd8ddb | 2015-06-02 07:02:47 | [diff] [blame] | 25 | } |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 26 | |
[email protected] | c2809346d | 2014-03-20 00:11:03 | [diff] [blame] | 27 | namespace content { |
28 | |||||
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 29 | // This class encapsulates a cross-platform description of a cursor. Platform |
30 | // specific methods are provided to translate the cross-platform cursor into a | ||||
31 | // platform specific cursor. It is also possible to serialize / de-serialize a | ||||
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 32 | // WebCursor. This class is highly similar to ui::Cursor. |
[email protected] | c2809346d | 2014-03-20 00:11:03 | [diff] [blame] | 33 | class CONTENT_EXPORT WebCursor { |
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 34 | public: |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 35 | WebCursor() = default; |
36 | explicit WebCursor(const CursorInfo& info); | ||||
37 | explicit WebCursor(const WebCursor& other); | ||||
[email protected] | cf4e5eb1 | 2009-01-09 01:20:38 | [diff] [blame] | 38 | ~WebCursor(); |
39 | |||||
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 40 | const CursorInfo& info() const { return info_; } |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 41 | |
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 42 | // Serialization / De-serialization |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 43 | bool Deserialize(const base::Pickle* m, base::PickleIterator* iter); |
Daniel Cheng | 0d89f922 | 2017-09-22 05:05:07 | [diff] [blame] | 44 | void Serialize(base::Pickle* pickle) const; |
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 45 | |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 46 | // Equality operator; performs bitmap content comparison as needed. |
47 | bool operator==(const WebCursor& other) const; | ||||
48 | bool operator!=(const WebCursor& other) const; | ||||
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 49 | |
[email protected] | f0b6b48 | 2010-11-23 00:55:28 | [diff] [blame] | 50 | // Returns a native cursor representing the current WebCursor instance. |
51 | gfx::NativeCursor GetNativeCursor(); | ||||
52 | |||||
[email protected] | c783955 | 2012-04-03 21:14:36 | [diff] [blame] | 53 | #if defined(USE_AURA) |
Evan Stade | 891067b2 | 2018-11-16 01:26:33 | [diff] [blame] | 54 | ui::PlatformCursor GetPlatformCursor(const ui::Cursor& cursor); |
[email protected] | 70050e7 | 2012-07-10 11:38:52 | [diff] [blame] | 55 | |
[email protected] | ee37dc65 | 2013-08-06 00:33:27 | [diff] [blame] | 56 | // Updates |device_scale_factor_| and |rotation_| based on |display|. |
oshima | 516f03b | 2016-04-28 15:40:11 | [diff] [blame] | 57 | void SetDisplayInfo(const display::Display& display); |
[email protected] | ee37dc65 | 2013-08-06 00:33:27 | [diff] [blame] | 58 | |
Evan Stade | 891067b2 | 2018-11-16 01:26:33 | [diff] [blame] | 59 | void CreateScaledBitmapAndHotspotFromCustomData(SkBitmap* bitmap, |
60 | gfx::Point* hotspot, | ||||
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 61 | float* scale); |
[email protected] | 67b2505 | 2008-10-23 21:57:51 | [diff] [blame] | 62 | #endif |
63 | |||||
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 64 | void set_info_for_testing(const CursorInfo& info) { info_ = info; } |
65 | |||||
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 66 | private: |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 67 | // Returns true if this cursor's platform data matches that of |other|. |
68 | bool IsPlatformDataEqual(const WebCursor& other) const; | ||||
[email protected] | cf4e5eb1 | 2009-01-09 01:20:38 | [diff] [blame] | 69 | |
70 | // Copies platform specific data from the WebCursor instance passed in. | ||||
71 | void CopyPlatformData(const WebCursor& other); | ||||
72 | |||||
73 | // Platform specific cleanup. | ||||
74 | void CleanupPlatformData(); | ||||
75 | |||||
[email protected] | 4605be7 | 2010-08-11 04:17:09 | [diff] [blame] | 76 | // Clamp the hotspot to the custom image's bounds, if this is a custom cursor. |
77 | void ClampHotspot(); | ||||
78 | |||||
Evan Stade | 891067b2 | 2018-11-16 01:26:33 | [diff] [blame] | 79 | float GetCursorScaleFactor(SkBitmap* bitmap); |
80 | |||||
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 81 | // The basic cursor info. |
82 | CursorInfo info_; | ||||
[email protected] | 2b99be2 | 2008-11-14 18:45:26 | [diff] [blame] | 83 | |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 84 | #if defined(USE_AURA) || defined(USE_OZONE) |
[email protected] | c783955 | 2012-04-03 21:14:36 | [diff] [blame] | 85 | // Only used for custom cursors. |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 86 | ui::PlatformCursor platform_cursor_ = 0; |
87 | float device_scale_factor_ = 1.f; | ||||
Evan Stade | 891067b2 | 2018-11-16 01:26:33 | [diff] [blame] | 88 | display::Display::Rotation rotation_ = display::Display::ROTATE_0; |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 89 | #endif |
Evan Stade | 891067b2 | 2018-11-16 01:26:33 | [diff] [blame] | 90 | |
[email protected] | 95539f00 | 2014-08-07 16:01:20 | [diff] [blame] | 91 | #if defined(USE_OZONE) |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame^] | 92 | // This matches ozone drm_util.cc's kDefaultCursorWidth/Height. |
93 | static constexpr int kDefaultMaxSize = 64; | ||||
94 | gfx::Size maximum_cursor_size_ = {kDefaultMaxSize, kDefaultMaxSize}; | ||||
[email protected] | 95539f00 | 2014-08-07 16:01:20 | [diff] [blame] | 95 | #endif |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 96 | }; |
97 | |||||
[email protected] | c2809346d | 2014-03-20 00:11:03 | [diff] [blame] | 98 | } // namespace content |
99 | |||||
100 | #endif // CONTENT_COMMON_CURSORS_WEBCURSOR_H_ |