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

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

Issue 155172: Start using WebCursorInfo from the WebKit API. WebCursorInfo is a... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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_mac.mm ('k') | webkit/glue/webplugin_delegate.h » ('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) 2008 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "config.h"
6 #include "NativeImageSkia.h"
7 #include "PlatformCursor.h"
8
9 #undef LOG
10 #include "base/gfx/gdi_util.h" 5 #include "base/gfx/gdi_util.h"
11 #include "base/logging.h" 6 #include "base/logging.h"
12 #include "base/pickle.h" 7 #include "base/pickle.h"
13 #include "grit/webkit_resources.h" 8 #include "grit/webkit_resources.h"
14 #include "third_party/skia/include/core/SkBitmap.h" 9 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "webkit/api/public/WebCursorInfo.h"
15 #include "webkit/glue/webcursor.h" 11 #include "webkit/glue/webcursor.h"
16 12
17 using WebCore::PlatformCursor; 13 using WebKit::WebCursorInfo;
18 14
19 static LPCWSTR ToCursorID(PlatformCursor::Type type) { 15 static LPCWSTR ToCursorID(WebCursorInfo::Type type) {
20 switch (type) { 16 switch (type) {
21 case PlatformCursor::TypePointer: 17 case WebCursorInfo::TypePointer:
22 return IDC_ARROW; 18 return IDC_ARROW;
23 case PlatformCursor::TypeCross: 19 case WebCursorInfo::TypeCross:
24 return IDC_CROSS; 20 return IDC_CROSS;
25 case PlatformCursor::TypeHand: 21 case WebCursorInfo::TypeHand:
26 return IDC_HAND; 22 return IDC_HAND;
27 case PlatformCursor::TypeIBeam: 23 case WebCursorInfo::TypeIBeam:
28 return IDC_IBEAM; 24 return IDC_IBEAM;
29 case PlatformCursor::TypeWait: 25 case WebCursorInfo::TypeWait:
30 return IDC_WAIT; 26 return IDC_WAIT;
31 case PlatformCursor::TypeHelp: 27 case WebCursorInfo::TypeHelp:
32 return IDC_HELP; 28 return IDC_HELP;
33 case PlatformCursor::TypeEastResize: 29 case WebCursorInfo::TypeEastResize:
34 return IDC_SIZEWE; 30 return IDC_SIZEWE;
35 case PlatformCursor::TypeNorthResize: 31 case WebCursorInfo::TypeNorthResize:
36 return IDC_SIZENS; 32 return IDC_SIZENS;
37 case PlatformCursor::TypeNorthEastResize: 33 case WebCursorInfo::TypeNorthEastResize:
38 return IDC_SIZENESW; 34 return IDC_SIZENESW;
39 case PlatformCursor::TypeNorthWestResize: 35 case WebCursorInfo::TypeNorthWestResize:
40 return IDC_SIZENWSE; 36 return IDC_SIZENWSE;
41 case PlatformCursor::TypeSouthResize: 37 case WebCursorInfo::TypeSouthResize:
42 return IDC_SIZENS; 38 return IDC_SIZENS;
43 case PlatformCursor::TypeSouthEastResize: 39 case WebCursorInfo::TypeSouthEastResize:
44 return IDC_SIZENWSE; 40 return IDC_SIZENWSE;
45 case PlatformCursor::TypeSouthWestResize: 41 case WebCursorInfo::TypeSouthWestResize:
46 return IDC_SIZENESW; 42 return IDC_SIZENESW;
47 case PlatformCursor::TypeWestResize: 43 case WebCursorInfo::TypeWestResize:
48 return IDC_SIZEWE; 44 return IDC_SIZEWE;
49 case PlatformCursor::TypeNorthSouthResize: 45 case WebCursorInfo::TypeNorthSouthResize:
50 return IDC_SIZENS; 46 return IDC_SIZENS;
51 case PlatformCursor::TypeEastWestResize: 47 case WebCursorInfo::TypeEastWestResize:
52 return IDC_SIZEWE; 48 return IDC_SIZEWE;
53 case PlatformCursor::TypeNorthEastSouthWestResize: 49 case WebCursorInfo::TypeNorthEastSouthWestResize:
54 return IDC_SIZENESW; 50 return IDC_SIZENESW;
55 case PlatformCursor::TypeNorthWestSouthEastResize: 51 case WebCursorInfo::TypeNorthWestSouthEastResize:
56 return IDC_SIZENWSE; 52 return IDC_SIZENWSE;
57 case PlatformCursor::TypeColumnResize: 53 case WebCursorInfo::TypeColumnResize:
58 return MAKEINTRESOURCE(IDC_COLRESIZE); 54 return MAKEINTRESOURCE(IDC_COLRESIZE);
59 case PlatformCursor::TypeRowResize: 55 case WebCursorInfo::TypeRowResize:
60 return MAKEINTRESOURCE(IDC_ROWRESIZE); 56 return MAKEINTRESOURCE(IDC_ROWRESIZE);
61 case PlatformCursor::TypeMiddlePanning: 57 case WebCursorInfo::TypeMiddlePanning:
62 return MAKEINTRESOURCE(IDC_PAN_MIDDLE); 58 return MAKEINTRESOURCE(IDC_PAN_MIDDLE);
63 case PlatformCursor::TypeEastPanning: 59 case WebCursorInfo::TypeEastPanning:
64 return MAKEINTRESOURCE(IDC_PAN_EAST); 60 return MAKEINTRESOURCE(IDC_PAN_EAST);
65 case PlatformCursor::TypeNorthPanning: 61 case WebCursorInfo::TypeNorthPanning:
66 return MAKEINTRESOURCE(IDC_PAN_NORTH); 62 return MAKEINTRESOURCE(IDC_PAN_NORTH);
67 case PlatformCursor::TypeNorthEastPanning: 63 case WebCursorInfo::TypeNorthEastPanning:
68 return MAKEINTRESOURCE(IDC_PAN_NORTH_EAST); 64 return MAKEINTRESOURCE(IDC_PAN_NORTH_EAST);
69 case PlatformCursor::TypeNorthWestPanning: 65 case WebCursorInfo::TypeNorthWestPanning:
70 return MAKEINTRESOURCE(IDC_PAN_NORTH_WEST); 66 return MAKEINTRESOURCE(IDC_PAN_NORTH_WEST);
71 case PlatformCursor::TypeSouthPanning: 67 case WebCursorInfo::TypeSouthPanning:
72 return MAKEINTRESOURCE(IDC_PAN_SOUTH); 68 return MAKEINTRESOURCE(IDC_PAN_SOUTH);
73 case PlatformCursor::TypeSouthEastPanning: 69 case WebCursorInfo::TypeSouthEastPanning:
74 return MAKEINTRESOURCE(IDC_PAN_SOUTH_EAST); 70 return MAKEINTRESOURCE(IDC_PAN_SOUTH_EAST);
75 case PlatformCursor::TypeSouthWestPanning: 71 case WebCursorInfo::TypeSouthWestPanning:
76 return MAKEINTRESOURCE(IDC_PAN_SOUTH_WEST); 72 return MAKEINTRESOURCE(IDC_PAN_SOUTH_WEST);
77 case PlatformCursor::TypeWestPanning: 73 case WebCursorInfo::TypeWestPanning:
78 return MAKEINTRESOURCE(IDC_PAN_WEST); 74 return MAKEINTRESOURCE(IDC_PAN_WEST);
79 case PlatformCursor::TypeMove: 75 case WebCursorInfo::TypeMove:
80 return IDC_SIZEALL; 76 return IDC_SIZEALL;
81 case PlatformCursor::TypeVerticalText: 77 case WebCursorInfo::TypeVerticalText:
82 return MAKEINTRESOURCE(IDC_VERTICALTEXT); 78 return MAKEINTRESOURCE(IDC_VERTICALTEXT);
83 case PlatformCursor::TypeCell: 79 case WebCursorInfo::TypeCell:
84 return MAKEINTRESOURCE(IDC_CELL); 80 return MAKEINTRESOURCE(IDC_CELL);
85 case PlatformCursor::TypeContextMenu: 81 case WebCursorInfo::TypeContextMenu:
86 return MAKEINTRESOURCE(IDC_ARROW); 82 return MAKEINTRESOURCE(IDC_ARROW);
87 case PlatformCursor::TypeAlias: 83 case WebCursorInfo::TypeAlias:
88 return MAKEINTRESOURCE(IDC_ALIAS); 84 return MAKEINTRESOURCE(IDC_ALIAS);
89 case PlatformCursor::TypeProgress: 85 case WebCursorInfo::TypeProgress:
90 return IDC_APPSTARTING; 86 return IDC_APPSTARTING;
91 case PlatformCursor::TypeNoDrop: 87 case WebCursorInfo::TypeNoDrop:
92 return IDC_NO; 88 return IDC_NO;
93 case PlatformCursor::TypeCopy: 89 case WebCursorInfo::TypeCopy:
94 return MAKEINTRESOURCE(IDC_COPYCUR); 90 return MAKEINTRESOURCE(IDC_COPYCUR);
95 case PlatformCursor::TypeNone: 91 case WebCursorInfo::TypeNone:
96 return IDC_ARROW; 92 return IDC_ARROW;
97 case PlatformCursor::TypeNotAllowed: 93 case WebCursorInfo::TypeNotAllowed:
98 return IDC_NO; 94 return IDC_NO;
99 case PlatformCursor::TypeZoomIn: 95 case WebCursorInfo::TypeZoomIn:
100 return MAKEINTRESOURCE(IDC_ZOOMIN); 96 return MAKEINTRESOURCE(IDC_ZOOMIN);
101 case PlatformCursor::TypeZoomOut: 97 case WebCursorInfo::TypeZoomOut:
102 return MAKEINTRESOURCE(IDC_ZOOMOUT); 98 return MAKEINTRESOURCE(IDC_ZOOMOUT);
103 } 99 }
104 NOTREACHED(); 100 NOTREACHED();
105 return NULL; 101 return NULL;
106 } 102 }
107 103
108 static bool IsSystemCursorID(LPCWSTR cursor_id) { 104 static bool IsSystemCursorID(LPCWSTR cursor_id) {
109 return cursor_id >= IDC_ARROW; // See WinUser.h 105 return cursor_id >= IDC_ARROW; // See WinUser.h
110 } 106 }
111 107
112 static PlatformCursor::Type ToPlatformCursorType(HCURSOR cursor) { 108 static WebCursorInfo::Type ToCursorType(HCURSOR cursor) {
113 static struct { 109 static struct {
114 HCURSOR cursor; 110 HCURSOR cursor;
115 PlatformCursor::Type type; 111 WebCursorInfo::Type type;
116 } kStandardCursors[] = { 112 } kStandardCursors[] = {
117 { LoadCursor(NULL, IDC_ARROW), PlatformCursor::TypePointer }, 113 { LoadCursor(NULL, IDC_ARROW), WebCursorInfo::TypePointer },
118 { LoadCursor(NULL, IDC_IBEAM), PlatformCursor::TypeIBeam }, 114 { LoadCursor(NULL, IDC_IBEAM), WebCursorInfo::TypeIBeam },
119 { LoadCursor(NULL, IDC_WAIT), PlatformCursor::TypeWait }, 115 { LoadCursor(NULL, IDC_WAIT), WebCursorInfo::TypeWait },
120 { LoadCursor(NULL, IDC_CROSS), PlatformCursor::TypeCross }, 116 { LoadCursor(NULL, IDC_CROSS), WebCursorInfo::TypeCross },
121 { LoadCursor(NULL, IDC_SIZENWSE), PlatformCursor::TypeNorthWestResize }, 117 { LoadCursor(NULL, IDC_SIZENWSE), WebCursorInfo::TypeNorthWestResize },
122 { LoadCursor(NULL, IDC_SIZENESW), PlatformCursor::TypeNorthEastResize }, 118 { LoadCursor(NULL, IDC_SIZENESW), WebCursorInfo::TypeNorthEastResize },
123 { LoadCursor(NULL, IDC_SIZEWE), PlatformCursor::TypeEastWestResize }, 119 { LoadCursor(NULL, IDC_SIZEWE), WebCursorInfo::TypeEastWestResize },
124 { LoadCursor(NULL, IDC_SIZENS), PlatformCursor::TypeNorthSouthResize }, 120 { LoadCursor(NULL, IDC_SIZENS), WebCursorInfo::TypeNorthSouthResize },
125 { LoadCursor(NULL, IDC_SIZEALL), PlatformCursor::TypeMove }, 121 { LoadCursor(NULL, IDC_SIZEALL), WebCursorInfo::TypeMove },
126 { LoadCursor(NULL, IDC_NO), PlatformCursor::TypeNotAllowed }, 122 { LoadCursor(NULL, IDC_NO), WebCursorInfo::TypeNotAllowed },
127 { LoadCursor(NULL, IDC_HAND), PlatformCursor::TypeHand }, 123 { LoadCursor(NULL, IDC_HAND), WebCursorInfo::TypeHand },
128 { LoadCursor(NULL, IDC_APPSTARTING), PlatformCursor::TypeProgress }, 124 { LoadCursor(NULL, IDC_APPSTARTING), WebCursorInfo::TypeProgress },
129 { LoadCursor(NULL, IDC_HELP), PlatformCursor::TypeHelp }, 125 { LoadCursor(NULL, IDC_HELP), WebCursorInfo::TypeHelp },
130 }; 126 };
131 for (int i = 0; i < arraysize(kStandardCursors); i++) { 127 for (int i = 0; i < arraysize(kStandardCursors); i++) {
132 if (cursor == kStandardCursors[i].cursor) 128 if (cursor == kStandardCursors[i].cursor)
133 return kStandardCursors[i].type; 129 return kStandardCursors[i].type;
134 } 130 }
135 return PlatformCursor::TypeCustom; 131 return WebCursorInfo::TypeCustom;
136 } 132 }
137 133
138 HCURSOR WebCursor::GetCursor(HINSTANCE module_handle){ 134 HCURSOR WebCursor::GetCursor(HINSTANCE module_handle){
139 if (!IsCustom()) { 135 if (!IsCustom()) {
140 const wchar_t* cursor_id = 136 const wchar_t* cursor_id =
141 ToCursorID(static_cast<PlatformCursor::Type>(type_)); 137 ToCursorID(static_cast<WebCursorInfo::Type>(type_));
142 138
143 if (IsSystemCursorID(cursor_id)) 139 if (IsSystemCursorID(cursor_id))
144 module_handle = NULL; 140 module_handle = NULL;
145 141
146 return LoadCursor(module_handle, cursor_id); 142 return LoadCursor(module_handle, cursor_id);
147 } 143 }
148 144
149 if (custom_cursor_) { 145 if (custom_cursor_) {
150 DCHECK(external_cursor_ == NULL); 146 DCHECK(external_cursor_ == NULL);
151 return custom_cursor_; 147 return custom_cursor_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 custom_cursor_ = CreateIconIndirect(&ii); 179 custom_cursor_ = CreateIconIndirect(&ii);
184 180
185 DeleteObject(mask); 181 DeleteObject(mask);
186 DeleteObject(bitmap_handle); 182 DeleteObject(bitmap_handle);
187 DeleteDC(workingDC); 183 DeleteDC(workingDC);
188 ReleaseDC(0, dc); 184 ReleaseDC(0, dc);
189 return custom_cursor_; 185 return custom_cursor_;
190 } 186 }
191 187
192 void WebCursor::InitFromExternalCursor(HCURSOR cursor) { 188 void WebCursor::InitFromExternalCursor(HCURSOR cursor) {
193 WebCore::PlatformCursor::Type cursor_type = ToPlatformCursorType(cursor); 189 WebCursorInfo::Type cursor_type = ToCursorType(cursor);
194 190
195 *this = WebCursor(cursor_type); 191 InitFromCursorInfo(WebCursorInfo(cursor_type));
196 192
197 if (cursor_type == WebCore::PlatformCursor::TypeCustom) { 193 if (cursor_type == WebCursorInfo::TypeCustom)
198 external_cursor_ = cursor; 194 external_cursor_ = cursor;
199 }
200 } 195 }
201 196
202 void WebCursor::InitPlatformData() { 197 void WebCursor::InitPlatformData() {
203 external_cursor_ = NULL; 198 external_cursor_ = NULL;
204 custom_cursor_ = NULL; 199 custom_cursor_ = NULL;
205 } 200 }
206 201
207 bool WebCursor::SerializePlatformData(Pickle* pickle) const { 202 bool WebCursor::SerializePlatformData(Pickle* pickle) const {
208 // There are some issues with converting certain HCURSORS to bitmaps. The 203 // There are some issues with converting certain HCURSORS to bitmaps. The
209 // HCURSOR being a user object can be marshaled as is. 204 // HCURSOR being a user object can be marshaled as is.
(...skipping 21 matching lines...) Expand all
231 } 226 }
232 227
233 void WebCursor::CleanupPlatformData() { 228 void WebCursor::CleanupPlatformData() {
234 external_cursor_ = NULL; 229 external_cursor_ = NULL;
235 230
236 if (custom_cursor_) { 231 if (custom_cursor_) {
237 DestroyIcon(custom_cursor_); 232 DestroyIcon(custom_cursor_);
238 custom_cursor_ = NULL; 233 custom_cursor_ = NULL;
239 } 234 }
240 } 235 }
OLDNEW
« no previous file with comments | « webkit/glue/webcursor_mac.mm ('k') | webkit/glue/webplugin_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698