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