diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-23 21:42:58 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-23 21:42:58 +0000 |
commit | b6d432335f59500e092de2be4fcf42ed303ae1c5 (patch) | |
tree | 0dae24ec6c0f89442ee37d18aeb17f5dcf48d6e0 /views/widget | |
parent | 599ea9fd7f5f029661916c191ff89b7358719f81 (diff) | |
download | chromium_src-b6d432335f59500e092de2be4fcf42ed303ae1c5.zip chromium_src-b6d432335f59500e092de2be4fcf42ed303ae1c5.tar.gz chromium_src-b6d432335f59500e092de2be4fcf42ed303ae1c5.tar.bz2 |
Implements file contents support in OSExchangeData and DropTarget
for gtk. Makes html and file contents support in OSExchangeData only
for windows (as that is the only place we need it), and makes dragging
files work.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/232002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26995 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r-- | views/widget/drop_target_gtk.cc | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/views/widget/drop_target_gtk.cc b/views/widget/drop_target_gtk.cc index 2947e63..62fc1a8 100644 --- a/views/widget/drop_target_gtk.cc +++ b/views/widget/drop_target_gtk.cc @@ -10,8 +10,10 @@ #include "app/drag_drop_types.h" #include "app/gtk_dnd_util.h" #include "app/os_exchange_data_provider_gtk.h" +#include "base/file_path.h" #include "base/gfx/point.h" #include "base/string_util.h" +#include "net/base/net_util.h" #include "views/widget/root_view.h" #include "views/widget/widget_gtk.h" @@ -27,14 +29,14 @@ std::string GdkAtomToString(GdkAtom atom) { // Returns true if |name| is a known name of plain text. bool IsTextType(const std::string& name) { return name == "text/plain" || name == "TEXT" || - name == "STRING" || name == "UTF8_STRING"; + name == "STRING" || name == "UTF8_STRING" || + name == "text/plain;charset=utf-8"; } // Returns the OSExchangeData::Formats in |targets| and all the // OSExchangeData::CustomFormats in |type_set|. int CalculateTypes(GList* targets, std::set<GdkAtom>* type_set) { int types = 0; - NOTIMPLEMENTED(); // Need to support FILE_NAME, FILE_CONTENTS for (GList* element = targets; element; element = g_list_next(element)) { GdkAtom atom = static_cast<GdkAtom>(element->data); @@ -42,15 +44,15 @@ int CalculateTypes(GList* targets, std::set<GdkAtom>* type_set) { if (atom == GDK_TARGET_STRING) { types |= OSExchangeData::STRING; } else if (atom == GtkDndUtil::GetAtomForTarget( - GtkDndUtil::CHROME_NAMED_URL) || - atom == GtkDndUtil::GetAtomForTarget( - GtkDndUtil::TEXT_URI_LIST)) { + GtkDndUtil::CHROME_NAMED_URL)) { types |= OSExchangeData::URL; + } else if (atom == GtkDndUtil::GetAtomForTarget( + GtkDndUtil::TEXT_URI_LIST)) { + // TEXT_URI_LIST is used for files as well as urls. + types |= OSExchangeData::URL | OSExchangeData::FILE_NAME; } else { std::string target_name = GdkAtomToString(atom); - if (target_name == "text/html") { - types |= OSExchangeData::HTML; - } else if (IsTextType(target_name)) { + if (IsTextType(target_name)) { types |= OSExchangeData::STRING; } else { // Assume any unknown data is pickled. @@ -117,16 +119,21 @@ void DropTargetGtk::OnDragDataReceived(GdkDragContext* context, GtkDndUtil::TEXT_URI_LIST)) { std::vector<GURL> urls; GtkDndUtil::ExtractURIList(data, &urls); - if (urls.size() == 1) { + if (urls.size() == 1 && urls[0].is_valid()) { data_provider().SetURL(urls[0], std::wstring()); + + // TEXT_URI_LIST is used for files as well as urls. + if (urls[0].SchemeIsFile()) { + FilePath file_path; + if (net::FileURLToFilePath(urls[0], &file_path)) + data_provider().SetFilename(file_path.ToWStringHack()); + } } else { // Consumers of OSExchangeData will see this as an invalid URL. That is, // when GetURL is invoked on the OSExchangeData this triggers false to // be returned. data_provider().SetURL(GURL(), std::wstring()); } - } else { - NOTIMPLEMENTED(); // Need to support FILE_NAME, FILE_CONTENTS, HTML. } if (!data_->HasAllFormats(requested_formats_, requested_custom_formats_)) @@ -271,6 +278,11 @@ void DropTargetGtk::RequestFormats(GdkDragContext* context, } else if (known_formats.count(gdk_atom_intern("text/plain", false))) { gtk_drag_get_data(widget, context, gdk_atom_intern("text/plain", false), time); + } else if (known_formats.count(gdk_atom_intern("text/plain;charset=utf-8", + false))) { + gtk_drag_get_data(widget, context, + gdk_atom_intern("text/plain;charset=utf-8", false), + time); } else if (known_formats.count(gdk_atom_intern("TEXT", false))) { gtk_drag_get_data(widget, context, gdk_atom_intern("TEXT", false), time); @@ -297,20 +309,12 @@ void DropTargetGtk::RequestFormats(GdkDragContext* context, GtkDndUtil::TEXT_URI_LIST), time); } } - if ((formats & OSExchangeData::FILE_CONTENTS) != 0 && - (requested_formats_ & OSExchangeData::FILE_CONTENTS) == 0) { - requested_formats_ |= OSExchangeData::FILE_CONTENTS; - NOTIMPLEMENTED(); - } if (((formats & OSExchangeData::FILE_NAME) != 0) && (requested_formats_ & OSExchangeData::FILE_NAME) == 0) { requested_formats_ |= OSExchangeData::FILE_NAME; - NOTIMPLEMENTED(); - } - if ((formats & OSExchangeData::HTML) != 0 && - (requested_formats_ & OSExchangeData::HTML) == 0) { - requested_formats_ |= OSExchangeData::HTML; - NOTIMPLEMENTED(); + gtk_drag_get_data(widget, context, + GtkDndUtil::GetAtomForTarget( + GtkDndUtil::TEXT_URI_LIST), time); } for (std::set<GdkAtom>::const_iterator i = custom_formats.begin(); i != custom_formats.end(); ++i) { |