Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(721)

Unified Diff: chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc

Issue 6462009: Allow dragging and dropping of URLs to any portion of the toolbar view.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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()));

Powered by Google App Engine
This is Rietveld 408576698