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

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

Issue 1408223008: [MD] Share button code between find bar and download shelf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: one more place Created 5 years, 1 month 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 <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/download/chrome_download_manager_delegate.h" 23 #include "chrome/browser/download/chrome_download_manager_delegate.h"
24 #include "chrome/browser/download/download_item_model.h" 24 #include "chrome/browser/download/download_item_model.h"
25 #include "chrome/browser/download/download_stats.h" 25 #include "chrome/browser/download/download_stats.h"
26 #include "chrome/browser/download/drag_download_item.h" 26 #include "chrome/browser/download/drag_download_item.h"
27 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" 27 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h"
28 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/safe_browsing/download_feedback_service.h" 29 #include "chrome/browser/safe_browsing/download_feedback_service.h"
30 #include "chrome/browser/safe_browsing/download_protection_service.h" 30 #include "chrome/browser/safe_browsing/download_protection_service.h"
31 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 31 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
32 #include "chrome/browser/themes/theme_properties.h" 32 #include "chrome/browser/themes/theme_properties.h"
33 #include "chrome/browser/ui/views/bar_control_button.h"
33 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h" 34 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h"
34 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h" 35 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h"
35 #include "chrome/browser/ui/views/download/download_shelf_view.h" 36 #include "chrome/browser/ui/views/download/download_shelf_view.h"
36 #include "chrome/browser/ui/views/frame/browser_view.h" 37 #include "chrome/browser/ui/views/frame/browser_view.h"
37 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
38 #include "chrome/grit/generated_resources.h" 39 #include "chrome/grit/generated_resources.h"
39 #include "content/public/browser/download_danger_type.h" 40 #include "content/public/browser/download_danger_type.h"
40 #include "third_party/icu/source/common/unicode/uchar.h" 41 #include "third_party/icu/source/common/unicode/uchar.h"
41 #include "ui/accessibility/ax_view_state.h" 42 #include "ui/accessibility/ax_view_state.h"
42 #include "ui/base/l10n/l10n_util.h" 43 #include "ui/base/l10n/l10n_util.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // The space between the Save and Discard buttons when prompting for a dangerous 97 // The space between the Save and Discard buttons when prompting for a dangerous
97 // download. 98 // download.
98 const int kButtonPadding = 5; 99 const int kButtonPadding = 5;
99 100
100 // The space on the left and right side of the dangerous download label. 101 // The space on the left and right side of the dangerous download label.
101 const int kLabelPadding = 8; 102 const int kLabelPadding = 8;
102 103
103 // Height/width of the warning icon, also in dp. 104 // Height/width of the warning icon, also in dp.
104 const int kWarningIconSize = 24; 105 const int kWarningIconSize = 24;
105 106
106 const SkColor kFileNameDisabledColor = SkColorSetRGB(171, 192, 212);
107
108 // How long the 'download complete' animation should last for. 107 // How long the 'download complete' animation should last for.
109 const int kCompleteAnimationDurationMs = 2500; 108 const int kCompleteAnimationDurationMs = 2500;
110 109
111 // How long the 'download interrupted' animation should last for. 110 // How long the 'download interrupted' animation should last for.
112 const int kInterruptedAnimationDurationMs = 2500; 111 const int kInterruptedAnimationDurationMs = 2500;
113 112
114 // How long we keep the item disabled after the user clicked it to open the 113 // How long we keep the item disabled after the user clicked it to open the
115 // downloaded item. 114 // downloaded item.
116 const int kDisabledOnOpenDuration = 3000; 115 const int kDisabledOnOpenDuration = 3000;
117 116
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 status_font_list_ = 172 status_font_list_ =
174 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(-2); 173 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(-2);
175 174
176 body_hover_animation_.reset(new gfx::SlideAnimation(this)); 175 body_hover_animation_.reset(new gfx::SlideAnimation(this));
177 drop_hover_animation_.reset(new gfx::SlideAnimation(this)); 176 drop_hover_animation_.reset(new gfx::SlideAnimation(this));
178 177
179 SetAccessibilityFocusable(true); 178 SetAccessibilityFocusable(true);
180 179
181 OnDownloadUpdated(download()); 180 OnDownloadUpdated(download());
182 181
183 // TODO(estade): share this button init code with the find in page bar; 182 dropdown_button_ = new BarControlButton(this);
184 // also fix theming.
185 dropdown_button_ = new views::ImageButton(this);
186 dropdown_button_->SetBorder(views::Border::CreateEmptyBorder(4, 4, 4, 4));
187 dropdown_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
188 views::ImageButton::ALIGN_MIDDLE);
189 AddChildView(dropdown_button_); 183 AddChildView(dropdown_button_);
190 SetDropdownState(NORMAL); 184 SetDropdownState(NORMAL);
191 UpdateColorsFromTheme(); 185 UpdateColorsFromTheme();
192 } 186 }
193 187
194 DownloadItemViewMd::~DownloadItemViewMd() { 188 DownloadItemViewMd::~DownloadItemViewMd() {
195 StopDownloadProgress(); 189 StopDownloadProgress();
196 download()->RemoveObserver(this); 190 download()->RemoveObserver(this);
197 191
198 // ExperienceSampling: If the user took no action to remove the warning 192 // ExperienceSampling: If the user took no action to remove the warning
(...skipping 16 matching lines...) Expand all
215 } 209 }
216 210
217 void DownloadItemViewMd::StopDownloadProgress() { 211 void DownloadItemViewMd::StopDownloadProgress() {
218 if (!progress_timer_.IsRunning()) 212 if (!progress_timer_.IsRunning())
219 return; 213 return;
220 previous_progress_elapsed_ += base::TimeTicks::Now() - progress_start_time_; 214 previous_progress_elapsed_ += base::TimeTicks::Now() - progress_start_time_;
221 progress_start_time_ = base::TimeTicks(); 215 progress_start_time_ = base::TimeTicks();
222 progress_timer_.Stop(); 216 progress_timer_.Stop();
223 } 217 }
224 218
219 // static
220 SkColor DownloadItemViewMd::GetTextColorForThemeProvider(
221 ui::ThemeProvider* theme) {
222 return theme ? theme->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)
223 : SK_ColorRED;
224 }
225
225 void DownloadItemViewMd::OnExtractIconComplete(gfx::Image* icon_bitmap) { 226 void DownloadItemViewMd::OnExtractIconComplete(gfx::Image* icon_bitmap) {
226 if (icon_bitmap) 227 if (icon_bitmap)
227 shelf_->SchedulePaint(); 228 shelf_->SchedulePaint();
228 } 229 }
229 230
230 // DownloadObserver interface. 231 // DownloadObserver interface.
231 232
232 // Update the progress graphic on the icon and our text status label 233 // Update the progress graphic on the icon and our text status label
233 // to reflect our current bytes downloaded, time remaining. 234 // to reflect our current bytes downloaded, time remaining.
234 void DownloadItemViewMd::OnDownloadUpdated(DownloadItem* download_item) { 235 void DownloadItemViewMd::OnDownloadUpdated(DownloadItem* download_item) {
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 void DownloadItemViewMd::DrawStatusText(gfx::Canvas* canvas) { 582 void DownloadItemViewMd::DrawStatusText(gfx::Canvas* canvas) {
582 if (status_text_.empty() || IsShowingWarningDialog()) 583 if (status_text_.empty() || IsShowingWarningDialog())
583 return; 584 return;
584 585
585 int mirrored_x = GetMirroredXWithWidthInView( 586 int mirrored_x = GetMirroredXWithWidthInView(
586 kStartPadding + DownloadShelf::kProgressIndicatorSize + 587 kStartPadding + DownloadShelf::kProgressIndicatorSize +
587 kProgressTextPadding, 588 kProgressTextPadding,
588 kTextWidth); 589 kTextWidth);
589 int y = 590 int y =
590 GetYForFilenameText() + font_list_.GetBaseline() + kVerticalTextPadding; 591 GetYForFilenameText() + font_list_.GetBaseline() + kVerticalTextPadding;
591 SkColor file_name_color = SkColorSetA(
592 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT), 0xC7);
593 canvas->DrawStringRect( 592 canvas->DrawStringRect(
594 status_text_, status_font_list_, file_name_color, 593 status_text_, status_font_list_, GetDimmedTextColor(),
595 gfx::Rect(mirrored_x, y, kTextWidth, status_font_list_.GetHeight())); 594 gfx::Rect(mirrored_x, y, kTextWidth, status_font_list_.GetHeight()));
596 } 595 }
597 596
598 void DownloadItemViewMd::DrawFilename(gfx::Canvas* canvas) { 597 void DownloadItemViewMd::DrawFilename(gfx::Canvas* canvas) {
599 if (IsShowingWarningDialog()) 598 if (IsShowingWarningDialog())
600 return; 599 return;
601 600
602 // Print the text, left aligned and always print the file extension. 601 // Print the text, left aligned and always print the file extension.
603 // Last value of x was the end of the right image, just before the button. 602 // Last value of x was the end of the right image, just before the button.
604 // Note that in dangerous mode we use a label (as the text is multi-line). 603 // Note that in dangerous mode we use a label (as the text is multi-line).
(...skipping 12 matching lines...) Expand all
617 kTextWidth - status_string_width); 616 kTextWidth - status_string_width);
618 // Last, concat the whole string. 617 // Last, concat the whole string.
619 filename = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, 618 filename = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING,
620 filename_string); 619 filename_string);
621 } 620 }
622 621
623 int mirrored_x = GetMirroredXWithWidthInView( 622 int mirrored_x = GetMirroredXWithWidthInView(
624 kStartPadding + DownloadShelf::kProgressIndicatorSize + 623 kStartPadding + DownloadShelf::kProgressIndicatorSize +
625 kProgressTextPadding, 624 kProgressTextPadding,
626 kTextWidth); 625 kTextWidth);
627 SkColor file_name_color =
628 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
629
630 canvas->DrawStringRect(filename, font_list_, 626 canvas->DrawStringRect(filename, font_list_,
631 enabled() ? file_name_color : kFileNameDisabledColor, 627 enabled() ? GetTextColor() : GetDimmedTextColor(),
632 gfx::Rect(mirrored_x, GetYForFilenameText(), 628 gfx::Rect(mirrored_x, GetYForFilenameText(),
633 kTextWidth, font_list_.GetHeight())); 629 kTextWidth, font_list_.GetHeight()));
634 } 630 }
635 631
636 void DownloadItemViewMd::DrawIcon(gfx::Canvas* canvas) { 632 void DownloadItemViewMd::DrawIcon(gfx::Canvas* canvas) {
637 if (IsShowingWarningDialog()) { 633 if (IsShowingWarningDialog()) {
638 int icon_x = base::i18n::IsRTL() 634 int icon_x = base::i18n::IsRTL()
639 ? width() - kWarningIconSize - kStartPadding 635 ? width() - kWarningIconSize - kStartPadding
640 : kStartPadding; 636 : kStartPadding;
641 int icon_y = (height() - kWarningIconSize) / 2; 637 int icon_y = (height() - kWarningIconSize) / 2;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 if (last_download_item_path_ == current_download_path) 749 if (last_download_item_path_ == current_download_path)
754 return; 750 return;
755 751
756 LoadIcon(); 752 LoadIcon();
757 } 753 }
758 754
759 void DownloadItemViewMd::UpdateColorsFromTheme() { 755 void DownloadItemViewMd::UpdateColorsFromTheme() {
760 if (!GetThemeProvider()) 756 if (!GetThemeProvider())
761 return; 757 return;
762 758
763 if (dangerous_download_label_) { 759 if (dangerous_download_label_)
764 dangerous_download_label_->SetEnabledColor( 760 dangerous_download_label_->SetEnabledColor(GetTextColor());
765 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT));
766 }
767 SetBorder(make_scoped_ptr(new SeparatorBorder( 761 SetBorder(make_scoped_ptr(new SeparatorBorder(
768 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR_SEPARATOR)))); 762 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR_SEPARATOR))));
769 } 763 }
770 764
771 void DownloadItemViewMd::ShowContextMenuImpl(const gfx::Rect& rect, 765 void DownloadItemViewMd::ShowContextMenuImpl(const gfx::Rect& rect,
772 ui::MenuSourceType source_type) { 766 ui::MenuSourceType source_type) {
773 // Similar hack as in MenuButton. 767 // Similar hack as in MenuButton.
774 // We're about to show the menu from a mouse press. By showing from the 768 // We're about to show the menu from a mouse press. By showing from the
775 // mouse press event we block RootView in mouse dispatching. This also 769 // mouse press event we block RootView in mouse dispatching. This also
776 // appears to cause RootView to get a mouse pressed BEFORE the mouse 770 // appears to cause RootView to get a mouse pressed BEFORE the mouse
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 OpenDownload(); 812 OpenDownload();
819 } 813 }
820 814
821 void DownloadItemViewMd::SetDropdownState(State new_state) { 815 void DownloadItemViewMd::SetDropdownState(State new_state) {
822 // Avoid extra SchedulePaint()s if the state is going to be the same and 816 // Avoid extra SchedulePaint()s if the state is going to be the same and
823 // |dropdown_button_| has already been initialized. 817 // |dropdown_button_| has already been initialized.
824 if (dropdown_state_ == new_state && 818 if (dropdown_state_ == new_state &&
825 !dropdown_button_->GetImage(views::CustomButton::STATE_NORMAL).isNull()) 819 !dropdown_button_->GetImage(views::CustomButton::STATE_NORMAL).isNull())
826 return; 820 return;
827 821
828 // TODO(estade): theme this color instead of using a constant. 822 dropdown_button_->SetIcon(
829 gfx::ImageSkia image = 823 new_state == PUSHED ? gfx::VectorIconId::FIND_NEXT
830 gfx::CreateVectorIcon(new_state == PUSHED ? gfx::VectorIconId::FIND_NEXT 824 : gfx::VectorIconId::FIND_PREV,
831 : gfx::VectorIconId::FIND_PREV, 825 base::Bind(&DownloadItemViewMd::GetTextColor, base::Unretained(this)));
832 16, gfx::kChromeIconGrey); 826 dropdown_button_->OnThemeChanged();
833 dropdown_button_->SetImage(views::CustomButton::STATE_NORMAL, &image);
834 dropdown_state_ = new_state; 827 dropdown_state_ = new_state;
835 SchedulePaint(); 828 SchedulePaint();
836 } 829 }
837 830
838 void DownloadItemViewMd::ClearWarningDialog() { 831 void DownloadItemViewMd::ClearWarningDialog() {
839 DCHECK(download()->GetDangerType() == 832 DCHECK(download()->GetDangerType() ==
840 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED); 833 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED);
841 DCHECK(mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE); 834 DCHECK(mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE);
842 835
843 mode_ = NORMAL_MODE; 836 mode_ = NORMAL_MODE;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 State to, 1063 State to,
1071 gfx::SlideAnimation* animation) { 1064 gfx::SlideAnimation* animation) {
1072 if (from == NORMAL && to == HOT) { 1065 if (from == NORMAL && to == HOT) {
1073 animation->Show(); 1066 animation->Show();
1074 } else if (from == HOT && to == NORMAL) { 1067 } else if (from == HOT && to == NORMAL) {
1075 animation->Hide(); 1068 animation->Hide();
1076 } else if (from != to) { 1069 } else if (from != to) {
1077 animation->Reset((to == HOT) ? 1.0 : 0.0); 1070 animation->Reset((to == HOT) ? 1.0 : 0.0);
1078 } 1071 }
1079 } 1072 }
1073
1074 SkColor DownloadItemViewMd::GetTextColor() {
1075 return GetTextColorForThemeProvider(GetThemeProvider());
1076 }
1077
1078 SkColor DownloadItemViewMd::GetDimmedTextColor() {
1079 return SkColorSetA(GetTextColor(), 0xC7);
1080 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698