Skip to content

Commit

Permalink
Allow dragging and dropping of URLs to any portion of the toolbar view.
Browse files Browse the repository at this point in the history
BUG=9181
TEST=Drag a URL or ay text to the toolbar area, including back/forward/reload
buttons, and the browser action/menu area.  This should not interfere with
dragging and dropping of browser actions.  Test that browser actions behave
as they should (i.e. should be able to change their order in the toolbar).

Review URL: http://codereview.chromium.org/6462009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75288 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rogerta@chromium.org committed Feb 17, 2011
1 parent 531b5d5 commit 557205c
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 89 deletions.
1 change: 1 addition & 0 deletions chrome/browser/autocomplete/autocomplete_edit_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class TestingAutocompleteEditView : public AutocompleteEditView {

#if defined(TOOLKIT_VIEWS)
virtual views::View* AddToView(views::View* parent) { return NULL; }
virtual int OnPerformDrop(const views::DropTargetEvent& event) { return 0; }
#endif

private:
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/autocomplete/autocomplete_edit_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class TabContents;

#if defined(TOOLKIT_VIEWS)
namespace views {
class DropTargetEvent;
class View;
} // namespace views
#endif
Expand Down Expand Up @@ -175,6 +176,9 @@ class AutocompleteEditView {
// Adds the autocomplete edit view to view hierarchy and
// returns the views::View of the edit view.
virtual views::View* AddToView(views::View* parent) = 0;

// Performs the drop of a drag and drop operation on the view.
virtual int OnPerformDrop(const views::DropTargetEvent& event) = 0;
#endif

virtual ~AutocompleteEditView() {}
Expand Down
45 changes: 43 additions & 2 deletions chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -65,6 +67,16 @@ size_t GetUTF8Offset(const string16& text, size_t text_offset) {
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)
Expand Down Expand Up @@ -843,6 +855,27 @@ views::View* AutocompleteEditViewGtk::AddToView(views::View* parent) {
return host;
}

int AutocompleteEditViewGtk::OnPerformDrop(
const views::DropTargetEvent& event) {
std::wstring text;
const ui::OSExchangeData& data = event.data();
if (data.HasURL()) {
GURL url;
std::wstring title;
if (data.GetURLAndTitle(&url, &title))
text = UTF8ToWide(url.spec());
} else {
std::wstring data_string;
if (data.GetString(&data_string))
text = CollapseWhitespace(data_string, true);
}

if (!text.empty() && OnPerformDropImpl(WideToUTF16(text)))
return CopyOrLinkDragOperation(event.source_operations());

return ui::DragDropTypes::DRAG_NONE;
}

void AutocompleteEditViewGtk::EnableAccessibility() {
accessible_widget_helper_.reset(
new AccessibleWidgetHelper(text_view(), model_->profile()));
Expand Down Expand Up @@ -1545,8 +1578,7 @@ void AutocompleteEditViewGtk::HandleDragDataReceived(

string16 possible_url = UTF8ToUTF16(reinterpret_cast<char*>(text));
g_free(text);
if (model_->CanPasteAndGo(CollapseWhitespace(possible_url, true))) {
model_->PasteAndGo();
if (OnPerformDropImpl(possible_url)) {
gtk_drag_finish(context, TRUE, TRUE, time);

static guint signal_id =
Expand Down Expand Up @@ -1737,6 +1769,15 @@ void AutocompleteEditViewGtk::HandleCopyOrCutClipboard(bool copy) {
OwnPrimarySelection(UTF16ToUTF8(text));
}

bool AutocompleteEditViewGtk::OnPerformDropImpl(const string16& text) {
if (model_->CanPasteAndGo(CollapseWhitespace(text, true))) {
model_->PasteAndGo();
return true;
}

return false;
}

gfx::Font AutocompleteEditViewGtk::GetFont() {
#if defined(TOOLKIT_VIEWS)
bool use_gtk = false;
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,

#if defined(TOOLKIT_VIEWS)
virtual views::View* AddToView(views::View* parent);
virtual int OnPerformDrop(const views::DropTargetEvent& event);

// Enables accessibility on AutocompleteEditView.
void EnableAccessibility();
Expand Down Expand Up @@ -276,6 +277,9 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,

void HandleCopyOrCutClipboard(bool copy);

// Common implementation for performing a drop on the edit view.
bool OnPerformDropImpl(const string16& text);

// Returns the font used in |text_view_|.
gfx::Font GetFont();

Expand Down
7 changes: 7 additions & 0 deletions chrome/browser/autocomplete/autocomplete_edit_view_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
#include "net/base/escape.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/font.h"
#include "views/border.h"
Expand Down Expand Up @@ -559,6 +560,12 @@ views::View* AutocompleteEditViewViews::AddToView(views::View* parent) {
return this;
}

int AutocompleteEditViewViews::OnPerformDrop(
const views::DropTargetEvent& event) {
NOTIMPLEMENTED();
return ui::DragDropTypes::DRAG_NONE;
}

////////////////////////////////////////////////////////////////////////////////
// AutocompleteEditViewViews, NotificationObserver implementation:

Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/autocomplete/autocomplete_edit_view_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ class TabContents;
// Views-implementation of AutocompleteEditView. This is based on
// gtk implementation. The following features are not yet supported.
//
// IME supoprt.
// IME support.
// LTR support.
// Selection behavior.
// Cut,copy and paste behavior.
// Drag and drop behavior.
// URL styles (strikestrough insecure scheme, emphasize host).
// Custom context menu for omnibox.
// Instant.
Expand Down Expand Up @@ -116,6 +117,7 @@ class AutocompleteEditViewViews : public views::View,
virtual int TextWidth() const;
virtual bool IsImeComposing() const;
virtual views::View* AddToView(views::View* parent);
virtual int OnPerformDrop(const views::DropTargetEvent& event);

// Overridden from NotificationObserver:
virtual void Observe(NotificationType type,
Expand Down
Loading

0 comments on commit 557205c

Please sign in to comment.