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

Unified Diff: chrome/browser/ui/views/tabs/tab_strip.cc

Issue 68133020: Fix dragging supported files to tab strip. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes Created 7 years, 1 month 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/ui/views/tabs/tab_strip.cc
diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc
index 1308d240a57f28d5ff6569fb8f77e5044af05327..84706b536eaf333dc923c5b1ebcf8f4fa7056685 100644
--- a/chrome/browser/ui/views/tabs/tab_strip.cc
+++ b/chrome/browser/ui/views/tabs/tab_strip.cc
@@ -990,6 +990,11 @@ void TabStrip::StopAnimating(bool layout) {
DoLayout();
}
+void TabStrip::FileSupported(const GURL& url, bool supported) {
+ if (drop_info_.get() && drop_info_->url == url)
+ drop_info_->file_supported = supported;
+}
+
const ui::ListSelectionModel& TabStrip::GetSelectionModel() {
return controller_->GetSelectionModel();
}
@@ -1400,10 +1405,28 @@ void TabStrip::OnDragEntered(const DropTargetEvent& event) {
StopAnimating(true);
UpdateDropIndex(event);
+
+ GURL url;
+ string16 title;
+
+ // Check whether the event data includes supported drop data.
+ if (event.data().GetURLAndTitle(&url, &title) && url.is_valid()) {
+ drop_info_->url = url;
+
+ // For file:// URLs, kick off a MIME type request in case they're dropped.
+ if (url.SchemeIsFile())
+ controller()->CheckFileSupported(url);
+ }
}
int TabStrip::OnDragUpdated(const DropTargetEvent& event) {
+ // Update the drop index even if the file is unsupported, to allow
+ // dragging a file to the contents of another tab.
UpdateDropIndex(event);
+
+ if (!drop_info_->file_supported)
+ return ui::DragDropTypes::DRAG_NONE;
+
return GetDropEffect(event);
}
@@ -1417,13 +1440,17 @@ int TabStrip::OnPerformDrop(const DropTargetEvent& event) {
const int drop_index = drop_info_->drop_index;
const bool drop_before = drop_info_->drop_before;
+ const bool file_supported = drop_info_->file_supported;
// Hide the drop indicator.
SetDropIndex(-1, false);
+ // Do nothing if the file was unsupported or the URL is invalid. The URL may
+ // have been changed after |drop_info_| was created.
GURL url;
string16 title;
- if (!event.data().GetURLAndTitle(&url, &title) || !url.is_valid())
+ if (!file_supported ||
+ !event.data().GetURLAndTitle(&url, &title) || !url.is_valid())
michaelpg 2013/11/26 04:50:13 Apparently we *do* need this check, because the Br
sky 2013/12/02 16:22:50 Can't we just check if drop_info_->url is not empt
michaelpg 2013/12/02 19:51:07 The URL could be non-empty but unsupported. For in
return ui::DragDropTypes::DRAG_NONE;
controller()->PerformDrop(drop_before, drop_index, url);
@@ -2432,7 +2459,8 @@ TabStrip::DropInfo::DropInfo(int drop_index,
views::Widget* context)
: drop_index(drop_index),
drop_before(drop_before),
- point_down(point_down) {
+ point_down(point_down),
+ file_supported(true) {
arrow_view = new views::ImageView;
arrow_view->SetImage(GetDropArrowImage(point_down));

Powered by Google App Engine
This is Rietveld 408576698