| OLD | NEW |
| 1 // Copyright (c) 2011 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 "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/Source/WebKit/chromium/public/WebCursorInfo.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" |
| 11 | 11 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 void WebCursor::GetCursorInfo(WebCursorInfo* cursor_info) const { | 63 void WebCursor::GetCursorInfo(WebCursorInfo* cursor_info) const { |
| 64 cursor_info->type = static_cast<WebCursorInfo::Type>(type_); | 64 cursor_info->type = static_cast<WebCursorInfo::Type>(type_); |
| 65 cursor_info->hotSpot = hotspot_; | 65 cursor_info->hotSpot = hotspot_; |
| 66 ImageFromCustomData(&cursor_info->customImage); | 66 ImageFromCustomData(&cursor_info->customImage); |
| 67 | 67 |
| 68 #if defined(OS_WIN) && !defined(USE_AURA) | 68 #if defined(OS_WIN) && !defined(USE_AURA) |
| 69 cursor_info->externalHandle = external_cursor_; | 69 cursor_info->externalHandle = external_cursor_; |
| 70 #endif | 70 #endif |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool WebCursor::Deserialize(const Pickle* pickle, void** iter) { | 73 bool WebCursor::Deserialize(PickleIterator* iter) { |
| 74 int type, hotspot_x, hotspot_y, size_x, size_y, data_len; | 74 int type, hotspot_x, hotspot_y, size_x, size_y, data_len; |
| 75 | 75 |
| 76 const char* data; | 76 const char* data; |
| 77 | 77 |
| 78 // Leave |this| unmodified unless we are going to return success. | 78 // Leave |this| unmodified unless we are going to return success. |
| 79 if (!pickle->ReadInt(iter, &type) || | 79 if (!iter->ReadInt(&type) || |
| 80 !pickle->ReadInt(iter, &hotspot_x) || | 80 !iter->ReadInt(&hotspot_x) || |
| 81 !pickle->ReadInt(iter, &hotspot_y) || | 81 !iter->ReadInt(&hotspot_y) || |
| 82 !pickle->ReadLength(iter, &size_x) || | 82 !iter->ReadLength(&size_x) || |
| 83 !pickle->ReadLength(iter, &size_y) || | 83 !iter->ReadLength(&size_y) || |
| 84 !pickle->ReadData(iter, &data, &data_len)) | 84 !iter->ReadData(&data, &data_len)) |
| 85 return false; | 85 return false; |
| 86 | 86 |
| 87 // Ensure the size is sane, and there is enough data. | 87 // Ensure the size is sane, and there is enough data. |
| 88 if (size_x > kMaxCursorDimension || | 88 if (size_x > kMaxCursorDimension || |
| 89 size_y > kMaxCursorDimension) | 89 size_y > kMaxCursorDimension) |
| 90 return false; | 90 return false; |
| 91 | 91 |
| 92 type_ = type; | 92 type_ = type; |
| 93 | 93 |
| 94 if (type == WebCursorInfo::TypeCustom) { | 94 if (type == WebCursorInfo::TypeCustom) { |
| 95 if (size_x > 0 && size_y > 0) { | 95 if (size_x > 0 && size_y > 0) { |
| 96 // The * 4 is because the expected format is an array of RGBA pixel | 96 // The * 4 is because the expected format is an array of RGBA pixel |
| 97 // values. | 97 // values. |
| 98 if (size_x * size_y * 4 > data_len) | 98 if (size_x * size_y * 4 > data_len) |
| 99 return false; | 99 return false; |
| 100 | 100 |
| 101 hotspot_.set_x(hotspot_x); | 101 hotspot_.set_x(hotspot_x); |
| 102 hotspot_.set_y(hotspot_y); | 102 hotspot_.set_y(hotspot_y); |
| 103 custom_size_.set_width(size_x); | 103 custom_size_.set_width(size_x); |
| 104 custom_size_.set_height(size_y); | 104 custom_size_.set_height(size_y); |
| 105 ClampHotspot(); | 105 ClampHotspot(); |
| 106 | 106 |
| 107 custom_data_.clear(); | 107 custom_data_.clear(); |
| 108 if (data_len > 0) { | 108 if (data_len > 0) { |
| 109 custom_data_.resize(data_len); | 109 custom_data_.resize(data_len); |
| 110 memcpy(&custom_data_[0], data, data_len); | 110 memcpy(&custom_data_[0], data, data_len); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 return DeserializePlatformData(pickle, iter); | 114 return DeserializePlatformData(iter); |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool WebCursor::Serialize(Pickle* pickle) const { | 117 bool WebCursor::Serialize(Pickle* pickle) const { |
| 118 if (!pickle->WriteInt(type_) || | 118 if (!pickle->WriteInt(type_) || |
| 119 !pickle->WriteInt(hotspot_.x()) || | 119 !pickle->WriteInt(hotspot_.x()) || |
| 120 !pickle->WriteInt(hotspot_.y()) || | 120 !pickle->WriteInt(hotspot_.y()) || |
| 121 !pickle->WriteInt(custom_size_.width()) || | 121 !pickle->WriteInt(custom_size_.width()) || |
| 122 !pickle->WriteInt(custom_size_.height())) | 122 !pickle->WriteInt(custom_size_.height())) |
| 123 return false; | 123 return false; |
| 124 | 124 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 void WebCursor::ClampHotspot() { | 200 void WebCursor::ClampHotspot() { |
| 201 if (!IsCustom()) | 201 if (!IsCustom()) |
| 202 return; | 202 return; |
| 203 | 203 |
| 204 // Clamp the hotspot to the custom image's dimensions. | 204 // Clamp the hotspot to the custom image's dimensions. |
| 205 hotspot_.set_x(std::max(0, | 205 hotspot_.set_x(std::max(0, |
| 206 std::min(custom_size_.width() - 1, hotspot_.x()))); | 206 std::min(custom_size_.width() - 1, hotspot_.x()))); |
| 207 hotspot_.set_y(std::max(0, | 207 hotspot_.set_y(std::max(0, |
| 208 std::min(custom_size_.height() - 1, hotspot_.y()))); | 208 std::min(custom_size_.height() - 1, hotspot_.y()))); |
| 209 } | 209 } |
| OLD | NEW |