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 "third_party/WebKit/public/platform/WebImage.h" | 9 #include "third_party/WebKit/public/platform/WebImage.h" |
10 | 10 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 if (!custom_data_.empty()) | 236 if (!custom_data_.empty()) |
237 memcpy(&custom_data_[0], bitmap.getPixels(), bitmap.getSize()); | 237 memcpy(&custom_data_[0], bitmap.getPixels(), bitmap.getSize()); |
238 custom_size_.set_width(bitmap.width()); | 238 custom_size_.set_width(bitmap.width()); |
239 custom_size_.set_height(bitmap.height()); | 239 custom_size_.set_height(bitmap.height()); |
240 } | 240 } |
241 | 241 |
242 void WebCursor::ImageFromCustomData(SkBitmap* image) const { | 242 void WebCursor::ImageFromCustomData(SkBitmap* image) const { |
243 if (custom_data_.empty()) | 243 if (custom_data_.empty()) |
244 return; | 244 return; |
245 | 245 |
246 if (!image->allocN32Pixels(custom_size_.width(), custom_size_.height())) | 246 if (!image->tryAllocN32Pixels(custom_size_.width(), custom_size_.height())) |
247 return; | 247 return; |
248 memcpy(image->getPixels(), &custom_data_[0], custom_data_.size()); | 248 memcpy(image->getPixels(), &custom_data_[0], custom_data_.size()); |
249 } | 249 } |
250 | 250 |
251 void WebCursor::ClampHotspot() { | 251 void WebCursor::ClampHotspot() { |
252 if (!IsCustom()) | 252 if (!IsCustom()) |
253 return; | 253 return; |
254 | 254 |
255 // Clamp the hotspot to the custom image's dimensions. | 255 // Clamp the hotspot to the custom image's dimensions. |
256 hotspot_.set_x(std::max(0, | 256 hotspot_.set_x(std::max(0, |
257 std::min(custom_size_.width() - 1, hotspot_.x()))); | 257 std::min(custom_size_.width() - 1, hotspot_.x()))); |
258 hotspot_.set_y(std::max(0, | 258 hotspot_.set_y(std::max(0, |
259 std::min(custom_size_.height() - 1, hotspot_.y()))); | 259 std::min(custom_size_.height() - 1, hotspot_.y()))); |
260 } | 260 } |
261 | 261 |
262 } // namespace content | 262 } // namespace content |
OLD | NEW |