Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(894)

Side by Side Diff: webkit/glue/webcursor.cc

Issue 155172: Start using WebCursorInfo from the WebKit API. WebCursorInfo is a... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/webcursor.h ('k') | webkit/glue/webcursor_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
8 #include "NativeImageSkia.h"
9 #include "PlatformCursor.h"
10
11 #undef LOG
12 #include "base/logging.h" 7 #include "base/logging.h"
13 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "webkit/api/public/WebCursorInfo.h"
10 #include "webkit/api/public/WebImage.h"
11
12 using WebKit::WebCursorInfo;
13 using WebKit::WebImage;
14 14
15 static const int kMaxCursorDimension = 1024; 15 static const int kMaxCursorDimension = 1024;
16 16
17 WebCursor::WebCursor() 17 WebCursor::WebCursor()
18 : type_(WebCore::PlatformCursor::TypePointer) { 18 : type_(WebCursorInfo::TypePointer) {
19 InitPlatformData(); 19 InitPlatformData();
20 } 20 }
21 21
22 WebCursor::WebCursor(const WebCore::PlatformCursor& platform_cursor) 22 WebCursor::WebCursor(const WebCursorInfo& cursor_info)
23 : type_(platform_cursor.type()), 23 : type_(WebCursorInfo::TypePointer) {
24 hotspot_(platform_cursor.hotSpot().x(), platform_cursor.hotSpot().y()) {
25 if (IsCustom())
26 SetCustomData(platform_cursor.customImage().get());
27
28 InitPlatformData(); 24 InitPlatformData();
25 InitFromCursorInfo(cursor_info);
29 } 26 }
30 27
31 WebCursor::~WebCursor() { 28 WebCursor::~WebCursor() {
32 Clear(); 29 Clear();
33 } 30 }
34 31
35 WebCursor::WebCursor(const WebCursor& other) { 32 WebCursor::WebCursor(const WebCursor& other) {
36 InitPlatformData(); 33 InitPlatformData();
37 Copy(other); 34 Copy(other);
38 } 35 }
39 36
40 const WebCursor& WebCursor::operator=(const WebCursor& other) { 37 const WebCursor& WebCursor::operator=(const WebCursor& other) {
41 if (this == &other) 38 if (this == &other)
42 return *this; 39 return *this;
43 40
44 Clear(); 41 Clear();
45 Copy(other); 42 Copy(other);
46 return *this; 43 return *this;
47 } 44 }
48 45
46 void WebCursor::InitFromCursorInfo(const WebCursorInfo& cursor_info) {
47 Clear();
48
49 #if defined(OS_WIN)
50 if (cursor_info.externalHandle) {
51 InitFromExternalCursor(cursor_info.externalHandle);
52 return;
53 }
54 #endif
55
56 type_ = cursor_info.type;
57 hotspot_ = cursor_info.hotSpot;
58 if (IsCustom())
59 SetCustomData(cursor_info.customImage);
60 }
61
62 void WebCursor::GetCursorInfo(WebCursorInfo* cursor_info) const {
63 cursor_info->type = static_cast<WebCursorInfo::Type>(type_);
64 cursor_info->hotSpot = hotspot_;
65 ImageFromCustomData(&cursor_info->customImage);
66
67 #if defined(OS_WIN)
68 cursor_info->externalHandle = external_cursor_;
69 #endif
70 }
71
49 bool WebCursor::Deserialize(const Pickle* pickle, void** iter) { 72 bool WebCursor::Deserialize(const Pickle* pickle, void** iter) {
50 int type, hotspot_x, hotspot_y, size_x, size_y, data_len; 73 int type, hotspot_x, hotspot_y, size_x, size_y, data_len;
51 74
52 const char* data; 75 const char* data;
53 76
54 // Leave |this| unmodified unless we are going to return success. 77 // Leave |this| unmodified unless we are going to return success.
55 if (!pickle->ReadInt(iter, &type) || 78 if (!pickle->ReadInt(iter, &type) ||
56 !pickle->ReadInt(iter, &hotspot_x) || 79 !pickle->ReadInt(iter, &hotspot_x) ||
57 !pickle->ReadInt(iter, &hotspot_y) || 80 !pickle->ReadInt(iter, &hotspot_y) ||
58 !pickle->ReadLength(iter, &size_x) || 81 !pickle->ReadLength(iter, &size_x) ||
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 const char* data = NULL; 118 const char* data = NULL;
96 if (!custom_data_.empty()) 119 if (!custom_data_.empty())
97 data = &custom_data_[0]; 120 data = &custom_data_[0];
98 if (!pickle->WriteData(data, custom_data_.size())) 121 if (!pickle->WriteData(data, custom_data_.size()))
99 return false; 122 return false;
100 123
101 return SerializePlatformData(pickle); 124 return SerializePlatformData(pickle);
102 } 125 }
103 126
104 bool WebCursor::IsCustom() const { 127 bool WebCursor::IsCustom() const {
105 return type_ == WebCore::PlatformCursor::TypeCustom; 128 return type_ == WebCursorInfo::TypeCustom;
106 } 129 }
107 130
108 bool WebCursor::IsEqual(const WebCursor& other) const { 131 bool WebCursor::IsEqual(const WebCursor& other) const {
109 if (type_ != other.type_) 132 if (type_ != other.type_)
110 return false; 133 return false;
111 134
112 if (!IsPlatformDataEqual(other)) 135 if (!IsPlatformDataEqual(other))
113 return false; 136 return false;
114 137
115 return hotspot_ == other.hotspot_ && 138 return hotspot_ == other.hotspot_ &&
116 custom_size_ == other.custom_size_ && 139 custom_size_ == other.custom_size_ &&
117 custom_data_ == other.custom_data_; 140 custom_data_ == other.custom_data_;
118 } 141 }
119 142
120 void WebCursor::Clear() { 143 void WebCursor::Clear() {
121 type_ = WebCore::PlatformCursor::TypePointer; 144 type_ = WebCursorInfo::TypePointer;
122 hotspot_.set_x(0); 145 hotspot_.set_x(0);
123 hotspot_.set_y(0); 146 hotspot_.set_y(0);
124 custom_size_.set_width(0); 147 custom_size_.set_width(0);
125 custom_size_.set_height(0); 148 custom_size_.set_height(0);
126 custom_data_.clear(); 149 custom_data_.clear();
127 CleanupPlatformData(); 150 CleanupPlatformData();
128 } 151 }
129 152
130 void WebCursor::Copy(const WebCursor& other) { 153 void WebCursor::Copy(const WebCursor& other) {
131 type_ = other.type_; 154 type_ = other.type_;
132 hotspot_ = other.hotspot_; 155 hotspot_ = other.hotspot_;
133 custom_size_ = other.custom_size_; 156 custom_size_ = other.custom_size_;
134 custom_data_ = other.custom_data_; 157 custom_data_ = other.custom_data_;
135 CopyPlatformData(other); 158 CopyPlatformData(other);
136 } 159 }
137 160
138 #if !defined(OS_MACOSX) 161 #if WEBKIT_USING_SKIA
139 // The Mac version of Chromium is built with PLATFORM(CG) while all other 162 // The WEBKIT_USING_CG implementation is in webcursor_mac.mm.
140 // versions are PLATFORM(SKIA). We'll keep this Skia implementation here for 163 void WebCursor::SetCustomData(const WebImage& image) {
141 // common use and put the Mac implementation in webcursor_mac.mm. 164 if (image.isNull())
142 void WebCursor::SetCustomData(WebCore::Image* image) {
143 if (!image)
144 return;
145
146 WebCore::NativeImagePtr image_ptr = image->nativeImageForCurrentFrame();
147 if (!image_ptr)
148 return; 165 return;
149 166
150 // Fill custom_data_ directly with the NativeImage pixels. 167 // Fill custom_data_ directly with the NativeImage pixels.
151 SkAutoLockPixels bitmap_lock(*image_ptr); 168 const SkBitmap& bitmap = image.getSkBitmap();
152 custom_data_.resize(image_ptr->getSize()); 169 SkAutoLockPixels bitmap_lock(bitmap);
153 memcpy(&custom_data_[0], image_ptr->getPixels(), image_ptr->getSize()); 170 custom_data_.resize(bitmap.getSize());
154 custom_size_.set_width(image_ptr->width()); 171 memcpy(&custom_data_[0], bitmap.getPixels(), bitmap.getSize());
155 custom_size_.set_height(image_ptr->height()); 172 custom_size_.set_width(bitmap.width());
173 custom_size_.set_height(bitmap.height());
174 }
175
176 void WebCursor::ImageFromCustomData(WebImage* image) const {
177 if (custom_data_.empty())
178 return;
179
180 SkBitmap bitmap;
181 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
182 custom_size_.width(),
183 custom_size_.height());
184 if (!bitmap.allocPixels())
185 return;
186 memcpy(bitmap.getPixels(), &custom_data_[0], custom_data_.size());
187
188 image->assign(bitmap);
156 } 189 }
157 #endif 190 #endif
OLDNEW
« no previous file with comments | « webkit/glue/webcursor.h ('k') | webkit/glue/webcursor_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698