Update V8 to version 4.6.72.
[chromium-blink-merge.git] / content / common / cursors / webcursor.h
blob3efc2ee234cd0df92d9bfe4781d5f791843e4923
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_
8 #include <vector>
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"
18 #if defined(USE_AURA)
19 #include "ui/base/cursor/cursor.h"
20 #endif
22 #if defined(OS_WIN)
23 typedef struct HINSTANCE__* HINSTANCE;
24 typedef struct HICON__* HICON;
25 typedef HICON HCURSOR;
26 #elif defined(OS_MACOSX)
27 #ifdef __OBJC__
28 @class NSCursor;
29 #else
30 class NSCursor;
31 #endif
32 #endif
34 namespace base {
35 class Pickle;
36 class PickleIterator;
39 namespace content {
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
44 // WebCursor.
45 class CONTENT_EXPORT WebCursor {
46 public:
47 struct CursorInfo {
48 explicit CursorInfo(blink::WebCursorInfo::Type cursor_type)
49 : type(cursor_type),
50 image_scale_factor(1) {
51 #if defined(OS_WIN)
52 external_handle = NULL;
53 #endif
56 CursorInfo()
57 : type(blink::WebCursorInfo::TypePointer),
58 image_scale_factor(1) {
59 #if defined(OS_WIN)
60 external_handle = NULL;
61 #endif
64 blink::WebCursorInfo::Type type;
65 gfx::Point hotspot;
66 float image_scale_factor;
67 SkBitmap custom_image;
68 #if defined(OS_WIN)
69 HCURSOR external_handle;
70 #endif
73 WebCursor();
74 explicit WebCursor(const CursorInfo& cursor_info);
75 ~WebCursor();
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();
101 #if defined(OS_WIN)
102 // Initialize this from the given Windows cursor. The caller must ensure that
103 // the HCURSOR remains valid by not invoking the DestroyCursor/DestroyIcon
104 // APIs on it.
105 void InitFromExternalCursor(HCURSOR handle);
106 #endif
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);
123 #endif
125 private:
126 // Copies the contents of the WebCursor instance passed in.
127 void Copy(const WebCursor& other);
129 // Cleans up the WebCursor instance.
130 void Clear();
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.
153 void ClampHotspot();
155 // WebCore::PlatformCursor type.
156 int type_;
158 // Hotspot in cursor image in pixels.
159 gfx::Point hotspot_;
161 // Custom cursor data, as 32-bit RGBA.
162 // Platform-inspecific because it can be serialized.
163 gfx::Size custom_size_; // In pixels.
164 float custom_scale_;
165 std::vector<char> custom_data_;
167 #if defined(OS_WIN)
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_;
171 #endif
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_;
180 #endif
182 #if defined(USE_OZONE)
183 gfx::Display::Rotation rotation_;
184 #endif
187 } // namespace content
189 #endif // CONTENT_COMMON_CURSORS_WEBCURSOR_H_