diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-28 21:42:59 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-28 21:42:59 +0000 |
commit | 4768c65bc656d4352632a6fc718c8eb6d5046c84 (patch) | |
tree | c75cffe227847e1e1ab0952d337c3c853692924e /app | |
parent | 6638b8716b5630233efa54f8e8ea4b4758f01ca4 (diff) | |
download | chromium_src-4768c65bc656d4352632a6fc718c8eb6d5046c84.zip chromium_src-4768c65bc656d4352632a6fc718c8eb6d5046c84.tar.gz chromium_src-4768c65bc656d4352632a6fc718c8eb6d5046c84.tar.bz2 |
Adds support for initiating drags from bookmark menus.
BUG=none
TEST=make sure bookmark menus work on Windows.
Review URL: http://codereview.chromium.org/176006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24801 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/os_exchange_data_gtk.cc | 75 | ||||
-rw-r--r-- | app/os_exchange_data_provider_gtk.cc | 99 | ||||
-rw-r--r-- | app/os_exchange_data_provider_gtk.h | 10 |
3 files changed, 104 insertions, 80 deletions
diff --git a/app/os_exchange_data_gtk.cc b/app/os_exchange_data_gtk.cc deleted file mode 100644 index b599470..0000000 --- a/app/os_exchange_data_gtk.cc +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "app/os_exchange_data.h" - -#include "base/logging.h" - -OSExchangeData::OSExchangeData() { -} - -OSExchangeData::~OSExchangeData() { -} - -void OSExchangeData::SetString(const std::wstring& data) { - NOTIMPLEMENTED(); -} - -void OSExchangeData::SetURL(const GURL& url, const std::wstring& title) { - NOTIMPLEMENTED(); -} - -void OSExchangeData::SetFilename(const std::wstring& full_path) { - NOTIMPLEMENTED(); -} - -void OSExchangeData::SetFileContents(const std::wstring& filename, - const std::string& file_contents) { - NOTIMPLEMENTED(); -} - -void OSExchangeData::SetHtml(const std::wstring& html, const GURL& base_url) { - NOTIMPLEMENTED(); -} - -bool OSExchangeData::GetString(std::wstring* data) const { - NOTIMPLEMENTED(); - return false; -} - -bool OSExchangeData::GetURLAndTitle(GURL* url, std::wstring* title) const { - NOTIMPLEMENTED(); - return false; -} - -bool OSExchangeData::GetFilename(std::wstring* full_path) const { - NOTIMPLEMENTED(); - return false; -} - -bool OSExchangeData::GetFileContents(std::wstring* filename, - std::string* file_contents) const { - NOTIMPLEMENTED(); - return false; -} - -bool OSExchangeData::GetHtml(std::wstring* html, GURL* base_url) const { - NOTIMPLEMENTED(); - return false; -} - -bool OSExchangeData::HasString() const { - NOTIMPLEMENTED(); - return false; -} - -bool OSExchangeData::HasURL() const { - NOTIMPLEMENTED(); - return false; -} - -bool OSExchangeData::HasFile() const { - NOTIMPLEMENTED(); - return false; -} diff --git a/app/os_exchange_data_provider_gtk.cc b/app/os_exchange_data_provider_gtk.cc index 5aaa414..f432c7c 100644 --- a/app/os_exchange_data_provider_gtk.cc +++ b/app/os_exchange_data_provider_gtk.cc @@ -6,6 +6,7 @@ #include <algorithm> +#include "app/gtk_dnd_util.h" #include "base/string_util.h" OSExchangeDataProviderGtk::OSExchangeDataProviderGtk( @@ -29,9 +30,99 @@ bool OSExchangeDataProviderGtk::HasDataForAllFormats( const std::set<GdkAtom>& custom_formats) const { if ((formats_ & formats) != formats) return false; - return std::includes(custom_formats_.begin(), - custom_formats_.end(), - custom_formats.begin(), custom_formats.end()); + for (std::set<GdkAtom>::iterator i = custom_formats.begin(); + i != custom_formats.end(); ++i) { + if (pickle_data_.find(*i) == pickle_data_.end()) + return false; + } + return true; +} + +GtkTargetList* OSExchangeDataProviderGtk::GetTargetList() const { + GtkTargetList* targets = gtk_target_list_new(NULL, 0); + + if ((formats_ & OSExchangeData::STRING) != 0) + gtk_target_list_add_text_targets(targets, OSExchangeData::STRING); + + if ((formats_ & OSExchangeData::URL) != 0) { + gtk_target_list_add_uri_targets(targets, OSExchangeData::URL); + gtk_target_list_add( + targets, + GtkDndUtil::GetAtomForTarget(GtkDndUtil::CHROME_NAMED_URL), + 0, + OSExchangeData::URL); + } + + if ((formats_ & OSExchangeData::FILE_CONTENTS) != 0) + NOTIMPLEMENTED(); + + if ((formats_ & OSExchangeData::FILE_NAME) != 0) + NOTIMPLEMENTED(); + + if ((formats_ & OSExchangeData::HTML) != 0) + NOTIMPLEMENTED(); + + + for (PickleData::const_iterator i = pickle_data_.begin(); + i != pickle_data_.end(); ++i) { + gtk_target_list_add(targets, i->first, 0, OSExchangeData::PICKLED_DATA); + } + + return targets; +} + +void OSExchangeDataProviderGtk::WriteFormatToSelection( + int format, + GtkSelectionData* selection) const { + if ((format & OSExchangeData::STRING) != 0) { + gtk_selection_data_set_text( + selection, + reinterpret_cast<const gchar*>(string_.c_str()), + -1); + } + + if ((format & OSExchangeData::URL) != 0) { + // TODO: this should be pulled out of TabContentsDragSource into a common + // place. + Pickle pickle; + pickle.WriteString(UTF16ToUTF8(title_)); + pickle.WriteString(url_.spec()); + gtk_selection_data_set( + selection, + GtkDndUtil::GetAtomForTarget(GtkDndUtil::CHROME_NAMED_URL), + 8, + reinterpret_cast<const guchar*>(pickle.data()), + pickle.size()); + + gchar* uri_array[2]; + uri_array[0] = strdup(url_.spec().c_str()); + uri_array[1] = NULL; + gtk_selection_data_set_uris(selection, uri_array); + free(uri_array[0]); + } + + if ((format & OSExchangeData::FILE_CONTENTS) != 0) + NOTIMPLEMENTED(); + + if ((format & OSExchangeData::FILE_NAME) != 0) + NOTIMPLEMENTED(); + + if ((format & OSExchangeData::HTML) != 0) + NOTIMPLEMENTED(); + + + if ((format & OSExchangeData::PICKLED_DATA) != 0) { + for (PickleData::const_iterator i = pickle_data_.begin(); + i != pickle_data_.end(); ++i) { + const Pickle& data = i->second; + gtk_selection_data_set( + selection, + i->first, + 8, + reinterpret_cast<const guchar*>(data.data()), + data.size()); + } + } } void OSExchangeDataProviderGtk::SetString(const std::wstring& data) { @@ -154,7 +245,7 @@ bool OSExchangeDataProviderGtk::HasHtml() const { bool OSExchangeDataProviderGtk::HasCustomFormat(GdkAtom format) const { return known_custom_formats_.find(format) != known_custom_formats_.end() || - custom_formats_.find(format) != custom_formats_.end(); + pickle_data_.find(format) != pickle_data_.end(); } /////////////////////////////////////////////////////////////////////////////// diff --git a/app/os_exchange_data_provider_gtk.h b/app/os_exchange_data_provider_gtk.h index dd9c009..5974cde 100644 --- a/app/os_exchange_data_provider_gtk.h +++ b/app/os_exchange_data_provider_gtk.h @@ -44,6 +44,15 @@ class OSExchangeDataProviderGtk : public OSExchangeData::Provider { bool HasDataForAllFormats(int formats, const std::set<GdkAtom>& custom_formats) const; + // Returns the set of formats available as a GtkTargetList. It is up to the + // caller to free (gtk_target_list_unref) the returned list. + GtkTargetList* GetTargetList() const; + + // Writes the data to |selection|. |format| is any combination of + // OSExchangeData::Formats. + void WriteFormatToSelection(int format, + GtkSelectionData* selection) const; + // Provider methods. virtual void SetString(const std::wstring& data); virtual void SetURL(const GURL& url, const std::wstring& title); @@ -80,7 +89,6 @@ class OSExchangeDataProviderGtk : public OSExchangeData::Provider { // Actual formats that have been set. See comment above |known_formats_| // for details. int formats_; - std::set<GdkAtom> custom_formats_; // String contents. string16 string_; |