OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/WebKit/chromium/public/WebCursorInfo.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebImage.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebImage.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 if (cursor_info.externalHandle) { | 50 if (cursor_info.externalHandle) { |
51 InitFromExternalCursor(cursor_info.externalHandle); | 51 InitFromExternalCursor(cursor_info.externalHandle); |
52 return; | 52 return; |
53 } | 53 } |
54 #endif | 54 #endif |
55 | 55 |
56 type_ = cursor_info.type; | 56 type_ = cursor_info.type; |
57 hotspot_ = cursor_info.hotSpot; | 57 hotspot_ = cursor_info.hotSpot; |
58 if (IsCustom()) | 58 if (IsCustom()) |
59 SetCustomData(cursor_info.customImage); | 59 SetCustomData(cursor_info.customImage); |
| 60 ClampHotspot(); |
60 } | 61 } |
61 | 62 |
62 void WebCursor::GetCursorInfo(WebCursorInfo* cursor_info) const { | 63 void WebCursor::GetCursorInfo(WebCursorInfo* cursor_info) const { |
63 cursor_info->type = static_cast<WebCursorInfo::Type>(type_); | 64 cursor_info->type = static_cast<WebCursorInfo::Type>(type_); |
64 cursor_info->hotSpot = hotspot_; | 65 cursor_info->hotSpot = hotspot_; |
65 ImageFromCustomData(&cursor_info->customImage); | 66 ImageFromCustomData(&cursor_info->customImage); |
66 | 67 |
67 #if defined(OS_WIN) | 68 #if defined(OS_WIN) |
68 cursor_info->externalHandle = external_cursor_; | 69 cursor_info->externalHandle = external_cursor_; |
69 #endif | 70 #endif |
(...skipping 23 matching lines...) Expand all Loading... |
93 | 94 |
94 // The * 4 is because the expected format is an array of RGBA pixel values. | 95 // The * 4 is because the expected format is an array of RGBA pixel values. |
95 if (size_x * size_y * 4 > data_len) | 96 if (size_x * size_y * 4 > data_len) |
96 return false; | 97 return false; |
97 | 98 |
98 type_ = type; | 99 type_ = type; |
99 hotspot_.set_x(hotspot_x); | 100 hotspot_.set_x(hotspot_x); |
100 hotspot_.set_y(hotspot_y); | 101 hotspot_.set_y(hotspot_y); |
101 custom_size_.set_width(size_x); | 102 custom_size_.set_width(size_x); |
102 custom_size_.set_height(size_y); | 103 custom_size_.set_height(size_y); |
| 104 ClampHotspot(); |
103 | 105 |
104 custom_data_.clear(); | 106 custom_data_.clear(); |
105 if (data_len > 0) { | 107 if (data_len > 0) { |
106 custom_data_.resize(data_len); | 108 custom_data_.resize(data_len); |
107 memcpy(&custom_data_[0], data, data_len); | 109 memcpy(&custom_data_[0], data, data_len); |
108 } | 110 } |
109 | 111 |
110 return DeserializePlatformData(pickle, iter); | 112 return DeserializePlatformData(pickle, iter); |
111 } | 113 } |
112 | 114 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 187 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
186 custom_size_.width(), | 188 custom_size_.width(), |
187 custom_size_.height()); | 189 custom_size_.height()); |
188 if (!bitmap.allocPixels()) | 190 if (!bitmap.allocPixels()) |
189 return; | 191 return; |
190 memcpy(bitmap.getPixels(), &custom_data_[0], custom_data_.size()); | 192 memcpy(bitmap.getPixels(), &custom_data_[0], custom_data_.size()); |
191 | 193 |
192 image->assign(bitmap); | 194 image->assign(bitmap); |
193 } | 195 } |
194 #endif | 196 #endif |
| 197 |
| 198 void WebCursor::ClampHotspot() { |
| 199 if (!IsCustom()) |
| 200 return; |
| 201 |
| 202 // Clamp the hotspot to the custom image's dimensions. |
| 203 hotspot_.set_x(std::max(0, |
| 204 std::min(custom_size_.width() - 1, hotspot_.x()))); |
| 205 hotspot_.set_y(std::max(0, |
| 206 std::min(custom_size_.height() - 1, hotspot_.y()))); |
| 207 } |
OLD | NEW |