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 "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" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 158 } |
159 | 159 |
160 void WebCursor::Copy(const WebCursor& other) { | 160 void WebCursor::Copy(const WebCursor& other) { |
161 type_ = other.type_; | 161 type_ = other.type_; |
162 hotspot_ = other.hotspot_; | 162 hotspot_ = other.hotspot_; |
163 custom_size_ = other.custom_size_; | 163 custom_size_ = other.custom_size_; |
164 custom_data_ = other.custom_data_; | 164 custom_data_ = other.custom_data_; |
165 CopyPlatformData(other); | 165 CopyPlatformData(other); |
166 } | 166 } |
167 | 167 |
168 #if WEBKIT_USING_SKIA | |
169 // The WEBKIT_USING_CG implementation is in webcursor_mac.mm. | |
170 void WebCursor::SetCustomData(const WebImage& image) { | 168 void WebCursor::SetCustomData(const WebImage& image) { |
171 if (image.isNull()) | 169 if (image.isNull()) |
172 return; | 170 return; |
173 | 171 |
174 // Fill custom_data_ directly with the NativeImage pixels. | 172 // Fill custom_data_ directly with the NativeImage pixels. |
175 const SkBitmap& bitmap = image.getSkBitmap(); | 173 const SkBitmap& bitmap = image.getSkBitmap(); |
176 SkAutoLockPixels bitmap_lock(bitmap); | 174 SkAutoLockPixels bitmap_lock(bitmap); |
177 custom_data_.resize(bitmap.getSize()); | 175 custom_data_.resize(bitmap.getSize()); |
178 if (!custom_data_.empty()) | 176 if (!custom_data_.empty()) |
179 memcpy(&custom_data_[0], bitmap.getPixels(), bitmap.getSize()); | 177 memcpy(&custom_data_[0], bitmap.getPixels(), bitmap.getSize()); |
180 custom_size_.set_width(bitmap.width()); | 178 custom_size_.set_width(bitmap.width()); |
181 custom_size_.set_height(bitmap.height()); | 179 custom_size_.set_height(bitmap.height()); |
182 } | 180 } |
183 | 181 |
184 void WebCursor::ImageFromCustomData(WebImage* image) const { | 182 void WebCursor::ImageFromCustomData(WebImage* image) const { |
185 if (custom_data_.empty()) | 183 if (custom_data_.empty()) |
186 return; | 184 return; |
187 | 185 |
188 SkBitmap bitmap; | 186 SkBitmap bitmap; |
189 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 187 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
190 custom_size_.width(), | 188 custom_size_.width(), |
191 custom_size_.height()); | 189 custom_size_.height()); |
192 if (!bitmap.allocPixels()) | 190 if (!bitmap.allocPixels()) |
193 return; | 191 return; |
194 memcpy(bitmap.getPixels(), &custom_data_[0], custom_data_.size()); | 192 memcpy(bitmap.getPixels(), &custom_data_[0], custom_data_.size()); |
195 | 193 |
196 image->assign(bitmap); | 194 image->assign(bitmap); |
197 } | 195 } |
198 #endif | |
199 | 196 |
200 void WebCursor::ClampHotspot() { | 197 void WebCursor::ClampHotspot() { |
201 if (!IsCustom()) | 198 if (!IsCustom()) |
202 return; | 199 return; |
203 | 200 |
204 // Clamp the hotspot to the custom image's dimensions. | 201 // Clamp the hotspot to the custom image's dimensions. |
205 hotspot_.set_x(std::max(0, | 202 hotspot_.set_x(std::max(0, |
206 std::min(custom_size_.width() - 1, hotspot_.x()))); | 203 std::min(custom_size_.width() - 1, hotspot_.x()))); |
207 hotspot_.set_y(std::max(0, | 204 hotspot_.set_y(std::max(0, |
208 std::min(custom_size_.height() - 1, hotspot_.y()))); | 205 std::min(custom_size_.height() - 1, hotspot_.y()))); |
209 } | 206 } |
OLD | NEW |