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 #if defined(USE_AURA) |
| 24 device_scale_factor_ = 1.0f; |
| 25 #endif |
23 InitPlatformData(); | 26 InitPlatformData(); |
24 } | 27 } |
25 | 28 |
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() { | 29 WebCursor::~WebCursor() { |
36 Clear(); | 30 Clear(); |
37 } | 31 } |
38 | 32 |
39 WebCursor::WebCursor(const WebCursor& other) { | 33 WebCursor::WebCursor(const WebCursor& other) { |
40 InitPlatformData(); | 34 InitPlatformData(); |
41 Copy(other); | 35 Copy(other); |
42 } | 36 } |
43 | 37 |
44 const WebCursor& WebCursor::operator=(const WebCursor& other) { | 38 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) { | 218 void WebCursor::Copy(const WebCursor& other) { |
225 type_ = other.type_; | 219 type_ = other.type_; |
226 hotspot_ = other.hotspot_; | 220 hotspot_ = other.hotspot_; |
227 custom_size_ = other.custom_size_; | 221 custom_size_ = other.custom_size_; |
228 custom_scale_ = other.custom_scale_; | 222 custom_scale_ = other.custom_scale_; |
229 custom_data_ = other.custom_data_; | 223 custom_data_ = other.custom_data_; |
230 CopyPlatformData(other); | 224 CopyPlatformData(other); |
231 } | 225 } |
232 | 226 |
233 void WebCursor::SetCustomData(const SkBitmap& bitmap) { | 227 void WebCursor::SetCustomData(const SkBitmap& bitmap) { |
| 228 CreateCustomData(bitmap, &custom_data_, &custom_size_); |
| 229 } |
| 230 |
| 231 void WebCursor::CreateCustomData(const SkBitmap& bitmap, |
| 232 std::vector<char>* custom_data, |
| 233 gfx::Size* custom_size) { |
234 if (bitmap.empty()) | 234 if (bitmap.empty()) |
235 return; | 235 return; |
236 | 236 |
237 // Fill custom_data_ directly with the NativeImage pixels. | 237 // Fill custom_data directly with the NativeImage pixels. |
238 custom_data_.resize(bitmap.getSize()); | 238 custom_data->resize(bitmap.getSize()); |
239 if (!custom_data_.empty()) { | 239 if (!custom_data->empty()) { |
240 //This will divide color values by alpha (un-premultiply) if necessary | 240 //This will divide color values by alpha (un-premultiply) if necessary |
241 SkImageInfo dstInfo = bitmap.info().makeAlphaType(kUnpremul_SkAlphaType); | 241 SkImageInfo dstInfo = bitmap.info().makeAlphaType(kUnpremul_SkAlphaType); |
242 bitmap.readPixels(dstInfo, &custom_data_[0], dstInfo.minRowBytes(), 0, 0); | 242 bitmap.readPixels(dstInfo, &(*custom_data)[0], dstInfo.minRowBytes(), 0, 0); |
243 } | 243 } |
244 custom_size_.set_width(bitmap.width()); | 244 custom_size->set_width(bitmap.width()); |
245 custom_size_.set_height(bitmap.height()); | 245 custom_size->set_height(bitmap.height()); |
246 } | 246 } |
247 | 247 |
248 void WebCursor::ImageFromCustomData(SkBitmap* image) const { | 248 void WebCursor::ImageFromCustomData(SkBitmap* image) const { |
249 if (custom_data_.empty()) | 249 if (custom_data_.empty()) |
250 return; | 250 return; |
251 | 251 |
252 SkImageInfo image_info = SkImageInfo::MakeN32(custom_size_.width(), | 252 SkImageInfo image_info = SkImageInfo::MakeN32(custom_size_.width(), |
253 custom_size_.height(), | 253 custom_size_.height(), |
254 kUnpremul_SkAlphaType); | 254 kUnpremul_SkAlphaType); |
255 if (!image->tryAllocPixels(image_info)) | 255 if (!image->tryAllocPixels(image_info)) |
256 return; | 256 return; |
257 memcpy(image->getPixels(), &custom_data_[0], custom_data_.size()); | 257 memcpy(image->getPixels(), &custom_data_[0], custom_data_.size()); |
258 } | 258 } |
259 | 259 |
260 void WebCursor::ClampHotspot() { | 260 void WebCursor::ClampHotspot() { |
261 if (!IsCustom()) | 261 if (!IsCustom()) |
262 return; | 262 return; |
263 | 263 |
264 // Clamp the hotspot to the custom image's dimensions. | 264 // Clamp the hotspot to the custom image's dimensions. |
265 hotspot_.set_x(std::max(0, | 265 hotspot_.set_x(std::max(0, |
266 std::min(custom_size_.width() - 1, hotspot_.x()))); | 266 std::min(custom_size_.width() - 1, hotspot_.x()))); |
267 hotspot_.set_y(std::max(0, | 267 hotspot_.set_y(std::max(0, |
268 std::min(custom_size_.height() - 1, hotspot_.y()))); | 268 std::min(custom_size_.height() - 1, hotspot_.y()))); |
269 } | 269 } |
270 | 270 |
271 } // namespace content | 271 } // namespace content |
OLD | NEW |