OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_GLUE_WEBCURSOR_H_ | 5 #ifndef WEBKIT_GLUE_WEBCURSOR_H_ |
6 #define WEBKIT_GLUE_WEBCURSOR_H_ | 6 #define WEBKIT_GLUE_WEBCURSOR_H_ |
7 | 7 |
| 8 #include "base/basictypes.h" |
8 #include "base/gfx/point.h" | 9 #include "base/gfx/point.h" |
9 #include "base/gfx/size.h" | 10 #include "base/gfx/size.h" |
10 | 11 |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
14 typedef struct HINSTANCE__* HINSTANCE; | 15 typedef struct HINSTANCE__* HINSTANCE; |
15 typedef struct HICON__* HICON; | 16 typedef struct HICON__* HICON; |
16 typedef HICON HCURSOR; | 17 typedef HICON HCURSOR; |
17 #elif defined(OS_LINUX) | 18 #elif defined(OS_LINUX) |
(...skipping 15 matching lines...) Expand all Loading... |
33 } | 34 } |
34 | 35 |
35 // This class encapsulates a cross-platform description of a cursor. Platform | 36 // This class encapsulates a cross-platform description of a cursor. Platform |
36 // specific methods are provided to translate the cross-platform cursor into a | 37 // specific methods are provided to translate the cross-platform cursor into a |
37 // platform specific cursor. It is also possible to serialize / de-serialize a | 38 // platform specific cursor. It is also possible to serialize / de-serialize a |
38 // WebCursor. | 39 // WebCursor. |
39 class WebCursor { | 40 class WebCursor { |
40 public: | 41 public: |
41 WebCursor(); | 42 WebCursor(); |
42 explicit WebCursor(const WebCore::PlatformCursor& platform_cursor); | 43 explicit WebCursor(const WebCore::PlatformCursor& platform_cursor); |
| 44 ~WebCursor(); |
| 45 |
| 46 // Copy constructor/assignment operator combine. |
| 47 WebCursor(const WebCursor& other); |
| 48 const WebCursor& operator=(const WebCursor& other); |
43 | 49 |
44 // Serialization / De-serialization | 50 // Serialization / De-serialization |
45 bool Deserialize(const Pickle* pickle, void** iter); | 51 bool Deserialize(const Pickle* pickle, void** iter); |
46 bool Serialize(Pickle* pickle) const; | 52 bool Serialize(Pickle* pickle) const; |
47 | 53 |
48 // Returns true if GetCustomCursor should be used to allocate a platform | 54 // Returns true if GetCustomCursor should be used to allocate a platform |
49 // specific cursor object. Otherwise GetCursor should be used. | 55 // specific cursor object. Otherwise GetCursor should be used. |
50 bool IsCustom() const; | 56 bool IsCustom() const; |
51 | 57 |
52 // Returns true if the current cursor object contains the same cursor as the | 58 // Returns true if the current cursor object contains the same cursor as the |
53 // cursor object passed in. If the current cursor is a custom cursor, we also | 59 // cursor object passed in. If the current cursor is a custom cursor, we also |
54 // compare the bitmaps to verify whether they are equal. | 60 // compare the bitmaps to verify whether they are equal. |
55 bool IsEqual(const WebCursor& other) const; | 61 bool IsEqual(const WebCursor& other) const; |
56 | 62 |
57 #if defined(OS_WIN) | 63 #if defined(OS_WIN) |
58 // If the underlying cursor type is not a custom cursor, this functions uses | 64 // Returns a HCURSOR representing the current WebCursor instance. |
59 // the LoadCursor API to load the cursor and returns it. The caller SHOULD | 65 // The ownership of the HCURSOR (does not apply to external cursors) remains |
60 // NOT pass the resulting handling to DestroyCursor. Returns NULL on error. | 66 // with the WebCursor instance. |
61 HCURSOR GetCursor(HINSTANCE module_handle) const; | 67 HCURSOR GetCursor(HINSTANCE module_handle); |
62 | 68 |
63 // If the underlying cursor type is a custom cursor, this function generates | 69 // Initialize this from the given Windows cursor. The caller must ensure that |
64 // a cursor and returns it. The responsiblity of freeing the cursor handle | 70 // the HCURSOR remains valid by not invoking the DestroyCursor/DestroyIcon |
65 // lies with the caller. Returns NULL on error. | 71 // APIs on it. |
66 HCURSOR GetCustomCursor() const; | 72 void InitFromExternalCursor(HCURSOR handle); |
67 | 73 |
68 // Initialize this from the given Windows cursor. | |
69 void InitFromCursor(HCURSOR handle); | |
70 #elif defined(OS_LINUX) | 74 #elif defined(OS_LINUX) |
71 // Return the stock GdkCursorType for this cursor, or GDK_CURSOR_IS_PIXMAP | 75 // Return the stock GdkCursorType for this cursor, or GDK_CURSOR_IS_PIXMAP |
72 // if it's a custom cursor. | 76 // if it's a custom cursor. |
73 GdkCursorType GetCursorType() const; | 77 GdkCursorType GetCursorType() const; |
74 | 78 |
75 // Return a new GdkCursor* for this cursor. Only valid if GetCursorType | 79 // Return a new GdkCursor* for this cursor. Only valid if GetCursorType |
76 // returns GDK_CURSOR_IS_PIXMAP. | 80 // returns GDK_CURSOR_IS_PIXMAP. |
77 GdkCursor* GetCustomCursor() const; | 81 GdkCursor* GetCustomCursor() const; |
78 #elif defined(OS_MACOSX) | 82 #elif defined(OS_MACOSX) |
79 NSCursor* GetCursor() const; | 83 NSCursor* GetCursor() const; |
80 #endif | 84 #endif |
81 | 85 |
82 private: | 86 private: |
| 87 // Copies the contents of the WebCursor instance passed in. |
| 88 void Copy(const WebCursor& other); |
| 89 |
| 90 // Cleans up the WebCursor instance. |
| 91 void Clear(); |
| 92 |
| 93 // Platform specific initialization goes here. |
| 94 void InitPlatformData(); |
| 95 |
| 96 // Platform specific Serialization / De-serialization |
| 97 bool SerializePlatformData(Pickle* pickle) const; |
| 98 bool DeserializePlatformData(const Pickle* pickle, void** iter); |
| 99 |
| 100 // Returns true if the platform data in the current cursor object |
| 101 // matches that of the cursor passed in. |
| 102 bool IsPlatformDataEqual(const WebCursor& other) const ; |
| 103 |
| 104 // Copies platform specific data from the WebCursor instance passed in. |
| 105 void CopyPlatformData(const WebCursor& other); |
| 106 |
| 107 // Platform specific cleanup. |
| 108 void CleanupPlatformData(); |
| 109 |
83 void SetCustomData(WebCore::Image* image); | 110 void SetCustomData(WebCore::Image* image); |
84 | 111 |
85 // WebCore::PlatformCursor type. | 112 // WebCore::PlatformCursor type. |
86 int type_; | 113 int type_; |
87 | 114 |
88 gfx::Point hotspot_; | 115 gfx::Point hotspot_; |
89 | 116 |
90 // Custom cursor data, as 32-bit RGBA. | 117 // Custom cursor data, as 32-bit RGBA. |
91 // Platform-inspecific because it can be serialized. | 118 // Platform-inspecific because it can be serialized. |
92 gfx::Size custom_size_; | 119 gfx::Size custom_size_; |
93 std::vector<char> custom_data_; | 120 std::vector<char> custom_data_; |
| 121 |
| 122 #if defined(OS_WIN) |
| 123 // An externally generated HCURSOR. We assume that it remains valid, i.e we |
| 124 // don't attempt to copy the HCURSOR. |
| 125 HCURSOR external_cursor_; |
| 126 // A custom cursor created from custom bitmap data by Webkit. |
| 127 HCURSOR custom_cursor_; |
| 128 #endif // OS_WIN |
94 }; | 129 }; |
95 | 130 |
96 #endif // WEBKIT_GLUE_WEBCURSOR_H_ | 131 #endif // WEBKIT_GLUE_WEBCURSOR_H_ |
OLD | NEW |