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 "third_party/WebKit/public/platform/WebImage.h" | 9 #include "third_party/WebKit/public/platform/WebImage.h" |
| 10 | 10 |
| 11 using blink::WebCursorInfo; | 11 using blink::WebCursorInfo; |
| 12 | 12 |
| 13 static const int kMaxCursorDimension = 1024; | 13 static const int kMaxCursorDimension = 1024; |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 WebCursor::WebCursor() | 17 WebCursor::WebCursor() |
| 18 : type_(WebCursorInfo::TypePointer), | 18 : type_(WebCursorInfo::TypePointer), |
| 19 custom_scale_(1) { | 19 custom_scale_(1) { |
| 20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 21 external_cursor_ = NULL; | 21 external_cursor_ = NULL; |
| 22 #endif | 22 #endif |
| 23 InitPlatformData(); | 23 InitPlatformData(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 WebCursor::WebCursor(const CursorInfo& cursor_info) | |
| 27 : type_(WebCursorInfo::TypePointer) { | |
| 28 #if defined(OS_WIN) | |
| 29 external_cursor_ = NULL; | |
| 30 #endif | |
| 31 InitPlatformData(); | |
| 32 InitFromCursorInfo(cursor_info); | |
| 33 } | |
| 34 | |
| 35 WebCursor::~WebCursor() { | 26 WebCursor::~WebCursor() { |
| 36 Clear(); | 27 Clear(); |
| 37 } | 28 } |
| 38 | 29 |
| 39 WebCursor::WebCursor(const WebCursor& other) { | 30 WebCursor::WebCursor(const WebCursor& other) { |
| 40 InitPlatformData(); | 31 InitPlatformData(); |
| 41 Copy(other); | 32 Copy(other); |
| 42 } | 33 } |
| 43 | 34 |
| 44 const WebCursor& WebCursor::operator=(const WebCursor& other) { | 35 const WebCursor& WebCursor::operator=(const WebCursor& other) { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 void WebCursor::Copy(const WebCursor& other) { | 215 void WebCursor::Copy(const WebCursor& other) { |
| 225 type_ = other.type_; | 216 type_ = other.type_; |
| 226 hotspot_ = other.hotspot_; | 217 hotspot_ = other.hotspot_; |
| 227 custom_size_ = other.custom_size_; | 218 custom_size_ = other.custom_size_; |
| 228 custom_scale_ = other.custom_scale_; | 219 custom_scale_ = other.custom_scale_; |
| 229 custom_data_ = other.custom_data_; | 220 custom_data_ = other.custom_data_; |
| 230 CopyPlatformData(other); | 221 CopyPlatformData(other); |
| 231 } | 222 } |
| 232 | 223 |
| 233 void WebCursor::SetCustomData(const SkBitmap& bitmap) { | 224 void WebCursor::SetCustomData(const SkBitmap& bitmap) { |
| 225 CreateCustomData(bitmap, custom_data_, custom_size_); | |
| 226 } | |
| 227 | |
| 228 void WebCursor::CreateCustomData(const SkBitmap& bitmap, | |
| 229 std::vector<char>& custom_data, | |
|
ananta
2015/12/15 23:28:17
Fix alignment for the remaining parameters to be o
Bret
2015/12/16 19:03:58
Done.
| |
| 230 gfx::Size& custom_size) { | |
| 234 if (bitmap.empty()) | 231 if (bitmap.empty()) |
| 235 return; | 232 return; |
| 236 | 233 |
| 237 // Fill custom_data_ directly with the NativeImage pixels. | 234 // Fill custom_data directly with the NativeImage pixels. |
| 238 custom_data_.resize(bitmap.getSize()); | 235 custom_data.resize(bitmap.getSize()); |
| 239 if (!custom_data_.empty()) { | 236 if (!custom_data.empty()) { |
| 240 //This will divide color values by alpha (un-premultiply) if necessary | 237 //This will divide color values by alpha (un-premultiply) if necessary |
| 241 SkImageInfo dstInfo = bitmap.info().makeAlphaType(kUnpremul_SkAlphaType); | 238 SkImageInfo dstInfo = bitmap.info().makeAlphaType(kUnpremul_SkAlphaType); |
| 242 bitmap.readPixels(dstInfo, &custom_data_[0], dstInfo.minRowBytes(), 0, 0); | 239 bitmap.readPixels(dstInfo, &custom_data[0], dstInfo.minRowBytes(), 0, 0); |
| 243 } | 240 } |
| 244 custom_size_.set_width(bitmap.width()); | 241 custom_size.set_width(bitmap.width()); |
| 245 custom_size_.set_height(bitmap.height()); | 242 custom_size.set_height(bitmap.height()); |
| 246 } | 243 } |
| 247 | 244 |
| 248 void WebCursor::ImageFromCustomData(SkBitmap* image) const { | 245 void WebCursor::ImageFromCustomData(SkBitmap* image) const { |
| 249 if (custom_data_.empty()) | 246 if (custom_data_.empty()) |
| 250 return; | 247 return; |
| 251 | 248 |
| 252 SkImageInfo image_info = SkImageInfo::MakeN32(custom_size_.width(), | 249 SkImageInfo image_info = SkImageInfo::MakeN32(custom_size_.width(), |
| 253 custom_size_.height(), | 250 custom_size_.height(), |
| 254 kUnpremul_SkAlphaType); | 251 kUnpremul_SkAlphaType); |
| 255 if (!image->tryAllocPixels(image_info)) | 252 if (!image->tryAllocPixels(image_info)) |
| 256 return; | 253 return; |
| 257 memcpy(image->getPixels(), &custom_data_[0], custom_data_.size()); | 254 memcpy(image->getPixels(), &custom_data_[0], custom_data_.size()); |
| 258 } | 255 } |
| 259 | 256 |
| 260 void WebCursor::ClampHotspot() { | 257 void WebCursor::ClampHotspot() { |
| 261 if (!IsCustom()) | 258 if (!IsCustom()) |
| 262 return; | 259 return; |
| 263 | 260 |
| 264 // Clamp the hotspot to the custom image's dimensions. | 261 // Clamp the hotspot to the custom image's dimensions. |
| 265 hotspot_.set_x(std::max(0, | 262 hotspot_.set_x(std::max(0, |
| 266 std::min(custom_size_.width() - 1, hotspot_.x()))); | 263 std::min(custom_size_.width() - 1, hotspot_.x()))); |
| 267 hotspot_.set_y(std::max(0, | 264 hotspot_.set_y(std::max(0, |
| 268 std::min(custom_size_.height() - 1, hotspot_.y()))); | 265 std::min(custom_size_.height() - 1, hotspot_.y()))); |
| 269 } | 266 } |
| 270 | 267 |
| 271 } // namespace content | 268 } // namespace content |
| OLD | NEW |