blob: 3a740af2e66caf71a7070753a07a099f245e5bed [file] [log] [blame]
Mike Wassermanf95c2d9d2019-04-17 00:44:211// Copyright 2019 The Chromium Authors. All rights reserved.
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
8#include <vector>
initial.commitf5b16fe2008-07-27 00:20:519
avia9aa7a82015-12-25 03:06:3110#include "build/build_config.h"
[email protected]c2809346d2014-03-20 00:11:0311#include "content/common/content_export.h"
dgozman9adbfb92017-04-14 00:52:3712#include "content/public/common/cursor_info.h"
oshima516f03b2016-04-28 15:40:1113#include "ui/display/display.h"
tfarina655f81d2014-12-23 02:38:5014#include "ui/gfx/geometry/point.h"
tfarinaebe974f02015-01-03 04:25:3215#include "ui/gfx/geometry/size.h"
[email protected]08397d52011-02-05 01:53:3816#include "ui/gfx/native_widget_types.h"
[email protected]67b25052008-10-23 21:57:5117
[email protected]84f43c972013-09-16 23:08:1918#if defined(USE_AURA)
19#include "ui/base/cursor/cursor.h"
20#endif
21
brettw05cfd8ddb2015-06-02 07:02:4722namespace base {
[email protected]4c870b42008-11-06 00:36:5223class Pickle;
[email protected]ce208f872012-03-07 20:42:5624class PickleIterator;
brettw05cfd8ddb2015-06-02 07:02:4725}
initial.commitf5b16fe2008-07-27 00:20:5126
[email protected]c2809346d2014-03-20 00:11:0327namespace content {
28
[email protected]4c870b42008-11-06 00:36:5229// 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 Wassermanf95c2d9d2019-04-17 00:44:2132// WebCursor. This class is highly similar to ui::Cursor.
[email protected]c2809346d2014-03-20 00:11:0333class CONTENT_EXPORT WebCursor {
[email protected]4c870b42008-11-06 00:36:5234 public:
Mike Wassermanf95c2d9d2019-04-17 00:44:2135 WebCursor() = default;
36 explicit WebCursor(const CursorInfo& info);
37 explicit WebCursor(const WebCursor& other);
[email protected]cf4e5eb12009-01-09 01:20:3838 ~WebCursor();
39
Mike Wassermanf95c2d9d2019-04-17 00:44:2140 const CursorInfo& info() const { return info_; }
[email protected]7c51b0ee2009-07-08 21:49:3041
[email protected]4c870b42008-11-06 00:36:5242 // Serialization / De-serialization
Mike Wassermanf95c2d9d2019-04-17 00:44:2143 bool Deserialize(const base::Pickle* m, base::PickleIterator* iter);
Daniel Cheng0d89f9222017-09-22 05:05:0744 void Serialize(base::Pickle* pickle) const;
[email protected]4c870b42008-11-06 00:36:5245
Mike Wassermanf95c2d9d2019-04-17 00:44:2146 // Equality operator; performs bitmap content comparison as needed.
47 bool operator==(const WebCursor& other) const;
48 bool operator!=(const WebCursor& other) const;
[email protected]4c870b42008-11-06 00:36:5249
[email protected]f0b6b482010-11-23 00:55:2850 // Returns a native cursor representing the current WebCursor instance.
51 gfx::NativeCursor GetNativeCursor();
52
[email protected]c7839552012-04-03 21:14:3653#if defined(USE_AURA)
Evan Stade891067b22018-11-16 01:26:3354 ui::PlatformCursor GetPlatformCursor(const ui::Cursor& cursor);
[email protected]70050e72012-07-10 11:38:5255
[email protected]ee37dc652013-08-06 00:33:2756 // Updates |device_scale_factor_| and |rotation_| based on |display|.
oshima516f03b2016-04-28 15:40:1157 void SetDisplayInfo(const display::Display& display);
[email protected]ee37dc652013-08-06 00:33:2758
Evan Stade891067b22018-11-16 01:26:3359 void CreateScaledBitmapAndHotspotFromCustomData(SkBitmap* bitmap,
60 gfx::Point* hotspot,
Mike Wassermanf95c2d9d2019-04-17 00:44:2161 float* scale);
[email protected]67b25052008-10-23 21:57:5162#endif
63
Mike Wassermanf95c2d9d2019-04-17 00:44:2164 void set_info_for_testing(const CursorInfo& info) { info_ = info; }
65
[email protected]4c870b42008-11-06 00:36:5266 private:
Mike Wassermanf95c2d9d2019-04-17 00:44:2167 // Returns true if this cursor's platform data matches that of |other|.
68 bool IsPlatformDataEqual(const WebCursor& other) const;
[email protected]cf4e5eb12009-01-09 01:20:3869
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]4605be72010-08-11 04:17:0976 // Clamp the hotspot to the custom image's bounds, if this is a custom cursor.
77 void ClampHotspot();
78
Evan Stade891067b22018-11-16 01:26:3379 float GetCursorScaleFactor(SkBitmap* bitmap);
80
Mike Wassermanf95c2d9d2019-04-17 00:44:2181 // The basic cursor info.
82 CursorInfo info_;
[email protected]2b99be22008-11-14 18:45:2683
Mike Wassermanf95c2d9d2019-04-17 00:44:2184#if defined(USE_AURA) || defined(USE_OZONE)
[email protected]c7839552012-04-03 21:14:3685 // Only used for custom cursors.
Mike Wassermanf95c2d9d2019-04-17 00:44:2186 ui::PlatformCursor platform_cursor_ = 0;
87 float device_scale_factor_ = 1.f;
Evan Stade891067b22018-11-16 01:26:3388 display::Display::Rotation rotation_ = display::Display::ROTATE_0;
Mike Wassermanf95c2d9d2019-04-17 00:44:2189#endif
Evan Stade891067b22018-11-16 01:26:3390
[email protected]95539f002014-08-07 16:01:2091#if defined(USE_OZONE)
Mike Wassermanf95c2d9d2019-04-17 00:44:2192 // 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]95539f002014-08-07 16:01:2095#endif
initial.commitf5b16fe2008-07-27 00:20:5196};
97
[email protected]c2809346d2014-03-20 00:11:0398} // namespace content
99
100#endif // CONTENT_COMMON_CURSORS_WEBCURSOR_H_