| 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 // 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 201 |
| 202 clipboard_owner_ = NULL; | 202 clipboard_owner_ = NULL; |
| 203 } | 203 } |
| 204 | 204 |
| 205 Clipboard::~Clipboard() { | 205 Clipboard::~Clipboard() { |
| 206 if (clipboard_owner_) | 206 if (clipboard_owner_) |
| 207 ::DestroyWindow(clipboard_owner_); | 207 ::DestroyWindow(clipboard_owner_); |
| 208 clipboard_owner_ = NULL; | 208 clipboard_owner_ = NULL; |
| 209 } | 209 } |
| 210 | 210 |
| 211 void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) { | 211 void Clipboard::WriteObjectsImpl(Buffer buffer, |
| 212 const ObjectMap& objects, |
| 213 SourceTag tag) { |
| 212 DCHECK_EQ(buffer, BUFFER_STANDARD); | 214 DCHECK_EQ(buffer, BUFFER_STANDARD); |
| 213 | 215 |
| 214 ScopedClipboard clipboard; | 216 ScopedClipboard clipboard; |
| 215 if (!clipboard.Acquire(GetClipboardWindow())) | 217 if (!clipboard.Acquire(GetClipboardWindow())) |
| 216 return; | 218 return; |
| 217 | 219 |
| 218 ::EmptyClipboard(); | 220 ::EmptyClipboard(); |
| 219 | 221 |
| 220 for (ObjectMap::const_iterator iter = objects.begin(); | 222 for (ObjectMap::const_iterator iter = objects.begin(); |
| 221 iter != objects.end(); ++iter) { | 223 iter != objects.end(); ++iter) { |
| 222 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); | 224 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); |
| 223 } | 225 } |
| 226 WriteSourceTag(tag); |
| 224 } | 227 } |
| 225 | 228 |
| 226 void Clipboard::WriteText(const char* text_data, size_t text_len) { | 229 void Clipboard::WriteText(const char* text_data, size_t text_len) { |
| 227 string16 text; | 230 string16 text; |
| 228 UTF8ToUTF16(text_data, text_len, &text); | 231 UTF8ToUTF16(text_data, text_len, &text); |
| 229 HGLOBAL glob = CreateGlobalData(text); | 232 HGLOBAL glob = CreateGlobalData(text); |
| 230 | 233 |
| 231 WriteToClipboard(CF_UNICODETEXT, glob); | 234 WriteToClipboard(CF_UNICODETEXT, glob); |
| 232 } | 235 } |
| 233 | 236 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 HGLOBAL hdata = ::GlobalAlloc(GMEM_MOVEABLE, data_len); | 357 HGLOBAL hdata = ::GlobalAlloc(GMEM_MOVEABLE, data_len); |
| 355 if (!hdata) | 358 if (!hdata) |
| 356 return; | 359 return; |
| 357 | 360 |
| 358 char* data = static_cast<char*>(::GlobalLock(hdata)); | 361 char* data = static_cast<char*>(::GlobalLock(hdata)); |
| 359 memcpy(data, data_data, data_len); | 362 memcpy(data, data_data, data_len); |
| 360 ::GlobalUnlock(data); | 363 ::GlobalUnlock(data); |
| 361 WriteToClipboard(format.ToUINT(), hdata); | 364 WriteToClipboard(format.ToUINT(), hdata); |
| 362 } | 365 } |
| 363 | 366 |
| 367 void Clipboard::WriteSourceTag(SourceTag tag) { |
| 368 if (tag != SourceTag()) { |
| 369 ObjectMapParam binary = SourceTag2Binary(tag); |
| 370 WriteData(GetSourceTagFormatType(), &binary[0], binary.size()); |
| 371 } |
| 372 } |
| 373 |
| 364 void Clipboard::WriteToClipboard(unsigned int format, HANDLE handle) { | 374 void Clipboard::WriteToClipboard(unsigned int format, HANDLE handle) { |
| 365 DCHECK(clipboard_owner_); | 375 DCHECK(clipboard_owner_); |
| 366 if (handle && !::SetClipboardData(format, handle)) { | 376 if (handle && !::SetClipboardData(format, handle)) { |
| 367 DCHECK(ERROR_CLIPBOARD_NOT_OPEN != GetLastError()); | 377 DCHECK(ERROR_CLIPBOARD_NOT_OPEN != GetLastError()); |
| 368 FreeData(format, handle); | 378 FreeData(format, handle); |
| 369 } | 379 } |
| 370 } | 380 } |
| 371 | 381 |
| 372 uint64 Clipboard::GetSequenceNumber(Buffer buffer) { | 382 uint64 Clipboard::GetSequenceNumber(Buffer buffer) { |
| 373 DCHECK_EQ(buffer, BUFFER_STANDARD); | 383 DCHECK_EQ(buffer, BUFFER_STANDARD); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 | 659 |
| 650 HANDLE data = ::GetClipboardData(format.ToUINT()); | 660 HANDLE data = ::GetClipboardData(format.ToUINT()); |
| 651 if (!data) | 661 if (!data) |
| 652 return; | 662 return; |
| 653 | 663 |
| 654 result->assign(static_cast<const char*>(::GlobalLock(data)), | 664 result->assign(static_cast<const char*>(::GlobalLock(data)), |
| 655 ::GlobalSize(data)); | 665 ::GlobalSize(data)); |
| 656 ::GlobalUnlock(data); | 666 ::GlobalUnlock(data); |
| 657 } | 667 } |
| 658 | 668 |
| 669 Clipboard::SourceTag Clipboard::ReadSourceTag() const { |
| 670 std::string result; |
| 671 ReadData(GetSourceTagFormatType(), &result); |
| 672 return Binary2SourceTag(result); |
| 673 } |
| 674 |
| 659 // static | 675 // static |
| 660 void Clipboard::ParseBookmarkClipboardFormat(const string16& bookmark, | 676 void Clipboard::ParseBookmarkClipboardFormat(const string16& bookmark, |
| 661 string16* title, | 677 string16* title, |
| 662 std::string* url) { | 678 std::string* url) { |
| 663 const string16 kDelim = ASCIIToUTF16("\r\n"); | 679 const string16 kDelim = ASCIIToUTF16("\r\n"); |
| 664 | 680 |
| 665 const size_t title_end = bookmark.find_first_of(kDelim); | 681 const size_t title_end = bookmark.find_first_of(kDelim); |
| 666 if (title) | 682 if (title) |
| 667 title->assign(bookmark.substr(0, title_end)); | 683 title->assign(bookmark.substr(0, title_end)); |
| 668 | 684 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 // static | 844 // static |
| 829 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { | 845 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { |
| 830 CR_DEFINE_STATIC_LOCAL( | 846 CR_DEFINE_STATIC_LOCAL( |
| 831 FormatType, | 847 FormatType, |
| 832 type, | 848 type, |
| 833 (ClipboardUtil::GetPepperCustomDataFormat()->cfFormat)); | 849 (ClipboardUtil::GetPepperCustomDataFormat()->cfFormat)); |
| 834 return type; | 850 return type; |
| 835 } | 851 } |
| 836 | 852 |
| 837 // static | 853 // static |
| 854 const Clipboard::FormatType& Clipboard::GetSourceTagFormatType() { |
| 855 CR_DEFINE_STATIC_LOCAL( |
| 856 FormatType, |
| 857 type, |
| 858 (ClipboardUtil::GetSourceTagFormat()->cfFormat)); |
| 859 return type; |
| 860 } |
| 861 |
| 862 // static |
| 838 void Clipboard::FreeData(unsigned int format, HANDLE data) { | 863 void Clipboard::FreeData(unsigned int format, HANDLE data) { |
| 839 if (format == CF_BITMAP) | 864 if (format == CF_BITMAP) |
| 840 ::DeleteObject(static_cast<HBITMAP>(data)); | 865 ::DeleteObject(static_cast<HBITMAP>(data)); |
| 841 else | 866 else |
| 842 ::GlobalFree(data); | 867 ::GlobalFree(data); |
| 843 } | 868 } |
| 844 | 869 |
| 845 HWND Clipboard::GetClipboardWindow() const { | 870 HWND Clipboard::GetClipboardWindow() const { |
| 846 if (!clipboard_owner_ && create_window_) { | 871 if (!clipboard_owner_ && create_window_) { |
| 847 clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass", | 872 clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass", |
| 848 L"ClipboardOwnerWindow", | 873 L"ClipboardOwnerWindow", |
| 849 0, 0, 0, 0, 0, | 874 0, 0, 0, 0, 0, |
| 850 HWND_MESSAGE, | 875 HWND_MESSAGE, |
| 851 0, 0, 0); | 876 0, 0, 0); |
| 852 } | 877 } |
| 853 return clipboard_owner_; | 878 return clipboard_owner_; |
| 854 } | 879 } |
| 855 | 880 |
| 856 } // namespace ui | 881 } // namespace ui |
| OLD | NEW |