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

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

Issue 10916253: Support custom cursors for windowless plugins on Windows Aura. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 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/webcursor.h ('k') | webkit/glue/webcursor_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "webkit/glue/webcursor.h" 5 #include "webkit/glue/webcursor.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
11 11
12 using WebKit::WebCursorInfo; 12 using WebKit::WebCursorInfo;
13 using WebKit::WebImage; 13 using WebKit::WebImage;
14 14
15 static const int kMaxCursorDimension = 1024; 15 static const int kMaxCursorDimension = 1024;
16 16
17 WebCursor::WebCursor() 17 WebCursor::WebCursor()
18 : type_(WebCursorInfo::TypePointer) { 18 : type_(WebCursorInfo::TypePointer) {
19 #if defined(OS_WIN)
20 external_cursor_ = NULL;
21 #endif
19 InitPlatformData(); 22 InitPlatformData();
20 } 23 }
21 24
22 WebCursor::WebCursor(const WebCursorInfo& cursor_info) 25 WebCursor::WebCursor(const WebCursorInfo& cursor_info)
23 : type_(WebCursorInfo::TypePointer) { 26 : type_(WebCursorInfo::TypePointer) {
27 #if defined(OS_WIN)
28 external_cursor_ = NULL;
29 #endif
24 InitPlatformData(); 30 InitPlatformData();
25 InitFromCursorInfo(cursor_info); 31 InitFromCursorInfo(cursor_info);
26 } 32 }
27 33
28 WebCursor::~WebCursor() { 34 WebCursor::~WebCursor() {
29 Clear(); 35 Clear();
30 } 36 }
31 37
32 WebCursor::WebCursor(const WebCursor& other) { 38 WebCursor::WebCursor(const WebCursor& other) {
33 InitPlatformData(); 39 InitPlatformData();
34 Copy(other); 40 Copy(other);
35 } 41 }
36 42
37 const WebCursor& WebCursor::operator=(const WebCursor& other) { 43 const WebCursor& WebCursor::operator=(const WebCursor& other) {
38 if (this == &other) 44 if (this == &other)
39 return *this; 45 return *this;
40 46
41 Clear(); 47 Clear();
42 Copy(other); 48 Copy(other);
43 return *this; 49 return *this;
44 } 50 }
45 51
46 void WebCursor::InitFromCursorInfo(const WebCursorInfo& cursor_info) { 52 void WebCursor::InitFromCursorInfo(const WebCursorInfo& cursor_info) {
47 Clear(); 53 Clear();
48 54
49 #if defined(OS_WIN) && !defined(USE_AURA) 55 #if defined(OS_WIN)
50 if (cursor_info.externalHandle) { 56 if (cursor_info.externalHandle) {
51 InitFromExternalCursor(cursor_info.externalHandle); 57 InitFromExternalCursor(cursor_info.externalHandle);
52 return; 58 return;
53 } 59 }
54 #endif 60 #endif
55 61
56 type_ = cursor_info.type; 62 type_ = cursor_info.type;
57 hotspot_ = cursor_info.hotSpot; 63 hotspot_ = cursor_info.hotSpot;
58 if (IsCustom()) 64 if (IsCustom())
59 SetCustomData(cursor_info.customImage); 65 SetCustomData(cursor_info.customImage);
60 ClampHotspot(); 66 ClampHotspot();
61 } 67 }
62 68
63 void WebCursor::GetCursorInfo(WebCursorInfo* cursor_info) const { 69 void WebCursor::GetCursorInfo(WebCursorInfo* cursor_info) const {
64 cursor_info->type = static_cast<WebCursorInfo::Type>(type_); 70 cursor_info->type = static_cast<WebCursorInfo::Type>(type_);
65 cursor_info->hotSpot = hotspot_; 71 cursor_info->hotSpot = hotspot_;
66 ImageFromCustomData(&cursor_info->customImage); 72 ImageFromCustomData(&cursor_info->customImage);
67 73
68 #if defined(OS_WIN) && !defined(USE_AURA) 74 #if defined(OS_WIN)
69 cursor_info->externalHandle = external_cursor_; 75 cursor_info->externalHandle = external_cursor_;
70 #endif 76 #endif
71 } 77 }
72 78
73 bool WebCursor::Deserialize(PickleIterator* iter) { 79 bool WebCursor::Deserialize(PickleIterator* iter) {
74 int type, hotspot_x, hotspot_y, size_x, size_y, data_len; 80 int type, hotspot_x, hotspot_y, size_x, size_y, data_len;
75 81
76 const char* data; 82 const char* data;
77 83
78 // Leave |this| unmodified unless we are going to return success. 84 // Leave |this| unmodified unless we are going to return success.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 return false; 146 return false;
141 147
142 if (!IsPlatformDataEqual(other)) 148 if (!IsPlatformDataEqual(other))
143 return false; 149 return false;
144 150
145 return hotspot_ == other.hotspot_ && 151 return hotspot_ == other.hotspot_ &&
146 custom_size_ == other.custom_size_ && 152 custom_size_ == other.custom_size_ &&
147 custom_data_ == other.custom_data_; 153 custom_data_ == other.custom_data_;
148 } 154 }
149 155
156 #if defined(OS_WIN)
157
158 static WebCursorInfo::Type ToCursorType(HCURSOR cursor) {
159 static struct {
160 HCURSOR cursor;
161 WebCursorInfo::Type type;
162 } kStandardCursors[] = {
163 { LoadCursor(NULL, IDC_ARROW), WebCursorInfo::TypePointer },
164 { LoadCursor(NULL, IDC_CROSS), WebCursorInfo::TypeCross },
165 { LoadCursor(NULL, IDC_HAND), WebCursorInfo::TypeHand },
166 { LoadCursor(NULL, IDC_IBEAM), WebCursorInfo::TypeIBeam },
167 { LoadCursor(NULL, IDC_WAIT), WebCursorInfo::TypeWait },
168 { LoadCursor(NULL, IDC_HELP), WebCursorInfo::TypeHelp },
169 { LoadCursor(NULL, IDC_SIZENESW), WebCursorInfo::TypeNorthEastResize },
170 { LoadCursor(NULL, IDC_SIZENWSE), WebCursorInfo::TypeNorthWestResize },
171 { LoadCursor(NULL, IDC_SIZENS), WebCursorInfo::TypeNorthSouthResize },
172 { LoadCursor(NULL, IDC_SIZEWE), WebCursorInfo::TypeEastWestResize },
173 { LoadCursor(NULL, IDC_SIZEALL), WebCursorInfo::TypeMove },
174 { LoadCursor(NULL, IDC_APPSTARTING), WebCursorInfo::TypeProgress },
175 { LoadCursor(NULL, IDC_NO), WebCursorInfo::TypeNotAllowed },
176 };
177 for (int i = 0; i < arraysize(kStandardCursors); i++) {
tony 2012/09/12 18:58:09 Nit: ++i
jam 2012/09/12 19:40:11 Done.
178 if (cursor == kStandardCursors[i].cursor)
179 return kStandardCursors[i].type;
180 }
181 return WebCursorInfo::TypeCustom;
182 }
183
184 void WebCursor::InitFromExternalCursor(HCURSOR cursor) {
185 WebCursorInfo::Type cursor_type = ToCursorType(cursor);
186
187 InitFromCursorInfo(WebCursorInfo(cursor_type));
188
189 if (cursor_type == WebCursorInfo::TypeCustom)
190 external_cursor_ = cursor;
191 }
192
193 #endif // defined(OS_WIN)
194
150 void WebCursor::Clear() { 195 void WebCursor::Clear() {
151 type_ = WebCursorInfo::TypePointer; 196 type_ = WebCursorInfo::TypePointer;
152 hotspot_.set_x(0); 197 hotspot_.set_x(0);
153 hotspot_.set_y(0); 198 hotspot_.set_y(0);
154 custom_size_.set_width(0); 199 custom_size_.set_width(0);
155 custom_size_.set_height(0); 200 custom_size_.set_height(0);
156 custom_data_.clear(); 201 custom_data_.clear();
157 CleanupPlatformData(); 202 CleanupPlatformData();
158 } 203 }
159 204
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 void WebCursor::ClampHotspot() { 242 void WebCursor::ClampHotspot() {
198 if (!IsCustom()) 243 if (!IsCustom())
199 return; 244 return;
200 245
201 // Clamp the hotspot to the custom image's dimensions. 246 // Clamp the hotspot to the custom image's dimensions.
202 hotspot_.set_x(std::max(0, 247 hotspot_.set_x(std::max(0,
203 std::min(custom_size_.width() - 1, hotspot_.x()))); 248 std::min(custom_size_.width() - 1, hotspot_.x())));
204 hotspot_.set_y(std::max(0, 249 hotspot_.set_y(std::max(0,
205 std::min(custom_size_.height() - 1, hotspot_.y()))); 250 std::min(custom_size_.height() - 1, hotspot_.y())));
206 } 251 }
OLDNEW
« no previous file with comments | « webkit/glue/webcursor.h ('k') | webkit/glue/webcursor_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698