1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_CURSORS_WEBCURSOR_H_
6 #define CONTENT_COMMON_CURSORS_WEBCURSOR_H_
10 #include "base/basictypes.h"
11 #include "content/common/content_export.h"
12 #include "third_party/WebKit/public/platform/WebCursorInfo.h"
13 #include "ui/gfx/display.h"
14 #include "ui/gfx/geometry/point.h"
15 #include "ui/gfx/geometry/size.h"
16 #include "ui/gfx/native_widget_types.h"
19 #include "ui/base/cursor/cursor.h"
23 typedef struct HINSTANCE__
* HINSTANCE
;
24 typedef struct HICON__
* HICON
;
25 typedef HICON HCURSOR
;
26 #elif defined(OS_MACOSX)
41 // This class encapsulates a cross-platform description of a cursor. Platform
42 // specific methods are provided to translate the cross-platform cursor into a
43 // platform specific cursor. It is also possible to serialize / de-serialize a
45 class CONTENT_EXPORT WebCursor
{
48 explicit CursorInfo(blink::WebCursorInfo::Type cursor_type
)
50 image_scale_factor(1) {
52 external_handle
= NULL
;
57 : type(blink::WebCursorInfo::TypePointer
),
58 image_scale_factor(1) {
60 external_handle
= NULL
;
64 blink::WebCursorInfo::Type type
;
66 float image_scale_factor
;
67 SkBitmap custom_image
;
69 HCURSOR external_handle
;
74 explicit WebCursor(const CursorInfo
& cursor_info
);
77 // Copy constructor/assignment operator combine.
78 WebCursor(const WebCursor
& other
);
79 const WebCursor
& operator=(const WebCursor
& other
);
81 // Conversion from/to CursorInfo.
82 void InitFromCursorInfo(const CursorInfo
& cursor_info
);
83 void GetCursorInfo(CursorInfo
* cursor_info
) const;
85 // Serialization / De-serialization
86 bool Deserialize(base::PickleIterator
* iter
);
87 bool Serialize(base::Pickle
* pickle
) const;
89 // Returns true if GetCustomCursor should be used to allocate a platform
90 // specific cursor object. Otherwise GetCursor should be used.
91 bool IsCustom() const;
93 // Returns true if the current cursor object contains the same cursor as the
94 // cursor object passed in. If the current cursor is a custom cursor, we also
95 // compare the bitmaps to verify whether they are equal.
96 bool IsEqual(const WebCursor
& other
) const;
98 // Returns a native cursor representing the current WebCursor instance.
99 gfx::NativeCursor
GetNativeCursor();
102 // Initialize this from the given Windows cursor. The caller must ensure that
103 // the HCURSOR remains valid by not invoking the DestroyCursor/DestroyIcon
105 void InitFromExternalCursor(HCURSOR handle
);
108 #if defined(USE_AURA)
109 ui::PlatformCursor
GetPlatformCursor();
111 // Updates |device_scale_factor_| and |rotation_| based on |display|.
112 void SetDisplayInfo(const gfx::Display
& display
);
114 #elif defined(OS_WIN)
115 // Returns a HCURSOR representing the current WebCursor instance.
116 // The ownership of the HCURSOR (does not apply to external cursors) remains
117 // with the WebCursor instance.
118 HCURSOR
GetCursor(HINSTANCE module_handle
);
120 #elif defined(OS_MACOSX)
121 // Initialize this from the given Cocoa NSCursor.
122 void InitFromNSCursor(NSCursor
* cursor
);
126 // Copies the contents of the WebCursor instance passed in.
127 void Copy(const WebCursor
& other
);
129 // Cleans up the WebCursor instance.
132 // Platform specific initialization goes here.
133 void InitPlatformData();
135 // Platform specific Serialization / De-serialization
136 bool SerializePlatformData(base::Pickle
* pickle
) const;
137 bool DeserializePlatformData(base::PickleIterator
* iter
);
139 // Returns true if the platform data in the current cursor object
140 // matches that of the cursor passed in.
141 bool IsPlatformDataEqual(const WebCursor
& other
) const ;
143 // Copies platform specific data from the WebCursor instance passed in.
144 void CopyPlatformData(const WebCursor
& other
);
146 // Platform specific cleanup.
147 void CleanupPlatformData();
149 void SetCustomData(const SkBitmap
& image
);
150 void ImageFromCustomData(SkBitmap
* image
) const;
152 // Clamp the hotspot to the custom image's bounds, if this is a custom cursor.
155 // WebCore::PlatformCursor type.
158 // Hotspot in cursor image in pixels.
161 // Custom cursor data, as 32-bit RGBA.
162 // Platform-inspecific because it can be serialized.
163 gfx::Size custom_size_
; // In pixels.
165 std::vector
<char> custom_data_
;
168 // An externally generated HCURSOR. We assume that it remains valid, i.e we
169 // don't attempt to copy the HCURSOR.
170 HCURSOR external_cursor_
;
173 #if defined(USE_AURA) && (defined(USE_X11) || defined(USE_OZONE))
174 // Only used for custom cursors.
175 ui::PlatformCursor platform_cursor_
;
176 float device_scale_factor_
;
177 #elif defined(OS_WIN)
178 // A custom cursor created from custom bitmap data by Webkit.
179 HCURSOR custom_cursor_
;
182 #if defined(USE_OZONE)
183 gfx::Display::Rotation rotation_
;
187 } // namespace content
189 #endif // CONTENT_COMMON_CURSORS_WEBCURSOR_H_