| 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.h" | 5 #include "chrome/browser/ui/views/download/download_item_view.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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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/vector_icons/vector_icons.h" | 60 #include "ui/vector_icons/vector_icons.h" |
| 61 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 61 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
| 62 #include "ui/views/animation/ink_drop_highlight.h" | 62 #include "ui/views/animation/ink_drop_highlight.h" |
| 63 #include "ui/views/animation/ink_drop_impl.h" | 63 #include "ui/views/animation/ink_drop_impl.h" |
| 64 #include "ui/views/border.h" | 64 #include "ui/views/border.h" |
| 65 #include "ui/views/controls/button/image_button.h" |
| 66 #include "ui/views/controls/button/image_button_factory.h" |
| 65 #include "ui/views/controls/button/md_text_button.h" | 67 #include "ui/views/controls/button/md_text_button.h" |
| 66 #include "ui/views/controls/button/vector_icon_button.h" | |
| 67 #include "ui/views/controls/focusable_border.h" | 68 #include "ui/views/controls/focusable_border.h" |
| 68 #include "ui/views/controls/label.h" | 69 #include "ui/views/controls/label.h" |
| 69 #include "ui/views/mouse_constants.h" | 70 #include "ui/views/mouse_constants.h" |
| 70 #include "ui/views/widget/root_view.h" | 71 #include "ui/views/widget/root_view.h" |
| 71 #include "ui/views/widget/widget.h" | 72 #include "ui/views/widget/widget.h" |
| 72 | 73 |
| 73 using content::DownloadItem; | 74 using content::DownloadItem; |
| 74 using extensions::ExperienceSamplingEvent; | 75 using extensions::ExperienceSamplingEvent; |
| 75 | 76 |
| 76 namespace { | 77 namespace { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 148 } |
| 148 | 149 |
| 149 private: | 150 private: |
| 150 SkColor color_; | 151 SkColor color_; |
| 151 | 152 |
| 152 DISALLOW_COPY_AND_ASSIGN(SeparatorBorder); | 153 DISALLOW_COPY_AND_ASSIGN(SeparatorBorder); |
| 153 }; | 154 }; |
| 154 | 155 |
| 155 } // namespace | 156 } // namespace |
| 156 | 157 |
| 157 // Allows the DownloadItemView to control the InkDrop on the drop down button. | |
| 158 class DownloadItemView::DropDownButton : public views::VectorIconButton { | |
| 159 public: | |
| 160 explicit DropDownButton(views::VectorIconButtonDelegate* delegate) | |
| 161 : views::VectorIconButton(delegate) {} | |
| 162 ~DropDownButton() override {} | |
| 163 | |
| 164 // Promoted visibility to public. | |
| 165 void AnimateInkDrop(views::InkDropState state) { | |
| 166 // TODO(bruthig): Plumb in the proper Event. | |
| 167 views::VectorIconButton::AnimateInkDrop(state, nullptr /* event */); | |
| 168 } | |
| 169 | |
| 170 private: | |
| 171 DISALLOW_COPY_AND_ASSIGN(DropDownButton); | |
| 172 }; | |
| 173 | |
| 174 DownloadItemView::DownloadItemView(DownloadItem* download_item, | 158 DownloadItemView::DownloadItemView(DownloadItem* download_item, |
| 175 DownloadShelfView* parent) | 159 DownloadShelfView* parent) |
| 176 : shelf_(parent), | 160 : shelf_(parent), |
| 177 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), | 161 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), |
| 178 dropdown_state_(NORMAL), | 162 dropdown_state_(NORMAL), |
| 179 mode_(NORMAL_MODE), | 163 mode_(NORMAL_MODE), |
| 180 dragging_(false), | 164 dragging_(false), |
| 181 starting_drag_(false), | 165 starting_drag_(false), |
| 182 model_(download_item), | 166 model_(download_item), |
| 183 save_button_(nullptr), | 167 save_button_(nullptr), |
| 184 discard_button_(nullptr), | 168 discard_button_(nullptr), |
| 185 dropdown_button_(new DropDownButton(this)), | 169 dropdown_button_(views::CreateVectorImageButton(this)), |
| 186 dangerous_download_label_(nullptr), | 170 dangerous_download_label_(nullptr), |
| 187 dangerous_download_label_sized_(false), | 171 dangerous_download_label_sized_(false), |
| 188 disabled_while_opening_(false), | 172 disabled_while_opening_(false), |
| 189 creation_time_(base::Time::Now()), | 173 creation_time_(base::Time::Now()), |
| 190 time_download_warning_shown_(base::Time()), | 174 time_download_warning_shown_(base::Time()), |
| 191 weak_ptr_factory_(this) { | 175 weak_ptr_factory_(this) { |
| 192 SetInkDropMode(InkDropMode::ON); | 176 SetInkDropMode(InkDropMode::ON); |
| 193 DCHECK(download()); | 177 DCHECK(download()); |
| 194 download()->AddObserver(this); | 178 download()->AddObserver(this); |
| 195 set_context_menu_controller(this); | 179 set_context_menu_controller(this); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 365 } |
| 382 | 366 |
| 383 if (mode_ != DANGEROUS_MODE) { | 367 if (mode_ != DANGEROUS_MODE) { |
| 384 dropdown_button_->SizeToPreferredSize(); | 368 dropdown_button_->SizeToPreferredSize(); |
| 385 dropdown_button_->SetPosition( | 369 dropdown_button_->SetPosition( |
| 386 gfx::Point(width() - dropdown_button_->width() - kEndPadding, | 370 gfx::Point(width() - dropdown_button_->width() - kEndPadding, |
| 387 (height() - dropdown_button_->height()) / 2)); | 371 (height() - dropdown_button_->height()) / 2)); |
| 388 } | 372 } |
| 389 } | 373 } |
| 390 | 374 |
| 375 void DownloadItemView::UpdateDropdownButton() { |
| 376 views::SetImageFromVectorIcon( |
| 377 dropdown_button_, |
| 378 dropdown_state_ == PUSHED ? kCaretDownIcon : kCaretUpIcon, |
| 379 GetTextColor()); |
| 380 } |
| 381 |
| 391 gfx::Size DownloadItemView::GetPreferredSize() const { | 382 gfx::Size DownloadItemView::GetPreferredSize() const { |
| 392 int width = 0; | 383 int width = 0; |
| 393 // We set the height to the height of two rows or text plus margins. | 384 // We set the height to the height of two rows or text plus margins. |
| 394 int child_height = font_list_.GetBaseline() + kVerticalTextPadding + | 385 int child_height = font_list_.GetBaseline() + kVerticalTextPadding + |
| 395 status_font_list_.GetHeight(); | 386 status_font_list_.GetHeight(); |
| 396 | 387 |
| 397 if (IsShowingWarningDialog()) { | 388 if (IsShowingWarningDialog()) { |
| 398 // Width. | 389 // Width. |
| 399 width = kStartPadding + kWarningIconSize + kStartPadding + | 390 width = kStartPadding + kWarningIconSize + kStartPadding + |
| 400 dangerous_download_label_->width() + kLabelPadding; | 391 dangerous_download_label_->width() + kLabelPadding; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 node_data->role = ui::AX_ROLE_BUTTON; | 488 node_data->role = ui::AX_ROLE_BUTTON; |
| 498 if (model_.IsDangerous()) | 489 if (model_.IsDangerous()) |
| 499 node_data->AddStateFlag(ui::AX_STATE_DISABLED); | 490 node_data->AddStateFlag(ui::AX_STATE_DISABLED); |
| 500 else | 491 else |
| 501 node_data->AddStateFlag(ui::AX_STATE_HASPOPUP); | 492 node_data->AddStateFlag(ui::AX_STATE_HASPOPUP); |
| 502 } | 493 } |
| 503 | 494 |
| 504 void DownloadItemView::OnThemeChanged() { | 495 void DownloadItemView::OnThemeChanged() { |
| 505 UpdateColorsFromTheme(); | 496 UpdateColorsFromTheme(); |
| 506 SchedulePaint(); | 497 SchedulePaint(); |
| 498 UpdateDropdownButton(); |
| 499 } |
| 500 |
| 501 void DownloadItemView::ViewHierarchyChanged( |
| 502 const ViewHierarchyChangedDetails& details) { |
| 503 if (details.is_add && details.child == this) { |
| 504 // This is only required because OnThemeChanged is not called when a view is |
| 505 // added as a child. |
| 506 UpdateDropdownButton(); |
| 507 } |
| 507 } | 508 } |
| 508 | 509 |
| 509 void DownloadItemView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 510 void DownloadItemView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 510 InkDropHostView::AddInkDropLayer(ink_drop_layer); | 511 InkDropHostView::AddInkDropLayer(ink_drop_layer); |
| 511 // The layer that's added to host the ink drop layer must mask to bounds | 512 // The layer that's added to host the ink drop layer must mask to bounds |
| 512 // so the hover effect is clipped while animating open. | 513 // so the hover effect is clipped while animating open. |
| 513 layer()->SetMasksToBounds(true); | 514 layer()->SetMasksToBounds(true); |
| 514 } | 515 } |
| 515 | 516 |
| 516 std::unique_ptr<views::InkDrop> DownloadItemView::CreateInkDrop() { | 517 std::unique_ptr<views::InkDrop> DownloadItemView::CreateInkDrop() { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 download()->ValidateDangerousDownload(); | 595 download()->ValidateDangerousDownload(); |
| 595 return; | 596 return; |
| 596 } | 597 } |
| 597 | 598 |
| 598 DCHECK_EQ(discard_button_, sender); | 599 DCHECK_EQ(discard_button_, sender); |
| 599 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); | 600 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); |
| 600 MaybeSubmitDownloadToFeedbackService(DownloadCommands::DISCARD); | 601 MaybeSubmitDownloadToFeedbackService(DownloadCommands::DISCARD); |
| 601 // WARNING: 'this' maybe deleted at this point. Don't access 'this'. | 602 // WARNING: 'this' maybe deleted at this point. Don't access 'this'. |
| 602 } | 603 } |
| 603 | 604 |
| 604 SkColor DownloadItemView::GetVectorIconBaseColor() const { | |
| 605 return GetTextColor(); | |
| 606 } | |
| 607 | |
| 608 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { | 605 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { |
| 609 // We don't care if what animation (body button/drop button/complete), | 606 // We don't care if what animation (body button/drop button/complete), |
| 610 // is calling back, as they all have to go through the same paint call. | 607 // is calling back, as they all have to go through the same paint call. |
| 611 SchedulePaint(); | 608 SchedulePaint(); |
| 612 } | 609 } |
| 613 | 610 |
| 614 void DownloadItemView::OnPaint(gfx::Canvas* canvas) { | 611 void DownloadItemView::OnPaint(gfx::Canvas* canvas) { |
| 615 // Make sure to draw |this| opaquely. Since the toolbar color can be partially | 612 // Make sure to draw |this| opaquely. Since the toolbar color can be partially |
| 616 // transparent, start with a black backdrop (which is the default initialized | 613 // transparent, start with a black backdrop (which is the default initialized |
| 617 // color for opaque canvases). | 614 // color for opaque canvases). |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 OpenDownload(); | 872 OpenDownload(); |
| 876 } | 873 } |
| 877 | 874 |
| 878 void DownloadItemView::SetDropdownState(State new_state) { | 875 void DownloadItemView::SetDropdownState(State new_state) { |
| 879 // Avoid extra SchedulePaint()s if the state is going to be the same and | 876 // Avoid extra SchedulePaint()s if the state is going to be the same and |
| 880 // |dropdown_button_| has already been initialized. | 877 // |dropdown_button_| has already been initialized. |
| 881 if (dropdown_state_ == new_state && | 878 if (dropdown_state_ == new_state && |
| 882 !dropdown_button_->GetImage(views::CustomButton::STATE_NORMAL).isNull()) | 879 !dropdown_button_->GetImage(views::CustomButton::STATE_NORMAL).isNull()) |
| 883 return; | 880 return; |
| 884 | 881 |
| 885 dropdown_button_->SetIcon(new_state == PUSHED ? kCaretDownIcon | |
| 886 : kCaretUpIcon); | |
| 887 if (new_state != dropdown_state_) { | 882 if (new_state != dropdown_state_) { |
| 888 dropdown_button_->AnimateInkDrop(new_state == PUSHED | 883 dropdown_button_->AnimateInkDrop(new_state == PUSHED |
| 889 ? views::InkDropState::ACTIVATED | 884 ? views::InkDropState::ACTIVATED |
| 890 : views::InkDropState::DEACTIVATED); | 885 : views::InkDropState::DEACTIVATED, |
| 886 nullptr); |
| 891 } | 887 } |
| 892 dropdown_button_->OnThemeChanged(); | |
| 893 dropdown_state_ = new_state; | 888 dropdown_state_ = new_state; |
| 889 UpdateDropdownButton(); |
| 894 SchedulePaint(); | 890 SchedulePaint(); |
| 895 } | 891 } |
| 896 | 892 |
| 897 void DownloadItemView::ToggleWarningDialog() { | 893 void DownloadItemView::ToggleWarningDialog() { |
| 898 if (model_.IsDangerous()) | 894 if (model_.IsDangerous()) |
| 899 ShowWarningDialog(); | 895 ShowWarningDialog(); |
| 900 else | 896 else |
| 901 ClearWarningDialog(); | 897 ClearWarningDialog(); |
| 902 | 898 |
| 903 // We need to load the icon now that the download has the real path. | 899 // We need to load the icon now that the download has the real path. |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 SchedulePaint(); | 1120 SchedulePaint(); |
| 1125 } | 1121 } |
| 1126 | 1122 |
| 1127 SkColor DownloadItemView::GetTextColor() const { | 1123 SkColor DownloadItemView::GetTextColor() const { |
| 1128 return GetTextColorForThemeProvider(GetThemeProvider()); | 1124 return GetTextColorForThemeProvider(GetThemeProvider()); |
| 1129 } | 1125 } |
| 1130 | 1126 |
| 1131 SkColor DownloadItemView::GetDimmedTextColor() const { | 1127 SkColor DownloadItemView::GetDimmedTextColor() const { |
| 1132 return SkColorSetA(GetTextColor(), 0xC7); | 1128 return SkColorSetA(GetTextColor(), 0xC7); |
| 1133 } | 1129 } |
| OLD | NEW |