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

Side by Side Diff: ui/base/clipboard/clipboard_win.cc

Issue 117983002: Prefix string16 with base:: in ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 7 years 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 | « ui/base/clipboard/clipboard_util_win.cc ('k') | ui/base/clipboard/custom_data_helper.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) 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 // Many of these functions are based on those found in 5 // Many of these functions are based on those found in
6 // webkit/port/platform/PasteboardWin.cpp 6 // webkit/port/platform/PasteboardWin.cpp
7 7
8 #include "ui/base/clipboard/clipboard.h" 8 #include "ui/base/clipboard/clipboard.h"
9 9
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 220
221 ::EmptyClipboard(); 221 ::EmptyClipboard();
222 222
223 for (ObjectMap::const_iterator iter = objects.begin(); 223 for (ObjectMap::const_iterator iter = objects.begin();
224 iter != objects.end(); ++iter) { 224 iter != objects.end(); ++iter) {
225 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); 225 DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
226 } 226 }
227 } 227 }
228 228
229 void Clipboard::WriteText(const char* text_data, size_t text_len) { 229 void Clipboard::WriteText(const char* text_data, size_t text_len) {
230 string16 text; 230 base::string16 text;
231 UTF8ToUTF16(text_data, text_len, &text); 231 UTF8ToUTF16(text_data, text_len, &text);
232 HGLOBAL glob = CreateGlobalData(text); 232 HGLOBAL glob = CreateGlobalData(text);
233 233
234 WriteToClipboard(CF_UNICODETEXT, glob); 234 WriteToClipboard(CF_UNICODETEXT, glob);
235 } 235 }
236 236
237 void Clipboard::WriteHTML(const char* markup_data, 237 void Clipboard::WriteHTML(const char* markup_data,
238 size_t markup_len, 238 size_t markup_len,
239 const char* url_data, 239 const char* url_data,
240 size_t url_len) { 240 size_t url_len) {
(...skipping 14 matching lines...) Expand all
255 } 255 }
256 256
257 void Clipboard::WriteBookmark(const char* title_data, 257 void Clipboard::WriteBookmark(const char* title_data,
258 size_t title_len, 258 size_t title_len,
259 const char* url_data, 259 const char* url_data,
260 size_t url_len) { 260 size_t url_len) {
261 std::string bookmark(title_data, title_len); 261 std::string bookmark(title_data, title_len);
262 bookmark.append(1, L'\n'); 262 bookmark.append(1, L'\n');
263 bookmark.append(url_data, url_len); 263 bookmark.append(url_data, url_len);
264 264
265 string16 wide_bookmark = UTF8ToWide(bookmark); 265 base::string16 wide_bookmark = UTF8ToWide(bookmark);
266 HGLOBAL glob = CreateGlobalData(wide_bookmark); 266 HGLOBAL glob = CreateGlobalData(wide_bookmark);
267 267
268 WriteToClipboard(GetUrlWFormatType().ToUINT(), glob); 268 WriteToClipboard(GetUrlWFormatType().ToUINT(), glob);
269 } 269 }
270 270
271 void Clipboard::WriteWebSmartPaste() { 271 void Clipboard::WriteWebSmartPaste() {
272 DCHECK(clipboard_owner_->hwnd() != NULL); 272 DCHECK(clipboard_owner_->hwnd() != NULL);
273 ::SetClipboardData(GetWebKitSmartPasteFormatType().ToUINT(), NULL); 273 ::SetClipboardData(GetWebKitSmartPasteFormatType().ToUINT(), NULL);
274 } 274 }
275 275
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 void Clipboard::Clear(ClipboardType type) { 388 void Clipboard::Clear(ClipboardType type) {
389 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); 389 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE);
390 ScopedClipboard clipboard; 390 ScopedClipboard clipboard;
391 if (!clipboard.Acquire(GetClipboardWindow())) 391 if (!clipboard.Acquire(GetClipboardWindow()))
392 return; 392 return;
393 393
394 ::EmptyClipboard(); 394 ::EmptyClipboard();
395 } 395 }
396 396
397 void Clipboard::ReadAvailableTypes(ClipboardType type, 397 void Clipboard::ReadAvailableTypes(ClipboardType type,
398 std::vector<string16>* types, 398 std::vector<base::string16>* types,
399 bool* contains_filenames) const { 399 bool* contains_filenames) const {
400 if (!types || !contains_filenames) { 400 if (!types || !contains_filenames) {
401 NOTREACHED(); 401 NOTREACHED();
402 return; 402 return;
403 } 403 }
404 404
405 types->clear(); 405 types->clear();
406 if (::IsClipboardFormatAvailable(GetPlainTextFormatType().ToUINT())) 406 if (::IsClipboardFormatAvailable(GetPlainTextFormatType().ToUINT()))
407 types->push_back(UTF8ToUTF16(kMimeTypeText)); 407 types->push_back(UTF8ToUTF16(kMimeTypeText));
408 if (::IsClipboardFormatAvailable(GetHtmlFormatType().ToUINT())) 408 if (::IsClipboardFormatAvailable(GetHtmlFormatType().ToUINT()))
(...skipping 10 matching lines...) Expand all
419 return; 419 return;
420 420
421 HANDLE hdata = ::GetClipboardData(GetWebCustomDataFormatType().ToUINT()); 421 HANDLE hdata = ::GetClipboardData(GetWebCustomDataFormatType().ToUINT());
422 if (!hdata) 422 if (!hdata)
423 return; 423 return;
424 424
425 ReadCustomDataTypes(::GlobalLock(hdata), ::GlobalSize(hdata), types); 425 ReadCustomDataTypes(::GlobalLock(hdata), ::GlobalSize(hdata), types);
426 ::GlobalUnlock(hdata); 426 ::GlobalUnlock(hdata);
427 } 427 }
428 428
429 void Clipboard::ReadText(ClipboardType type, string16* result) const { 429 void Clipboard::ReadText(ClipboardType type, base::string16* result) const {
430 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); 430 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE);
431 if (!result) { 431 if (!result) {
432 NOTREACHED(); 432 NOTREACHED();
433 return; 433 return;
434 } 434 }
435 435
436 result->clear(); 436 result->clear();
437 437
438 // Acquire the clipboard. 438 // Acquire the clipboard.
439 ScopedClipboard clipboard; 439 ScopedClipboard clipboard;
(...skipping 24 matching lines...) Expand all
464 464
465 HANDLE data = ::GetClipboardData(CF_TEXT); 465 HANDLE data = ::GetClipboardData(CF_TEXT);
466 if (!data) 466 if (!data)
467 return; 467 return;
468 468
469 result->assign(static_cast<const char*>(::GlobalLock(data))); 469 result->assign(static_cast<const char*>(::GlobalLock(data)));
470 ::GlobalUnlock(data); 470 ::GlobalUnlock(data);
471 } 471 }
472 472
473 void Clipboard::ReadHTML(ClipboardType type, 473 void Clipboard::ReadHTML(ClipboardType type,
474 string16* markup, 474 base::string16* markup,
475 std::string* src_url, 475 std::string* src_url,
476 uint32* fragment_start, 476 uint32* fragment_start,
477 uint32* fragment_end) const { 477 uint32* fragment_end) const {
478 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); 478 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE);
479 479
480 markup->clear(); 480 markup->clear();
481 // TODO(dcheng): Remove these checks, I don't think they should be optional. 481 // TODO(dcheng): Remove these checks, I don't think they should be optional.
482 DCHECK(src_url); 482 DCHECK(src_url);
483 if (src_url) 483 if (src_url)
484 src_url->clear(); 484 src_url->clear();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 BitmapHasInvalidPremultipliedColors(device_bitmap); 592 BitmapHasInvalidPremultipliedColors(device_bitmap);
593 if (has_invalid_alpha_channel) { 593 if (has_invalid_alpha_channel) {
594 MakeBitmapOpaque(device_bitmap); 594 MakeBitmapOpaque(device_bitmap);
595 } 595 }
596 } 596 }
597 597
598 return canvas.ExtractImageRep().sk_bitmap(); 598 return canvas.ExtractImageRep().sk_bitmap();
599 } 599 }
600 600
601 void Clipboard::ReadCustomData(ClipboardType clipboard_type, 601 void Clipboard::ReadCustomData(ClipboardType clipboard_type,
602 const string16& type, 602 const base::string16& type,
603 string16* result) const { 603 base::string16* result) const {
604 DCHECK_EQ(clipboard_type, CLIPBOARD_TYPE_COPY_PASTE); 604 DCHECK_EQ(clipboard_type, CLIPBOARD_TYPE_COPY_PASTE);
605 605
606 // Acquire the clipboard. 606 // Acquire the clipboard.
607 ScopedClipboard clipboard; 607 ScopedClipboard clipboard;
608 if (!clipboard.Acquire(GetClipboardWindow())) 608 if (!clipboard.Acquire(GetClipboardWindow()))
609 return; 609 return;
610 610
611 HANDLE hdata = ::GetClipboardData(GetWebCustomDataFormatType().ToUINT()); 611 HANDLE hdata = ::GetClipboardData(GetWebCustomDataFormatType().ToUINT());
612 if (!hdata) 612 if (!hdata)
613 return; 613 return;
614 614
615 ReadCustomDataForType(::GlobalLock(hdata), ::GlobalSize(hdata), type, result); 615 ReadCustomDataForType(::GlobalLock(hdata), ::GlobalSize(hdata), type, result);
616 ::GlobalUnlock(hdata); 616 ::GlobalUnlock(hdata);
617 } 617 }
618 618
619 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 619 void Clipboard::ReadBookmark(base::string16* title, std::string* url) const {
620 if (title) 620 if (title)
621 title->clear(); 621 title->clear();
622 622
623 if (url) 623 if (url)
624 url->clear(); 624 url->clear();
625 625
626 // Acquire the clipboard. 626 // Acquire the clipboard.
627 ScopedClipboard clipboard; 627 ScopedClipboard clipboard;
628 if (!clipboard.Acquire(GetClipboardWindow())) 628 if (!clipboard.Acquire(GetClipboardWindow()))
629 return; 629 return;
630 630
631 HANDLE data = ::GetClipboardData(GetUrlWFormatType().ToUINT()); 631 HANDLE data = ::GetClipboardData(GetUrlWFormatType().ToUINT());
632 if (!data) 632 if (!data)
633 return; 633 return;
634 634
635 string16 bookmark(static_cast<const char16*>(::GlobalLock(data))); 635 base::string16 bookmark(static_cast<const char16*>(::GlobalLock(data)));
636 ::GlobalUnlock(data); 636 ::GlobalUnlock(data);
637 637
638 ParseBookmarkClipboardFormat(bookmark, title, url); 638 ParseBookmarkClipboardFormat(bookmark, title, url);
639 } 639 }
640 640
641 void Clipboard::ReadData(const FormatType& format, std::string* result) const { 641 void Clipboard::ReadData(const FormatType& format, std::string* result) const {
642 if (!result) { 642 if (!result) {
643 NOTREACHED(); 643 NOTREACHED();
644 return; 644 return;
645 } 645 }
646 646
647 ScopedClipboard clipboard; 647 ScopedClipboard clipboard;
648 if (!clipboard.Acquire(GetClipboardWindow())) 648 if (!clipboard.Acquire(GetClipboardWindow()))
649 return; 649 return;
650 650
651 HANDLE data = ::GetClipboardData(format.ToUINT()); 651 HANDLE data = ::GetClipboardData(format.ToUINT());
652 if (!data) 652 if (!data)
653 return; 653 return;
654 654
655 result->assign(static_cast<const char*>(::GlobalLock(data)), 655 result->assign(static_cast<const char*>(::GlobalLock(data)),
656 ::GlobalSize(data)); 656 ::GlobalSize(data));
657 ::GlobalUnlock(data); 657 ::GlobalUnlock(data);
658 } 658 }
659 659
660 // static 660 // static
661 void Clipboard::ParseBookmarkClipboardFormat(const string16& bookmark, 661 void Clipboard::ParseBookmarkClipboardFormat(const base::string16& bookmark,
662 string16* title, 662 base::string16* title,
663 std::string* url) { 663 std::string* url) {
664 const string16 kDelim = ASCIIToUTF16("\r\n"); 664 const base::string16 kDelim = ASCIIToUTF16("\r\n");
665 665
666 const size_t title_end = bookmark.find_first_of(kDelim); 666 const size_t title_end = bookmark.find_first_of(kDelim);
667 if (title) 667 if (title)
668 title->assign(bookmark.substr(0, title_end)); 668 title->assign(bookmark.substr(0, title_end));
669 669
670 if (url) { 670 if (url) {
671 const size_t url_start = bookmark.find_first_not_of(kDelim, title_end); 671 const size_t url_start = bookmark.find_first_not_of(kDelim, title_end);
672 if (url_start != string16::npos) 672 if (url_start != base::string16::npos)
673 *url = UTF16ToUTF8(bookmark.substr(url_start, string16::npos)); 673 *url = UTF16ToUTF8(bookmark.substr(url_start, base::string16::npos));
674 } 674 }
675 } 675 }
676 676
677 // static 677 // static
678 Clipboard::FormatType Clipboard::GetFormatType( 678 Clipboard::FormatType Clipboard::GetFormatType(
679 const std::string& format_string) { 679 const std::string& format_string) {
680 return FormatType( 680 return FormatType(
681 ::RegisterClipboardFormat(ASCIIToWide(format_string).c_str())); 681 ::RegisterClipboardFormat(ASCIIToWide(format_string).c_str()));
682 } 682 }
683 683
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 if (!clipboard_owner_) 825 if (!clipboard_owner_)
826 return NULL; 826 return NULL;
827 827
828 if (clipboard_owner_->hwnd() == NULL) 828 if (clipboard_owner_->hwnd() == NULL)
829 clipboard_owner_->Create(base::Bind(&ClipboardOwnerWndProc)); 829 clipboard_owner_->Create(base::Bind(&ClipboardOwnerWndProc));
830 830
831 return clipboard_owner_->hwnd(); 831 return clipboard_owner_->hwnd();
832 } 832 }
833 833
834 } // namespace ui 834 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_util_win.cc ('k') | ui/base/clipboard/custom_data_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698