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;
// 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.
void DragDownloadItem(const download::DownloadItem* download,
gfx::Image* icon,
const gfx::Image* icon,
gfx::NativeView view);
#endif // CHROME_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_ITEM_H_
......@@ -29,7 +29,7 @@
#endif
void DragDownloadItem(const download::DownloadItem* download,
gfx::Image* icon,
const gfx::Image* icon,
gfx::NativeView view) {
DCHECK(download);
DCHECK_EQ(download::DownloadItem::COMPLETE, download->GetState());
......
......@@ -35,7 +35,7 @@ id<NSDraggingSource> GetDraggingSource() {
}
void DragDownloadItem(const download::DownloadItem* download,
gfx::Image* icon,
const gfx::Image* icon,
gfx::NativeView native_view) {
DCHECK_EQ(download::DownloadItem::COMPLETE, download->GetState());
NSView* view = native_view.GetNativeNSView();
......
......@@ -302,7 +302,6 @@ DownloadItemView::DownloadItemView(DownloadUIModel::DownloadUIModelPtr download,
dropdown_state_(NORMAL),
mode_(NORMAL_MODE),
dragging_(false),
starting_drag_(false),
model_(std::move(download)),
save_button_(nullptr),
discard_button_(nullptr),
......@@ -444,31 +443,27 @@ void DownloadItemView::Layout() {
}
}
// Handle drag (file copy) operations.
bool DownloadItemView::OnMouseDragged(const ui::MouseEvent& event) {
// Handle drag (file copy) operations.
// Mouse should not activate us in dangerous mode.
if (IsShowingWarningDialog() || IsShowingMixedContentDialog())
return true;
if (!starting_drag_) {
starting_drag_ = true;
if (!drag_start_point_)
drag_start_point_ = event.location();
}
if (dragging_) {
if (model_->GetState() == DownloadItem::COMPLETE) {
IconManager* im = g_browser_process->icon_manager();
gfx::Image* icon = im->LookupIconFromFilepath(model_->GetTargetFilePath(),
IconLoader::SMALL);
views::Widget* widget = GetWidget();
if (model_->download()) {
// TODO(shaktisahu): Make DragDownloadItem work with a model.
DragDownloadItem(model_->download(), icon,
widget ? widget->GetNativeView() : nullptr);
RecordDownloadShelfDragEvent(DownloadShelfDragEvent::STARTED);
}
}
} else if (ExceededDragThreshold(event.location() - drag_start_point_)) {
dragging_ = true;
if (!dragging_) {
dragging_ = ExceededDragThreshold(event.location() - *drag_start_point_);
} else if ((model_->GetState() == DownloadItem::COMPLETE) &&
model_->download()) {
const gfx::Image* const file_icon =
g_browser_process->icon_manager()->LookupIconFromFilepath(
model_->GetTargetFilePath(), IconLoader::SMALL);
const views::Widget* const widget = GetWidget();
// TODO(shaktisahu): Make DragDownloadItem work with a model.
DragDownloadItem(model_->download(), file_icon,
widget ? widget->GetNativeView() : nullptr);
RecordDownloadShelfDragEvent(DownloadShelfDragEvent::STARTED);
}
return true;
}
......@@ -481,7 +476,7 @@ void DownloadItemView::OnMouseCaptureLost() {
if (dragging_) {
// Starting a drag results in a MouseCaptureLost.
dragging_ = false;
starting_drag_ = false;
drag_start_point_.reset();
}
}
......
......@@ -22,6 +22,7 @@
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/strings/string_util.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/time/time.h"
......@@ -318,11 +319,8 @@ class DownloadItemView : public views::View,
// Whether we are dragging the download button.
bool dragging_;
// Whether we are tracking a possible drag.
bool starting_drag_;
// 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.
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