diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 00:17:56 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 00:17:56 +0000 |
commit | cd6966178e34f1b71bdb36bb6f1b4cc39e103297 (patch) | |
tree | 44fb525549c7bee0fb145fccd4179d88a9d22785 | |
parent | 0195ac6a92a2348df849d367e4ec229af3f168e5 (diff) | |
download | chromium_src-cd6966178e34f1b71bdb36bb6f1b4cc39e103297.zip chromium_src-cd6966178e34f1b71bdb36bb6f1b4cc39e103297.tar.gz chromium_src-cd6966178e34f1b71bdb36bb6f1b4cc39e103297.tar.bz2 |
Allow dragging a link from the web contents to the bookmark bar to get a named bookmark.
Also, change the naming scheme of the DnD targets.
BUG=16791
TEST=select a link in the web page and drag it to the bookmark bar.
Review URL: http://codereview.chromium.org/155661
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20921 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.cc | 76 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_manager_gtk.cc | 12 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_menu_controller_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_utils_gtk.cc | 19 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_utils_gtk.h | 8 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 6 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_dnd_util.cc | 52 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_dnd_util.h | 20 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_strip_gtk.cc | 6 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_gtk.cc | 53 |
11 files changed, 162 insertions, 94 deletions
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index c2753b9..44b6be6 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -138,7 +138,8 @@ void BookmarkBarGtk::Init(Profile* profile) { gtk_drag_dest_set(bookmark_toolbar_.get(), GTK_DEST_DEFAULT_DROP, NULL, 0, GDK_ACTION_MOVE); GtkDndUtil::SetDestTargetListFromCodeMask(bookmark_toolbar_.get(), - GtkDndUtil::X_CHROME_BOOKMARK_ITEM); + GtkDndUtil::CHROME_BOOKMARK_ITEM | + GtkDndUtil::CHROME_NAMED_URL); g_signal_connect(bookmark_toolbar_.get(), "drag-motion", G_CALLBACK(&OnToolbarDragMotion), this); g_signal_connect(bookmark_toolbar_.get(), "drag-leave", @@ -384,9 +385,10 @@ GtkWidget* BookmarkBarGtk::CreateBookmarkButton(const BookmarkNode* node) { // The tool item is also a source for dragging gtk_drag_source_set(button, GDK_BUTTON1_MASK, NULL, 0, GDK_ACTION_MOVE); - GtkDndUtil::SetSourceTargetListFromCodeMask( - button, GtkDndUtil::X_CHROME_BOOKMARK_ITEM | - GtkDndUtil::X_CHROME_TEXT_URI_LIST); + int target_mask = GtkDndUtil::CHROME_BOOKMARK_ITEM; + if (node->is_url()) + target_mask |= GtkDndUtil::TEXT_URI_LIST; + GtkDndUtil::SetSourceTargetListFromCodeMask(button, target_mask); g_signal_connect(G_OBJECT(button), "drag-begin", G_CALLBACK(&OnButtonDragBegin), this); g_signal_connect(G_OBJECT(button), "drag-end", @@ -428,7 +430,8 @@ GtkToolItem* BookmarkBarGtk::CreateBookmarkToolItem(const BookmarkNode* node) { void BookmarkBarGtk::ConnectFolderButtonEvents(GtkWidget* widget) { gtk_drag_dest_set(widget, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_MOVE); GtkDndUtil::SetDestTargetListFromCodeMask(widget, - GtkDndUtil::X_CHROME_BOOKMARK_ITEM); + GtkDndUtil::CHROME_BOOKMARK_ITEM | + GtkDndUtil::CHROME_NAMED_URL); g_signal_connect(widget, "drag-data-received", G_CALLBACK(&OnFolderDragReceived), this); @@ -645,17 +648,26 @@ void BookmarkBarGtk::OnFolderDragReceived(GtkWidget* widget, const BookmarkNode* dest_node = bar->GetNodeForToolButton(widget); DCHECK(dest_node->is_folder()); - std::vector<const BookmarkNode*> nodes = - bookmark_utils::GetNodesFromSelection(context, selection_data, - target_type, - bar->profile_, - &delete_selection_data, - &dnd_success); - DCHECK(!nodes.empty()); - - for (std::vector<const BookmarkNode*>::iterator it = nodes.begin(); - it != nodes.end(); ++it) { - bar->model_->Move(*it, dest_node, dest_node->GetChildCount()); + + if (target_type == GtkDndUtil::CHROME_BOOKMARK_ITEM) { + std::vector<const BookmarkNode*> nodes = + bookmark_utils::GetNodesFromSelection(context, selection_data, + target_type, + bar->profile_, + &delete_selection_data, + &dnd_success); + DCHECK(!nodes.empty()); + DCHECK(dnd_success); + + for (std::vector<const BookmarkNode*>::iterator it = nodes.begin(); + it != nodes.end(); ++it) { + bar->model_->Move(*it, dest_node, dest_node->GetChildCount()); + } + } else if (target_type == GtkDndUtil::CHROME_NAMED_URL) { + dnd_success = bookmark_utils::CreateNewBookmarkFromNamedUrl( + selection_data, bar->model_, dest_node, dest_node->GetChildCount()); + } else { + NOTREACHED(); } gtk_drag_finish(context, dnd_success, delete_selection_data, time); @@ -742,7 +754,7 @@ gboolean BookmarkBarGtk::OnToolbarDragDrop( if (context->targets) { GdkAtom target_type = GDK_POINTER_TO_ATOM(g_list_nth_data( - context->targets, GtkDndUtil::X_CHROME_BOOKMARK_ITEM)); + context->targets, GtkDndUtil::CHROME_BOOKMARK_ITEM)); gtk_drag_get_data(widget, context, target_type, time); is_valid_drop_site = TRUE; @@ -761,19 +773,27 @@ void BookmarkBarGtk::OnToolbarDragReceived(GtkWidget* widget, gboolean dnd_success = FALSE; gboolean delete_selection_data = FALSE; - std::vector<const BookmarkNode*> nodes = - bookmark_utils::GetNodesFromSelection(context, selection_data, - target_type, - bar->profile_, - &delete_selection_data, - &dnd_success); - DCHECK(!nodes.empty()); gint index = gtk_toolbar_get_drop_index( GTK_TOOLBAR(bar->bookmark_toolbar_.get()), x, y); - for (std::vector<const BookmarkNode*>::iterator it = nodes.begin(); - it != nodes.end(); ++it) { - bar->model_->Move(*it, bar->model_->GetBookmarkBarNode(), index); - index = bar->model_->GetBookmarkBarNode()->IndexOfChild(*it) + 1; + + if (target_type == GtkDndUtil::CHROME_BOOKMARK_ITEM) { + std::vector<const BookmarkNode*> nodes = + bookmark_utils::GetNodesFromSelection(context, selection_data, + target_type, + bar->profile_, + &delete_selection_data, + &dnd_success); + DCHECK(!nodes.empty()); + for (std::vector<const BookmarkNode*>::iterator it = nodes.begin(); + it != nodes.end(); ++it) { + bar->model_->Move(*it, bar->model_->GetBookmarkBarNode(), index); + index = bar->model_->GetBookmarkBarNode()->IndexOfChild(*it) + 1; + } + } else if (target_type == GtkDndUtil::CHROME_NAMED_URL) { + dnd_success = bookmark_utils::CreateNewBookmarkFromNamedUrl( + selection_data, bar->model_, bar->model_->GetBookmarkBarNode(), index); + } else { + NOTREACHED(); } gtk_drag_finish(context, dnd_success, delete_selection_data, time); diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc index 787b1f19..eea1bbc 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.cc +++ b/chrome/browser/gtk/bookmark_manager_gtk.cc @@ -417,7 +417,7 @@ GtkWidget* BookmarkManagerGtk::MakeLeftPane() { gtk_drag_dest_set(left_tree_view_, GTK_DEST_DEFAULT_DROP, NULL, 0, GDK_ACTION_MOVE); GtkDndUtil::SetDestTargetListFromCodeMask(left_tree_view_, - GtkDndUtil::X_CHROME_BOOKMARK_ITEM); + GtkDndUtil::CHROME_BOOKMARK_ITEM); g_signal_connect(left_tree_view_, "drag-data-received", G_CALLBACK(&OnLeftTreeViewDragReceived), this); @@ -487,8 +487,8 @@ GtkWidget* BookmarkManagerGtk::MakeRightPane() { GDK_BUTTON1_MASK, NULL, 0, GDK_ACTION_MOVE); GtkDndUtil::SetSourceTargetListFromCodeMask( - right_tree_view_, GtkDndUtil::X_CHROME_BOOKMARK_ITEM | - GtkDndUtil::X_CHROME_TEXT_URI_LIST); + right_tree_view_, GtkDndUtil::CHROME_BOOKMARK_ITEM | + GtkDndUtil::TEXT_URI_LIST); // We connect to drag dest signals, but we don't actually enable the widget // as a drag destination unless it corresponds to the contents of a folder. @@ -581,7 +581,7 @@ void BookmarkManagerGtk::BuildRightStore() { gtk_drag_dest_set(right_tree_view_, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_MOVE); GtkDndUtil::SetDestTargetListFromCodeMask(right_tree_view_, - GtkDndUtil::X_CHROME_BOOKMARK_ITEM); + GtkDndUtil::CHROME_BOOKMARK_ITEM); } else { SaveColumnConfiguration(); gtk_tree_view_column_set_visible(path_column_, TRUE); @@ -1132,8 +1132,8 @@ gboolean BookmarkManagerGtk::OnRightTreeViewMotion(GtkWidget* tree_view, bm->mousedown_event_.x, bm->mousedown_event_.y, event->x, event->y)) { bm->delaying_mousedown_ = false; GtkTargetList* targets = GtkDndUtil::GetTargetListFromCodeMask( - GtkDndUtil::X_CHROME_BOOKMARK_ITEM | - GtkDndUtil::X_CHROME_TEXT_URI_LIST); + GtkDndUtil::CHROME_BOOKMARK_ITEM | + GtkDndUtil::TEXT_URI_LIST); gtk_drag_begin(tree_view, targets, GDK_ACTION_MOVE, 1, reinterpret_cast<GdkEvent*>(event)); // The drag adds a ref; let it own the list. diff --git a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc index b68b51c..7e1968d 100644 --- a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc +++ b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc @@ -149,7 +149,7 @@ void BookmarkMenuController::BuildMenu(const BookmarkNode* parent, gtk_drag_source_set(menu_item, GDK_BUTTON1_MASK, NULL, 0, GDK_ACTION_MOVE); GtkDndUtil::SetSourceTargetListFromCodeMask( - menu_item, GtkDndUtil::X_CHROME_BOOKMARK_ITEM); + menu_item, GtkDndUtil::CHROME_BOOKMARK_ITEM); g_signal_connect(G_OBJECT(menu_item), "drag-begin", G_CALLBACK(&OnMenuItemDragBegin), this); g_signal_connect(G_OBJECT(menu_item), "drag-end", diff --git a/chrome/browser/gtk/bookmark_utils_gtk.cc b/chrome/browser/gtk/bookmark_utils_gtk.cc index b83553f..fa2a56e 100644 --- a/chrome/browser/gtk/bookmark_utils_gtk.cc +++ b/chrome/browser/gtk/bookmark_utils_gtk.cc @@ -192,7 +192,7 @@ void WriteBookmarksToSelection(const std::vector<const BookmarkNode*>& nodes, guint target_type, Profile* profile) { switch (target_type) { - case GtkDndUtil::X_CHROME_BOOKMARK_ITEM: { + case GtkDndUtil::CHROME_BOOKMARK_ITEM: { BookmarkDragData data(nodes); Pickle pickle; data.WriteToPickle(profile, &pickle); @@ -203,7 +203,7 @@ void WriteBookmarksToSelection(const std::vector<const BookmarkNode*>& nodes, pickle.size()); break; } - case GtkDndUtil::X_CHROME_TEXT_URI_LIST: { + case GtkDndUtil::TEXT_URI_LIST: { gchar** uris = reinterpret_cast<gchar**>(malloc(sizeof(gchar*) * (nodes.size() + 1))); for (size_t i = 0; i < nodes.size(); ++i) { @@ -243,7 +243,7 @@ std::vector<const BookmarkNode*> GetNodesFromSelection( } switch (target_type) { - case GtkDndUtil::X_CHROME_BOOKMARK_ITEM: { + case GtkDndUtil::CHROME_BOOKMARK_ITEM: { *dnd_success = TRUE; Pickle pickle(reinterpret_cast<char*>(selection_data->data), selection_data->length); @@ -260,4 +260,17 @@ std::vector<const BookmarkNode*> GetNodesFromSelection( return std::vector<const BookmarkNode*>(); } +bool CreateNewBookmarkFromNamedUrl(GtkSelectionData* selection_data, + BookmarkModel* model, const BookmarkNode* parent, int idx) { + Pickle data(reinterpret_cast<char*>(selection_data->data), + selection_data->length); + void* iter = NULL; + std::string title_utf8, url_utf8; + bool rv = data.ReadString(&iter, &title_utf8); + rv = rv && data.ReadString(&iter, &url_utf8); + if (rv) + model->AddURL(parent, idx, UTF8ToWide(title_utf8), GURL(url_utf8)); + return rv; +} + } // namespace bookmark_utils diff --git a/chrome/browser/gtk/bookmark_utils_gtk.h b/chrome/browser/gtk/bookmark_utils_gtk.h index 9f252c6..d2d0143 100644 --- a/chrome/browser/gtk/bookmark_utils_gtk.h +++ b/chrome/browser/gtk/bookmark_utils_gtk.h @@ -75,6 +75,14 @@ std::vector<const BookmarkNode*> GetNodesFromSelection( gboolean* delete_selection_data, gboolean* dnd_success); +// Unpickle a new bookmark of the CHROME_NAMED_URL drag type, and put it in +// the appropriate location in the model. +bool CreateNewBookmarkFromNamedUrl( + GtkSelectionData* selection_data, + BookmarkModel* model, + const BookmarkNode* parent, + int idx); + } // namespace bookmark_utils #endif // CHROME_BROWSER_GTK_BOOKMARK_UTILS_GTK_H_ diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index 3fd79b5..ea39041 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -394,8 +394,8 @@ void BrowserToolbarGtk::SetUpDragForHomeButton() { gtk_drag_dest_set(home_->widget(), GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY); GtkDndUtil::SetDestTargetListFromCodeMask(home_->widget(), - GtkDndUtil::X_CHROME_TEXT_PLAIN | - GtkDndUtil::X_CHROME_TEXT_URI_LIST); + GtkDndUtil::TEXT_PLAIN | + GtkDndUtil::TEXT_URI_LIST); g_signal_connect(home_->widget(), "drag-data-received", G_CALLBACK(OnDragDataReceived), this); @@ -526,7 +526,7 @@ void BrowserToolbarGtk::OnDragDataReceived(GtkWidget* widget, GdkDragContext* drag_context, gint x, gint y, GtkSelectionData* data, guint info, guint time, BrowserToolbarGtk* toolbar) { - if (info != GtkDndUtil::X_CHROME_TEXT_PLAIN) { + if (info != GtkDndUtil::TEXT_PLAIN) { NOTIMPLEMENTED() << "Only support plain text drops for now, sorry!"; return; } diff --git a/chrome/browser/gtk/gtk_dnd_util.cc b/chrome/browser/gtk/gtk_dnd_util.cc index 2174019..ebc2412 100644 --- a/chrome/browser/gtk/gtk_dnd_util.cc +++ b/chrome/browser/gtk/gtk_dnd_util.cc @@ -6,34 +6,50 @@ #include "base/logging.h" +namespace { + +void AddApplicationTarget(GtkTargetList* targets, int code_mask, int target) { + if (code_mask & target) { + gtk_target_list_add(targets, GtkDndUtil::GetAtomForTarget(target), + GTK_TARGET_SAME_APP, target); + } +} + +} // namespace + // static GdkAtom GtkDndUtil::GetAtomForTarget(int target) { switch (target) { - case X_CHROME_TAB: + case CHROME_TAB: static GdkAtom tab_atom = gdk_atom_intern( const_cast<char*>("application/x-chrome-tab"), false); return tab_atom; - case X_CHROME_TEXT_HTML: + case TEXT_HTML: static GdkAtom html_atom = gdk_atom_intern( const_cast<char*>("text/html"), false); return html_atom; - case X_CHROME_BOOKMARK_ITEM: + case CHROME_BOOKMARK_ITEM: static GdkAtom bookmark_atom = gdk_atom_intern( const_cast<char*>("application/x-chrome-bookmark-item"), false); return bookmark_atom; - case X_CHROME_TEXT_PLAIN: + case TEXT_PLAIN: static GdkAtom text_atom = gdk_atom_intern( const_cast<char*>("text/plain"), false); return text_atom; - case X_CHROME_TEXT_URI_LIST: + case TEXT_URI_LIST: static GdkAtom uris_atom = gdk_atom_intern( const_cast<char*>("text/uri-list"), false); return uris_atom; + case CHROME_NAMED_URL: + static GdkAtom named_url = gdk_atom_intern( + const_cast<char*>("application/x-chrome-named-url"), false); + return named_url; + default: NOTREACHED(); } @@ -45,26 +61,18 @@ GdkAtom GtkDndUtil::GetAtomForTarget(int target) { GtkTargetList* GtkDndUtil::GetTargetListFromCodeMask(int code_mask) { GtkTargetList* targets = gtk_target_list_new(NULL, 0); - if (code_mask & X_CHROME_TAB) { - gtk_target_list_add(targets, GetAtomForTarget(X_CHROME_TAB), - GTK_TARGET_SAME_APP, X_CHROME_TAB); - } + if (code_mask & TEXT_PLAIN) + gtk_target_list_add_text_targets(targets, TEXT_PLAIN); - if (code_mask & X_CHROME_TEXT_PLAIN) - gtk_target_list_add_text_targets(targets, X_CHROME_TEXT_PLAIN); + if (code_mask & TEXT_URI_LIST) + gtk_target_list_add_uri_targets(targets, TEXT_URI_LIST); - if (code_mask & X_CHROME_TEXT_URI_LIST) - gtk_target_list_add_uri_targets(targets, X_CHROME_TEXT_URI_LIST); + if (code_mask & TEXT_HTML) + gtk_target_list_add(targets, GetAtomForTarget(TEXT_PLAIN), 0, TEXT_HTML); - if (code_mask & X_CHROME_TEXT_HTML) { - gtk_target_list_add(targets, GetAtomForTarget(X_CHROME_TEXT_PLAIN), - 0, X_CHROME_TEXT_HTML); - } - - if (code_mask & X_CHROME_BOOKMARK_ITEM) { - gtk_target_list_add(targets, GetAtomForTarget(X_CHROME_BOOKMARK_ITEM), - GTK_TARGET_SAME_APP, X_CHROME_BOOKMARK_ITEM); - } + AddApplicationTarget(targets, code_mask, CHROME_TAB); + AddApplicationTarget(targets, code_mask, CHROME_BOOKMARK_ITEM); + AddApplicationTarget(targets, code_mask, CHROME_NAMED_URL); return targets; } diff --git a/chrome/browser/gtk/gtk_dnd_util.h b/chrome/browser/gtk/gtk_dnd_util.h index 38036f8..42432c7 100644 --- a/chrome/browser/gtk/gtk_dnd_util.h +++ b/chrome/browser/gtk/gtk_dnd_util.h @@ -11,20 +11,24 @@ class GtkDndUtil { public: // Registry of all internal int codes for drag and drop. enum { - X_CHROME_TAB = 1 << 0, - X_CHROME_TEXT_PLAIN = 1 << 1, - X_CHROME_TEXT_URI_LIST = 1 << 2, - X_CHROME_TEXT_HTML = 1 << 3, - X_CHROME_BOOKMARK_ITEM = 1 << 4, - X_CHROME_WEBDROP_FILE_CONTENTS = 1 << 5, + // Intra-application types. + CHROME_TAB = 1 << 0, + CHROME_BOOKMARK_ITEM = 1 << 1, + CHROME_WEBDROP_FILE_CONTENTS = 1 << 2, + CHROME_NAMED_URL = 1 << 3, + + // Standard types. + TEXT_PLAIN = 1 << 4, + TEXT_URI_LIST = 1 << 5, + TEXT_HTML = 1 << 6, }; // Get the atom for a given target (of the above enum type). Will return NULL - // for non-custom targets, such as X_CHROME_TEXT_PLAIN. + // for non-custom targets, such as CHROME_TEXT_PLAIN. static GdkAtom GetAtomForTarget(int target); // Creates a target list from the given mask. The mask should be an OR of - // X_CHROME_* values. The target list is returned with ref count 1; the caller + // CHROME_* values. The target list is returned with ref count 1; the caller // is responsible for unreffing it when it is no longer needed. // Since the MIME type for WEBDROP_FILE_CONTENTS depends on the file's // contents, that flag is ignored by this function. It is the responsibility diff --git a/chrome/browser/gtk/tabs/tab_gtk.cc b/chrome/browser/gtk/tabs/tab_gtk.cc index bd63a5e..f596780 100644 --- a/chrome/browser/gtk/tabs/tab_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_gtk.cc @@ -118,7 +118,7 @@ TabGtk::TabGtk(TabDelegate* delegate) gtk_drag_source_set(event_box_, GDK_BUTTON1_MASK, NULL, 0, GDK_ACTION_MOVE); GtkDndUtil::SetSourceTargetListFromCodeMask(event_box_, - GtkDndUtil::X_CHROME_TAB); + GtkDndUtil::CHROME_TAB); g_signal_connect(G_OBJECT(event_box_), "button-press-event", G_CALLBACK(OnMousePress), this); g_signal_connect(G_OBJECT(event_box_), "button-release-event", diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc index ed28ffc..c931ab0 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc @@ -699,8 +699,8 @@ void TabStripGtk::Init() { static_cast<GdkDragAction>( GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK)); GtkDndUtil::SetDestTargetListFromCodeMask(tabstrip_.get(), - GtkDndUtil::X_CHROME_TEXT_URI_LIST | - GtkDndUtil::X_CHROME_TEXT_PLAIN); + GtkDndUtil::TEXT_URI_LIST | + GtkDndUtil::TEXT_PLAIN); g_signal_connect(G_OBJECT(tabstrip_.get()), "expose-event", G_CALLBACK(OnExpose), this); @@ -1856,7 +1856,7 @@ gboolean TabStripGtk::OnDragDataReceived(GtkWidget* widget, bool success = false; // TODO(jhawkins): Parse URI lists. - if (info == GtkDndUtil::X_CHROME_TEXT_PLAIN) { + if (info == GtkDndUtil::TEXT_PLAIN) { success = tabstrip->CompleteDrop(data->data); } diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc index 80f762f..3dd9dd5 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc @@ -184,9 +184,9 @@ class WebDragDest { is_drop_target_ = false; static int supported_targets[] = { - GtkDndUtil::X_CHROME_TEXT_PLAIN, - GtkDndUtil::X_CHROME_TEXT_URI_LIST, - GtkDndUtil::X_CHROME_TEXT_HTML, + GtkDndUtil::TEXT_PLAIN, + GtkDndUtil::TEXT_URI_LIST, + GtkDndUtil::TEXT_HTML, // TODO(estade): support image drags? }; @@ -226,7 +226,7 @@ class WebDragDest { // If the source can't provide us with valid data for a requested target, // data->data will be NULL. if (data->target == - GtkDndUtil::GetAtomForTarget(GtkDndUtil::X_CHROME_TEXT_PLAIN)) { + GtkDndUtil::GetAtomForTarget(GtkDndUtil::TEXT_PLAIN)) { guchar* text = gtk_selection_data_get_text(data); if (text) { drop_data_->plain_text = UTF8ToUTF16(std::string( @@ -234,7 +234,7 @@ class WebDragDest { g_free(text); } } else if (data->target == - GtkDndUtil::GetAtomForTarget(GtkDndUtil::X_CHROME_TEXT_URI_LIST)) { + GtkDndUtil::GetAtomForTarget(GtkDndUtil::TEXT_URI_LIST)) { gchar** uris = gtk_selection_data_get_uris(data); if (uris) { for (gchar** uri_iter = uris; *uri_iter; uri_iter++) { @@ -247,7 +247,7 @@ class WebDragDest { g_strfreev(uris); } } else if (data->target == - GtkDndUtil::GetAtomForTarget(GtkDndUtil::X_CHROME_TEXT_HTML)) { + GtkDndUtil::GetAtomForTarget(GtkDndUtil::TEXT_HTML)) { // TODO(estade): Can the html have a non-UTF8 encoding? drop_data_->text_html = UTF8ToUTF16(std::string( reinterpret_cast<char*>(data->data), data->length)); @@ -603,13 +603,15 @@ void TabContentsViewGtk::StartDragging(const WebDropData& drop_data) { int targets_mask = 0; if (!drop_data.plain_text.empty()) - targets_mask |= GtkDndUtil::X_CHROME_TEXT_PLAIN; - if (drop_data.url.is_valid()) - targets_mask |= GtkDndUtil::X_CHROME_TEXT_URI_LIST; + targets_mask |= GtkDndUtil::TEXT_PLAIN; + if (drop_data.url.is_valid()) { + targets_mask |= GtkDndUtil::TEXT_URI_LIST; + targets_mask |= GtkDndUtil::CHROME_NAMED_URL; + } if (!drop_data.text_html.empty()) - targets_mask |= GtkDndUtil::X_CHROME_TEXT_HTML; + targets_mask |= GtkDndUtil::TEXT_HTML; if (!drop_data.file_contents.empty()) - targets_mask |= GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS; + targets_mask |= GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS; if (targets_mask == 0) { NOTIMPLEMENTED(); @@ -620,11 +622,11 @@ void TabContentsViewGtk::StartDragging(const WebDropData& drop_data) { drop_data_.reset(new WebDropData(drop_data)); GtkTargetList* list = GtkDndUtil::GetTargetListFromCodeMask(targets_mask); - if (targets_mask & GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS) { + if (targets_mask & GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS) { drag_file_mime_type_ = gdk_atom_intern( mime_util::GetDataMimeType(drop_data.file_contents).c_str(), FALSE); gtk_target_list_add(list, drag_file_mime_type_, - 0, GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS); + 0, GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS); } // If we don't pass an event, GDK won't know what event time to start grabbing @@ -648,35 +650,48 @@ void TabContentsViewGtk::OnDragDataGet( GdkDragContext* context, GtkSelectionData* selection_data, guint target_type, guint time, TabContentsViewGtk* view) { const int bits_per_byte = 8; - // We must make this initialization here or gcc complains about jumping past + // We must make these initializations here or gcc complains about jumping past // it in the switch statement. std::string utf8_text; + Pickle pickle; switch (target_type) { - case GtkDndUtil::X_CHROME_TEXT_PLAIN: + case GtkDndUtil::TEXT_PLAIN: utf8_text = UTF16ToUTF8(view->drop_data_->plain_text); gtk_selection_data_set_text(selection_data, utf8_text.c_str(), utf8_text.length()); break; - case GtkDndUtil::X_CHROME_TEXT_URI_LIST: + + case GtkDndUtil::TEXT_URI_LIST: gchar* uri_array[2]; uri_array[0] = strdup(view->drop_data_->url.spec().c_str()); uri_array[1] = NULL; gtk_selection_data_set_uris(selection_data, uri_array); free(uri_array[0]); break; - case GtkDndUtil::X_CHROME_TEXT_HTML: + + case GtkDndUtil::TEXT_HTML: // TODO(estade): change relative links to be absolute using // |html_base_url|. utf8_text = UTF16ToUTF8(view->drop_data_->text_html); gtk_selection_data_set(selection_data, - GtkDndUtil::GetAtomForTarget(GtkDndUtil::X_CHROME_TEXT_HTML), + GtkDndUtil::GetAtomForTarget(GtkDndUtil::TEXT_HTML), bits_per_byte, reinterpret_cast<const guchar*>(utf8_text.c_str()), utf8_text.length()); break; - case GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS: + case GtkDndUtil::CHROME_NAMED_URL: + pickle.WriteString(UTF16ToUTF8(view->drop_data_->url_title)); + pickle.WriteString(view->drop_data_->url.spec()); + gtk_selection_data_set(selection_data, + GtkDndUtil::GetAtomForTarget(GtkDndUtil::CHROME_NAMED_URL), + bits_per_byte, + reinterpret_cast<const guchar*>(pickle.data()), + pickle.size()); + break; + + case GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS: gtk_selection_data_set(selection_data, view->drag_file_mime_type_, bits_per_byte, reinterpret_cast<const guchar*>( |