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/dragdrop/os_exchange_data_provider_win.h" | 5 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 new DataObjectImpl::StoredDataInfo(CF_TEXT, storage)); | 320 new DataObjectImpl::StoredDataInfo(CF_TEXT, storage)); |
321 } | 321 } |
322 | 322 |
323 void OSExchangeDataProviderWin::SetFilename(const FilePath& path) { | 323 void OSExchangeDataProviderWin::SetFilename(const FilePath& path) { |
324 STGMEDIUM* storage = GetStorageForFileName(path); | 324 STGMEDIUM* storage = GetStorageForFileName(path); |
325 DataObjectImpl::StoredDataInfo* info = | 325 DataObjectImpl::StoredDataInfo* info = |
326 new DataObjectImpl::StoredDataInfo(CF_HDROP, storage); | 326 new DataObjectImpl::StoredDataInfo(CF_HDROP, storage); |
327 data_->contents_.push_back(info); | 327 data_->contents_.push_back(info); |
328 } | 328 } |
329 | 329 |
| 330 void OSExchangeDataProviderWin::SetFilenames( |
| 331 const std::vector<OSExchangeData::FileInfo>& filenames) { |
| 332 for (size_t i = 0; i < filenames.size(); ++i) { |
| 333 STGMEDIUM* storage = GetStorageForFileName(filenames[i].path); |
| 334 DataObjectImpl::StoredDataInfo* info = |
| 335 new DataObjectImpl::StoredDataInfo(CF_HDROP, storage); |
| 336 data_->contents_.push_back(info); |
| 337 } |
| 338 } |
| 339 |
330 void OSExchangeDataProviderWin::SetPickledData(CLIPFORMAT format, | 340 void OSExchangeDataProviderWin::SetPickledData(CLIPFORMAT format, |
331 const Pickle& data) { | 341 const Pickle& data) { |
332 STGMEDIUM* storage = GetStorageForBytes(static_cast<const char*>(data.data()), | 342 STGMEDIUM* storage = GetStorageForBytes(static_cast<const char*>(data.data()), |
333 data.size()); | 343 data.size()); |
334 data_->contents_.push_back( | 344 data_->contents_.push_back( |
335 new DataObjectImpl::StoredDataInfo(format, storage)); | 345 new DataObjectImpl::StoredDataInfo(format, storage)); |
336 } | 346 } |
337 | 347 |
338 void OSExchangeDataProviderWin::SetFileContents( | 348 void OSExchangeDataProviderWin::SetFileContents( |
339 const FilePath& filename, | 349 const FilePath& filename, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 } | 398 } |
389 | 399 |
390 bool OSExchangeDataProviderWin::GetFilename(FilePath* path) const { | 400 bool OSExchangeDataProviderWin::GetFilename(FilePath* path) const { |
391 std::vector<string16> filenames; | 401 std::vector<string16> filenames; |
392 bool success = ClipboardUtil::GetFilenames(source_object_, &filenames); | 402 bool success = ClipboardUtil::GetFilenames(source_object_, &filenames); |
393 if (success) | 403 if (success) |
394 *path = FilePath(filenames[0]); | 404 *path = FilePath(filenames[0]); |
395 return success; | 405 return success; |
396 } | 406 } |
397 | 407 |
| 408 bool OSExchangeDataProviderWin::GetFilenames( |
| 409 std::vector<OSExchangeData::FileInfo>* filenames) const { |
| 410 std::vector<string16> filenames_local; |
| 411 bool success = ClipboardUtil::GetFilenames(source_object_, &filenames_local); |
| 412 if (success) { |
| 413 for (size_t i = 0; i < filenames_local.size(); ++i) |
| 414 filenames->push_back( |
| 415 OSExchangeData::FileInfo(FilePath(filenames_local[i]), FilePath())); |
| 416 } |
| 417 return success; |
| 418 } |
| 419 |
398 bool OSExchangeDataProviderWin::GetPickledData(CLIPFORMAT format, | 420 bool OSExchangeDataProviderWin::GetPickledData(CLIPFORMAT format, |
399 Pickle* data) const { | 421 Pickle* data) const { |
400 DCHECK(data); | 422 DCHECK(data); |
401 FORMATETC format_etc = | 423 FORMATETC format_etc = |
402 { format, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; | 424 { format, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; |
403 bool success = false; | 425 bool success = false; |
404 STGMEDIUM medium; | 426 STGMEDIUM medium; |
405 if (SUCCEEDED(source_object_->GetData(&format_etc, &medium))) { | 427 if (SUCCEEDED(source_object_->GetData(&format_etc, &medium))) { |
406 if (medium.tymed & TYMED_HGLOBAL) { | 428 if (medium.tymed & TYMED_HGLOBAL) { |
407 base::win::ScopedHGlobal<char> c_data(medium.hGlobal); | 429 base::win::ScopedHGlobal<char> c_data(medium.hGlobal); |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 return new OSExchangeDataProviderWin(); | 965 return new OSExchangeDataProviderWin(); |
944 } | 966 } |
945 | 967 |
946 // static | 968 // static |
947 OSExchangeData::CustomFormat OSExchangeData::RegisterCustomFormat( | 969 OSExchangeData::CustomFormat OSExchangeData::RegisterCustomFormat( |
948 const std::string& type) { | 970 const std::string& type) { |
949 return RegisterClipboardFormat(ASCIIToUTF16(type).c_str()); | 971 return RegisterClipboardFormat(ASCIIToUTF16(type).c_str()); |
950 } | 972 } |
951 | 973 |
952 } // namespace ui | 974 } // namespace ui |
OLD | NEW |