summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-28 02:27:48 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-28 02:27:48 +0000
commit84eb368957b9ae951894bc97673384d317addcfc (patch)
tree6371a1a075a3f90d0727b2b13e44ac143b5a281e
parentac120ff0d2d174c9a3497f0d84b8311bf354cd0e (diff)
downloadchromium_src-84eb368957b9ae951894bc97673384d317addcfc.zip
chromium_src-84eb368957b9ae951894bc97673384d317addcfc.tar.gz
chromium_src-84eb368957b9ae951894bc97673384d317addcfc.tar.bz2
GTK: make tabbed bookmark manager compatible with more types of drops.
BUG=42466 TEST=see bug. Also, drags from firefox bookmark bar to tabbed bookmark manager should work. Review URL: http://codereview.chromium.org/1691018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45778 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/bookmarks/bookmark_drag_data.cc27
-rw-r--r--chrome/browser/bookmarks/bookmark_drag_data.h3
-rw-r--r--chrome/browser/tab_contents/web_drag_dest_gtk.cc20
3 files changed, 38 insertions, 12 deletions
diff --git a/chrome/browser/bookmarks/bookmark_drag_data.cc b/chrome/browser/bookmarks/bookmark_drag_data.cc
index d722659..f8a2ed4 100644
--- a/chrome/browser/bookmarks/bookmark_drag_data.cc
+++ b/chrome/browser/bookmarks/bookmark_drag_data.cc
@@ -105,6 +105,22 @@ bool BookmarkDragData::ReadFromVector(
return true;
}
+bool BookmarkDragData::ReadFromTuple(const GURL& url, const string16& title) {
+ Clear();
+
+ if (!url.is_valid())
+ return false;
+
+ Element element;
+ element.title = title;
+ element.url = url;
+ element.is_url = true;
+
+ elements.push_back(element);
+
+ return true;
+}
+
#if !defined(OS_MACOSX)
void BookmarkDragData::WriteToClipboard(Profile* profile) const {
ScopedClipboardWriter scw(g_browser_process->clipboard());
@@ -214,14 +230,11 @@ bool BookmarkDragData::Read(const OSExchangeData& data) {
} else {
// See if there is a URL on the clipboard.
Element element;
+ GURL url;
std::wstring title;
- if (data.GetURLAndTitle(&element.url, &title) &&
- element.url.is_valid()) {
- element.title = WideToUTF16(title);
- element.is_url = true;
- elements.push_back(element);
- }
- }
+ if (data.GetURLAndTitle(&url, &title))
+ ReadFromTuple(url, WideToUTF16(title));
+ }
return is_valid();
}
diff --git a/chrome/browser/bookmarks/bookmark_drag_data.h b/chrome/browser/bookmarks/bookmark_drag_data.h
index 7f007a2..b4b65da 100644
--- a/chrome/browser/bookmarks/bookmark_drag_data.h
+++ b/chrome/browser/bookmarks/bookmark_drag_data.h
@@ -89,6 +89,9 @@ struct BookmarkDragData {
// Reads bookmarks from the given vector.
bool ReadFromVector(const std::vector<const BookmarkNode*>& nodes);
+ // Creates a single-bookmark DragData from url/title pair.
+ bool ReadFromTuple(const GURL& url, const string16& title);
+
// Writes elements to the clipboard.
void WriteToClipboard(Profile* profile) const;
diff --git a/chrome/browser/tab_contents/web_drag_dest_gtk.cc b/chrome/browser/tab_contents/web_drag_dest_gtk.cc
index 0fd6caa..bc07971 100644
--- a/chrome/browser/tab_contents/web_drag_dest_gtk.cc
+++ b/chrome/browser/tab_contents/web_drag_dest_gtk.cc
@@ -73,6 +73,7 @@ gboolean WebDragDestGtk::OnDragMotion(GtkWidget* sender,
if (context_ != context) {
context_ = context;
drop_data_.reset(new WebDropData);
+ bookmark_drag_data_.Clear();
is_drop_target_ = false;
static int supported_targets[] = {
@@ -158,23 +159,32 @@ void WebDragDestGtk::OnDragDataReceived(
data->length);
size_t split = netscape_url.find_first_of('\n');
if (split != std::string::npos) {
- drop_data_->url_title = UTF8ToUTF16(netscape_url.substr(0, split));
+ drop_data_->url = GURL(netscape_url.substr(0, split));
if (split < netscape_url.size() - 1)
- drop_data_->url = GURL(netscape_url.substr(split + 1));
+ drop_data_->url_title = UTF8ToUTF16(netscape_url.substr(split + 1));
}
} else if (data->target ==
gtk_dnd_util::GetAtomForTarget(gtk_dnd_util::CHROME_NAMED_URL)) {
gtk_dnd_util::ExtractNamedURL(data,
&drop_data_->url, &drop_data_->url_title);
- } else if (data->target ==
- gtk_dnd_util::GetAtomForTarget(
- gtk_dnd_util::CHROME_BOOKMARK_ITEM)) {
+ }
+ }
+
+ // For CHROME_BOOKMARK_ITEM, we have to handle the case where the drag source
+ // doesn't have any data available for us. In this case we try to synthesize a
+ // URL bookmark.
+ if (data->target ==
+ gtk_dnd_util::GetAtomForTarget(gtk_dnd_util::CHROME_BOOKMARK_ITEM)) {
+ if (data->data) {
bookmark_drag_data_.ReadFromVector(
bookmark_utils::GetNodesFromSelection(
NULL, data,
gtk_dnd_util::CHROME_BOOKMARK_ITEM,
tab_contents_->profile(), NULL, NULL));
bookmark_drag_data_.SetOriginatingProfile(tab_contents_->profile());
+ } else {
+ bookmark_drag_data_.ReadFromTuple(drop_data_->url,
+ drop_data_->url_title);
}
}