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