Commit 1bc8d56d authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Minor cleanup for download item dragging.

* Make more things const.
* Remove |starting_drag_| member by making |drag_start_point_| an
  Optional.
* Reduce nesting by reordering conditionals.

Bug: none
Change-Id: I1910ddf86af8d1545095f7b9a7e3d5c7c8ad6653
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2255386Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780893}
parent 0abd67f6
...@@ -19,7 +19,7 @@ class Image; ...@@ -19,7 +19,7 @@ class Image;
// DownloadItem. If |icon| is NULL, no image will be accompany the drag. |view| // DownloadItem. If |icon| is NULL, no image will be accompany the drag. |view|
// is only required for Mac OS X, elsewhere it can be NULL. // is only required for Mac OS X, elsewhere it can be NULL.
void DragDownloadItem(const download::DownloadItem* download, void DragDownloadItem(const download::DownloadItem* download,
gfx::Image* icon, const gfx::Image* icon,
gfx::NativeView view); gfx::NativeView view);
#endif // CHROME_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_ITEM_H_ #endif // CHROME_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_ITEM_H_
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#endif #endif
void DragDownloadItem(const download::DownloadItem* download, void DragDownloadItem(const download::DownloadItem* download,
gfx::Image* icon, const gfx::Image* icon,
gfx::NativeView view) { gfx::NativeView view) {
DCHECK(download); DCHECK(download);
DCHECK_EQ(download::DownloadItem::COMPLETE, download->GetState()); DCHECK_EQ(download::DownloadItem::COMPLETE, download->GetState());
......
...@@ -35,7 +35,7 @@ id<NSDraggingSource> GetDraggingSource() { ...@@ -35,7 +35,7 @@ id<NSDraggingSource> GetDraggingSource() {
} }
void DragDownloadItem(const download::DownloadItem* download, void DragDownloadItem(const download::DownloadItem* download,
gfx::Image* icon, const gfx::Image* icon,
gfx::NativeView native_view) { gfx::NativeView native_view) {
DCHECK_EQ(download::DownloadItem::COMPLETE, download->GetState()); DCHECK_EQ(download::DownloadItem::COMPLETE, download->GetState());
NSView* view = native_view.GetNativeNSView(); NSView* view = native_view.GetNativeNSView();
......
...@@ -302,7 +302,6 @@ DownloadItemView::DownloadItemView(DownloadUIModel::DownloadUIModelPtr download, ...@@ -302,7 +302,6 @@ DownloadItemView::DownloadItemView(DownloadUIModel::DownloadUIModelPtr download,
dropdown_state_(NORMAL), dropdown_state_(NORMAL),
mode_(NORMAL_MODE), mode_(NORMAL_MODE),
dragging_(false), dragging_(false),
starting_drag_(false),
model_(std::move(download)), model_(std::move(download)),
save_button_(nullptr), save_button_(nullptr),
discard_button_(nullptr), discard_button_(nullptr),
...@@ -444,31 +443,27 @@ void DownloadItemView::Layout() { ...@@ -444,31 +443,27 @@ void DownloadItemView::Layout() {
} }
} }
// Handle drag (file copy) operations.
bool DownloadItemView::OnMouseDragged(const ui::MouseEvent& event) { bool DownloadItemView::OnMouseDragged(const ui::MouseEvent& event) {
// Handle drag (file copy) operations.
// Mouse should not activate us in dangerous mode. // Mouse should not activate us in dangerous mode.
if (IsShowingWarningDialog() || IsShowingMixedContentDialog()) if (IsShowingWarningDialog() || IsShowingMixedContentDialog())
return true; return true;
if (!starting_drag_) { if (!drag_start_point_)
starting_drag_ = true;
drag_start_point_ = event.location(); drag_start_point_ = event.location();
} if (!dragging_) {
if (dragging_) { dragging_ = ExceededDragThreshold(event.location() - *drag_start_point_);
if (model_->GetState() == DownloadItem::COMPLETE) { } else if ((model_->GetState() == DownloadItem::COMPLETE) &&
IconManager* im = g_browser_process->icon_manager(); model_->download()) {
gfx::Image* icon = im->LookupIconFromFilepath(model_->GetTargetFilePath(), const gfx::Image* const file_icon =
IconLoader::SMALL); g_browser_process->icon_manager()->LookupIconFromFilepath(
views::Widget* widget = GetWidget(); model_->GetTargetFilePath(), IconLoader::SMALL);
if (model_->download()) { const views::Widget* const widget = GetWidget();
// TODO(shaktisahu): Make DragDownloadItem work with a model. // TODO(shaktisahu): Make DragDownloadItem work with a model.
DragDownloadItem(model_->download(), icon, DragDownloadItem(model_->download(), file_icon,
widget ? widget->GetNativeView() : nullptr); widget ? widget->GetNativeView() : nullptr);
RecordDownloadShelfDragEvent(DownloadShelfDragEvent::STARTED); RecordDownloadShelfDragEvent(DownloadShelfDragEvent::STARTED);
}
}
} else if (ExceededDragThreshold(event.location() - drag_start_point_)) {
dragging_ = true;
} }
return true; return true;
} }
...@@ -481,7 +476,7 @@ void DownloadItemView::OnMouseCaptureLost() { ...@@ -481,7 +476,7 @@ void DownloadItemView::OnMouseCaptureLost() {
if (dragging_) { if (dragging_) {
// Starting a drag results in a MouseCaptureLost. // Starting a drag results in a MouseCaptureLost.
dragging_ = false; dragging_ = false;
starting_drag_ = false; drag_start_point_.reset();
} }
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/task/cancelable_task_tracker.h" #include "base/task/cancelable_task_tracker.h"
#include "base/time/time.h" #include "base/time/time.h"
...@@ -318,11 +319,8 @@ class DownloadItemView : public views::View, ...@@ -318,11 +319,8 @@ class DownloadItemView : public views::View,
// Whether we are dragging the download button. // Whether we are dragging the download button.
bool dragging_; bool dragging_;
// Whether we are tracking a possible drag.
bool starting_drag_;
// Position that a possible drag started at. // Position that a possible drag started at.
gfx::Point drag_start_point_; base::Optional<gfx::Point> drag_start_point_;
// For canceling an in progress icon request. // For canceling an in progress icon request.
base::CancelableTaskTracker cancelable_task_tracker_; base::CancelableTaskTracker cancelable_task_tracker_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment