| 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 "config.h" | 7 #include "config.h" |
| 8 #include "NativeImageSkia.h" | 8 #include "NativeImageSkia.h" |
| 9 #include "PlatformCursor.h" | 9 #include "PlatformCursor.h" |
| 10 | 10 |
| 11 #undef LOG | 11 #undef LOG |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/pickle.h" | 13 #include "base/pickle.h" |
| 14 | 14 |
| 15 WebCursor::WebCursor() | 15 WebCursor::WebCursor() |
| 16 : type_(WebCore::PlatformCursor::typePointer) { | 16 : type_(WebCore::PlatformCursor::typePointer) { |
| 17 InitPlatformData(); |
| 17 } | 18 } |
| 18 | 19 |
| 19 WebCursor::WebCursor(const WebCore::PlatformCursor& platform_cursor) | 20 WebCursor::WebCursor(const WebCore::PlatformCursor& platform_cursor) |
| 20 : type_(platform_cursor.type()), | 21 : type_(platform_cursor.type()), |
| 21 hotspot_(platform_cursor.hotSpot().x(), platform_cursor.hotSpot().y()) { | 22 hotspot_(platform_cursor.hotSpot().x(), platform_cursor.hotSpot().y()) { |
| 22 if (IsCustom()) | 23 if (IsCustom()) |
| 23 SetCustomData(platform_cursor.customImage().get()); | 24 SetCustomData(platform_cursor.customImage().get()); |
| 25 |
| 26 InitPlatformData(); |
| 27 } |
| 28 |
| 29 WebCursor::~WebCursor() { |
| 30 Clear(); |
| 31 } |
| 32 |
| 33 WebCursor::WebCursor(const WebCursor& other) { |
| 34 InitPlatformData(); |
| 35 Copy(other); |
| 36 } |
| 37 |
| 38 const WebCursor& WebCursor::operator=(const WebCursor& other) { |
| 39 if (this == &other) |
| 40 return *this; |
| 41 |
| 42 Clear(); |
| 43 Copy(other); |
| 44 return *this; |
| 24 } | 45 } |
| 25 | 46 |
| 26 bool WebCursor::Deserialize(const Pickle* pickle, void** iter) { | 47 bool WebCursor::Deserialize(const Pickle* pickle, void** iter) { |
| 27 int type, hotspot_x, hotspot_y, size_x, size_y, data_len; | 48 int type, hotspot_x, hotspot_y, size_x, size_y, data_len; |
| 49 |
| 28 const char* data; | 50 const char* data; |
| 29 | 51 |
| 30 // Leave |this| unmodified unless we are going to return success. | 52 // Leave |this| unmodified unless we are going to return success. |
| 31 if (!pickle->ReadInt(iter, &type) || | 53 if (!pickle->ReadInt(iter, &type) || |
| 32 !pickle->ReadInt(iter, &hotspot_x) || | 54 !pickle->ReadInt(iter, &hotspot_x) || |
| 33 !pickle->ReadInt(iter, &hotspot_y) || | 55 !pickle->ReadInt(iter, &hotspot_y) || |
| 34 !pickle->ReadInt(iter, &size_x) || | 56 !pickle->ReadInt(iter, &size_x) || |
| 35 !pickle->ReadInt(iter, &size_y) || | 57 !pickle->ReadInt(iter, &size_y) || |
| 36 !pickle->ReadData(iter, &data, &data_len)) | 58 !pickle->ReadData(iter, &data, &data_len)) |
| 37 return false; | 59 return false; |
| 38 | 60 |
| 39 type_ = type; | 61 type_ = type; |
| 40 hotspot_.set_x(hotspot_x); | 62 hotspot_.set_x(hotspot_x); |
| 41 hotspot_.set_y(hotspot_y); | 63 hotspot_.set_y(hotspot_y); |
| 42 custom_size_.set_width(size_x); | 64 custom_size_.set_width(size_x); |
| 43 custom_size_.set_height(size_y); | 65 custom_size_.set_height(size_y); |
| 44 | 66 |
| 45 custom_data_.clear(); | 67 custom_data_.clear(); |
| 46 if (data_len > 0) { | 68 if (data_len > 0) { |
| 47 custom_data_.resize(data_len); | 69 custom_data_.resize(data_len); |
| 48 memcpy(&custom_data_[0], data, data_len); | 70 memcpy(&custom_data_[0], data, data_len); |
| 49 } | 71 } |
| 50 | 72 |
| 51 return true; | 73 return DeserializePlatformData(pickle, iter); |
| 52 } | 74 } |
| 53 | 75 |
| 54 bool WebCursor::Serialize(Pickle* pickle) const { | 76 bool WebCursor::Serialize(Pickle* pickle) const { |
| 55 if (!pickle->WriteInt(type_) || | 77 if (!pickle->WriteInt(type_) || |
| 56 !pickle->WriteInt(hotspot_.x()) || | 78 !pickle->WriteInt(hotspot_.x()) || |
| 57 !pickle->WriteInt(hotspot_.y()) || | 79 !pickle->WriteInt(hotspot_.y()) || |
| 58 !pickle->WriteInt(custom_size_.width()) || | 80 !pickle->WriteInt(custom_size_.width()) || |
| 59 !pickle->WriteInt(custom_size_.height())) | 81 !pickle->WriteInt(custom_size_.height())) |
| 60 return false; | 82 return false; |
| 61 | 83 |
| 62 const char* data = NULL; | 84 const char* data = NULL; |
| 63 if (!custom_data_.empty()) | 85 if (!custom_data_.empty()) |
| 64 data = &custom_data_[0]; | 86 data = &custom_data_[0]; |
| 65 return pickle->WriteData(data, custom_data_.size()); | 87 if (!pickle->WriteData(data, custom_data_.size())) |
| 88 return false; |
| 89 |
| 90 return SerializePlatformData(pickle); |
| 66 } | 91 } |
| 67 | 92 |
| 68 bool WebCursor::IsCustom() const { | 93 bool WebCursor::IsCustom() const { |
| 69 return type_ == WebCore::PlatformCursor::typeCustom; | 94 return type_ == WebCore::PlatformCursor::typeCustom; |
| 70 } | 95 } |
| 71 | 96 |
| 72 bool WebCursor::IsEqual(const WebCursor& other) const { | 97 bool WebCursor::IsEqual(const WebCursor& other) const { |
| 73 if (!IsCustom()) | 98 if (type_ != other.type_) |
| 74 return type_ == other.type_; | 99 return false; |
| 100 |
| 101 if (!IsPlatformDataEqual(other)) |
| 102 return false; |
| 75 | 103 |
| 76 return hotspot_ == other.hotspot_ && | 104 return hotspot_ == other.hotspot_ && |
| 77 custom_size_ == other.custom_size_ && | 105 custom_size_ == other.custom_size_ && |
| 78 custom_data_ == other.custom_data_; | 106 custom_data_ == other.custom_data_; |
| 79 } | 107 } |
| 80 | 108 |
| 109 void WebCursor::Clear() { |
| 110 type_ = WebCore::PlatformCursor::typePointer; |
| 111 hotspot_.set_x(0); |
| 112 hotspot_.set_y(0); |
| 113 custom_size_.set_width(0); |
| 114 custom_size_.set_height(0); |
| 115 custom_data_.clear(); |
| 116 CleanupPlatformData(); |
| 117 } |
| 118 |
| 119 void WebCursor::Copy(const WebCursor& other) { |
| 120 type_ = other.type_; |
| 121 hotspot_ = other.hotspot_; |
| 122 custom_size_ = other.custom_size_; |
| 123 custom_data_ = other.custom_data_; |
| 124 CopyPlatformData(other); |
| 125 } |
| 126 |
| 81 #if !defined(OS_MACOSX) | 127 #if !defined(OS_MACOSX) |
| 82 // The Mac version of Chromium is built with PLATFORM(CG) while all other | 128 // The Mac version of Chromium is built with PLATFORM(CG) while all other |
| 83 // versions are PLATFORM(SKIA). We'll keep this Skia implementation here for | 129 // versions are PLATFORM(SKIA). We'll keep this Skia implementation here for |
| 84 // common use and put the Mac implementation in webcursor_mac.mm. | 130 // common use and put the Mac implementation in webcursor_mac.mm. |
| 85 void WebCursor::SetCustomData(WebCore::Image* image) { | 131 void WebCursor::SetCustomData(WebCore::Image* image) { |
| 132 if (!image) |
| 133 return; |
| 134 |
| 86 WebCore::NativeImagePtr image_ptr = image->nativeImageForCurrentFrame(); | 135 WebCore::NativeImagePtr image_ptr = image->nativeImageForCurrentFrame(); |
| 87 if (!image_ptr) | 136 if (!image_ptr) |
| 88 return; | 137 return; |
| 89 | 138 |
| 90 // Fill custom_data_ directly with the NativeImage pixels. | 139 // Fill custom_data_ directly with the NativeImage pixels. |
| 91 SkAutoLockPixels bitmap_lock(*image_ptr); | 140 SkAutoLockPixels bitmap_lock(*image_ptr); |
| 92 custom_data_.resize(image_ptr->getSize()); | 141 custom_data_.resize(image_ptr->getSize()); |
| 93 memcpy(&custom_data_[0], image_ptr->getPixels(), image_ptr->getSize()); | 142 memcpy(&custom_data_[0], image_ptr->getPixels(), image_ptr->getSize()); |
| 94 custom_size_.set_width(image_ptr->width()); | 143 custom_size_.set_width(image_ptr->width()); |
| 95 custom_size_.set_height(image_ptr->height()); | 144 custom_size_.set_height(image_ptr->height()); |
| 96 } | 145 } |
| 97 #endif | 146 #endif |
| OLD | NEW |