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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #include "ui/gfx/text_utils.h" | 54 #include "ui/gfx/text_utils.h" |
55 #include "ui/views/controls/button/label_button.h" | 55 #include "ui/views/controls/button/label_button.h" |
56 #include "ui/views/controls/label.h" | 56 #include "ui/views/controls/label.h" |
57 #include "ui/views/mouse_constants.h" | 57 #include "ui/views/mouse_constants.h" |
58 #include "ui/views/widget/root_view.h" | 58 #include "ui/views/widget/root_view.h" |
59 #include "ui/views/widget/widget.h" | 59 #include "ui/views/widget/widget.h" |
60 | 60 |
61 using content::DownloadItem; | 61 using content::DownloadItem; |
62 using extensions::ExperienceSamplingEvent; | 62 using extensions::ExperienceSamplingEvent; |
63 | 63 |
| 64 namespace { |
| 65 |
64 // TODO(paulg): These may need to be adjusted when download progress | 66 // TODO(paulg): These may need to be adjusted when download progress |
65 // animation is added, and also possibly to take into account | 67 // animation is added, and also possibly to take into account |
66 // different screen resolutions. | 68 // different screen resolutions. |
67 static const int kTextWidth = 140; // Pixels | 69 const int kTextWidth = 140; // Pixels |
68 static const int kDangerousTextWidth = 200; // Pixels | 70 const int kDangerousTextWidth = 200; // Pixels |
69 static const int kVerticalPadding = 3; // Pixels | 71 const int kVerticalPadding = 3; // Pixels |
70 static const int kVerticalTextPadding = 2; // Pixels | 72 const int kVerticalTextPadding = 2; // Pixels |
71 static const int kTooltipMaxWidth = 800; // Pixels | 73 const int kTooltipMaxWidth = 800; // Pixels |
72 | 74 |
73 // Padding around progress indicator, on all sides. | 75 // Padding around progress indicator, on all sides. |
74 static const int kProgressPadding = 7; | 76 const int kProgressPadding = 7; |
75 | 77 |
76 // We add some padding before the left image so that the progress animation icon | 78 // We add some padding before the left image so that the progress animation icon |
77 // hides the corners of the left image. | 79 // hides the corners of the left image. |
78 static const int kLeftPadding = 0; // Pixels. | 80 const int kLeftPadding = 0; // Pixels. |
79 | 81 |
80 // The space between the Save and Discard buttons when prompting for a dangerous | 82 // The space between the Save and Discard buttons when prompting for a dangerous |
81 // download. | 83 // download. |
82 static const int kButtonPadding = 5; // Pixels. | 84 const int kButtonPadding = 5; // Pixels. |
83 | 85 |
84 // The space on the left and right side of the dangerous download label. | 86 // The space on the left and right side of the dangerous download label. |
85 static const int kLabelPadding = 4; // Pixels. | 87 const int kLabelPadding = 4; // Pixels. |
86 | 88 |
87 static const SkColor kFileNameDisabledColor = SkColorSetRGB(171, 192, 212); | 89 const SkColor kFileNameDisabledColor = SkColorSetRGB(171, 192, 212); |
88 | 90 |
89 // How long the 'download complete' animation should last for. | 91 // How long the 'download complete' animation should last for. |
90 static const int kCompleteAnimationDurationMs = 2500; | 92 const int kCompleteAnimationDurationMs = 2500; |
91 | 93 |
92 // How long the 'download interrupted' animation should last for. | 94 // How long the 'download interrupted' animation should last for. |
93 static const int kInterruptedAnimationDurationMs = 2500; | 95 const int kInterruptedAnimationDurationMs = 2500; |
94 | 96 |
95 // How long we keep the item disabled after the user clicked it to open the | 97 // How long we keep the item disabled after the user clicked it to open the |
96 // downloaded item. | 98 // downloaded item. |
97 static const int kDisabledOnOpenDuration = 3000; | 99 const int kDisabledOnOpenDuration = 3000; |
98 | 100 |
99 // Darken light-on-dark download status text by 20% before drawing, thus | 101 } // namespace |
100 // creating a "muted" version of title text for both dark-on-light and | |
101 // light-on-dark themes. | |
102 static const double kDownloadItemLuminanceMod = 0.8; | |
103 | 102 |
104 DownloadItemView::DownloadItemView(DownloadItem* download_item, | 103 DownloadItemView::DownloadItemView(DownloadItem* download_item, |
105 DownloadShelfView* parent) | 104 DownloadShelfView* parent) |
106 : warning_icon_(NULL), | 105 : warning_icon_(NULL), |
107 shelf_(parent), | 106 shelf_(parent), |
108 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), | 107 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), |
109 body_state_(NORMAL), | 108 body_state_(NORMAL), |
110 drop_down_state_(NORMAL), | 109 drop_down_state_(NORMAL), |
111 mode_(NORMAL_MODE), | 110 mode_(NORMAL_MODE), |
112 drop_down_pressed_(false), | 111 drop_down_pressed_(false), |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 if (!IsShowingWarningDialog()) { | 691 if (!IsShowingWarningDialog()) { |
693 if (!status_text_.empty()) { | 692 if (!status_text_.empty()) { |
694 int mirrored_x = GetMirroredXWithWidthInView( | 693 int mirrored_x = GetMirroredXWithWidthInView( |
695 2 * kProgressPadding + DownloadShelf::kProgressIndicatorSize, | 694 2 * kProgressPadding + DownloadShelf::kProgressIndicatorSize, |
696 kTextWidth); | 695 kTextWidth); |
697 // Add font_list_.height() to compensate for title, which is drawn later. | 696 // Add font_list_.height() to compensate for title, which is drawn later. |
698 int y = box_y_ + kVerticalPadding + font_list_.GetHeight() + | 697 int y = box_y_ + kVerticalPadding + font_list_.GetHeight() + |
699 kVerticalTextPadding; | 698 kVerticalTextPadding; |
700 SkColor file_name_color = GetThemeProvider()->GetColor( | 699 SkColor file_name_color = GetThemeProvider()->GetColor( |
701 ThemeProperties::COLOR_BOOKMARK_TEXT); | 700 ThemeProperties::COLOR_BOOKMARK_TEXT); |
702 // If text is light-on-dark, lightening it alone will do nothing. | 701 // If text is light-on-dark, lightening it alone will do nothing. In this |
703 // Therefore we mute luminance a wee bit before drawing in this case. | 702 // case we multiply color components by 80% before drawing. |
704 if (color_utils::RelativeLuminance(file_name_color) > 0.5) | 703 if (!color_utils::IsDark(file_name_color)) { |
705 file_name_color = SkColorSetRGB( | 704 file_name_color = |
706 static_cast<int>(kDownloadItemLuminanceMod * | 705 color_utils::AlphaBlend(SK_ColorBLACK, file_name_color, 255 / 5); |
707 SkColorGetR(file_name_color)), | 706 } |
708 static_cast<int>(kDownloadItemLuminanceMod * | |
709 SkColorGetG(file_name_color)), | |
710 static_cast<int>(kDownloadItemLuminanceMod * | |
711 SkColorGetB(file_name_color))); | |
712 canvas->DrawStringRect(status_text_, font_list_, file_name_color, | 707 canvas->DrawStringRect(status_text_, font_list_, file_name_color, |
713 gfx::Rect(mirrored_x, y, kTextWidth, | 708 gfx::Rect(mirrored_x, y, kTextWidth, |
714 font_list_.GetHeight())); | 709 font_list_.GetHeight())); |
715 } | 710 } |
716 } | 711 } |
717 | 712 |
718 // Paint the background images. | 713 // Paint the background images. |
719 int x = kLeftPadding; | 714 int x = kLeftPadding; |
720 canvas->Save(); | 715 canvas->Save(); |
721 if (base::i18n::IsRTL()) { | 716 if (base::i18n::IsRTL()) { |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 animation->Reset((to == HOT) ? 1.0 : 0.0); | 1363 animation->Reset((to == HOT) ? 1.0 : 0.0); |
1369 } | 1364 } |
1370 } | 1365 } |
1371 | 1366 |
1372 void DownloadItemView::ProgressTimerFired() { | 1367 void DownloadItemView::ProgressTimerFired() { |
1373 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only | 1368 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only |
1374 // when there's an update notified via OnDownloadUpdated(). | 1369 // when there's an update notified via OnDownloadUpdated(). |
1375 if (model_.PercentComplete() < 0) | 1370 if (model_.PercentComplete() < 0) |
1376 SchedulePaint(); | 1371 SchedulePaint(); |
1377 } | 1372 } |
OLD | NEW |