| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_COMMON_CURSORS_WEBCURSOR_H_ | 5 #ifndef CONTENT_COMMON_CURSORS_WEBCURSOR_H_ |
| 6 #define CONTENT_COMMON_CURSORS_WEBCURSOR_H_ | 6 #define CONTENT_COMMON_CURSORS_WEBCURSOR_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | |
| 11 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 12 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 13 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 12 #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
| 14 #include "ui/display/display.h" | 13 #include "ui/display/display.h" |
| 15 #include "ui/gfx/geometry/point.h" | 14 #include "ui/gfx/geometry/point.h" |
| 16 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
| 17 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
| 18 | 17 |
| 19 #if defined(USE_AURA) | 18 #if defined(USE_AURA) |
| 20 #include "ui/base/cursor/cursor.h" | 19 #include "ui/base/cursor/cursor.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 42 // This class encapsulates a cross-platform description of a cursor. Platform | 41 // This class encapsulates a cross-platform description of a cursor. Platform |
| 43 // specific methods are provided to translate the cross-platform cursor into a | 42 // specific methods are provided to translate the cross-platform cursor into a |
| 44 // platform specific cursor. It is also possible to serialize / de-serialize a | 43 // platform specific cursor. It is also possible to serialize / de-serialize a |
| 45 // WebCursor. | 44 // WebCursor. |
| 46 class CONTENT_EXPORT WebCursor { | 45 class CONTENT_EXPORT WebCursor { |
| 47 public: | 46 public: |
| 48 struct CursorInfo { | 47 struct CursorInfo { |
| 49 explicit CursorInfo(blink::WebCursorInfo::Type cursor_type) | 48 explicit CursorInfo(blink::WebCursorInfo::Type cursor_type) |
| 50 : type(cursor_type), | 49 : type(cursor_type), |
| 51 image_scale_factor(1) { | 50 image_scale_factor(1) { |
| 52 #if defined(OS_WIN) | |
| 53 external_handle = NULL; | |
| 54 #endif | |
| 55 } | 51 } |
| 56 | 52 |
| 57 CursorInfo() | 53 CursorInfo() |
| 58 : type(blink::WebCursorInfo::TypePointer), | 54 : type(blink::WebCursorInfo::TypePointer), |
| 59 image_scale_factor(1) { | 55 image_scale_factor(1) { |
| 60 #if defined(OS_WIN) | |
| 61 external_handle = NULL; | |
| 62 #endif | |
| 63 } | 56 } |
| 64 | 57 |
| 65 blink::WebCursorInfo::Type type; | 58 blink::WebCursorInfo::Type type; |
| 66 gfx::Point hotspot; | 59 gfx::Point hotspot; |
| 67 float image_scale_factor; | 60 float image_scale_factor; |
| 68 SkBitmap custom_image; | 61 SkBitmap custom_image; |
| 69 #if defined(OS_WIN) | |
| 70 HCURSOR external_handle; | |
| 71 #endif | |
| 72 }; | 62 }; |
| 73 | 63 |
| 74 WebCursor(); | 64 WebCursor(); |
| 75 ~WebCursor(); | 65 ~WebCursor(); |
| 76 | 66 |
| 77 // Copy constructor/assignment operator combine. | 67 // Copy constructor/assignment operator combine. |
| 78 WebCursor(const WebCursor& other); | 68 WebCursor(const WebCursor& other); |
| 79 const WebCursor& operator=(const WebCursor& other); | 69 const WebCursor& operator=(const WebCursor& other); |
| 80 | 70 |
| 81 // Conversion from/to CursorInfo. | 71 // Conversion from/to CursorInfo. |
| 82 void InitFromCursorInfo(const CursorInfo& cursor_info); | 72 void InitFromCursorInfo(const CursorInfo& cursor_info); |
| 83 void GetCursorInfo(CursorInfo* cursor_info) const; | 73 void GetCursorInfo(CursorInfo* cursor_info) const; |
| 84 | 74 |
| 85 // Serialization / De-serialization | 75 // Serialization / De-serialization |
| 86 bool Deserialize(base::PickleIterator* iter); | 76 bool Deserialize(base::PickleIterator* iter); |
| 87 bool Serialize(base::Pickle* pickle) const; | 77 bool Serialize(base::Pickle* pickle) const; |
| 88 | 78 |
| 89 // Returns true if GetCustomCursor should be used to allocate a platform | 79 // Returns true if GetCustomCursor should be used to allocate a platform |
| 90 // specific cursor object. Otherwise GetCursor should be used. | 80 // specific cursor object. Otherwise GetCursor should be used. |
| 91 bool IsCustom() const; | 81 bool IsCustom() const; |
| 92 | 82 |
| 93 // Returns true if the current cursor object contains the same cursor as the | 83 // 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 | 84 // cursor object passed in. If the current cursor is a custom cursor, we also |
| 95 // compare the bitmaps to verify whether they are equal. | 85 // compare the bitmaps to verify whether they are equal. |
| 96 bool IsEqual(const WebCursor& other) const; | 86 bool IsEqual(const WebCursor& other) const; |
| 97 | 87 |
| 98 // Returns a native cursor representing the current WebCursor instance. | 88 // Returns a native cursor representing the current WebCursor instance. |
| 99 gfx::NativeCursor GetNativeCursor(); | 89 gfx::NativeCursor GetNativeCursor(); |
| 100 | 90 |
| 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 | |
| 107 | |
| 108 #if defined(USE_AURA) | 91 #if defined(USE_AURA) |
| 109 ui::PlatformCursor GetPlatformCursor(); | 92 ui::PlatformCursor GetPlatformCursor(); |
| 110 | 93 |
| 111 // Updates |device_scale_factor_| and |rotation_| based on |display|. | 94 // Updates |device_scale_factor_| and |rotation_| based on |display|. |
| 112 void SetDisplayInfo(const display::Display& display); | 95 void SetDisplayInfo(const display::Display& display); |
| 113 | 96 |
| 114 float GetCursorScaleFactor(); | 97 float GetCursorScaleFactor(); |
| 115 | 98 |
| 116 void CreateScaledBitmapAndHotspotFromCustomData( | 99 void CreateScaledBitmapAndHotspotFromCustomData( |
| 117 SkBitmap* bitmap, | 100 SkBitmap* bitmap, |
| 118 gfx::Point* hotspot); | 101 gfx::Point* hotspot); |
| 119 FRIEND_TEST_ALL_PREFIXES(WebCursorTest, | |
| 120 CreateScaledBitmapAndHotspotFromCustomData); | |
| 121 | 102 |
| 122 #elif defined(OS_WIN) | 103 #elif defined(OS_WIN) |
| 123 // Returns a HCURSOR representing the current WebCursor instance. | 104 // Returns a HCURSOR representing the current WebCursor instance. |
| 124 // The ownership of the HCURSOR (does not apply to external cursors) remains | 105 // The ownership of the HCURSOR remains with the WebCursor instance. |
| 125 // with the WebCursor instance. | |
| 126 HCURSOR GetCursor(HINSTANCE module_handle); | 106 HCURSOR GetCursor(HINSTANCE module_handle); |
| 127 | 107 |
| 128 #elif defined(OS_MACOSX) | 108 #elif defined(OS_MACOSX) |
| 129 // Initialize this from the given Cocoa NSCursor. | 109 // Initialize this from the given Cocoa NSCursor. |
| 130 void InitFromNSCursor(NSCursor* cursor); | 110 void InitFromNSCursor(NSCursor* cursor); |
| 131 #endif | 111 #endif |
| 132 | 112 |
| 133 private: | 113 private: |
| 134 // Copies the contents of the WebCursor instance passed in. | 114 // Copies the contents of the WebCursor instance passed in. |
| 135 void Copy(const WebCursor& other); | 115 void Copy(const WebCursor& other); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 152 |
| 173 // Hotspot in cursor image in pixels. | 153 // Hotspot in cursor image in pixels. |
| 174 gfx::Point hotspot_; | 154 gfx::Point hotspot_; |
| 175 | 155 |
| 176 // Custom cursor data, as 32-bit RGBA. | 156 // Custom cursor data, as 32-bit RGBA. |
| 177 // Platform-inspecific because it can be serialized. | 157 // Platform-inspecific because it can be serialized. |
| 178 gfx::Size custom_size_; // In pixels. | 158 gfx::Size custom_size_; // In pixels. |
| 179 float custom_scale_; | 159 float custom_scale_; |
| 180 std::vector<char> custom_data_; | 160 std::vector<char> custom_data_; |
| 181 | 161 |
| 182 #if defined(OS_WIN) | |
| 183 // An externally generated HCURSOR. We assume that it remains valid, i.e we | |
| 184 // don't attempt to copy the HCURSOR. | |
| 185 HCURSOR external_cursor_; | |
| 186 #endif | |
| 187 | |
| 188 #if defined(USE_AURA) && (defined(USE_X11) || defined(USE_OZONE)) | 162 #if defined(USE_AURA) && (defined(USE_X11) || defined(USE_OZONE)) |
| 189 // Only used for custom cursors. | 163 // Only used for custom cursors. |
| 190 ui::PlatformCursor platform_cursor_; | 164 ui::PlatformCursor platform_cursor_; |
| 191 #elif defined(OS_WIN) | 165 #elif defined(OS_WIN) |
| 192 // A custom cursor created from custom bitmap data by Webkit. | 166 // A custom cursor created from custom bitmap data by Webkit. |
| 193 HCURSOR custom_cursor_; | 167 HCURSOR custom_cursor_; |
| 194 #endif | 168 #endif |
| 195 #if defined(USE_AURA) | 169 #if defined(USE_AURA) |
| 196 float device_scale_factor_; | 170 float device_scale_factor_; |
| 197 #endif | 171 #endif |
| 198 | 172 |
| 199 #if defined(USE_OZONE) | 173 #if defined(USE_OZONE) |
| 200 display::Display::Rotation rotation_; | 174 display::Display::Rotation rotation_; |
| 201 gfx::Size maximum_cursor_size_; | 175 gfx::Size maximum_cursor_size_; |
| 202 #endif | 176 #endif |
| 203 }; | 177 }; |
| 204 | 178 |
| 205 } // namespace content | 179 } // namespace content |
| 206 | 180 |
| 207 #endif // CONTENT_COMMON_CURSORS_WEBCURSOR_H_ | 181 #endif // CONTENT_COMMON_CURSORS_WEBCURSOR_H_ |
| OLD | NEW |