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

Side by Side Diff: ui/base/dragdrop/os_exchange_data_provider_win.cc

Issue 2322253004: Drag and dropping text, parsable as url (Closed)
Patch Set: initial patch for windows Created 4 years, 3 months 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
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 #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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 215 }
216 // Carry over 216 // Carry over
217 e->cursor_ = other->cursor_; 217 e->cursor_ = other->cursor_;
218 return e; 218 return e;
219 } 219 }
220 220
221 /////////////////////////////////////////////////////////////////////////////// 221 ///////////////////////////////////////////////////////////////////////////////
222 // OSExchangeDataProviderWin, public: 222 // OSExchangeDataProviderWin, public:
223 223
224 // static 224 // static
225 bool OSExchangeDataProviderWin::HasPlainTextURL(IDataObject* source) {
226 base::string16 plain_text;
227 return (ClipboardUtil::GetPlainText(source, &plain_text) &&
228 !plain_text.empty() && GURL(plain_text).is_valid());
229 }
230
231 // static
232 bool OSExchangeDataProviderWin::GetPlainTextURL(IDataObject* source,
233 GURL* url) {
234 base::string16 plain_text;
235 if (ClipboardUtil::GetPlainText(source, &plain_text) &&
236 !plain_text.empty()) {
237 GURL gurl(plain_text);
238 if (gurl.is_valid()) {
239 *url = gurl;
240 return true;
241 }
242 }
243 return false;
244 }
245
246 // static
247 DataObjectImpl* OSExchangeDataProviderWin::GetDataObjectImpl( 225 DataObjectImpl* OSExchangeDataProviderWin::GetDataObjectImpl(
248 const OSExchangeData& data) { 226 const OSExchangeData& data) {
249 return static_cast<const OSExchangeDataProviderWin*>(&data.provider())-> 227 return static_cast<const OSExchangeDataProviderWin*>(&data.provider())->
250 data_.get(); 228 data_.get();
251 } 229 }
252 230
253 // static 231 // static
254 IDataObject* OSExchangeDataProviderWin::GetIDataObject( 232 IDataObject* OSExchangeDataProviderWin::GetIDataObject(
255 const OSExchangeData& data) { 233 const OSExchangeData& data) {
256 return static_cast<const OSExchangeDataProviderWin*>(&data.provider())-> 234 return static_cast<const OSExchangeDataProviderWin*>(&data.provider())->
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 385
408 bool OSExchangeDataProviderWin::GetString(base::string16* data) const { 386 bool OSExchangeDataProviderWin::GetString(base::string16* data) const {
409 return ClipboardUtil::GetPlainText(source_object_.get(), data); 387 return ClipboardUtil::GetPlainText(source_object_.get(), data);
410 } 388 }
411 389
412 bool OSExchangeDataProviderWin::GetURLAndTitle( 390 bool OSExchangeDataProviderWin::GetURLAndTitle(
413 OSExchangeData::FilenameToURLPolicy policy, 391 OSExchangeData::FilenameToURLPolicy policy,
414 GURL* url, 392 GURL* url,
415 base::string16* title) const { 393 base::string16* title) const {
416 base::string16 url_str; 394 base::string16 url_str;
417 bool success = ClipboardUtil::GetUrl( 395 if (ClipboardUtil::GetUrl(
418 source_object_.get(), url, title, 396 source_object_.get(), url, title,
419 policy == OSExchangeData::CONVERT_FILENAMES ? true : false); 397 policy == OSExchangeData::CONVERT_FILENAMES ? true : false)) {
420 if (success) {
421 DCHECK(url->is_valid()); 398 DCHECK(url->is_valid());
422 return true; 399 return true;
423 } else if (GetPlainTextURL(source_object_.get(), url)) {
424 if (url->is_valid())
425 *title = net::GetSuggestedFilename(*url, "", "", "", "", std::string());
426 else
427 title->clear();
428 return true;
429 } 400 }
401 *url = GURL();
402 title->clear();
430 return false; 403 return false;
431 } 404 }
432 405
433 bool OSExchangeDataProviderWin::GetFilename(base::FilePath* path) const { 406 bool OSExchangeDataProviderWin::GetFilename(base::FilePath* path) const {
434 std::vector<base::string16> filenames; 407 std::vector<base::string16> filenames;
435 bool success = ClipboardUtil::GetFilenames(source_object_.get(), &filenames); 408 bool success = ClipboardUtil::GetFilenames(source_object_.get(), &filenames);
436 if (success) 409 if (success)
437 *path = base::FilePath(filenames[0]); 410 *path = base::FilePath(filenames[0]);
438 return success; 411 return success;
439 } 412 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 *base_url = GURL(url); 463 *base_url = GURL(url);
491 return success; 464 return success;
492 } 465 }
493 466
494 bool OSExchangeDataProviderWin::HasString() const { 467 bool OSExchangeDataProviderWin::HasString() const {
495 return ClipboardUtil::HasPlainText(source_object_.get()); 468 return ClipboardUtil::HasPlainText(source_object_.get());
496 } 469 }
497 470
498 bool OSExchangeDataProviderWin::HasURL( 471 bool OSExchangeDataProviderWin::HasURL(
499 OSExchangeData::FilenameToURLPolicy policy) const { 472 OSExchangeData::FilenameToURLPolicy policy) const {
500 return (ClipboardUtil::HasUrl( 473 return ClipboardUtil::HasUrl(source_object_.get(),
501 source_object_.get(), 474 policy == OSExchangeData::CONVERT_FILENAMES);
502 policy == OSExchangeData::CONVERT_FILENAMES ? true : false) ||
503 HasPlainTextURL(source_object_.get()));
504 } 475 }
505 476
506 bool OSExchangeDataProviderWin::HasFile() const { 477 bool OSExchangeDataProviderWin::HasFile() const {
507 return ClipboardUtil::HasFilenames(source_object_.get()); 478 return ClipboardUtil::HasFilenames(source_object_.get());
508 } 479 }
509 480
510 bool OSExchangeDataProviderWin::HasFileContents() const { 481 bool OSExchangeDataProviderWin::HasFileContents() const {
511 return ClipboardUtil::HasFileContents(source_object_.get()); 482 return ClipboardUtil::HasFileContents(source_object_.get());
512 } 483 }
513 484
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 std::min(file_name.size(), static_cast<size_t>(MAX_PATH - 1u))); 1032 std::min(file_name.size(), static_cast<size_t>(MAX_PATH - 1u)));
1062 1033
1063 STGMEDIUM* storage = new STGMEDIUM; 1034 STGMEDIUM* storage = new STGMEDIUM;
1064 storage->tymed = TYMED_HGLOBAL; 1035 storage->tymed = TYMED_HGLOBAL;
1065 storage->hGlobal = hdata; 1036 storage->hGlobal = hdata;
1066 storage->pUnkForRelease = NULL; 1037 storage->pUnkForRelease = NULL;
1067 return storage; 1038 return storage;
1068 } 1039 }
1069 1040
1070 } // namespace ui 1041 } // namespace ui
OLDNEW
« ui/base/dragdrop/os_exchange_data.cc ('K') | « ui/base/dragdrop/os_exchange_data_provider_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698