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)
39 // This class encapsulates a cross-platform description of a cursor. Platform
40 // specific methods are provided to translate the cross-platform cursor into a
41 // platform specific cursor. It is also possible to serialize / de-serialize a
43 class CONTENT_EXPORT WebCursor
{
46 explicit CursorInfo(blink::WebCursorInfo::Type cursor_type
)
48 image_scale_factor(1) {
50 external_handle
= NULL
;
55 : type(blink::WebCursorInfo::TypePointer
),
56 image_scale_factor(1) {
58 external_handle
= NULL
;
62 blink::WebCursorInfo::Type type
;
64 float image_scale_factor
;
65 SkBitmap custom_image
;
67 HCURSOR external_handle
;
72 explicit WebCursor(const CursorInfo
& cursor_info
);
75 // Copy constructor/assignment operator combine.
76 WebCursor(const WebCursor
& other
);
77 const WebCursor
& operator=(const WebCursor
& other
);
79 // Conversion from/to CursorInfo.
80 void InitFromCursorInfo(const CursorInfo
& cursor_info
);
81 void GetCursorInfo(CursorInfo
* cursor_info
) const;
83 // Serialization / De-serialization
84 bool Deserialize(PickleIterator
* iter
);
85 bool Serialize(Pickle
* pickle
) const;
87 // Returns true if GetCustomCursor should be used to allocate a platform
88 // specific cursor object. Otherwise GetCursor should be used.
89 bool IsCustom() const;
91 // Returns true if the current cursor object contains the same cursor as the
92 // cursor object passed in. If the current cursor is a custom cursor, we also
93 // compare the bitmaps to verify whether they are equal.
94 bool IsEqual(const WebCursor
& other
) const;
96 // Returns a native cursor representing the current WebCursor instance.
97 gfx::NativeCursor
GetNativeCursor();
100 // Initialize this from the given Windows cursor. The caller must ensure that
101 // the HCURSOR remains valid by not invoking the DestroyCursor/DestroyIcon
103 void InitFromExternalCursor(HCURSOR handle
);
106 #if defined(USE_AURA)
107 ui::PlatformCursor
GetPlatformCursor();
109 // Updates |device_scale_factor_| and |rotation_| based on |display|.
110 void SetDisplayInfo(const gfx::Display
& display
);
112 #elif defined(OS_WIN)
113 // Returns a HCURSOR representing the current WebCursor instance.
114 // The ownership of the HCURSOR (does not apply to external cursors) remains
115 // with the WebCursor instance.
116 HCURSOR
GetCursor(HINSTANCE module_handle
);
118 #elif defined(OS_MACOSX)
119 // Initialize this from the given Cocoa NSCursor.
120 void InitFromNSCursor(NSCursor
* cursor
);
124 // Copies the contents of the WebCursor instance passed in.
125 void Copy(const WebCursor
& other
);
127 // Cleans up the WebCursor instance.
130 // Platform specific initialization goes here.
131 void InitPlatformData();
133 // Platform specific Serialization / De-serialization
134 bool SerializePlatformData(Pickle
* pickle
) const;
135 bool DeserializePlatformData(PickleIterator
* iter
);
137 // Returns true if the platform data in the current cursor object
138 // matches that of the cursor passed in.
139 bool IsPlatformDataEqual(const WebCursor
& other
) const ;
141 // Copies platform specific data from the WebCursor instance passed in.
142 void CopyPlatformData(const WebCursor
& other
);
144 // Platform specific cleanup.
145 void CleanupPlatformData();
147 void SetCustomData(const SkBitmap
& image
);
148 void ImageFromCustomData(SkBitmap
* image
) const;
150 // Clamp the hotspot to the custom image's bounds, if this is a custom cursor.
153 // WebCore::PlatformCursor type.
156 // Hotspot in cursor image in pixels.
159 // Custom cursor data, as 32-bit RGBA.
160 // Platform-inspecific because it can be serialized.
161 gfx::Size custom_size_
; // In pixels.
163 std::vector
<char> custom_data_
;
166 // An externally generated HCURSOR. We assume that it remains valid, i.e we
167 // don't attempt to copy the HCURSOR.
168 HCURSOR external_cursor_
;
171 #if defined(USE_AURA) && (defined(USE_X11) || defined(USE_OZONE))
172 // Only used for custom cursors.
173 ui::PlatformCursor platform_cursor_
;
174 float device_scale_factor_
;
175 #elif defined(OS_WIN)
176 // A custom cursor created from custom bitmap data by Webkit.
177 HCURSOR custom_cursor_
;
180 #if defined(USE_OZONE)
181 gfx::Display::Rotation rotation_
;
185 } // namespace content
187 #endif // CONTENT_COMMON_CURSORS_WEBCURSOR_H_