| OLD | NEW |
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include "ui/events/event.h" | 51 #include "ui/events/event.h" |
| 52 #include "ui/gfx/animation/slide_animation.h" | 52 #include "ui/gfx/animation/slide_animation.h" |
| 53 #include "ui/gfx/canvas.h" | 53 #include "ui/gfx/canvas.h" |
| 54 #include "ui/gfx/color_palette.h" | 54 #include "ui/gfx/color_palette.h" |
| 55 #include "ui/gfx/color_utils.h" | 55 #include "ui/gfx/color_utils.h" |
| 56 #include "ui/gfx/image/image.h" | 56 #include "ui/gfx/image/image.h" |
| 57 #include "ui/gfx/paint_vector_icon.h" | 57 #include "ui/gfx/paint_vector_icon.h" |
| 58 #include "ui/gfx/text_elider.h" | 58 #include "ui/gfx/text_elider.h" |
| 59 #include "ui/gfx/text_utils.h" | 59 #include "ui/gfx/text_utils.h" |
| 60 #include "ui/gfx/vector_icons_public.h" | 60 #include "ui/gfx/vector_icons_public.h" |
| 61 #include "ui/views/animation/button_ink_drop_delegate.h" | |
| 62 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 61 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
| 63 #include "ui/views/animation/ink_drop_highlight.h" | 62 #include "ui/views/animation/ink_drop_highlight.h" |
| 64 #include "ui/views/border.h" | 63 #include "ui/views/border.h" |
| 65 #include "ui/views/controls/button/image_button.h" | 64 #include "ui/views/controls/button/image_button.h" |
| 66 #include "ui/views/controls/button/md_text_button.h" | 65 #include "ui/views/controls/button/md_text_button.h" |
| 67 #include "ui/views/controls/label.h" | 66 #include "ui/views/controls/label.h" |
| 68 #include "ui/views/mouse_constants.h" | 67 #include "ui/views/mouse_constants.h" |
| 69 #include "ui/views/widget/root_view.h" | 68 #include "ui/views/widget/root_view.h" |
| 70 #include "ui/views/widget/widget.h" | 69 #include "ui/views/widget/widget.h" |
| 71 | 70 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 143 } |
| 145 | 144 |
| 146 private: | 145 private: |
| 147 SkColor color_; | 146 SkColor color_; |
| 148 | 147 |
| 149 DISALLOW_COPY_AND_ASSIGN(SeparatorBorder); | 148 DISALLOW_COPY_AND_ASSIGN(SeparatorBorder); |
| 150 }; | 149 }; |
| 151 | 150 |
| 152 } // namespace | 151 } // namespace |
| 153 | 152 |
| 153 // Allows the DownloadItemViewMd to control the InkDrop on the drop down button. |
| 154 class DownloadItemViewMd::DropDownButton : public BarControlButton { |
| 155 public: |
| 156 explicit DropDownButton(views::ButtonListener* listener) |
| 157 : BarControlButton(listener) {} |
| 158 ~DropDownButton() override {} |
| 159 |
| 160 // Promoted visibility to public. |
| 161 void AnimateInkDrop(views::InkDropState state) { |
| 162 BarControlButton::AnimateInkDrop(state); |
| 163 } |
| 164 |
| 165 private: |
| 166 DISALLOW_COPY_AND_ASSIGN(DropDownButton); |
| 167 }; |
| 168 |
| 154 DownloadItemViewMd::DownloadItemViewMd(DownloadItem* download_item, | 169 DownloadItemViewMd::DownloadItemViewMd(DownloadItem* download_item, |
| 155 DownloadShelfView* parent) | 170 DownloadShelfView* parent) |
| 156 : shelf_(parent), | 171 : shelf_(parent), |
| 157 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), | 172 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), |
| 158 dropdown_state_(NORMAL), | 173 dropdown_state_(NORMAL), |
| 159 mode_(NORMAL_MODE), | 174 mode_(NORMAL_MODE), |
| 160 dragging_(false), | 175 dragging_(false), |
| 161 starting_drag_(false), | 176 starting_drag_(false), |
| 162 model_(download_item), | 177 model_(download_item), |
| 163 button_ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)), | |
| 164 save_button_(nullptr), | 178 save_button_(nullptr), |
| 165 discard_button_(nullptr), | 179 discard_button_(nullptr), |
| 166 dropdown_button_(new BarControlButton(this)), | 180 dropdown_button_(new DropDownButton(this)), |
| 167 dangerous_download_label_(nullptr), | 181 dangerous_download_label_(nullptr), |
| 168 dangerous_download_label_sized_(false), | 182 dangerous_download_label_sized_(false), |
| 169 disabled_while_opening_(false), | 183 disabled_while_opening_(false), |
| 170 creation_time_(base::Time::Now()), | 184 creation_time_(base::Time::Now()), |
| 171 time_download_warning_shown_(base::Time()), | 185 time_download_warning_shown_(base::Time()), |
| 172 weak_ptr_factory_(this) { | 186 weak_ptr_factory_(this) { |
| 173 set_ink_drop_delegate(base::WrapUnique(button_ink_drop_delegate_)); | 187 SetHasInkDrop(true); |
| 174 DCHECK(download()); | 188 DCHECK(download()); |
| 175 DCHECK(ui::MaterialDesignController::IsModeMaterial()); | 189 DCHECK(ui::MaterialDesignController::IsModeMaterial()); |
| 176 download()->AddObserver(this); | 190 download()->AddObserver(this); |
| 177 set_context_menu_controller(this); | 191 set_context_menu_controller(this); |
| 178 | 192 |
| 179 dropdown_button_->SetBorder( | 193 dropdown_button_->SetBorder( |
| 180 views::Border::CreateEmptyBorder(gfx::Insets(kDropdownBorderWidth))); | 194 views::Border::CreateEmptyBorder(gfx::Insets(kDropdownBorderWidth))); |
| 181 dropdown_button_->set_ink_drop_size(gfx::Size(32, 32)); | 195 dropdown_button_->set_ink_drop_size(gfx::Size(32, 32)); |
| 182 AddChildView(dropdown_button_); | 196 AddChildView(dropdown_button_); |
| 183 | 197 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 400 |
| 387 // Handle drag (file copy) operations. | 401 // Handle drag (file copy) operations. |
| 388 bool DownloadItemViewMd::OnMouseDragged(const ui::MouseEvent& event) { | 402 bool DownloadItemViewMd::OnMouseDragged(const ui::MouseEvent& event) { |
| 389 // Mouse should not activate us in dangerous mode. | 403 // Mouse should not activate us in dangerous mode. |
| 390 if (IsShowingWarningDialog()) | 404 if (IsShowingWarningDialog()) |
| 391 return true; | 405 return true; |
| 392 | 406 |
| 393 if (!starting_drag_) { | 407 if (!starting_drag_) { |
| 394 starting_drag_ = true; | 408 starting_drag_ = true; |
| 395 drag_start_point_ = event.location(); | 409 drag_start_point_ = event.location(); |
| 396 button_ink_drop_delegate_->OnAction(views::InkDropState::HIDDEN); | 410 AnimateInkDrop(views::InkDropState::HIDDEN); |
| 397 } | 411 } |
| 398 if (dragging_) { | 412 if (dragging_) { |
| 399 if (download()->GetState() == DownloadItem::COMPLETE) { | 413 if (download()->GetState() == DownloadItem::COMPLETE) { |
| 400 IconManager* im = g_browser_process->icon_manager(); | 414 IconManager* im = g_browser_process->icon_manager(); |
| 401 gfx::Image* icon = im->LookupIconFromFilepath( | 415 gfx::Image* icon = im->LookupIconFromFilepath( |
| 402 download()->GetTargetFilePath(), IconLoader::SMALL); | 416 download()->GetTargetFilePath(), IconLoader::SMALL); |
| 403 views::Widget* widget = GetWidget(); | 417 views::Widget* widget = GetWidget(); |
| 404 DragDownloadItem(download(), icon, | 418 DragDownloadItem(download(), icon, |
| 405 widget ? widget->GetNativeView() : NULL); | 419 widget ? widget->GetNativeView() : NULL); |
| 406 } | 420 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 426 } | 440 } |
| 427 } | 441 } |
| 428 | 442 |
| 429 bool DownloadItemViewMd::OnKeyPressed(const ui::KeyEvent& event) { | 443 bool DownloadItemViewMd::OnKeyPressed(const ui::KeyEvent& event) { |
| 430 // Key press should not activate us in dangerous mode. | 444 // Key press should not activate us in dangerous mode. |
| 431 if (IsShowingWarningDialog()) | 445 if (IsShowingWarningDialog()) |
| 432 return true; | 446 return true; |
| 433 | 447 |
| 434 if (event.key_code() == ui::VKEY_SPACE || | 448 if (event.key_code() == ui::VKEY_SPACE || |
| 435 event.key_code() == ui::VKEY_RETURN) { | 449 event.key_code() == ui::VKEY_RETURN) { |
| 436 button_ink_drop_delegate_->set_last_ink_drop_location( | |
| 437 GetLocalBounds().CenterPoint()); | |
| 438 // OpenDownload may delete this, so don't add any code after this line. | 450 // OpenDownload may delete this, so don't add any code after this line. |
| 439 OpenDownload(); | 451 OpenDownload(); |
| 440 return true; | 452 return true; |
| 441 } | 453 } |
| 442 return false; | 454 return false; |
| 443 } | 455 } |
| 444 | 456 |
| 445 bool DownloadItemViewMd::GetTooltipText(const gfx::Point& p, | 457 bool DownloadItemViewMd::GetTooltipText(const gfx::Point& p, |
| 446 base::string16* tooltip) const { | 458 base::string16* tooltip) const { |
| 447 if (IsShowingWarningDialog()) { | 459 if (IsShowingWarningDialog()) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 471 void DownloadItemViewMd::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 483 void DownloadItemViewMd::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 472 InkDropHostView::AddInkDropLayer(ink_drop_layer); | 484 InkDropHostView::AddInkDropLayer(ink_drop_layer); |
| 473 // The layer that's added to host the ink drop layer must mask to bounds | 485 // The layer that's added to host the ink drop layer must mask to bounds |
| 474 // so the hover effect is clipped while animating open. | 486 // so the hover effect is clipped while animating open. |
| 475 layer()->SetMasksToBounds(true); | 487 layer()->SetMasksToBounds(true); |
| 476 } | 488 } |
| 477 | 489 |
| 478 std::unique_ptr<views::InkDropRipple> DownloadItemViewMd::CreateInkDropRipple() | 490 std::unique_ptr<views::InkDropRipple> DownloadItemViewMd::CreateInkDropRipple() |
| 479 const { | 491 const { |
| 480 return base::WrapUnique(new views::FloodFillInkDropRipple( | 492 return base::WrapUnique(new views::FloodFillInkDropRipple( |
| 481 GetLocalBounds(), button_ink_drop_delegate_->last_ink_drop_location(), | 493 GetLocalBounds(), GetLocalBounds().CenterPoint(), |
| 482 color_utils::DeriveDefaultIconColor(GetTextColor()))); | 494 color_utils::DeriveDefaultIconColor(GetTextColor()))); |
| 483 } | 495 } |
| 484 | 496 |
| 485 std::unique_ptr<views::InkDropHighlight> | 497 std::unique_ptr<views::InkDropHighlight> |
| 486 DownloadItemViewMd::CreateInkDropHighlight() const { | 498 DownloadItemViewMd::CreateInkDropHighlight() const { |
| 487 if (IsShowingWarningDialog()) | 499 if (IsShowingWarningDialog()) |
| 488 return nullptr; | 500 return nullptr; |
| 489 | 501 |
| 490 gfx::Size size = GetPreferredSize(); | 502 gfx::Size size = GetPreferredSize(); |
| 491 return base::WrapUnique(new views::InkDropHighlight( | 503 return base::WrapUnique(new views::InkDropHighlight( |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 } | 746 } |
| 735 | 747 |
| 736 void DownloadItemViewMd::OpenDownload() { | 748 void DownloadItemViewMd::OpenDownload() { |
| 737 DCHECK(!IsShowingWarningDialog()); | 749 DCHECK(!IsShowingWarningDialog()); |
| 738 // We're interested in how long it takes users to open downloads. If they | 750 // We're interested in how long it takes users to open downloads. If they |
| 739 // open downloads super quickly, we should be concerned about clickjacking. | 751 // open downloads super quickly, we should be concerned about clickjacking. |
| 740 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", | 752 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", |
| 741 base::Time::Now() - creation_time_); | 753 base::Time::Now() - creation_time_); |
| 742 | 754 |
| 743 UpdateAccessibleName(); | 755 UpdateAccessibleName(); |
| 744 button_ink_drop_delegate_->OnAction(views::InkDropState::ACTION_TRIGGERED); | 756 AnimateInkDrop(views::InkDropState::ACTION_TRIGGERED); |
| 745 | 757 |
| 746 // Calling download()->OpenDownload may delete this, so this must be | 758 // Calling download()->OpenDownload may delete this, so this must be |
| 747 // the last thing we do. | 759 // the last thing we do. |
| 748 download()->OpenDownload(); | 760 download()->OpenDownload(); |
| 749 } | 761 } |
| 750 | 762 |
| 751 bool DownloadItemViewMd::SubmitDownloadToFeedbackService() { | 763 bool DownloadItemViewMd::SubmitDownloadToFeedbackService() { |
| 752 #if defined(FULL_SAFE_BROWSING) | 764 #if defined(FULL_SAFE_BROWSING) |
| 753 safe_browsing::SafeBrowsingService* sb_service = | 765 safe_browsing::SafeBrowsingService* sb_service = |
| 754 g_browser_process->safe_browsing_service(); | 766 g_browser_process->safe_browsing_service(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 return; | 846 return; |
| 835 | 847 |
| 836 // Stop any completion animation. | 848 // Stop any completion animation. |
| 837 if (complete_animation_.get() && complete_animation_->is_animating()) | 849 if (complete_animation_.get() && complete_animation_->is_animating()) |
| 838 complete_animation_->End(); | 850 complete_animation_->End(); |
| 839 | 851 |
| 840 // Don't show the ripple for right clicks. | 852 // Don't show the ripple for right clicks. |
| 841 if (!active_event) | 853 if (!active_event) |
| 842 return; | 854 return; |
| 843 | 855 |
| 844 button_ink_drop_delegate_->set_last_ink_drop_location(event.location()); | 856 AnimateInkDrop(views::InkDropState::ACTION_PENDING); |
| 845 button_ink_drop_delegate_->OnAction(views::InkDropState::ACTION_PENDING); | |
| 846 } | 857 } |
| 847 | 858 |
| 848 void DownloadItemViewMd::HandleClickEvent(const ui::LocatedEvent& event, | 859 void DownloadItemViewMd::HandleClickEvent(const ui::LocatedEvent& event, |
| 849 bool active_event) { | 860 bool active_event) { |
| 850 // Mouse should not activate us in dangerous mode. | 861 // Mouse should not activate us in dangerous mode. |
| 851 if (mode_ == DANGEROUS_MODE) | 862 if (mode_ == DANGEROUS_MODE) |
| 852 return; | 863 return; |
| 853 | 864 |
| 854 if (!active_event || IsShowingWarningDialog()) | 865 if (!active_event || IsShowingWarningDialog()) |
| 855 return; | 866 return; |
| 856 | 867 |
| 857 // OpenDownload may delete this, so don't add any code after this line. | 868 // OpenDownload may delete this, so don't add any code after this line. |
| 858 OpenDownload(); | 869 OpenDownload(); |
| 859 } | 870 } |
| 860 | 871 |
| 861 void DownloadItemViewMd::SetDropdownState(State new_state) { | 872 void DownloadItemViewMd::SetDropdownState(State new_state) { |
| 862 // Avoid extra SchedulePaint()s if the state is going to be the same and | 873 // Avoid extra SchedulePaint()s if the state is going to be the same and |
| 863 // |dropdown_button_| has already been initialized. | 874 // |dropdown_button_| has already been initialized. |
| 864 if (dropdown_state_ == new_state && | 875 if (dropdown_state_ == new_state && |
| 865 !dropdown_button_->GetImage(views::CustomButton::STATE_NORMAL).isNull()) | 876 !dropdown_button_->GetImage(views::CustomButton::STATE_NORMAL).isNull()) |
| 866 return; | 877 return; |
| 867 | 878 |
| 868 dropdown_button_->SetIcon( | 879 dropdown_button_->SetIcon( |
| 869 new_state == PUSHED ? gfx::VectorIconId::FIND_NEXT | 880 new_state == PUSHED ? gfx::VectorIconId::FIND_NEXT |
| 870 : gfx::VectorIconId::FIND_PREV, | 881 : gfx::VectorIconId::FIND_PREV, |
| 871 base::Bind(&DownloadItemViewMd::GetTextColor, base::Unretained(this))); | 882 base::Bind(&DownloadItemViewMd::GetTextColor, base::Unretained(this))); |
| 872 if (new_state != dropdown_state_) { | 883 if (new_state != dropdown_state_) { |
| 873 dropdown_button_->ink_drop_delegate()->OnAction( | 884 dropdown_button_->AnimateInkDrop(new_state == PUSHED |
| 874 new_state == PUSHED ? views::InkDropState::ACTIVATED | 885 ? views::InkDropState::ACTIVATED |
| 875 : views::InkDropState::DEACTIVATED); | 886 : views::InkDropState::DEACTIVATED); |
| 876 } | 887 } |
| 877 dropdown_button_->OnThemeChanged(); | 888 dropdown_button_->OnThemeChanged(); |
| 878 dropdown_state_ = new_state; | 889 dropdown_state_ = new_state; |
| 879 SchedulePaint(); | 890 SchedulePaint(); |
| 880 } | 891 } |
| 881 | 892 |
| 882 void DownloadItemViewMd::ToggleWarningDialog() { | 893 void DownloadItemViewMd::ToggleWarningDialog() { |
| 883 if (model_.IsDangerous()) | 894 if (model_.IsDangerous()) |
| 884 ShowWarningDialog(); | 895 ShowWarningDialog(); |
| 885 else | 896 else |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 SchedulePaint(); | 1128 SchedulePaint(); |
| 1118 } | 1129 } |
| 1119 | 1130 |
| 1120 SkColor DownloadItemViewMd::GetTextColor() const { | 1131 SkColor DownloadItemViewMd::GetTextColor() const { |
| 1121 return GetTextColorForThemeProvider(GetThemeProvider()); | 1132 return GetTextColorForThemeProvider(GetThemeProvider()); |
| 1122 } | 1133 } |
| 1123 | 1134 |
| 1124 SkColor DownloadItemViewMd::GetDimmedTextColor() const { | 1135 SkColor DownloadItemViewMd::GetDimmedTextColor() const { |
| 1125 return SkColorSetA(GetTextColor(), 0xC7); | 1136 return SkColorSetA(GetTextColor(), 0xC7); |
| 1126 } | 1137 } |
| OLD | NEW |