Chromium Code Reviews| 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 "content/common/cursors/webcursor.h" | 5 #include "content/common/cursors/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 "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "third_party/WebKit/public/platform/WebImage.h" | 10 #include "third_party/WebKit/public/platform/WebImage.h" |
| 11 | 11 |
| 12 using blink::WebCursorInfo; | 12 using blink::WebCursorInfo; |
| 13 | 13 |
| 14 static const int kMaxCursorDimension = 1024; | 14 static const int kMaxCursorDimension = 1024; |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 WebCursor::WebCursor() | 18 WebCursor::WebCursor() |
| 19 : type_(WebCursorInfo::TypePointer), | 19 : type_(WebCursorInfo::TypePointer), |
| 20 custom_scale_(1) { | 20 custom_scale_(1) { |
| 21 #if defined(OS_WIN) | |
| 22 external_cursor_ = NULL; | |
| 23 #endif | |
| 24 #if defined(USE_AURA) | |
| 25 device_scale_factor_ = 1.0f; | |
| 26 #endif | |
| 27 InitPlatformData(); | 21 InitPlatformData(); |
| 28 } | 22 } |
| 29 | 23 |
| 30 WebCursor::~WebCursor() { | 24 WebCursor::~WebCursor() { |
| 31 Clear(); | 25 Clear(); |
| 32 } | 26 } |
| 33 | 27 |
| 34 WebCursor::WebCursor(const WebCursor& other) { | 28 WebCursor::WebCursor(const WebCursor& other) { |
| 35 InitPlatformData(); | 29 InitPlatformData(); |
| 36 Copy(other); | 30 Copy(other); |
| 37 } | 31 } |
| 38 | 32 |
| 39 const WebCursor& WebCursor::operator=(const WebCursor& other) { | 33 const WebCursor& WebCursor::operator=(const WebCursor& other) { |
| 40 if (this == &other) | 34 if (this == &other) |
| 41 return *this; | 35 return *this; |
| 42 | 36 |
| 43 Clear(); | 37 Clear(); |
| 44 Copy(other); | 38 Copy(other); |
| 45 return *this; | 39 return *this; |
| 46 } | 40 } |
| 47 | 41 |
| 48 void WebCursor::InitFromCursorInfo(const CursorInfo& cursor_info) { | 42 void WebCursor::InitFromCursorInfo(const CursorInfo& cursor_info) { |
| 49 Clear(); | 43 Clear(); |
| 50 | 44 |
| 51 #if defined(OS_WIN) | |
| 52 if (cursor_info.external_handle) { | |
| 53 InitFromExternalCursor(cursor_info.external_handle); | |
| 54 return; | |
| 55 } | |
| 56 #endif | |
| 57 | |
| 58 type_ = cursor_info.type; | 45 type_ = cursor_info.type; |
| 59 hotspot_ = cursor_info.hotspot; | 46 hotspot_ = cursor_info.hotspot; |
| 60 if (IsCustom()) | 47 if (IsCustom()) |
| 61 SetCustomData(cursor_info.custom_image); | 48 SetCustomData(cursor_info.custom_image); |
| 62 custom_scale_ = cursor_info.image_scale_factor; | 49 custom_scale_ = cursor_info.image_scale_factor; |
| 63 CHECK(custom_scale_ > 0); | 50 CHECK(custom_scale_ > 0); |
| 64 ClampHotspot(); | 51 ClampHotspot(); |
| 65 } | 52 } |
| 66 | 53 |
| 67 void WebCursor::GetCursorInfo(CursorInfo* cursor_info) const { | 54 void WebCursor::GetCursorInfo(CursorInfo* cursor_info) const { |
| 68 cursor_info->type = static_cast<WebCursorInfo::Type>(type_); | 55 cursor_info->type = static_cast<WebCursorInfo::Type>(type_); |
| 69 cursor_info->hotspot = hotspot_; | 56 cursor_info->hotspot = hotspot_; |
| 70 ImageFromCustomData(&cursor_info->custom_image); | 57 ImageFromCustomData(&cursor_info->custom_image); |
| 71 cursor_info->image_scale_factor = custom_scale_; | 58 cursor_info->image_scale_factor = custom_scale_; |
| 72 | |
| 73 #if defined(OS_WIN) | |
| 74 cursor_info->external_handle = external_cursor_; | |
| 75 #endif | |
| 76 } | 59 } |
| 77 | 60 |
| 78 bool WebCursor::Deserialize(base::PickleIterator* iter) { | 61 bool WebCursor::Deserialize(base::PickleIterator* iter) { |
| 79 int type, hotspot_x, hotspot_y, size_x, size_y, data_len; | 62 int type, hotspot_x, hotspot_y, size_x, size_y, data_len; |
| 80 float scale; | 63 float scale; |
| 81 const char* data; | 64 const char* data; |
| 82 | 65 |
| 83 // Leave |this| unmodified unless we are going to return success. | 66 // Leave |this| unmodified unless we are going to return success. |
| 84 if (!iter->ReadInt(&type) || | 67 if (!iter->ReadInt(&type) || |
| 85 !iter->ReadInt(&hotspot_x) || | 68 !iter->ReadInt(&hotspot_x) || |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 if (cursor == kStandardCursor.cursor) | 174 if (cursor == kStandardCursor.cursor) |
| 192 return kStandardCursor.type; | 175 return kStandardCursor.type; |
| 193 } | 176 } |
| 194 return WebCursorInfo::TypeCustom; | 177 return WebCursorInfo::TypeCustom; |
| 195 } | 178 } |
| 196 | 179 |
| 197 void WebCursor::InitFromExternalCursor(HCURSOR cursor) { | 180 void WebCursor::InitFromExternalCursor(HCURSOR cursor) { |
| 198 WebCursorInfo::Type cursor_type = ToCursorType(cursor); | 181 WebCursorInfo::Type cursor_type = ToCursorType(cursor); |
| 199 | 182 |
| 200 InitFromCursorInfo(CursorInfo(cursor_type)); | 183 InitFromCursorInfo(CursorInfo(cursor_type)); |
| 201 | |
| 202 if (cursor_type == WebCursorInfo::TypeCustom) | |
|
scottmg
2016/05/13 00:27:21
Do we need to CHECK(cursor_type != WebCursorInfo::
Bret
2016/05/13 00:53:16
Ah nope, just forgot to delete this function.
| |
| 203 external_cursor_ = cursor; | |
| 204 } | 184 } |
| 205 | 185 |
| 206 #endif // defined(OS_WIN) | 186 #endif // defined(OS_WIN) |
| 207 | 187 |
| 208 void WebCursor::Clear() { | 188 void WebCursor::Clear() { |
| 209 type_ = WebCursorInfo::TypePointer; | 189 type_ = WebCursorInfo::TypePointer; |
| 210 hotspot_.set_x(0); | 190 hotspot_.set_x(0); |
| 211 hotspot_.set_y(0); | 191 hotspot_.set_y(0); |
| 212 custom_size_.set_width(0); | 192 custom_size_.set_width(0); |
| 213 custom_size_.set_height(0); | 193 custom_size_.set_height(0); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 return; | 243 return; |
| 264 | 244 |
| 265 // Clamp the hotspot to the custom image's dimensions. | 245 // Clamp the hotspot to the custom image's dimensions. |
| 266 hotspot_.set_x(std::max(0, | 246 hotspot_.set_x(std::max(0, |
| 267 std::min(custom_size_.width() - 1, hotspot_.x()))); | 247 std::min(custom_size_.width() - 1, hotspot_.x()))); |
| 268 hotspot_.set_y(std::max(0, | 248 hotspot_.set_y(std::max(0, |
| 269 std::min(custom_size_.height() - 1, hotspot_.y()))); | 249 std::min(custom_size_.height() - 1, hotspot_.y()))); |
| 270 } | 250 } |
| 271 | 251 |
| 272 } // namespace content | 252 } // namespace content |
| OLD | NEW |