summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/frame
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-08 20:24:12 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-08 20:24:12 +0000
commitcdb4782bf9c5d59fb23eca751aafaea3fb93d46f (patch)
treefa66d986e7237ef7b12decc60fa7d6334a176f83 /chrome/browser/views/frame
parent2b55f08bd457f3d0feba66093aed584e6817ce9e (diff)
downloadchromium_src-cdb4782bf9c5d59fb23eca751aafaea3fb93d46f.zip
chromium_src-cdb4782bf9c5d59fb23eca751aafaea3fb93d46f.tar.gz
chromium_src-cdb4782bf9c5d59fb23eca751aafaea3fb93d46f.tar.bz2
Fixes regression introduced in dnd refactoring. I removed a check for
the URL that I shouldn't have (it won't be needed at some point, but it is now). BUG=21198 TEST=Select a URL and drag to the tab strip. Make sure you get the drop target and you can drop the text to create a new tab. Do the same with www.google.com, you shouldn't get a drop target. Review URL: http://codereview.chromium.org/202010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25653 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/frame')
-rw-r--r--chrome/browser/views/frame/browser_frame_gtk.cc3
-rw-r--r--chrome/browser/views/frame/browser_frame_win.cc3
-rw-r--r--chrome/browser/views/frame/browser_root_view.cc113
-rw-r--r--chrome/browser/views/frame/browser_root_view.h25
4 files changed, 105 insertions, 39 deletions
diff --git a/chrome/browser/views/frame/browser_frame_gtk.cc b/chrome/browser/views/frame/browser_frame_gtk.cc
index 2538038..a2ce1db 100644
--- a/chrome/browser/views/frame/browser_frame_gtk.cc
+++ b/chrome/browser/views/frame/browser_frame_gtk.cc
@@ -43,7 +43,6 @@ views::Window* BrowserFrameGtk::GetWindow() {
}
void BrowserFrameGtk::TabStripCreated(TabStripWrapper* tabstrip) {
- root_view_->set_tabstrip(tabstrip);
}
int BrowserFrameGtk::GetMinimizeButtonOffset() const {
@@ -79,6 +78,6 @@ ThemeProvider* BrowserFrameGtk::GetDefaultThemeProvider() const {
}
views::RootView* BrowserFrameGtk::CreateRootView() {
- root_view_ = new BrowserRootView(this);
+ root_view_ = new BrowserRootView(browser_view_, this);
return root_view_;
}
diff --git a/chrome/browser/views/frame/browser_frame_win.cc b/chrome/browser/views/frame/browser_frame_win.cc
index d8484f4..343def5 100644
--- a/chrome/browser/views/frame/browser_frame_win.cc
+++ b/chrome/browser/views/frame/browser_frame_win.cc
@@ -69,7 +69,6 @@ views::Window* BrowserFrameWin::GetWindow() {
}
void BrowserFrameWin::TabStripCreated(TabStripWrapper* tabstrip) {
- root_view_->set_tabstrip(tabstrip);
}
int BrowserFrameWin::GetMinimizeButtonOffset() const {
@@ -319,7 +318,7 @@ void BrowserFrameWin::UpdateFrameAfterFrameChange() {
}
views::RootView* BrowserFrameWin::CreateRootView() {
- root_view_ = new BrowserRootView(this);
+ root_view_ = new BrowserRootView(browser_view_, this);
return root_view_;
}
diff --git a/chrome/browser/views/frame/browser_root_view.cc b/chrome/browser/views/frame/browser_root_view.cc
index 753a3314..f0a3cb2 100644
--- a/chrome/browser/views/frame/browser_root_view.cc
+++ b/chrome/browser/views/frame/browser_root_view.cc
@@ -6,52 +6,69 @@
#include "app/drag_drop_types.h"
#include "app/os_exchange_data.h"
+#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
+#include "chrome/browser/location_bar.h"
#include "chrome/browser/views/frame/browser_view.h"
#include "chrome/browser/views/frame/browser_frame.h"
#include "chrome/browser/views/tabs/tab_strip_wrapper.h"
-BrowserRootView::BrowserRootView(views::Widget* widget)
+BrowserRootView::BrowserRootView(BrowserView* browser_view,
+ views::Widget* widget)
: views::RootView(widget),
- tabstrip_(NULL),
+ browser_view_(browser_view),
forwarding_to_tab_strip_(false) {
}
bool BrowserRootView::GetDropFormats(
int* formats,
std::set<OSExchangeData::CustomFormat>* custom_formats) {
- if (tabstrip_ && tabstrip_->GetView()->IsVisible() &&
- !tabstrip_->IsAnimating()) {
- *formats = OSExchangeData::URL;
+ if (tabstrip() && tabstrip()->GetView()->IsVisible() &&
+ !tabstrip()->IsAnimating()) {
+ *formats = OSExchangeData::URL | OSExchangeData::STRING;
return true;
}
return false;
}
+bool BrowserRootView::AreDropTypesRequired() {
+ return true;
+}
+
bool BrowserRootView::CanDrop(const OSExchangeData& data) {
- return (tabstrip_ && tabstrip_->GetView()->IsVisible() &&
- !tabstrip_->IsAnimating());
+ if (!tabstrip() || !tabstrip()->GetView()->IsVisible() ||
+ tabstrip()->IsAnimating())
+ return false;
+
+ // If there is a URL, we'll allow the drop.
+ if (data.HasURL())
+ return true;
+
+ // If there isn't a URL, see if we can 'paste and go'.
+ return GetPasteAndGoURL(data, NULL);
}
void BrowserRootView::OnDragEntered(const views::DropTargetEvent& event) {
if (ShouldForwardToTabStrip(event)) {
forwarding_to_tab_strip_ = true;
- scoped_ptr<views::DropTargetEvent> mapped_event(MapEventToTabStrip(event));
- tabstrip_->GetView()->OnDragEntered(*mapped_event.get());
+ scoped_ptr<views::DropTargetEvent> mapped_event(
+ MapEventToTabStrip(event, event.GetData()));
+ tabstrip()->GetView()->OnDragEntered(*mapped_event.get());
}
}
int BrowserRootView::OnDragUpdated(const views::DropTargetEvent& event) {
if (ShouldForwardToTabStrip(event)) {
scoped_ptr<views::DropTargetEvent> mapped_event(
- MapEventToTabStrip(event));
+ MapEventToTabStrip(event, event.GetData()));
if (!forwarding_to_tab_strip_) {
- tabstrip_->GetView()->OnDragEntered(*mapped_event.get());
+ tabstrip()->GetView()->OnDragEntered(*mapped_event.get());
forwarding_to_tab_strip_ = true;
}
- return tabstrip_->GetView()->OnDragUpdated(*mapped_event.get());
+ return tabstrip()->GetView()->OnDragUpdated(*mapped_event.get());
} else if (forwarding_to_tab_strip_) {
forwarding_to_tab_strip_ = false;
- tabstrip_->GetView()->OnDragExited();
+ tabstrip()->GetView()->OnDragExited();
}
return DragDropTypes::DRAG_NONE;
}
@@ -59,37 +76,81 @@ int BrowserRootView::OnDragUpdated(const views::DropTargetEvent& event) {
void BrowserRootView::OnDragExited() {
if (forwarding_to_tab_strip_) {
forwarding_to_tab_strip_ = false;
- tabstrip_->GetView()->OnDragExited();
+ tabstrip()->GetView()->OnDragExited();
}
}
int BrowserRootView::OnPerformDrop(const views::DropTargetEvent& event) {
- if (forwarding_to_tab_strip_) {
- forwarding_to_tab_strip_ = false;
- scoped_ptr<views::DropTargetEvent> mapped_event(
- MapEventToTabStrip(event));
- return tabstrip_->GetView()->OnPerformDrop(*mapped_event.get());
+ if (!forwarding_to_tab_strip_)
+ return DragDropTypes::DRAG_NONE;
+
+ // Extract the URL and create a new OSExchangeData containing the URL. We do
+ // this as the TabStrip doesn't know about the autocomplete edit and neeeds
+ // to know about it to handle 'paste and go'.
+ GURL url;
+ std::wstring title;
+ OSExchangeData mapped_data;
+ if (!event.GetData().GetURLAndTitle(&url, &title) || !url.is_valid()) {
+ // The url isn't valid. Use the paste and go url.
+ if (GetPasteAndGoURL(event.GetData(), &url))
+ mapped_data.SetURL(url, std::wstring());
+ // else case: couldn't extract a url or 'paste and go' url. This ends up
+ // passing through an OSExchangeData with nothing in it. We need to do this
+ // so that the tab strip cleans up properly.
+ } else {
+ mapped_data.SetURL(url, std::wstring());
}
- return DragDropTypes::DRAG_NONE;
+ forwarding_to_tab_strip_ = false;
+ scoped_ptr<views::DropTargetEvent> mapped_event(
+ MapEventToTabStrip(event, mapped_data));
+ return tabstrip()->GetView()->OnPerformDrop(*mapped_event);
}
bool BrowserRootView::ShouldForwardToTabStrip(
const views::DropTargetEvent& event) {
- if (!tabstrip_->GetView()->IsVisible())
+ if (!tabstrip()->GetView()->IsVisible())
return false;
// Allow the drop as long as the mouse is over the tabstrip or vertically
// before it.
gfx::Point tab_loc_in_host;
- ConvertPointToView(tabstrip_->GetView(), this, &tab_loc_in_host);
- return event.y() < tab_loc_in_host.y() + tabstrip_->GetView()->height();
+ ConvertPointToView(tabstrip()->GetView(), this, &tab_loc_in_host);
+ return event.y() < tab_loc_in_host.y() + tabstrip()->GetView()->height();
}
views::DropTargetEvent* BrowserRootView::MapEventToTabStrip(
- const views::DropTargetEvent& event) {
+ const views::DropTargetEvent& event,
+ const OSExchangeData& data) {
gfx::Point tab_strip_loc(event.location());
- ConvertPointToView(this, tabstrip_->GetView(), &tab_strip_loc);
- return new views::DropTargetEvent(event.GetData(), tab_strip_loc.x(),
+ ConvertPointToView(this, tabstrip()->GetView(), &tab_strip_loc);
+ return new views::DropTargetEvent(data, tab_strip_loc.x(),
tab_strip_loc.y(),
event.GetSourceOperations());
}
+
+TabStripWrapper* BrowserRootView::tabstrip() const {
+ return browser_view_->tabstrip();
+}
+
+bool BrowserRootView::GetPasteAndGoURL(const OSExchangeData& data,
+ GURL* url) {
+ if (!data.HasString())
+ return false;
+
+ LocationBar* location_bar = browser_view_->GetLocationBar();
+ if (!location_bar)
+ return false;
+
+ AutocompleteEditView* edit = location_bar->location_entry();
+ if (!edit)
+ return false;
+
+ std::wstring text;
+ if (!data.GetString(&text) || text.empty() ||
+ !edit->model()->CanPasteAndGo(text)) {
+ return false;
+ }
+ if (url)
+ *url = edit->model()->paste_and_go_url();
+ return true;
+}
diff --git a/chrome/browser/views/frame/browser_root_view.h b/chrome/browser/views/frame/browser_root_view.h
index 5ead7cc..5e846a3 100644
--- a/chrome/browser/views/frame/browser_root_view.h
+++ b/chrome/browser/views/frame/browser_root_view.h
@@ -7,6 +7,7 @@
#include "views/widget/root_view.h"
+class BrowserView;
class OSExchangeData;
class TabStripWrapper;
@@ -18,16 +19,12 @@ class TabStripWrapper;
class BrowserRootView : public views::RootView {
public:
// You must call set_tabstrip before this class will accept drops.
- BrowserRootView(views::Widget* widget);
-
- // Sets the tabstrip associated with this window. This is used to forward
- // drag and drop operations to, so no drops will be accepted if there is no
- // tabstrip set.
- void set_tabstrip(TabStripWrapper* tabstrip) { tabstrip_ = tabstrip; }
+ BrowserRootView(BrowserView* browser_view, views::Widget* widget);
virtual bool GetDropFormats(
int* formats,
std::set<OSExchangeData::CustomFormat>* custom_formats);
+ virtual bool AreDropTypesRequired();
virtual bool CanDrop(const OSExchangeData& data);
virtual void OnDragEntered(const views::DropTargetEvent& event);
virtual int OnDragUpdated(const views::DropTargetEvent& event);
@@ -41,10 +38,20 @@ class BrowserRootView : public views::RootView {
// Converts the event from the hosts coordinate system to the tabstrips
// coordinate system.
views::DropTargetEvent* MapEventToTabStrip(
- const views::DropTargetEvent& event);
+ const views::DropTargetEvent& event,
+ const OSExchangeData& data);
+
+ TabStripWrapper* tabstrip() const;
+
+ // Returns true if |data| has string contents and the user can "paste and go"
+ // (see AutocompleteEditModel::CanPasteAndGo for details). If |url| is
+ // non-null and the user can "paste and go", |url| is set to the
+ // "paste and go" url.
+ bool GetPasteAndGoURL(const OSExchangeData& data,
+ GURL* url);
- // The TabStrip.
- TabStripWrapper* tabstrip_;
+ // The BrowserView.
+ BrowserView* browser_view_;
// If true, drag and drop events are being forwarded to the tab strip.
// This is used to determine when to send OnDragEntered and OnDragExited