| 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" |
| 65 #include "ui/views/controls/button/md_text_button.h" | 66 #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" | 67 #include "ui/views/controls/focusable_border.h" |
| 68 #include "ui/views/controls/label.h" | 68 #include "ui/views/controls/label.h" |
| 69 #include "ui/views/mouse_constants.h" | 69 #include "ui/views/mouse_constants.h" |
| 70 #include "ui/views/widget/root_view.h" | 70 #include "ui/views/widget/root_view.h" |
| 71 #include "ui/views/widget/widget.h" | 71 #include "ui/views/widget/widget.h" |
| 72 | 72 |
| 73 using content::DownloadItem; | 73 using content::DownloadItem; |
| 74 using extensions::ExperienceSamplingEvent; | 74 using extensions::ExperienceSamplingEvent; |
| 75 | 75 |
| 76 namespace { | 76 namespace { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 147 } |
| 148 | 148 |
| 149 private: | 149 private: |
| 150 SkColor color_; | 150 SkColor color_; |
| 151 | 151 |
| 152 DISALLOW_COPY_AND_ASSIGN(SeparatorBorder); | 152 DISALLOW_COPY_AND_ASSIGN(SeparatorBorder); |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 } // namespace | 155 } // namespace |
| 156 | 156 |
| 157 // Allows the DownloadItemView to control the InkDrop on the drop down button. | 157 DownloadItemView::DropDownButtonImageUpdater::DropDownButtonImageUpdater( |
| 158 class DownloadItemView::DropDownButton : public views::VectorIconButton { | 158 const gfx::VectorIcon& icon, |
| 159 public: | 159 const DownloadItemView* parent) |
| 160 explicit DropDownButton(views::VectorIconButtonDelegate* delegate) | 160 : VectorIconImageUpdater(icon), parent_(parent) {} |
| 161 : views::VectorIconButton(delegate) {} | |
| 162 ~DropDownButton() override {} | |
| 163 | 161 |
| 164 // Promoted visibility to public. | 162 SkColor DownloadItemView::DropDownButtonImageUpdater::GetVectorIconColor() |
| 165 void AnimateInkDrop(views::InkDropState state) { | 163 const { |
| 166 // TODO(bruthig): Plumb in the proper Event. | 164 return parent_->GetTextColor(); |
| 167 views::VectorIconButton::AnimateInkDrop(state, nullptr /* event */); | 165 } |
| 168 } | |
| 169 | |
| 170 private: | |
| 171 DISALLOW_COPY_AND_ASSIGN(DropDownButton); | |
| 172 }; | |
| 173 | 166 |
| 174 DownloadItemView::DownloadItemView(DownloadItem* download_item, | 167 DownloadItemView::DownloadItemView(DownloadItem* download_item, |
| 175 DownloadShelfView* parent) | 168 DownloadShelfView* parent) |
| 176 : shelf_(parent), | 169 : shelf_(parent), |
| 177 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), | 170 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), |
| 178 dropdown_state_(NORMAL), | 171 dropdown_state_(NORMAL), |
| 179 mode_(NORMAL_MODE), | 172 mode_(NORMAL_MODE), |
| 180 dragging_(false), | 173 dragging_(false), |
| 181 starting_drag_(false), | 174 starting_drag_(false), |
| 182 model_(download_item), | 175 model_(download_item), |
| 183 save_button_(nullptr), | 176 save_button_(nullptr), |
| 184 discard_button_(nullptr), | 177 discard_button_(nullptr), |
| 185 dropdown_button_(new DropDownButton(this)), | |
| 186 dangerous_download_label_(nullptr), | 178 dangerous_download_label_(nullptr), |
| 187 dangerous_download_label_sized_(false), | 179 dangerous_download_label_sized_(false), |
| 188 disabled_while_opening_(false), | 180 disabled_while_opening_(false), |
| 189 creation_time_(base::Time::Now()), | 181 creation_time_(base::Time::Now()), |
| 190 time_download_warning_shown_(base::Time()), | 182 time_download_warning_shown_(base::Time()), |
| 191 weak_ptr_factory_(this) { | 183 weak_ptr_factory_(this) { |
| 192 SetInkDropMode(InkDropMode::ON); | 184 SetInkDropMode(InkDropMode::ON); |
| 193 DCHECK(download()); | 185 DCHECK(download()); |
| 194 download()->AddObserver(this); | 186 download()->AddObserver(this); |
| 195 set_context_menu_controller(this); | 187 set_context_menu_controller(this); |
| 196 | 188 |
| 197 dropdown_button_->SetBorder( | 189 button_image_updater_ = new DropDownButtonImageUpdater(kCaretUpIcon, this); |
| 198 views::CreateEmptyBorder(gfx::Insets(kDropdownBorderWidth))); | 190 dropdown_button_ = |
| 191 views::CreateImageButtonWithImageUpdater(button_image_updater_, this); |
| 192 dropdown_button_->SetPadding(gfx::Insets(kDropdownBorderWidth)); |
| 199 AddChildView(dropdown_button_); | 193 AddChildView(dropdown_button_); |
| 200 | 194 |
| 201 LoadIcon(); | 195 LoadIcon(); |
| 202 | 196 |
| 203 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 197 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 204 font_list_ = | 198 font_list_ = |
| 205 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(1); | 199 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(1); |
| 206 status_font_list_ = | 200 status_font_list_ = |
| 207 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(-2); | 201 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(-2); |
| 208 | 202 |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 download()->ValidateDangerousDownload(); | 588 download()->ValidateDangerousDownload(); |
| 595 return; | 589 return; |
| 596 } | 590 } |
| 597 | 591 |
| 598 DCHECK_EQ(discard_button_, sender); | 592 DCHECK_EQ(discard_button_, sender); |
| 599 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); | 593 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); |
| 600 MaybeSubmitDownloadToFeedbackService(DownloadCommands::DISCARD); | 594 MaybeSubmitDownloadToFeedbackService(DownloadCommands::DISCARD); |
| 601 // WARNING: 'this' maybe deleted at this point. Don't access 'this'. | 595 // WARNING: 'this' maybe deleted at this point. Don't access 'this'. |
| 602 } | 596 } |
| 603 | 597 |
| 604 SkColor DownloadItemView::GetVectorIconBaseColor() const { | |
| 605 return GetTextColor(); | |
| 606 } | |
| 607 | |
| 608 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { | 598 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { |
| 609 // We don't care if what animation (body button/drop button/complete), | 599 // 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. | 600 // is calling back, as they all have to go through the same paint call. |
| 611 SchedulePaint(); | 601 SchedulePaint(); |
| 612 } | 602 } |
| 613 | 603 |
| 614 void DownloadItemView::OnPaint(gfx::Canvas* canvas) { | 604 void DownloadItemView::OnPaint(gfx::Canvas* canvas) { |
| 615 // Make sure to draw |this| opaquely. Since the toolbar color can be partially | 605 // 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 | 606 // transparent, start with a black backdrop (which is the default initialized |
| 617 // color for opaque canvases). | 607 // color for opaque canvases). |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 OpenDownload(); | 865 OpenDownload(); |
| 876 } | 866 } |
| 877 | 867 |
| 878 void DownloadItemView::SetDropdownState(State new_state) { | 868 void DownloadItemView::SetDropdownState(State new_state) { |
| 879 // Avoid extra SchedulePaint()s if the state is going to be the same and | 869 // Avoid extra SchedulePaint()s if the state is going to be the same and |
| 880 // |dropdown_button_| has already been initialized. | 870 // |dropdown_button_| has already been initialized. |
| 881 if (dropdown_state_ == new_state && | 871 if (dropdown_state_ == new_state && |
| 882 !dropdown_button_->GetImage(views::CustomButton::STATE_NORMAL).isNull()) | 872 !dropdown_button_->GetImage(views::CustomButton::STATE_NORMAL).isNull()) |
| 883 return; | 873 return; |
| 884 | 874 |
| 885 dropdown_button_->SetIcon(new_state == PUSHED ? kCaretDownIcon | 875 button_image_updater_->SetIcon(new_state == PUSHED ? kCaretDownIcon |
| 886 : kCaretUpIcon); | 876 : kCaretUpIcon); |
| 887 if (new_state != dropdown_state_) { | 877 if (new_state != dropdown_state_) { |
| 878 // TODO(bruthig): Plumb in the proper Event. |
| 888 dropdown_button_->AnimateInkDrop(new_state == PUSHED | 879 dropdown_button_->AnimateInkDrop(new_state == PUSHED |
| 889 ? views::InkDropState::ACTIVATED | 880 ? views::InkDropState::ACTIVATED |
| 890 : views::InkDropState::DEACTIVATED); | 881 : views::InkDropState::DEACTIVATED, |
| 882 nullptr); |
| 891 } | 883 } |
| 892 dropdown_button_->OnThemeChanged(); | |
| 893 dropdown_state_ = new_state; | 884 dropdown_state_ = new_state; |
| 894 SchedulePaint(); | 885 SchedulePaint(); |
| 895 } | 886 } |
| 896 | 887 |
| 897 void DownloadItemView::ToggleWarningDialog() { | 888 void DownloadItemView::ToggleWarningDialog() { |
| 898 if (model_.IsDangerous()) | 889 if (model_.IsDangerous()) |
| 899 ShowWarningDialog(); | 890 ShowWarningDialog(); |
| 900 else | 891 else |
| 901 ClearWarningDialog(); | 892 ClearWarningDialog(); |
| 902 | 893 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 SchedulePaint(); | 1115 SchedulePaint(); |
| 1125 } | 1116 } |
| 1126 | 1117 |
| 1127 SkColor DownloadItemView::GetTextColor() const { | 1118 SkColor DownloadItemView::GetTextColor() const { |
| 1128 return GetTextColorForThemeProvider(GetThemeProvider()); | 1119 return GetTextColorForThemeProvider(GetThemeProvider()); |
| 1129 } | 1120 } |
| 1130 | 1121 |
| 1131 SkColor DownloadItemView::GetDimmedTextColor() const { | 1122 SkColor DownloadItemView::GetDimmedTextColor() const { |
| 1132 return SkColorSetA(GetTextColor(), 0xC7); | 1123 return SkColorSetA(GetTextColor(), 0xC7); |
| 1133 } | 1124 } |
| OLD | NEW |