Removing flow to demote App Launcher to App Host, so app_host.exe can be deleted...
[chromium-blink-merge.git] / webkit / glue / webcursor.h
blob3b94548c54404306e623bd81294fb96cebf989ba
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 WEBKIT_GLUE_WEBCURSOR_H_
6 #define WEBKIT_GLUE_WEBCURSOR_H_
8 #include "base/basictypes.h"
9 #include "ui/gfx/native_widget_types.h"
10 #include "ui/gfx/point.h"
11 #include "ui/gfx/size.h"
12 #include "webkit/glue/webkit_glue_export.h"
14 #include <vector>
16 #if defined(OS_WIN)
17 typedef struct HINSTANCE__* HINSTANCE;
18 typedef struct HICON__* HICON;
19 typedef HICON HCURSOR;
20 #elif defined(TOOLKIT_GTK)
21 typedef struct _GdkCursor GdkCursor;
22 #elif defined(OS_MACOSX)
23 #ifdef __OBJC__
24 @class NSCursor;
25 #else
26 class NSCursor;
27 #endif
28 #endif
30 class Pickle;
31 class PickleIterator;
33 namespace WebKit {
34 class WebImage;
35 struct WebCursorInfo;
38 // This class encapsulates a cross-platform description of a cursor. Platform
39 // specific methods are provided to translate the cross-platform cursor into a
40 // platform specific cursor. It is also possible to serialize / de-serialize a
41 // WebCursor.
42 class WEBKIT_GLUE_EXPORT WebCursor {
43 public:
44 WebCursor();
45 explicit WebCursor(const WebKit::WebCursorInfo& cursor_info);
46 ~WebCursor();
48 // Copy constructor/assignment operator combine.
49 WebCursor(const WebCursor& other);
50 const WebCursor& operator=(const WebCursor& other);
52 // Conversion from/to WebCursorInfo.
53 void InitFromCursorInfo(const WebKit::WebCursorInfo& cursor_info);
54 void GetCursorInfo(WebKit::WebCursorInfo* cursor_info) const;
56 // Serialization / De-serialization
57 bool Deserialize(PickleIterator* iter);
58 bool Serialize(Pickle* pickle) const;
60 // Returns true if GetCustomCursor should be used to allocate a platform
61 // specific cursor object. Otherwise GetCursor should be used.
62 bool IsCustom() const;
64 // Returns true if the current cursor object contains the same cursor as the
65 // cursor object passed in. If the current cursor is a custom cursor, we also
66 // compare the bitmaps to verify whether they are equal.
67 bool IsEqual(const WebCursor& other) const;
69 // Returns a native cursor representing the current WebCursor instance.
70 gfx::NativeCursor GetNativeCursor();
72 #if defined(OS_WIN)
73 // Initialize this from the given Windows cursor. The caller must ensure that
74 // the HCURSOR remains valid by not invoking the DestroyCursor/DestroyIcon
75 // APIs on it.
76 void InitFromExternalCursor(HCURSOR handle);
77 #endif
79 #if defined(USE_AURA)
80 const ui::PlatformCursor GetPlatformCursor();
82 void SetDeviceScaleFactor(float scale_factor);
83 #elif defined(OS_WIN)
84 // Returns a HCURSOR representing the current WebCursor instance.
85 // The ownership of the HCURSOR (does not apply to external cursors) remains
86 // with the WebCursor instance.
87 HCURSOR GetCursor(HINSTANCE module_handle);
89 #elif defined(TOOLKIT_GTK)
90 // Return the stock GdkCursorType for this cursor, or GDK_CURSOR_IS_PIXMAP
91 // if it's a custom cursor. Return GDK_LAST_CURSOR to indicate that the cursor
92 // should be set to the system default.
93 // Returns an int so we don't need to include GDK headers in this header file.
94 int GetCursorType() const;
96 // Return a new GdkCursor* for this cursor. Only valid if GetCursorType
97 // returns GDK_CURSOR_IS_PIXMAP.
98 GdkCursor* GetCustomCursor();
99 #elif defined(OS_MACOSX)
100 // Initialize this from the given Cocoa NSCursor.
101 void InitFromNSCursor(NSCursor* cursor);
102 #endif
104 private:
105 // Copies the contents of the WebCursor instance passed in.
106 void Copy(const WebCursor& other);
108 // Cleans up the WebCursor instance.
109 void Clear();
111 // Platform specific initialization goes here.
112 void InitPlatformData();
114 // Platform specific Serialization / De-serialization
115 bool SerializePlatformData(Pickle* pickle) const;
116 bool DeserializePlatformData(PickleIterator* iter);
118 // Returns true if the platform data in the current cursor object
119 // matches that of the cursor passed in.
120 bool IsPlatformDataEqual(const WebCursor& other) const ;
122 // Copies platform specific data from the WebCursor instance passed in.
123 void CopyPlatformData(const WebCursor& other);
125 // Platform specific cleanup.
126 void CleanupPlatformData();
128 void SetCustomData(const WebKit::WebImage& image);
129 void ImageFromCustomData(WebKit::WebImage* image) const;
131 // Clamp the hotspot to the custom image's bounds, if this is a custom cursor.
132 void ClampHotspot();
134 // WebCore::PlatformCursor type.
135 int type_;
137 // Hot spot in cursor image in physical image coordinate space.
138 gfx::Point hotspot_;
140 // Custom cursor data, as 32-bit RGBA.
141 // Platform-inspecific because it can be serialized.
142 gfx::Size custom_size_;
143 float custom_scale_;
144 std::vector<char> custom_data_;
146 #if defined(OS_WIN)
147 // An externally generated HCURSOR. We assume that it remains valid, i.e we
148 // don't attempt to copy the HCURSOR.
149 HCURSOR external_cursor_;
150 #endif
152 #if defined(USE_AURA) && defined(USE_X11)
153 // Only used for custom cursors.
154 ui::PlatformCursor platform_cursor_;
155 float device_scale_factor_;
156 #elif defined(OS_WIN)
157 // A custom cursor created from custom bitmap data by Webkit.
158 HCURSOR custom_cursor_;
159 #elif defined(TOOLKIT_GTK)
160 // A custom cursor created that should be unref'ed from the destructor.
161 GdkCursor* unref_;
162 #endif
165 #endif // WEBKIT_GLUE_WEBCURSOR_H_