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) |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 17 | #include <optional> |
[email protected] | 84f43c97 | 2013-09-16 23:08:19 | [diff] [blame] | 18 | #endif |
19 | |||||
[email protected] | c2809346d | 2014-03-20 00:11:03 | [diff] [blame] | 20 | namespace content { |
21 | |||||
Henrique Ferreiro | fd3d14e | 2023-01-23 20:38:41 | [diff] [blame] | 22 | // NOTE(https://crbug.com/1149906): This class is deprecated and ui::Cursor |
23 | // should be used instead. | ||||
24 | // | ||||
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 25 | // This class encapsulates a cross-platform description of a cursor. Platform |
26 | // specific methods are provided to translate the cross-platform cursor into a | ||||
27 | // platform specific cursor. It is also possible to serialize / de-serialize a | ||||
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 28 | // WebCursor. This class is highly similar to ui::Cursor. |
[email protected] | c2809346d | 2014-03-20 00:11:03 | [diff] [blame] | 29 | class CONTENT_EXPORT WebCursor { |
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 30 | public: |
Mitsuru Oshima | d15e3786 | 2020-01-14 07:55:21 | [diff] [blame] | 31 | WebCursor(); |
Henrique Ferreiro | 35aa76ef | 2020-03-10 22:29:29 | [diff] [blame] | 32 | explicit WebCursor(const ui::Cursor& info); |
[email protected] | cf4e5eb1 | 2009-01-09 01:20:38 | [diff] [blame] | 33 | ~WebCursor(); |
34 | |||||
Henrique Ferreiro | 35aa76ef | 2020-03-10 22:29:29 | [diff] [blame] | 35 | const ui::Cursor& cursor() const { return cursor_; } |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 36 | |
[email protected] | f0b6b48 | 2010-11-23 00:55:28 | [diff] [blame] | 37 | // Returns a native cursor representing the current WebCursor instance. |
38 | gfx::NativeCursor GetNativeCursor(); | ||||
39 | |||||
[email protected] | c783955 | 2012-04-03 21:14:36 | [diff] [blame] | 40 | #if defined(USE_AURA) |
Max Ihlenfeldt | 9a0990a | 2024-07-02 16:53:14 | [diff] [blame] | 41 | // Updates |device_scale_factor_| and |rotation_| based on |window|'s |
42 | // preferred scale (if any) and its display information. | ||||
43 | void UpdateDisplayInfoForWindow(aura::Window* window); | ||||
[email protected] | ee37dc65 | 2013-08-06 00:33:27 | [diff] [blame] | 44 | |
Mitsuru Oshima | d15e3786 | 2020-01-14 07:55:21 | [diff] [blame] | 45 | bool has_custom_cursor_for_test() const { return !!custom_cursor_; } |
[email protected] | 67b2505 | 2008-10-23 21:57:51 | [diff] [blame] | 46 | #endif |
47 | |||||
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 48 | private: |
Evan Stade | 891067b2 | 2018-11-16 01:26:33 | [diff] [blame] | 49 | float GetCursorScaleFactor(SkBitmap* bitmap); |
50 | |||||
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 51 | // The basic cursor info. |
Henrique Ferreiro | 35aa76ef | 2020-03-10 22:29:29 | [diff] [blame] | 52 | ui::Cursor cursor_; |
[email protected] | 2b99be2 | 2008-11-14 18:45:26 | [diff] [blame] | 53 | |
Henrique Ferreiro | d1e80f7 | 2023-03-20 14:31:01 | [diff] [blame] | 54 | #if defined(USE_AURA) |
[email protected] | c783955 | 2012-04-03 21:14:36 | [diff] [blame] | 55 | // Only used for custom cursors. |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 56 | float device_scale_factor_ = 1.f; |
Evan Stade | 891067b2 | 2018-11-16 01:26:33 | [diff] [blame] | 57 | display::Display::Rotation rotation_ = display::Display::ROTATE_0; |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 58 | #endif |
Evan Stade | 891067b2 | 2018-11-16 01:26:33 | [diff] [blame] | 59 | |
Georg Neis | 18fc514 | 2024-12-18 00:58:41 | [diff] [blame] | 60 | #if BUILDFLAG(IS_CHROMEOS) |
Mike Wasserman | f95c2d9d | 2019-04-17 00:44:21 | [diff] [blame] | 61 | // This matches ozone drm_util.cc's kDefaultCursorWidth/Height. |
62 | static constexpr int kDefaultMaxSize = 64; | ||||
63 | gfx::Size maximum_cursor_size_ = {kDefaultMaxSize, kDefaultMaxSize}; | ||||
[email protected] |