blob: 012540d67ac255b0827c67e60f8b06b9ed21bc89 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2019 The Chromium Authors
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitf5b16fe2008-07-27 00:20:514
[email protected]c2809346d2014-03-20 00:11:035#ifndef CONTENT_COMMON_CURSORS_WEBCURSOR_H_
6#define CONTENT_COMMON_CURSORS_WEBCURSOR_H_
7
avia9aa7a82015-12-25 03:06:318#include "build/build_config.h"
[email protected]c2809346d2014-03-20 00:11:039#include "content/common/content_export.h"
Henrique Ferreiro35aa76ef2020-03-10 22:29:2910#include "ui/base/cursor/cursor.h"
oshima516f03b2016-04-28 15:40:1111#include "ui/display/display.h"
tfarina655f81d2014-12-23 02:38:5012#include "ui/gfx/geometry/point.h"
tfarinaebe974f02015-01-03 04:25:3213#include "ui/gfx/geometry/size.h"
[email protected]08397d52011-02-05 01:53:3814#include "ui/gfx/native_widget_types.h"
[email protected]67b25052008-10-23 21:57:5115
[email protected]84f43c972013-09-16 23:08:1916#if defined(USE_AURA)
Anton Bikineevf62d1bf2021-05-15 17:56:0717#include "third_party/abseil-cpp/absl/types/optional.h"
[email protected]84f43c972013-09-16 23:08:1918#include "ui/base/cursor/cursor.h"
19#endif
20
[email protected]c2809346d2014-03-20 00:11:0321namespace content {
22
[email protected]4c870b42008-11-06 00:36:5223// 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 Wassermanf95c2d9d2019-04-17 00:44:2126// WebCursor. This class is highly similar to ui::Cursor.
[email protected]c2809346d2014-03-20 00:11:0327class CONTENT_EXPORT WebCursor {
[email protected]4c870b42008-11-06 00:36:5228 public:
Mitsuru Oshimad15e37862020-01-14 07:55:2129 WebCursor();
Henrique Ferreiro35aa76ef2020-03-10 22:29:2930 explicit WebCursor(const ui::Cursor& info);
Mike Wassermanf95c2d9d2019-04-17 00:44:2131 explicit WebCursor(const WebCursor& other);
[email protected]cf4e5eb12009-01-09 01:20:3832 ~WebCursor();
33
Henrique Ferreiro35aa76ef2020-03-10 22:29:2934 const ui::Cursor& cursor() const { return cursor_; }
[email protected]7c51b0ee2009-07-08 21:49:3035
Henrique Ferreiro35aa76ef2020-03-10 22:29:2936 // Sets the ui::Cursor |cursor|; returns whether it has reasonable values.
37 bool SetCursor(const ui::Cursor& cursor);
[email protected]4c870b42008-11-06 00:36:5238
Mike Wassermanf95c2d9d2019-04-17 00:44:2139 // Equality operator; performs bitmap content comparison as needed.
40 bool operator==(const WebCursor& other) const;
41 bool operator!=(const WebCursor& other) const;
[email protected]4c870b42008-11-06 00:36:5242
[email protected]f0b6b482010-11-23 00:55:2843 // Returns a native cursor representing the current WebCursor instance.
44 gfx::NativeCursor GetNativeCursor();
45
[email protected]c7839552012-04-03 21:14:3646#if defined(USE_AURA)
[email protected]ee37dc652013-08-06 00:33:2747 // Updates |device_scale_factor_| and |rotation_| based on |display|.
oshima516f03b2016-04-28 15:40:1148 void SetDisplayInfo(const display::Display& display);
[email protected]ee37dc652013-08-06 00:33:2749
Evan Stade891067b22018-11-16 01:26:3350 void CreateScaledBitmapAndHotspotFromCustomData(SkBitmap* bitmap,
51 gfx::Point* hotspot,
Mike Wassermanf95c2d9d2019-04-17 00:44:2152 float* scale);
Mitsuru Oshimad15e37862020-01-14 07:55:2153
54 bool has_custom_cursor_for_test() const { return !!custom_cursor_; }
[email protected]67b25052008-10-23 21:57:5155#endif
56
[email protected]4c870b42008-11-06 00:36:5257 private:
[email protected]cf4e5eb12009-01-09 01:20:3858 // Platform specific cleanup.
59 void CleanupPlatformData();
60
Evan Stade891067b22018-11-16 01:26:3361 float GetCursorScaleFactor(SkBitmap* bitmap);
62
Mike Wassermanf95c2d9d2019-04-17 00:44:2163 // The basic cursor info.
Henrique Ferreiro35aa76ef2020-03-10 22:29:2964 ui::Cursor cursor_;
[email protected]2b99be22008-11-14 18:45:2665
Mike Wassermanf95c2d9d2019-04-17 00:44:2166#if defined(USE_AURA) || defined(USE_OZONE)
[email protected]c7839552012-04-03 21:14:3667 // Only used for custom cursors.
Mike Wassermanf95c2d9d2019-04-17 00:44:2168 float device_scale_factor_ = 1.f;
Evan Stade891067b22018-11-16 01:26:3369 display::Display::Rotation rotation_ = display::Display::ROTATE_0;
Mike Wassermanf95c2d9d2019-04-17 00:44:2170#endif
Evan Stade891067b22018-11-16 01:26:3371
[email protected]95539f002014-08-07 16:01:2072#if defined(USE_OZONE)
Mike Wassermanf95c2d9d2019-04-17 00:44:2173 // 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]95539f002014-08-07 16:01:2076#endif
Mitsuru Oshimad15e37862020-01-14 07:55:2177
78#if defined(USE_AURA)
Anton Bikineevf62d1bf2021-05-15 17:56:0779 absl::optional<ui::Cursor> custom_cursor_;
Mitsuru Oshimad15e37862020-01-14 07:55:2180#endif
initial.commitf5b16fe2008-07-27 00:20:5181};
82
[email protected]c2809346d2014-03-20 00:11:0383} // namespace content
84
85#endif // CONTENT_COMMON_CURSORS_WEBCURSOR_H_