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 "ui/base/clipboard/clipboard.h" | 5 #include "ui/base/clipboard/clipboard.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 bool IsFormatAvailable(AuraClipboardFormat format) const { | 179 bool IsFormatAvailable(AuraClipboardFormat format) const { |
180 switch (format) { | 180 switch (format) { |
181 case TEXT: | 181 case TEXT: |
182 return HasFormat(TEXT) || HasFormat(BOOKMARK); | 182 return HasFormat(TEXT) || HasFormat(BOOKMARK); |
183 default: | 183 default: |
184 return HasFormat(format); | 184 return HasFormat(format); |
185 } | 185 } |
186 } | 186 } |
187 | 187 |
188 // Reads text from the data at the top of clipboard stack. | 188 // Reads text from the data at the top of clipboard stack. |
189 void ReadText(string16* result) const { | 189 void ReadText(base::string16* result) const { |
190 std::string utf8_result; | 190 std::string utf8_result; |
191 ReadAsciiText(&utf8_result); | 191 ReadAsciiText(&utf8_result); |
192 *result = UTF8ToUTF16(utf8_result); | 192 *result = UTF8ToUTF16(utf8_result); |
193 } | 193 } |
194 | 194 |
195 // Reads ascii text from the data at the top of clipboard stack. | 195 // Reads ascii text from the data at the top of clipboard stack. |
196 void ReadAsciiText(std::string* result) const { | 196 void ReadAsciiText(std::string* result) const { |
197 result->clear(); | 197 result->clear(); |
198 const ClipboardData* data = GetData(); | 198 const ClipboardData* data = GetData(); |
199 if (!data) | 199 if (!data) |
200 return; | 200 return; |
201 if (HasFormat(TEXT)) | 201 if (HasFormat(TEXT)) |
202 *result = data->text(); | 202 *result = data->text(); |
203 else if (HasFormat(HTML)) | 203 else if (HasFormat(HTML)) |
204 *result = data->markup_data(); | 204 *result = data->markup_data(); |
205 else if (HasFormat(BOOKMARK)) | 205 else if (HasFormat(BOOKMARK)) |
206 *result = data->bookmark_url(); | 206 *result = data->bookmark_url(); |
207 } | 207 } |
208 | 208 |
209 // Reads HTML from the data at the top of clipboard stack. | 209 // Reads HTML from the data at the top of clipboard stack. |
210 void ReadHTML(string16* markup, | 210 void ReadHTML(base::string16* markup, |
211 std::string* src_url, | 211 std::string* src_url, |
212 uint32* fragment_start, | 212 uint32* fragment_start, |
213 uint32* fragment_end) const { | 213 uint32* fragment_end) const { |
214 markup->clear(); | 214 markup->clear(); |
215 if (src_url) | 215 if (src_url) |
216 src_url->clear(); | 216 src_url->clear(); |
217 *fragment_start = 0; | 217 *fragment_start = 0; |
218 *fragment_end = 0; | 218 *fragment_end = 0; |
219 | 219 |
220 if (!HasFormat(HTML)) | 220 if (!HasFormat(HTML)) |
(...skipping 24 matching lines...) Expand all Loading... |
245 if (!HasFormat(BITMAP)) | 245 if (!HasFormat(BITMAP)) |
246 return img; | 246 return img; |
247 | 247 |
248 // A shallow copy should be fine here, but just to be safe... | 248 // A shallow copy should be fine here, but just to be safe... |
249 const SkBitmap& clipboard_bitmap = GetData()->bitmap(); | 249 const SkBitmap& clipboard_bitmap = GetData()->bitmap(); |
250 clipboard_bitmap.copyTo(&img, clipboard_bitmap.getConfig()); | 250 clipboard_bitmap.copyTo(&img, clipboard_bitmap.getConfig()); |
251 return img; | 251 return img; |
252 } | 252 } |
253 | 253 |
254 // Reads data of type |type| from the data at the top of clipboard stack. | 254 // Reads data of type |type| from the data at the top of clipboard stack. |
255 void ReadCustomData(const string16& type, string16* result) const { | 255 void ReadCustomData(const base::string16& type, |
| 256 base::string16* result) const { |
256 result->clear(); | 257 result->clear(); |
257 const ClipboardData* data = GetData(); | 258 const ClipboardData* data = GetData(); |
258 if (!HasFormat(CUSTOM)) | 259 if (!HasFormat(CUSTOM)) |
259 return; | 260 return; |
260 | 261 |
261 ui::ReadCustomDataForType(data->custom_data_data().c_str(), | 262 ui::ReadCustomDataForType(data->custom_data_data().c_str(), |
262 data->custom_data_data().size(), | 263 data->custom_data_data().size(), |
263 type, result); | 264 type, result); |
264 } | 265 } |
265 | 266 |
266 // Reads bookmark from the data at the top of clipboard stack. | 267 // Reads bookmark from the data at the top of clipboard stack. |
267 void ReadBookmark(string16* title, std::string* url) const { | 268 void ReadBookmark(base::string16* title, std::string* url) const { |
268 title->clear(); | 269 title->clear(); |
269 url->clear(); | 270 url->clear(); |
270 if (!HasFormat(BOOKMARK)) | 271 if (!HasFormat(BOOKMARK)) |
271 return; | 272 return; |
272 | 273 |
273 const ClipboardData* data = GetData(); | 274 const ClipboardData* data = GetData(); |
274 *title = UTF8ToUTF16(data->bookmark_title()); | 275 *title = UTF8ToUTF16(data->bookmark_title()); |
275 *url = data->bookmark_url(); | 276 *url = data->bookmark_url(); |
276 } | 277 } |
277 | 278 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 475 } |
475 | 476 |
476 void Clipboard::Clear(ClipboardType type) { | 477 void Clipboard::Clear(ClipboardType type) { |
477 DCHECK(CalledOnValidThread()); | 478 DCHECK(CalledOnValidThread()); |
478 DCHECK(IsSupportedClipboardType(type)); | 479 DCHECK(IsSupportedClipboardType(type)); |
479 AuraClipboard* clipboard = GetClipboard(); | 480 AuraClipboard* clipboard = GetClipboard(); |
480 clipboard->Clear(); | 481 clipboard->Clear(); |
481 } | 482 } |
482 | 483 |
483 void Clipboard::ReadAvailableTypes(ClipboardType type, | 484 void Clipboard::ReadAvailableTypes(ClipboardType type, |
484 std::vector<string16>* types, | 485 std::vector<base::string16>* types, |
485 bool* contains_filenames) const { | 486 bool* contains_filenames) const { |
486 DCHECK(CalledOnValidThread()); | 487 DCHECK(CalledOnValidThread()); |
487 if (!types || !contains_filenames) { | 488 if (!types || !contains_filenames) { |
488 NOTREACHED(); | 489 NOTREACHED(); |
489 return; | 490 return; |
490 } | 491 } |
491 | 492 |
492 types->clear(); | 493 types->clear(); |
493 *contains_filenames = false; | 494 *contains_filenames = false; |
494 if (IsFormatAvailable(GetPlainTextFormatType(), type)) | 495 if (IsFormatAvailable(GetPlainTextFormatType(), type)) |
495 types->push_back(UTF8ToUTF16(GetPlainTextFormatType().ToString())); | 496 types->push_back(UTF8ToUTF16(GetPlainTextFormatType().ToString())); |
496 if (IsFormatAvailable(GetHtmlFormatType(), type)) | 497 if (IsFormatAvailable(GetHtmlFormatType(), type)) |
497 types->push_back(UTF8ToUTF16(GetHtmlFormatType().ToString())); | 498 types->push_back(UTF8ToUTF16(GetHtmlFormatType().ToString())); |
498 if (IsFormatAvailable(GetRtfFormatType(), type)) | 499 if (IsFormatAvailable(GetRtfFormatType(), type)) |
499 types->push_back(UTF8ToUTF16(GetRtfFormatType().ToString())); | 500 types->push_back(UTF8ToUTF16(GetRtfFormatType().ToString())); |
500 if (IsFormatAvailable(GetBitmapFormatType(), type)) | 501 if (IsFormatAvailable(GetBitmapFormatType(), type)) |
501 types->push_back(UTF8ToUTF16(kMimeTypePNG)); | 502 types->push_back(UTF8ToUTF16(kMimeTypePNG)); |
502 | 503 |
503 AuraClipboard* clipboard = GetClipboard(); | 504 AuraClipboard* clipboard = GetClipboard(); |
504 if (clipboard->IsFormatAvailable(CUSTOM) && clipboard->GetData()) { | 505 if (clipboard->IsFormatAvailable(CUSTOM) && clipboard->GetData()) { |
505 ui::ReadCustomDataTypes(clipboard->GetData()->custom_data_data().c_str(), | 506 ui::ReadCustomDataTypes(clipboard->GetData()->custom_data_data().c_str(), |
506 clipboard->GetData()->custom_data_data().size(), types); | 507 clipboard->GetData()->custom_data_data().size(), types); |
507 } | 508 } |
508 } | 509 } |
509 | 510 |
510 void Clipboard::ReadText(ClipboardType type, string16* result) const { | 511 void Clipboard::ReadText(ClipboardType type, base::string16* result) const { |
511 DCHECK(CalledOnValidThread()); | 512 DCHECK(CalledOnValidThread()); |
512 GetClipboard()->ReadText(result); | 513 GetClipboard()->ReadText(result); |
513 } | 514 } |
514 | 515 |
515 void Clipboard::ReadAsciiText(ClipboardType type, std::string* result) const { | 516 void Clipboard::ReadAsciiText(ClipboardType type, std::string* result) const { |
516 DCHECK(CalledOnValidThread()); | 517 DCHECK(CalledOnValidThread()); |
517 GetClipboard()->ReadAsciiText(result); | 518 GetClipboard()->ReadAsciiText(result); |
518 } | 519 } |
519 | 520 |
520 void Clipboard::ReadHTML(ClipboardType type, | 521 void Clipboard::ReadHTML(ClipboardType type, |
521 string16* markup, | 522 base::string16* markup, |
522 std::string* src_url, | 523 std::string* src_url, |
523 uint32* fragment_start, | 524 uint32* fragment_start, |
524 uint32* fragment_end) const { | 525 uint32* fragment_end) const { |
525 DCHECK(CalledOnValidThread()); | 526 DCHECK(CalledOnValidThread()); |
526 GetClipboard()->ReadHTML(markup, src_url, fragment_start, fragment_end); | 527 GetClipboard()->ReadHTML(markup, src_url, fragment_start, fragment_end); |
527 } | 528 } |
528 | 529 |
529 void Clipboard::ReadRTF(ClipboardType type, std::string* result) const { | 530 void Clipboard::ReadRTF(ClipboardType type, std::string* result) const { |
530 DCHECK(CalledOnValidThread()); | 531 DCHECK(CalledOnValidThread()); |
531 GetClipboard()->ReadRTF(result); | 532 GetClipboard()->ReadRTF(result); |
532 } | 533 } |
533 | 534 |
534 SkBitmap Clipboard::ReadImage(ClipboardType type) const { | 535 SkBitmap Clipboard::ReadImage(ClipboardType type) const { |
535 DCHECK(CalledOnValidThread()); | 536 DCHECK(CalledOnValidThread()); |
536 return GetClipboard()->ReadImage(); | 537 return GetClipboard()->ReadImage(); |
537 } | 538 } |
538 | 539 |
539 void Clipboard::ReadCustomData(ClipboardType clipboard_type, | 540 void Clipboard::ReadCustomData(ClipboardType clipboard_type, |
540 const string16& type, | 541 const base::string16& type, |
541 string16* result) const { | 542 base::string16* result) const { |
542 DCHECK(CalledOnValidThread()); | 543 DCHECK(CalledOnValidThread()); |
543 GetClipboard()->ReadCustomData(type, result); | 544 GetClipboard()->ReadCustomData(type, result); |
544 } | 545 } |
545 | 546 |
546 void Clipboard::ReadBookmark(string16* title, std::string* url) const { | 547 void Clipboard::ReadBookmark(base::string16* title, std::string* url) const { |
547 DCHECK(CalledOnValidThread()); | 548 DCHECK(CalledOnValidThread()); |
548 GetClipboard()->ReadBookmark(title, url); | 549 GetClipboard()->ReadBookmark(title, url); |
549 } | 550 } |
550 | 551 |
551 void Clipboard::ReadData(const FormatType& format, std::string* result) const { | 552 void Clipboard::ReadData(const FormatType& format, std::string* result) const { |
552 DCHECK(CalledOnValidThread()); | 553 DCHECK(CalledOnValidThread()); |
553 GetClipboard()->ReadData(format.ToString(), result); | 554 GetClipboard()->ReadData(format.ToString(), result); |
554 } | 555 } |
555 | 556 |
556 uint64 Clipboard::GetSequenceNumber(ClipboardType type) { | 557 uint64 Clipboard::GetSequenceNumber(ClipboardType type) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 return type; | 664 return type; |
664 } | 665 } |
665 | 666 |
666 // static | 667 // static |
667 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { | 668 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { |
668 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); | 669 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); |
669 return type; | 670 return type; |
670 } | 671 } |
671 | 672 |
672 } // namespace ui | 673 } // namespace ui |
OLD | NEW |