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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebImage.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebImage.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 !pickle->ReadLength(iter, &size_x) || | 82 !pickle->ReadLength(iter, &size_x) || |
83 !pickle->ReadLength(iter, &size_y) || | 83 !pickle->ReadLength(iter, &size_y) || |
84 !pickle->ReadData(iter, &data, &data_len)) | 84 !pickle->ReadData(iter, &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 if (type == WebCursorInfo::TypeCustom && (size_x == 0 || size_y == 0)) | 92 if (type == WebCursorInfo::TypeCustom) { |
93 return false; | 93 type_ = type; |
| 94 if (size_x > 0 && size_y > 0) { |
| 95 // The * 4 is because the expected format is an array of RGBA pixel |
| 96 // values. |
| 97 if (size_x * size_y * 4 > data_len) |
| 98 return false; |
94 | 99 |
95 // The * 4 is because the expected format is an array of RGBA pixel values. | 100 hotspot_.set_x(hotspot_x); |
96 if (size_x * size_y * 4 > data_len) | 101 hotspot_.set_y(hotspot_y); |
97 return false; | 102 custom_size_.set_width(size_x); |
| 103 custom_size_.set_height(size_y); |
| 104 ClampHotspot(); |
98 | 105 |
99 type_ = type; | 106 custom_data_.clear(); |
100 hotspot_.set_x(hotspot_x); | 107 if (data_len > 0) { |
101 hotspot_.set_y(hotspot_y); | 108 custom_data_.resize(data_len); |
102 custom_size_.set_width(size_x); | 109 memcpy(&custom_data_[0], data, data_len); |
103 custom_size_.set_height(size_y); | 110 } |
104 ClampHotspot(); | 111 } |
105 | |
106 custom_data_.clear(); | |
107 if (data_len > 0) { | |
108 custom_data_.resize(data_len); | |
109 memcpy(&custom_data_[0], data, data_len); | |
110 } | 112 } |
111 | |
112 return DeserializePlatformData(pickle, iter); | 113 return DeserializePlatformData(pickle, iter); |
113 } | 114 } |
114 | 115 |
115 bool WebCursor::Serialize(Pickle* pickle) const { | 116 bool WebCursor::Serialize(Pickle* pickle) const { |
116 if (!pickle->WriteInt(type_) || | 117 if (!pickle->WriteInt(type_) || |
117 !pickle->WriteInt(hotspot_.x()) || | 118 !pickle->WriteInt(hotspot_.x()) || |
118 !pickle->WriteInt(hotspot_.y()) || | 119 !pickle->WriteInt(hotspot_.y()) || |
119 !pickle->WriteInt(custom_size_.width()) || | 120 !pickle->WriteInt(custom_size_.width()) || |
120 !pickle->WriteInt(custom_size_.height())) | 121 !pickle->WriteInt(custom_size_.height())) |
121 return false; | 122 return false; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 void WebCursor::ClampHotspot() { | 199 void WebCursor::ClampHotspot() { |
199 if (!IsCustom()) | 200 if (!IsCustom()) |
200 return; | 201 return; |
201 | 202 |
202 // Clamp the hotspot to the custom image's dimensions. | 203 // Clamp the hotspot to the custom image's dimensions. |
203 hotspot_.set_x(std::max(0, | 204 hotspot_.set_x(std::max(0, |
204 std::min(custom_size_.width() - 1, hotspot_.x()))); | 205 std::min(custom_size_.width() - 1, hotspot_.x()))); |
205 hotspot_.set_y(std::max(0, | 206 hotspot_.set_y(std::max(0, |
206 std::min(custom_size_.height() - 1, hotspot_.y()))); | 207 std::min(custom_size_.height() - 1, hotspot_.y()))); |
207 } | 208 } |
OLD | NEW |