Index: chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc |
=================================================================== |
--- chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc (revision 74430) |
+++ chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc (working copy) |
@@ -31,6 +31,7 @@ |
#include "net/base/escape.h" |
#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/l10n/l10n_util.h" |
#include "ui/base/resource/resource_bundle.h" |
#include "ui/gfx/color_utils.h" |
@@ -44,6 +45,7 @@ |
#include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.h" |
#include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
#include "views/controls/textfield/native_textfield_views.h" |
+#include "views/events/event.h" |
#else |
#include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" |
#include "chrome/browser/ui/gtk/gtk_theme_provider.h" |
@@ -65,6 +67,16 @@ |
return UTF16ToUTF8(text.substr(0, text_offset)).size(); |
} |
+// A helper method for determining a valid drag operation given the allowed |
+// operation. We prefer copy over link. |
+int CopyOrLinkDragOperation(int drag_operation) { |
+ if (drag_operation & ui::DragDropTypes::DRAG_COPY) |
+ return ui::DragDropTypes::DRAG_COPY; |
+ if (drag_operation & ui::DragDropTypes::DRAG_LINK) |
+ return ui::DragDropTypes::DRAG_LINK; |
+ return ui::DragDropTypes::DRAG_NONE; |
+} |
+ |
// Stores GTK+-specific state so it can be restored after switching tabs. |
struct ViewState { |
explicit ViewState(const AutocompleteEditViewGtk::CharRange& selection_range) |
@@ -845,6 +857,31 @@ |
return host; |
} |
+int AutocompleteEditViewGtk::OnPerformDrop( |
+ const views::DropTargetEvent& event) { |
+ const ui::OSExchangeData& data = event.data(); |
sky
2011/02/11 01:06:07
What if the drag originated from this view?
Roger Tawa OOO till Jul 10th
2011/02/11 15:20:17
Good point. This code should be equivalent to the
|
+ if (data.HasURL()) { |
+ GURL url; |
+ std::wstring title; |
+ if (data.GetURLAndTitle(&url, &title)) { |
+ SetUserText(WideToUTF16(UTF8ToWide(url.spec()))); |
+ model()->AcceptInput(CURRENT_TAB, true); |
+ return CopyOrLinkDragOperation(event.source_operations()); |
+ } |
+ } else { |
+ std::wstring text; |
+ if (data.GetString(&text)) { |
+ text = CollapseWhitespace(text, true); |
+ if (model()->CanPasteAndGo(WideToUTF16(text))) { |
+ model()->PasteAndGo(); |
+ return CopyOrLinkDragOperation(event.source_operations()); |
+ } |
+ } |
+ } |
+ |
+ return ui::DragDropTypes::DRAG_NONE; |
+} |
+ |
void AutocompleteEditViewGtk::EnableAccessibility() { |
accessible_widget_helper_.reset( |
new AccessibleWidgetHelper(text_view(), model_->profile())); |