| 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 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/pickle.h" | 6 #include "base/pickle.h" |
| 7 #include "grit/webkit_resources.h" | 7 #include "grit/webkit_resources.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.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 "ui/gfx/gdi_util.h" | 10 #include "ui/gfx/gdi_util.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return MAKEINTRESOURCE(IDC_HAND_GRABBING); | 102 return MAKEINTRESOURCE(IDC_HAND_GRABBING); |
| 103 } | 103 } |
| 104 NOTREACHED(); | 104 NOTREACHED(); |
| 105 return NULL; | 105 return NULL; |
| 106 } | 106 } |
| 107 | 107 |
| 108 static bool IsSystemCursorID(LPCWSTR cursor_id) { | 108 static bool IsSystemCursorID(LPCWSTR cursor_id) { |
| 109 return cursor_id >= IDC_ARROW; // See WinUser.h | 109 return cursor_id >= IDC_ARROW; // See WinUser.h |
| 110 } | 110 } |
| 111 | 111 |
| 112 static WebCursorInfo::Type ToCursorType(HCURSOR cursor) { | |
| 113 static struct { | |
| 114 HCURSOR cursor; | |
| 115 WebCursorInfo::Type type; | |
| 116 } kStandardCursors[] = { | |
| 117 { LoadCursor(NULL, IDC_ARROW), WebCursorInfo::TypePointer }, | |
| 118 { LoadCursor(NULL, IDC_CROSS), WebCursorInfo::TypeCross }, | |
| 119 { LoadCursor(NULL, IDC_HAND), WebCursorInfo::TypeHand }, | |
| 120 { LoadCursor(NULL, IDC_IBEAM), WebCursorInfo::TypeIBeam }, | |
| 121 { LoadCursor(NULL, IDC_WAIT), WebCursorInfo::TypeWait }, | |
| 122 { LoadCursor(NULL, IDC_HELP), WebCursorInfo::TypeHelp }, | |
| 123 { LoadCursor(NULL, IDC_SIZENESW), WebCursorInfo::TypeNorthEastResize }, | |
| 124 { LoadCursor(NULL, IDC_SIZENWSE), WebCursorInfo::TypeNorthWestResize }, | |
| 125 { LoadCursor(NULL, IDC_SIZENS), WebCursorInfo::TypeNorthSouthResize }, | |
| 126 { LoadCursor(NULL, IDC_SIZEWE), WebCursorInfo::TypeEastWestResize }, | |
| 127 { LoadCursor(NULL, IDC_SIZEALL), WebCursorInfo::TypeMove }, | |
| 128 { LoadCursor(NULL, IDC_APPSTARTING), WebCursorInfo::TypeProgress }, | |
| 129 { LoadCursor(NULL, IDC_NO), WebCursorInfo::TypeNotAllowed }, | |
| 130 }; | |
| 131 for (int i = 0; i < arraysize(kStandardCursors); i++) { | |
| 132 if (cursor == kStandardCursors[i].cursor) | |
| 133 return kStandardCursors[i].type; | |
| 134 } | |
| 135 return WebCursorInfo::TypeCustom; | |
| 136 } | |
| 137 | |
| 138 HCURSOR WebCursor::GetCursor(HINSTANCE module_handle){ | 112 HCURSOR WebCursor::GetCursor(HINSTANCE module_handle){ |
| 139 if (!IsCustom()) { | 113 if (!IsCustom()) { |
| 140 const wchar_t* cursor_id = | 114 const wchar_t* cursor_id = |
| 141 ToCursorID(static_cast<WebCursorInfo::Type>(type_)); | 115 ToCursorID(static_cast<WebCursorInfo::Type>(type_)); |
| 142 | 116 |
| 143 if (IsSystemCursorID(cursor_id)) | 117 if (IsSystemCursorID(cursor_id)) |
| 144 module_handle = NULL; | 118 module_handle = NULL; |
| 145 | 119 |
| 146 return LoadCursor(module_handle, cursor_id); | 120 return LoadCursor(module_handle, cursor_id); |
| 147 } | 121 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 DeleteObject(bitmap_handle); | 161 DeleteObject(bitmap_handle); |
| 188 DeleteDC(workingDC); | 162 DeleteDC(workingDC); |
| 189 ReleaseDC(0, dc); | 163 ReleaseDC(0, dc); |
| 190 return custom_cursor_; | 164 return custom_cursor_; |
| 191 } | 165 } |
| 192 | 166 |
| 193 gfx::NativeCursor WebCursor::GetNativeCursor() { | 167 gfx::NativeCursor WebCursor::GetNativeCursor() { |
| 194 return GetCursor(NULL); | 168 return GetCursor(NULL); |
| 195 } | 169 } |
| 196 | 170 |
| 197 void WebCursor::InitFromExternalCursor(HCURSOR cursor) { | |
| 198 WebCursorInfo::Type cursor_type = ToCursorType(cursor); | |
| 199 | |
| 200 InitFromCursorInfo(WebCursorInfo(cursor_type)); | |
| 201 | |
| 202 if (cursor_type == WebCursorInfo::TypeCustom) | |
| 203 external_cursor_ = cursor; | |
| 204 } | |
| 205 | |
| 206 void WebCursor::InitPlatformData() { | 171 void WebCursor::InitPlatformData() { |
| 207 external_cursor_ = NULL; | |
| 208 custom_cursor_ = NULL; | 172 custom_cursor_ = NULL; |
| 209 } | 173 } |
| 210 | 174 |
| 211 bool WebCursor::SerializePlatformData(Pickle* pickle) const { | 175 bool WebCursor::SerializePlatformData(Pickle* pickle) const { |
| 212 // There are some issues with converting certain HCURSORS to bitmaps. The | 176 // There are some issues with converting certain HCURSORS to bitmaps. The |
| 213 // HCURSOR being a user object can be marshaled as is. | 177 // HCURSOR being a user object can be marshaled as is. |
| 214 // HCURSORs are always 32 bits on Windows, even on 64 bit systems. | 178 // HCURSORs are always 32 bits on Windows, even on 64 bit systems. |
| 215 return pickle->WriteUInt32(reinterpret_cast<uint32>(external_cursor_)); | 179 return pickle->WriteUInt32(reinterpret_cast<uint32>(external_cursor_)); |
| 216 } | 180 } |
| 217 | 181 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 235 } | 199 } |
| 236 | 200 |
| 237 void WebCursor::CleanupPlatformData() { | 201 void WebCursor::CleanupPlatformData() { |
| 238 external_cursor_ = NULL; | 202 external_cursor_ = NULL; |
| 239 | 203 |
| 240 if (custom_cursor_) { | 204 if (custom_cursor_) { |
| 241 DestroyIcon(custom_cursor_); | 205 DestroyIcon(custom_cursor_); |
| 242 custom_cursor_ = NULL; | 206 custom_cursor_ = NULL; |
| 243 } | 207 } |
| 244 } | 208 } |
| OLD | NEW |