Chromium Code Reviews| Index: chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc |
| =================================================================== |
| --- chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc (revision 106056) |
| +++ chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc (working copy) |
| @@ -21,6 +21,8 @@ |
| #include "chrome/browser/defaults.h" |
| #include "chrome/browser/instant/instant_controller.h" |
| #include "chrome/browser/platform_util.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_list.h" |
| #include "chrome/browser/ui/gtk/gtk_util.h" |
| #include "chrome/browser/ui/gtk/view_id_util.h" |
| #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| @@ -33,6 +35,7 @@ |
| #include "third_party/undoview/undo_view.h" |
| #include "ui/base/animation/multi_animation.h" |
| #include "ui/base/dragdrop/drag_drop_types.h" |
| +#include "ui/base/dragdrop/gtk_dnd_util.h" |
| #include "ui/base/gtk/gtk_hig_constants.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| @@ -244,6 +247,7 @@ |
| tag_table_ = gtk_text_tag_table_new(); |
| text_buffer_ = gtk_text_buffer_new(tag_table_); |
| g_object_set_data(G_OBJECT(text_buffer_), kOmniboxViewGtkKey, this); |
| + copy_targets_ = gtk_text_buffer_get_copy_target_list(text_buffer_); |
|
Evan Stade
2011/10/21 19:16:11
doing this opens a can of worms regarding object o
SanjoyPal
2011/10/22 03:34:02
Done.
|
| // We need to run this two handlers before undo manager's handlers, so that |
| // text iterators modified by these handlers can be passed down to undo |
| @@ -1610,17 +1614,35 @@ |
| switch (target_type) { |
| case GTK_TEXT_BUFFER_TARGET_INFO_TEXT: { |
| gtk_selection_data_set_text(selection_data, dragged_text_.c_str(), -1); |
| + break; |
| } |
| + case ui::TEXT_URI_LIST: { |
| + TabContents* current_tab = |
| + BrowserList::GetLastActive()->GetSelectedTabContents(); |
| + string16 tab_title = current_tab->GetTitle(); |
| + // Pass an empty string if user has edited the URL. |
| + if (current_tab->GetURL().spec() != dragged_text_) |
| + tab_title = string16(); |
| + ui::WriteURLWithName(selection_data, GURL(dragged_text_), |
| + tab_title, target_type); |
| + break; |
| + } |
| } |
| } |
| void OmniboxViewGtk::HandleDragBegin(GtkWidget* widget, |
| GdkDragContext* context) { |
| + // Add TEXT_URI_TARGET to the omnibox target list only if its a valid url. |
| + if (GURL(selected_text_).is_valid()) |
|
Evan Stade
2011/10/21 19:16:11
no. You need to use AdjustTextForCopy
SanjoyPal
2011/10/22 03:34:02
Done.
|
| + gtk_target_list_add_uri_targets(copy_targets_, ui::TEXT_URI_LIST); |
| dragged_text_ = selected_text_; |
| } |
| void OmniboxViewGtk::HandleDragEnd(GtkWidget* widget, |
| GdkDragContext* context) { |
| + GdkAtom text_uri_atom = ui::GetAtomForTarget(ui::TEXT_URI_LIST); |
| + if (gtk_target_list_find(copy_targets_, text_uri_atom, NULL)) |
|
Evan Stade
2011/10/21 19:16:11
I don't think you need this check
SanjoyPal
2011/10/22 03:34:02
Done.
|
| + gtk_target_list_remove(copy_targets_, text_uri_atom); |
| dragged_text_.clear(); |
| } |