Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: webkit/glue/webcursor.h

Issue 15971005: Move the WebCursor sources from webkit/glue to webkit/common/cursors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/cursor_utils.cc ('k') | webkit/glue/webcursor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef WEBKIT_GLUE_WEBCURSOR_H_
6 #define WEBKIT_GLUE_WEBCURSOR_H_
7
8 #include "base/basictypes.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
10 #include "ui/gfx/native_widget_types.h"
11 #include "ui/gfx/point.h"
12 #include "ui/gfx/size.h"
13 #include "webkit/glue/webkit_glue_export.h"
14
15 #include <vector>
16
17 #if defined(OS_WIN)
18 typedef struct HINSTANCE__* HINSTANCE;
19 typedef struct HICON__* HICON;
20 typedef HICON HCURSOR;
21 #elif defined(TOOLKIT_GTK)
22 typedef struct _GdkCursor GdkCursor;
23 #elif defined(OS_MACOSX)
24 #ifdef __OBJC__
25 @class NSCursor;
26 #else
27 class NSCursor;
28 #endif
29 #endif
30
31 class Pickle;
32 class PickleIterator;
33
34 // This class encapsulates a cross-platform description of a cursor. Platform
35 // specific methods are provided to translate the cross-platform cursor into a
36 // platform specific cursor. It is also possible to serialize / de-serialize a
37 // WebCursor.
38 class WEBKIT_GLUE_EXPORT WebCursor {
39 public:
40 struct CursorInfo {
41 explicit CursorInfo(WebKit::WebCursorInfo::Type cursor_type)
42 : type(cursor_type),
43 image_scale_factor(1) {
44 #if defined(OS_WIN)
45 external_handle = NULL;
46 #endif
47 }
48
49 CursorInfo()
50 : type(WebKit::WebCursorInfo::TypePointer),
51 image_scale_factor(1) {
52 #if defined(OS_WIN)
53 external_handle = NULL;
54 #endif
55 }
56
57 WebKit::WebCursorInfo::Type type;
58 gfx::Point hotspot;
59 float image_scale_factor;
60 SkBitmap custom_image;
61 #if defined(OS_WIN)
62 HCURSOR external_handle;
63 #endif
64 };
65
66 WebCursor();
67 explicit WebCursor(const CursorInfo& cursor_info);
68 ~WebCursor();
69
70 // Copy constructor/assignment operator combine.
71 WebCursor(const WebCursor& other);
72 const WebCursor& operator=(const WebCursor& other);
73
74 // Conversion from/to CursorInfo.
75 void InitFromCursorInfo(const CursorInfo& cursor_info);
76 void GetCursorInfo(CursorInfo* cursor_info) const;
77
78 // Serialization / De-serialization
79 bool Deserialize(PickleIterator* iter);
80 bool Serialize(Pickle* pickle) const;
81
82 // Returns true if GetCustomCursor should be used to allocate a platform
83 // specific cursor object. Otherwise GetCursor should be used.
84 bool IsCustom() const;
85
86 // Returns true if the current cursor object contains the same cursor as the
87 // cursor object passed in. If the current cursor is a custom cursor, we also
88 // compare the bitmaps to verify whether they are equal.
89 bool IsEqual(const WebCursor& other) const;
90
91 // Returns a native cursor representing the current WebCursor instance.
92 gfx::NativeCursor GetNativeCursor();
93
94 #if defined(OS_WIN)
95 // Initialize this from the given Windows cursor. The caller must ensure that
96 // the HCURSOR remains valid by not invoking the DestroyCursor/DestroyIcon
97 // APIs on it.
98 void InitFromExternalCursor(HCURSOR handle);
99 #endif
100
101 #if defined(USE_AURA)
102 const ui::PlatformCursor GetPlatformCursor();
103
104 void SetDeviceScaleFactor(float scale_factor);
105 #elif defined(OS_WIN)
106 // Returns a HCURSOR representing the current WebCursor instance.
107 // The ownership of the HCURSOR (does not apply to external cursors) remains
108 // with the WebCursor instance.
109 HCURSOR GetCursor(HINSTANCE module_handle);
110
111 #elif defined(TOOLKIT_GTK)
112 // Return the stock GdkCursorType for this cursor, or GDK_CURSOR_IS_PIXMAP
113 // if it's a custom cursor. Return GDK_LAST_CURSOR to indicate that the cursor
114 // should be set to the system default.
115 // Returns an int so we don't need to include GDK headers in this header file.
116 int GetCursorType() const;
117
118 // Return a new GdkCursor* for this cursor. Only valid if GetCursorType
119 // returns GDK_CURSOR_IS_PIXMAP.
120 GdkCursor* GetCustomCursor();
121 #elif defined(OS_MACOSX)
122 // Initialize this from the given Cocoa NSCursor.
123 void InitFromNSCursor(NSCursor* cursor);
124 #endif
125
126 private:
127 // Copies the contents of the WebCursor instance passed in.
128 void Copy(const WebCursor& other);
129
130 // Cleans up the WebCursor instance.
131 void Clear();
132
133 // Platform specific initialization goes here.
134 void InitPlatformData();
135
136 // Platform specific Serialization / De-serialization
137 bool SerializePlatformData(Pickle* pickle) const;
138 bool DeserializePlatformData(PickleIterator* iter);
139
140 // Returns true if the platform data in the current cursor object
141 // matches that of the cursor passed in.
142 bool IsPlatformDataEqual(const WebCursor& other) const ;
143
144 // Copies platform specific data from the WebCursor instance passed in.
145 void CopyPlatformData(const WebCursor& other);
146
147 // Platform specific cleanup.
148 void CleanupPlatformData();
149
150 void SetCustomData(const SkBitmap& image);
151 void ImageFromCustomData(SkBitmap* image) const;
152
153 // Clamp the hotspot to the custom image's bounds, if this is a custom cursor.
154 void ClampHotspot();
155
156 // WebCore::PlatformCursor type.
157 int type_;
158
159 // Hotspot in cursor image in pixels.
160 gfx::Point hotspot_;
161
162 // Custom cursor data, as 32-bit RGBA.
163 // Platform-inspecific because it can be serialized.
164 gfx::Size custom_size_; // In pixels.
165 float custom_scale_;
166 std::vector<char> custom_data_;
167
168 #if defined(OS_WIN)
169 // An externally generated HCURSOR. We assume that it remains valid, i.e we
170 // don't attempt to copy the HCURSOR.
171 HCURSOR external_cursor_;
172 #endif
173
174 #if defined(USE_AURA) && defined(USE_X11)
175 // Only used for custom cursors.
176 ui::PlatformCursor platform_cursor_;
177 float device_scale_factor_;
178 #elif defined(OS_WIN)
179 // A custom cursor created from custom bitmap data by Webkit.
180 HCURSOR custom_cursor_;
181 #elif defined(TOOLKIT_GTK)
182 // A custom cursor created that should be unref'ed from the destructor.
183 GdkCursor* unref_;
184 #endif
185 };
186
187 #endif // WEBKIT_GLUE_WEBCURSOR_H_
OLDNEW
« no previous file with comments | « webkit/glue/cursor_utils.cc ('k') | webkit/glue/webcursor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698