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(Buffer buffer) const { |
| 670 DCHECK_EQ(buffer, BUFFER_STANDARD); |
| 671 std::string result; |
| 672 ReadData(GetSourceTagFormatType(), &result); |
| 673 return Binary2SourceTag(result); |
| 674 } |
| 675 |
659 // static | 676 // static |
660 void Clipboard::ParseBookmarkClipboardFormat(const string16& bookmark, | 677 void Clipboard::ParseBookmarkClipboardFormat(const string16& bookmark, |
661 string16* title, | 678 string16* title, |
662 std::string* url) { | 679 std::string* url) { |
663 const string16 kDelim = ASCIIToUTF16("\r\n"); | 680 const string16 kDelim = ASCIIToUTF16("\r\n"); |
664 | 681 |
665 const size_t title_end = bookmark.find_first_of(kDelim); | 682 const size_t title_end = bookmark.find_first_of(kDelim); |
666 if (title) | 683 if (title) |
667 title->assign(bookmark.substr(0, title_end)); | 684 title->assign(bookmark.substr(0, title_end)); |
668 | 685 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 // static | 845 // static |
829 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { | 846 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { |
830 CR_DEFINE_STATIC_LOCAL( | 847 CR_DEFINE_STATIC_LOCAL( |
831 FormatType, | 848 FormatType, |
832 type, | 849 type, |
833 (ClipboardUtil::GetPepperCustomDataFormat()->cfFormat)); | 850 (ClipboardUtil::GetPepperCustomDataFormat()->cfFormat)); |
834 return type; | 851 return type; |
835 } | 852 } |
836 | 853 |
837 // static | 854 // 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 |
838 void Clipboard::FreeData(unsigned int format, HANDLE data) { | 864 void Clipboard::FreeData(unsigned int format, HANDLE data) { |
839 if (format == CF_BITMAP) | 865 if (format == CF_BITMAP) |
840 ::DeleteObject(static_cast<HBITMAP>(data)); | 866 ::DeleteObject(static_cast<HBITMAP>(data)); |
841 else | 867 else |
842 ::GlobalFree(data); | 868 ::GlobalFree(data); |
843 } | 869 } |
844 | 870 |
845 HWND Clipboard::GetClipboardWindow() const { | 871 HWND Clipboard::GetClipboardWindow() const { |
846 if (!clipboard_owner_ && create_window_) { | 872 if (!clipboard_owner_ && create_window_) { |
847 clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass", | 873 clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass", |
848 L"ClipboardOwnerWindow", | 874 L"ClipboardOwnerWindow", |
849 0, 0, 0, 0, 0, | 875 0, 0, 0, 0, 0, |
850 HWND_MESSAGE, | 876 HWND_MESSAGE, |
851 0, 0, 0); | 877 0, 0, 0); |
852 } | 878 } |
853 return clipboard_owner_; | 879 return clipboard_owner_; |
854 } | 880 } |
855 | 881 |
856 } // namespace ui | 882 } // namespace ui |
OLD | NEW |