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

Side by Side Diff: chrome/browser/ui/views/download/download_item_view_md.cc

Issue 1832963002: MD - add ripples to DL shelf items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates after bruthig chat Created 4 years, 8 months 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/download/download_item_view_md.h" 5 #include "chrome/browser/ui/views/download/download_item_view_md.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "ui/events/event.h" 50 #include "ui/events/event.h"
51 #include "ui/gfx/animation/slide_animation.h" 51 #include "ui/gfx/animation/slide_animation.h"
52 #include "ui/gfx/canvas.h" 52 #include "ui/gfx/canvas.h"
53 #include "ui/gfx/color_palette.h" 53 #include "ui/gfx/color_palette.h"
54 #include "ui/gfx/color_utils.h" 54 #include "ui/gfx/color_utils.h"
55 #include "ui/gfx/image/image.h" 55 #include "ui/gfx/image/image.h"
56 #include "ui/gfx/paint_vector_icon.h" 56 #include "ui/gfx/paint_vector_icon.h"
57 #include "ui/gfx/text_elider.h" 57 #include "ui/gfx/text_elider.h"
58 #include "ui/gfx/text_utils.h" 58 #include "ui/gfx/text_utils.h"
59 #include "ui/gfx/vector_icons_public.h" 59 #include "ui/gfx/vector_icons_public.h"
60 #include "ui/views/animation/flood_fill_ink_drop_animation.h"
60 #include "ui/views/animation/ink_drop_delegate.h" 61 #include "ui/views/animation/ink_drop_delegate.h"
62 #include "ui/views/animation/ink_drop_hover.h"
61 #include "ui/views/border.h" 63 #include "ui/views/border.h"
62 #include "ui/views/controls/button/image_button.h" 64 #include "ui/views/controls/button/image_button.h"
63 #include "ui/views/controls/button/label_button.h" 65 #include "ui/views/controls/button/label_button.h"
64 #include "ui/views/controls/button/md_text_button.h" 66 #include "ui/views/controls/button/md_text_button.h"
65 #include "ui/views/controls/label.h" 67 #include "ui/views/controls/label.h"
66 #include "ui/views/mouse_constants.h" 68 #include "ui/views/mouse_constants.h"
67 #include "ui/views/widget/root_view.h" 69 #include "ui/views/widget/root_view.h"
68 #include "ui/views/widget/widget.h" 70 #include "ui/views/widget/widget.h"
69 71
70 using content::DownloadItem; 72 using content::DownloadItem;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 153
152 DownloadItemViewMd::DownloadItemViewMd(DownloadItem* download_item, 154 DownloadItemViewMd::DownloadItemViewMd(DownloadItem* download_item,
153 DownloadShelfView* parent) 155 DownloadShelfView* parent)
154 : shelf_(parent), 156 : shelf_(parent),
155 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), 157 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)),
156 dropdown_state_(NORMAL), 158 dropdown_state_(NORMAL),
157 mode_(NORMAL_MODE), 159 mode_(NORMAL_MODE),
158 dragging_(false), 160 dragging_(false),
159 starting_drag_(false), 161 starting_drag_(false),
160 model_(download_item), 162 model_(download_item),
163 ink_drop_delegate_(this, this),
161 save_button_(nullptr), 164 save_button_(nullptr),
162 discard_button_(nullptr), 165 discard_button_(nullptr),
163 dropdown_button_(new BarControlButton(this)), 166 dropdown_button_(new BarControlButton(this)),
164 dangerous_download_label_(nullptr), 167 dangerous_download_label_(nullptr),
165 dangerous_download_label_sized_(false), 168 dangerous_download_label_sized_(false),
166 disabled_while_opening_(false), 169 disabled_while_opening_(false),
167 creation_time_(base::Time::Now()), 170 creation_time_(base::Time::Now()),
168 time_download_warning_shown_(base::Time()), 171 time_download_warning_shown_(base::Time()),
169 weak_ptr_factory_(this) { 172 weak_ptr_factory_(this) {
170 DCHECK(download()); 173 DCHECK(download());
171 DCHECK(ui::MaterialDesignController::IsModeMaterial()); 174 DCHECK(ui::MaterialDesignController::IsModeMaterial());
172 download()->AddObserver(this); 175 download()->AddObserver(this);
173 set_context_menu_controller(this); 176 set_context_menu_controller(this);
174 177
175 dropdown_button_->SetBorder( 178 dropdown_button_->SetBorder(
176 views::Border::CreateEmptyBorder(gfx::Insets(kDropdownBorderWidth))); 179 views::Border::CreateEmptyBorder(gfx::Insets(kDropdownBorderWidth)));
177 dropdown_button_->set_ink_drop_size(gfx::Size(32, 32)); 180 dropdown_button_->set_ink_drop_size(gfx::Size(32, 32));
178 AddChildView(dropdown_button_); 181 AddChildView(dropdown_button_);
179 182
180 LoadIcon(); 183 LoadIcon();
181 184
182 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 185 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
183 font_list_ = 186 font_list_ =
184 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(1); 187 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(1);
185 status_font_list_ = 188 status_font_list_ =
186 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(-2); 189 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(-2);
187 190
188 body_hover_animation_.reset(new gfx::SlideAnimation(this));
189 drop_hover_animation_.reset(new gfx::SlideAnimation(this));
190
191 SetAccessibilityFocusable(true); 191 SetAccessibilityFocusable(true);
192 192
193 OnDownloadUpdated(download()); 193 OnDownloadUpdated(download());
194 194
195 SetDropdownState(NORMAL); 195 SetDropdownState(NORMAL);
196 UpdateColorsFromTheme(); 196 UpdateColorsFromTheme();
197 } 197 }
198 198
199 DownloadItemViewMd::~DownloadItemViewMd() { 199 DownloadItemViewMd::~DownloadItemViewMd() {
200 StopDownloadProgress(); 200 StopDownloadProgress();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 } else { 369 } else {
370 width = kStartPadding + DownloadShelf::kProgressIndicatorSize + 370 width = kStartPadding + DownloadShelf::kProgressIndicatorSize +
371 kProgressTextPadding + kTextWidth + 371 kProgressTextPadding + kTextWidth +
372 dropdown_button_->GetPreferredSize().width() + kEndPadding; 372 dropdown_button_->GetPreferredSize().width() + kEndPadding;
373 } 373 }
374 374
375 return gfx::Size(width, std::max(kDefaultHeight, 375 return gfx::Size(width, std::max(kDefaultHeight,
376 2 * kMinimumVerticalPadding + child_height)); 376 2 * kMinimumVerticalPadding + child_height));
377 } 377 }
378 378
379 // Handle a mouse click and open the context menu if the mouse is
380 // over the drop-down region.
381 bool DownloadItemViewMd::OnMousePressed(const ui::MouseEvent& event) { 379 bool DownloadItemViewMd::OnMousePressed(const ui::MouseEvent& event) {
382 HandlePressEvent(event, event.IsOnlyLeftMouseButton()); 380 HandlePressEvent(event, event.IsOnlyLeftMouseButton());
383 return true; 381 return true;
384 } 382 }
385 383
386 // Handle drag (file copy) operations. 384 // Handle drag (file copy) operations.
387 bool DownloadItemViewMd::OnMouseDragged(const ui::MouseEvent& event) { 385 bool DownloadItemViewMd::OnMouseDragged(const ui::MouseEvent& event) {
388 // Mouse should not activate us in dangerous mode. 386 // Mouse should not activate us in dangerous mode.
389 if (IsShowingWarningDialog()) 387 if (IsShowingWarningDialog())
390 return true; 388 return true;
391 389
392 if (!starting_drag_) { 390 if (!starting_drag_) {
393 starting_drag_ = true; 391 starting_drag_ = true;
394 drag_start_point_ = event.location(); 392 drag_start_point_ = event.location();
393 ink_drop_delegate_.OnAction(views::InkDropState::HIDDEN);
395 } 394 }
396 if (dragging_) { 395 if (dragging_) {
397 if (download()->GetState() == DownloadItem::COMPLETE) { 396 if (download()->GetState() == DownloadItem::COMPLETE) {
398 IconManager* im = g_browser_process->icon_manager(); 397 IconManager* im = g_browser_process->icon_manager();
399 gfx::Image* icon = im->LookupIconFromFilepath( 398 gfx::Image* icon = im->LookupIconFromFilepath(
400 download()->GetTargetFilePath(), IconLoader::SMALL); 399 download()->GetTargetFilePath(), IconLoader::SMALL);
401 views::Widget* widget = GetWidget(); 400 views::Widget* widget = GetWidget();
402 DragDownloadItem(download(), icon, 401 DragDownloadItem(download(), icon,
403 widget ? widget->GetNativeView() : NULL); 402 widget ? widget->GetNativeView() : NULL);
404 } 403 }
405 } else if (ExceededDragThreshold(event.location() - drag_start_point_)) { 404 } else if (ExceededDragThreshold(event.location() - drag_start_point_)) {
406 dragging_ = true; 405 dragging_ = true;
407 } 406 }
408 return true; 407 return true;
409 } 408 }
410 409
411 void DownloadItemViewMd::OnMouseReleased(const ui::MouseEvent& event) { 410 void DownloadItemViewMd::OnMouseReleased(const ui::MouseEvent& event) {
412 HandleClickEvent(event, event.IsOnlyLeftMouseButton()); 411 HandleClickEvent(event, event.IsOnlyLeftMouseButton());
413 } 412 }
414 413
415 void DownloadItemViewMd::OnMouseCaptureLost() { 414 void DownloadItemViewMd::OnMouseCaptureLost() {
416 // Mouse should not activate us in dangerous mode. 415 // Mouse should not activate us in dangerous mode.
417 if (mode_ == DANGEROUS_MODE) 416 if (mode_ != NORMAL_MODE)
418 return; 417 return;
419 418
420 if (dragging_) { 419 if (dragging_) {
421 // Starting a drag results in a MouseCaptureLost. 420 // Starting a drag results in a MouseCaptureLost.
422 dragging_ = false; 421 dragging_ = false;
423 starting_drag_ = false; 422 starting_drag_ = false;
424 } 423 }
425 } 424 }
426 425
427 bool DownloadItemViewMd::OnKeyPressed(const ui::KeyEvent& event) { 426 bool DownloadItemViewMd::OnKeyPressed(const ui::KeyEvent& event) {
428 // Key press should not activate us in dangerous mode. 427 // Key press should not activate us in dangerous mode.
429 if (IsShowingWarningDialog()) 428 if (IsShowingWarningDialog())
430 return true; 429 return true;
431 430
432 if (event.key_code() == ui::VKEY_SPACE || 431 if (event.key_code() == ui::VKEY_SPACE ||
433 event.key_code() == ui::VKEY_RETURN) { 432 event.key_code() == ui::VKEY_RETURN) {
433 ink_drop_delegate_.set_last_ink_drop_location(
434 GetLocalBounds().CenterPoint());
434 // OpenDownload may delete this, so don't add any code after this line. 435 // OpenDownload may delete this, so don't add any code after this line.
435 OpenDownload(); 436 OpenDownload();
436 return true; 437 return true;
437 } 438 }
438 return false; 439 return false;
439 } 440 }
440 441
441 bool DownloadItemViewMd::GetTooltipText(const gfx::Point& p, 442 bool DownloadItemViewMd::GetTooltipText(const gfx::Point& p,
442 base::string16* tooltip) const { 443 base::string16* tooltip) const {
443 if (IsShowingWarningDialog()) { 444 if (IsShowingWarningDialog()) {
(...skipping 12 matching lines...) Expand all
456 if (model_.IsDangerous()) 457 if (model_.IsDangerous())
457 state->AddStateFlag(ui::AX_STATE_DISABLED); 458 state->AddStateFlag(ui::AX_STATE_DISABLED);
458 else 459 else
459 state->AddStateFlag(ui::AX_STATE_HASPOPUP); 460 state->AddStateFlag(ui::AX_STATE_HASPOPUP);
460 } 461 }
461 462
462 void DownloadItemViewMd::OnThemeChanged() { 463 void DownloadItemViewMd::OnThemeChanged() {
463 UpdateColorsFromTheme(); 464 UpdateColorsFromTheme();
464 } 465 }
465 466
467 scoped_ptr<views::InkDropAnimation> DownloadItemViewMd::CreateInkDropAnimation()
468 const {
469 return make_scoped_ptr(new views::FloodFillInkDropAnimation(
470 size(), ink_drop_delegate_.last_ink_drop_location(),
471 color_utils::DeriveDefaultIconColor(GetTextColor())));
472 }
473
474 scoped_ptr<views::InkDropHover> DownloadItemViewMd::CreateInkDropHover() const {
475 if (IsShowingWarningDialog())
476 return nullptr;
477
478 // TODO(estade): when the item is animating open and the user hovers, the
479 // effect gets stuck at that size and does not grow with the item. Using
480 // GetPreferredSize() instead of size() here does not fix it.
481 return make_scoped_ptr(new views::InkDropHover(
482 size(), kInkDropSmallCornerRadius, GetLocalBounds().CenterPoint(),
483 color_utils::DeriveDefaultIconColor(GetTextColor())));
484 }
485
466 void DownloadItemViewMd::OnGestureEvent(ui::GestureEvent* event) { 486 void DownloadItemViewMd::OnGestureEvent(ui::GestureEvent* event) {
467 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { 487 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
468 HandlePressEvent(*event, true); 488 HandlePressEvent(*event, true);
469 event->SetHandled(); 489 event->SetHandled();
470 return; 490 return;
471 } 491 }
472 492
473 if (event->type() == ui::ET_GESTURE_TAP) { 493 if (event->type() == ui::ET_GESTURE_TAP) {
474 HandleClickEvent(*event, true); 494 HandleClickEvent(*event, true);
475 event->SetHandled(); 495 event->SetHandled();
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 } 717 }
698 718
699 void DownloadItemViewMd::OpenDownload() { 719 void DownloadItemViewMd::OpenDownload() {
700 DCHECK(!IsShowingWarningDialog()); 720 DCHECK(!IsShowingWarningDialog());
701 // We're interested in how long it takes users to open downloads. If they 721 // We're interested in how long it takes users to open downloads. If they
702 // open downloads super quickly, we should be concerned about clickjacking. 722 // open downloads super quickly, we should be concerned about clickjacking.
703 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", 723 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download",
704 base::Time::Now() - creation_time_); 724 base::Time::Now() - creation_time_);
705 725
706 UpdateAccessibleName(); 726 UpdateAccessibleName();
727 ink_drop_delegate_.OnAction(views::InkDropState::ACTION_TRIGGERED);
707 728
708 // Calling download()->OpenDownload may delete this, so this must be 729 // Calling download()->OpenDownload may delete this, so this must be
709 // the last thing we do. 730 // the last thing we do.
710 download()->OpenDownload(); 731 download()->OpenDownload();
711 } 732 }
712 733
713 bool DownloadItemViewMd::SubmitDownloadToFeedbackService() { 734 bool DownloadItemViewMd::SubmitDownloadToFeedbackService() {
714 #if defined(FULL_SAFE_BROWSING) 735 #if defined(FULL_SAFE_BROWSING)
715 safe_browsing::SafeBrowsingService* sb_service = 736 safe_browsing::SafeBrowsingService* sb_service =
716 g_browser_process->safe_browsing_service(); 737 g_browser_process->safe_browsing_service();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 813
793 void DownloadItemViewMd::HandlePressEvent(const ui::LocatedEvent& event, 814 void DownloadItemViewMd::HandlePressEvent(const ui::LocatedEvent& event,
794 bool active_event) { 815 bool active_event) {
795 // The event should not activate us in dangerous mode. 816 // The event should not activate us in dangerous mode.
796 if (mode_ == DANGEROUS_MODE) 817 if (mode_ == DANGEROUS_MODE)
797 return; 818 return;
798 819
799 // Stop any completion animation. 820 // Stop any completion animation.
800 if (complete_animation_.get() && complete_animation_->is_animating()) 821 if (complete_animation_.get() && complete_animation_->is_animating())
801 complete_animation_->End(); 822 complete_animation_->End();
823
824 ink_drop_delegate_.set_last_ink_drop_location(event.location());
825 ink_drop_delegate_.OnAction(views::InkDropState::ACTION_PENDING);
802 } 826 }
803 827
804 void DownloadItemViewMd::HandleClickEvent(const ui::LocatedEvent& event, 828 void DownloadItemViewMd::HandleClickEvent(const ui::LocatedEvent& event,
805 bool active_event) { 829 bool active_event) {
806 // Mouse should not activate us in dangerous mode. 830 // Mouse should not activate us in dangerous mode.
807 if (mode_ == DANGEROUS_MODE) 831 if (mode_ == DANGEROUS_MODE)
808 return; 832 return;
809 833
810 if (!active_event || IsShowingWarningDialog()) 834 if (!active_event || IsShowingWarningDialog())
811 return; 835 return;
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 } 1090 }
1067 } 1091 }
1068 1092
1069 void DownloadItemViewMd::ProgressTimerFired() { 1093 void DownloadItemViewMd::ProgressTimerFired() {
1070 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only 1094 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only
1071 // when there's an update notified via OnDownloadUpdated(). 1095 // when there's an update notified via OnDownloadUpdated().
1072 if (model_.PercentComplete() < 0) 1096 if (model_.PercentComplete() < 0)
1073 SchedulePaint(); 1097 SchedulePaint();
1074 } 1098 }
1075 1099
1076 SkColor DownloadItemViewMd::GetTextColor() { 1100 SkColor DownloadItemViewMd::GetTextColor() const {
1077 return GetTextColorForThemeProvider(GetThemeProvider()); 1101 return GetTextColorForThemeProvider(GetThemeProvider());
1078 } 1102 }
1079 1103
1080 SkColor DownloadItemViewMd::GetDimmedTextColor() { 1104 SkColor DownloadItemViewMd::GetDimmedTextColor() const {
1081 return SkColorSetA(GetTextColor(), 0xC7); 1105 return SkColorSetA(GetTextColor(), 0xC7);
1082 } 1106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698