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 "content/common/cursors/webcursor.h" | 5 #include "content/common/cursors/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/public/platform/WebImage.h" | 9 #include "third_party/WebKit/public/platform/WebImage.h" |
10 | 10 |
11 using blink::WebCursorInfo; | 11 using blink::WebCursorInfo; |
12 | 12 |
13 static const int kMaxCursorDimension = 1024; | 13 static const int kMaxCursorDimension = 1024; |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 WebCursor::WebCursor() | 17 WebCursor::WebCursor() |
18 : type_(WebCursorInfo::TypePointer), | 18 : type_(WebCursorInfo::TypePointer), |
19 custom_scale_(1) { | 19 custom_scale_(1) { |
20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
21 external_cursor_ = NULL; | 21 external_cursor_ = nullptr; |
22 #endif | 22 #endif |
23 InitPlatformData(); | 23 InitPlatformData(); |
24 } | 24 } |
25 | 25 |
26 WebCursor::WebCursor(const CursorInfo& cursor_info) | 26 WebCursor::WebCursor(const CursorInfo& cursor_info) |
27 : type_(WebCursorInfo::TypePointer) { | 27 : type_(WebCursorInfo::TypePointer) { |
28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
29 external_cursor_ = NULL; | 29 external_cursor_ = nullptr; |
30 #endif | 30 #endif |
31 InitPlatformData(); | 31 InitPlatformData(); |
32 InitFromCursorInfo(cursor_info); | 32 InitFromCursorInfo(cursor_info); |
33 } | 33 } |
34 | 34 |
35 WebCursor::~WebCursor() { | 35 WebCursor::~WebCursor() { |
36 Clear(); | 36 Clear(); |
37 } | 37 } |
38 | 38 |
39 WebCursor::WebCursor(const WebCursor& other) { | 39 WebCursor::WebCursor(const WebCursor& other) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 bool WebCursor::Serialize(Pickle* pickle) const { | 135 bool WebCursor::Serialize(Pickle* pickle) const { |
136 if (!pickle->WriteInt(type_) || | 136 if (!pickle->WriteInt(type_) || |
137 !pickle->WriteInt(hotspot_.x()) || | 137 !pickle->WriteInt(hotspot_.x()) || |
138 !pickle->WriteInt(hotspot_.y()) || | 138 !pickle->WriteInt(hotspot_.y()) || |
139 !pickle->WriteInt(custom_size_.width()) || | 139 !pickle->WriteInt(custom_size_.width()) || |
140 !pickle->WriteInt(custom_size_.height()) || | 140 !pickle->WriteInt(custom_size_.height()) || |
141 !pickle->WriteFloat(custom_scale_)) | 141 !pickle->WriteFloat(custom_scale_)) |
142 return false; | 142 return false; |
143 | 143 |
144 const char* data = NULL; | 144 const char* data = nullptr; |
145 if (!custom_data_.empty()) | 145 if (!custom_data_.empty()) |
146 data = &custom_data_[0]; | 146 data = &custom_data_[0]; |
147 if (!pickle->WriteData(data, custom_data_.size())) | 147 if (!pickle->WriteData(data, custom_data_.size())) |
148 return false; | 148 return false; |
149 | 149 |
150 return SerializePlatformData(pickle); | 150 return SerializePlatformData(pickle); |
151 } | 151 } |
152 | 152 |
153 bool WebCursor::IsCustom() const { | 153 bool WebCursor::IsCustom() const { |
154 return type_ == WebCursorInfo::TypeCustom; | 154 return type_ == WebCursorInfo::TypeCustom; |
(...skipping 12 matching lines...) Expand all Loading... |
167 custom_data_ == other.custom_data_; | 167 custom_data_ == other.custom_data_; |
168 } | 168 } |
169 | 169 |
170 #if defined(OS_WIN) | 170 #if defined(OS_WIN) |
171 | 171 |
172 static WebCursorInfo::Type ToCursorType(HCURSOR cursor) { | 172 static WebCursorInfo::Type ToCursorType(HCURSOR cursor) { |
173 static struct { | 173 static struct { |
174 HCURSOR cursor; | 174 HCURSOR cursor; |
175 WebCursorInfo::Type type; | 175 WebCursorInfo::Type type; |
176 } kStandardCursors[] = { | 176 } kStandardCursors[] = { |
177 { LoadCursor(NULL, IDC_ARROW), WebCursorInfo::TypePointer }, | 177 { LoadCursor(nullptr, IDC_ARROW), WebCursorInfo::TypePointer }, |
178 { LoadCursor(NULL, IDC_CROSS), WebCursorInfo::TypeCross }, | 178 { LoadCursor(nullptr, IDC_CROSS), WebCursorInfo::TypeCross }, |
179 { LoadCursor(NULL, IDC_HAND), WebCursorInfo::TypeHand }, | 179 { LoadCursor(nullptr, IDC_HAND), WebCursorInfo::TypeHand }, |
180 { LoadCursor(NULL, IDC_IBEAM), WebCursorInfo::TypeIBeam }, | 180 { LoadCursor(nullptr, IDC_IBEAM), WebCursorInfo::TypeIBeam }, |
181 { LoadCursor(NULL, IDC_WAIT), WebCursorInfo::TypeWait }, | 181 { LoadCursor(nullptr, IDC_WAIT), WebCursorInfo::TypeWait }, |
182 { LoadCursor(NULL, IDC_HELP), WebCursorInfo::TypeHelp }, | 182 { LoadCursor(nullptr, IDC_HELP), WebCursorInfo::TypeHelp }, |
183 { LoadCursor(NULL, IDC_SIZENESW), WebCursorInfo::TypeNorthEastResize }, | 183 { LoadCursor(nullptr, IDC_SIZENESW), |
184 { LoadCursor(NULL, IDC_SIZENWSE), WebCursorInfo::TypeNorthWestResize }, | 184 WebCursorInfo::TypeNorthEastResize }, |
185 { LoadCursor(NULL, IDC_SIZENS), WebCursorInfo::TypeNorthSouthResize }, | 185 { LoadCursor(nullptr, IDC_SIZENWSE), |
186 { LoadCursor(NULL, IDC_SIZEWE), WebCursorInfo::TypeEastWestResize }, | 186 WebCursorInfo::TypeNorthWestResize }, |
187 { LoadCursor(NULL, IDC_SIZEALL), WebCursorInfo::TypeMove }, | 187 { LoadCursor(nullptr, IDC_SIZENS), |
188 { LoadCursor(NULL, IDC_APPSTARTING), WebCursorInfo::TypeProgress }, | 188 WebCursorInfo::TypeNorthSouthResize }, |
189 { LoadCursor(NULL, IDC_NO), WebCursorInfo::TypeNotAllowed }, | 189 { LoadCursor(nullptr, IDC_SIZEWE), WebCursorInfo::TypeEastWestResize }, |
| 190 { LoadCursor(nullptr, IDC_SIZEALL), WebCursorInfo::TypeMove }, |
| 191 { LoadCursor(nullptr, IDC_APPSTARTING), WebCursorInfo::TypeProgress }, |
| 192 { LoadCursor(nullptr, IDC_NO), WebCursorInfo::TypeNotAllowed }, |
190 }; | 193 }; |
191 for (int i = 0; i < arraysize(kStandardCursors); ++i) { | 194 for (int i = 0; i < arraysize(kStandardCursors); ++i) { |
192 if (cursor == kStandardCursors[i].cursor) | 195 if (cursor == kStandardCursors[i].cursor) |
193 return kStandardCursors[i].type; | 196 return kStandardCursors[i].type; |
194 } | 197 } |
195 return WebCursorInfo::TypeCustom; | 198 return WebCursorInfo::TypeCustom; |
196 } | 199 } |
197 | 200 |
198 void WebCursor::InitFromExternalCursor(HCURSOR cursor) { | 201 void WebCursor::InitFromExternalCursor(HCURSOR cursor) { |
199 WebCursorInfo::Type cursor_type = ToCursorType(cursor); | 202 WebCursorInfo::Type cursor_type = ToCursorType(cursor); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 return; | 256 return; |
254 | 257 |
255 // Clamp the hotspot to the custom image's dimensions. | 258 // Clamp the hotspot to the custom image's dimensions. |
256 hotspot_.set_x(std::max(0, | 259 hotspot_.set_x(std::max(0, |
257 std::min(custom_size_.width() - 1, hotspot_.x()))); | 260 std::min(custom_size_.width() - 1, hotspot_.x()))); |
258 hotspot_.set_y(std::max(0, | 261 hotspot_.set_y(std::max(0, |
259 std::min(custom_size_.height() - 1, hotspot_.y()))); | 262 std::min(custom_size_.height() - 1, hotspot_.y()))); |
260 } | 263 } |
261 | 264 |
262 } // namespace content | 265 } // namespace content |
OLD | NEW |