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 <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 // TODO(paulg): These may need to be adjusted when download progress | 62 // TODO(paulg): These may need to be adjusted when download progress |
63 // animation is added, and also possibly to take into account | 63 // animation is added, and also possibly to take into account |
64 // different screen resolutions. | 64 // different screen resolutions. |
65 static const int kTextWidth = 140; // Pixels | 65 static const int kTextWidth = 140; // Pixels |
66 static const int kDangerousTextWidth = 200; // Pixels | 66 static const int kDangerousTextWidth = 200; // Pixels |
67 static const int kVerticalPadding = 3; // Pixels | 67 static const int kVerticalPadding = 3; // Pixels |
68 static const int kVerticalTextPadding = 2; // Pixels | 68 static const int kVerticalTextPadding = 2; // Pixels |
69 static const int kTooltipMaxWidth = 800; // Pixels | 69 static const int kTooltipMaxWidth = 800; // Pixels |
70 | 70 |
| 71 // Padding around progress indicator, on all sides. |
| 72 static const int kProgressPadding = 7; |
| 73 |
71 // We add some padding before the left image so that the progress animation icon | 74 // We add some padding before the left image so that the progress animation icon |
72 // hides the corners of the left image. | 75 // hides the corners of the left image. |
73 static const int kLeftPadding = 0; // Pixels. | 76 static const int kLeftPadding = 0; // Pixels. |
74 | 77 |
75 // The space between the Save and Discard buttons when prompting for a dangerous | 78 // The space between the Save and Discard buttons when prompting for a dangerous |
76 // download. | 79 // download. |
77 static const int kButtonPadding = 5; // Pixels. | 80 static const int kButtonPadding = 5; // Pixels. |
78 | 81 |
79 // The space on the left and right side of the dangerous download label. | 82 // The space on the left and right side of the dangerous download label. |
80 static const int kLabelPadding = 4; // Pixels. | 83 static const int kLabelPadding = 4; // Pixels. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 202 |
200 LoadIcon(); | 203 LoadIcon(); |
201 | 204 |
202 font_list_ = rb.GetFontList(ui::ResourceBundle::BaseFont); | 205 font_list_ = rb.GetFontList(ui::ResourceBundle::BaseFont); |
203 box_height_ = std::max<int>(2 * kVerticalPadding + font_list_.GetHeight() + | 206 box_height_ = std::max<int>(2 * kVerticalPadding + font_list_.GetHeight() + |
204 kVerticalTextPadding + font_list_.GetHeight(), | 207 kVerticalTextPadding + font_list_.GetHeight(), |
205 2 * kVerticalPadding + | 208 2 * kVerticalPadding + |
206 normal_body_image_set_.top_left->height() + | 209 normal_body_image_set_.top_left->height() + |
207 normal_body_image_set_.bottom_left->height()); | 210 normal_body_image_set_.bottom_left->height()); |
208 | 211 |
209 if (DownloadShelf::kProgressIndicatorSize > box_height_) | 212 box_y_ = std::max(0, (2 * kProgressPadding + |
210 box_y_ = (DownloadShelf::kProgressIndicatorSize - box_height_) / 2; | 213 DownloadShelf::kProgressIndicatorSize - box_height_) / |
211 else | 214 2); |
212 box_y_ = 0; | |
213 | 215 |
214 body_hover_animation_.reset(new gfx::SlideAnimation(this)); | 216 body_hover_animation_.reset(new gfx::SlideAnimation(this)); |
215 drop_hover_animation_.reset(new gfx::SlideAnimation(this)); | 217 drop_hover_animation_.reset(new gfx::SlideAnimation(this)); |
216 | 218 |
217 SetAccessibilityFocusable(true); | 219 SetAccessibilityFocusable(true); |
218 | 220 |
219 OnDownloadUpdated(download()); | 221 OnDownloadUpdated(download()); |
220 UpdateDropDownButtonPosition(); | 222 UpdateDropDownButtonPosition(); |
221 } | 223 } |
222 | 224 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 } | 376 } |
375 } | 377 } |
376 | 378 |
377 gfx::Size DownloadItemView::GetPreferredSize() const { | 379 gfx::Size DownloadItemView::GetPreferredSize() const { |
378 int width, height; | 380 int width, height; |
379 | 381 |
380 // First, we set the height to the height of two rows or text plus margins. | 382 // First, we set the height to the height of two rows or text plus margins. |
381 height = 2 * kVerticalPadding + 2 * font_list_.GetHeight() + | 383 height = 2 * kVerticalPadding + 2 * font_list_.GetHeight() + |
382 kVerticalTextPadding; | 384 kVerticalTextPadding; |
383 // Then we increase the size if the progress icon doesn't fit. | 385 // Then we increase the size if the progress icon doesn't fit. |
384 height = std::max<int>(height, DownloadShelf::kProgressIndicatorSize); | 386 height = std::max<int>( |
| 387 height, DownloadShelf::kProgressIndicatorSize + 2 * kProgressPadding); |
385 | 388 |
386 if (IsShowingWarningDialog()) { | 389 if (IsShowingWarningDialog()) { |
387 const BodyImageSet* body_image_set = | 390 const BodyImageSet* body_image_set = |
388 (mode_ == DANGEROUS_MODE) ? &dangerous_mode_body_image_set_ : | 391 (mode_ == DANGEROUS_MODE) ? &dangerous_mode_body_image_set_ : |
389 &malicious_mode_body_image_set_; | 392 &malicious_mode_body_image_set_; |
390 width = kLeftPadding + body_image_set->top_left->width(); | 393 width = kLeftPadding + body_image_set->top_left->width(); |
391 width += warning_icon_->width() + kLabelPadding; | 394 width += warning_icon_->width() + kLabelPadding; |
392 width += dangerous_download_label_->width() + kLabelPadding; | 395 width += dangerous_download_label_->width() + kLabelPadding; |
393 gfx::Size button_size = GetButtonSize(); | 396 gfx::Size button_size = GetButtonSize(); |
394 // Make sure the button fits. | 397 // Make sure the button fits. |
395 height = std::max<int>(height, 2 * kVerticalPadding + button_size.height()); | 398 height = std::max<int>(height, 2 * kVerticalPadding + button_size.height()); |
396 // Then we make sure the warning icon fits. | 399 // Then we make sure the warning icon fits. |
397 height = std::max<int>(height, 2 * kVerticalPadding + | 400 height = std::max<int>(height, 2 * kVerticalPadding + |
398 warning_icon_->height()); | 401 warning_icon_->height()); |
399 if (save_button_) | 402 if (save_button_) |
400 width += button_size.width() + kButtonPadding; | 403 width += button_size.width() + kButtonPadding; |
401 width += button_size.width(); | 404 width += button_size.width(); |
402 width += body_image_set->top_right->width(); | 405 width += body_image_set->top_right->width(); |
403 if (mode_ == MALICIOUS_MODE) | 406 if (mode_ == MALICIOUS_MODE) |
404 width += normal_drop_down_image_set_.top->width(); | 407 width += normal_drop_down_image_set_.top->width(); |
405 } else { | 408 } else { |
406 width = kLeftPadding + normal_body_image_set_.top_left->width(); | 409 width = kLeftPadding + normal_body_image_set_.top_left->width(); |
407 width += DownloadShelf::kProgressIndicatorSize; | 410 width += DownloadShelf::kProgressIndicatorSize + 2 * kProgressPadding; |
408 width += kTextWidth; | 411 width += kTextWidth; |
409 width += normal_body_image_set_.top_right->width(); | 412 width += normal_body_image_set_.top_right->width(); |
410 width += normal_drop_down_image_set_.top->width(); | 413 width += normal_drop_down_image_set_.top->width(); |
411 } | 414 } |
412 return gfx::Size(width, height); | 415 return gfx::Size(width, height); |
413 } | 416 } |
414 | 417 |
415 // Handle a mouse click and open the context menu if the mouse is | 418 // Handle a mouse click and open the context menu if the mouse is |
416 // over the drop-down region. | 419 // over the drop-down region. |
417 bool DownloadItemView::OnMousePressed(const ui::MouseEvent& event) { | 420 bool DownloadItemView::OnMousePressed(const ui::MouseEvent& event) { |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 | 696 |
694 // May be caused by animation. | 697 // May be caused by animation. |
695 if (center_width <= 0) | 698 if (center_width <= 0) |
696 return; | 699 return; |
697 | 700 |
698 // Draw status before button image to effectively lighten text. No status for | 701 // Draw status before button image to effectively lighten text. No status for |
699 // warning dialogs. | 702 // warning dialogs. |
700 if (!IsShowingWarningDialog()) { | 703 if (!IsShowingWarningDialog()) { |
701 if (!status_text_.empty()) { | 704 if (!status_text_.empty()) { |
702 int mirrored_x = GetMirroredXWithWidthInView( | 705 int mirrored_x = GetMirroredXWithWidthInView( |
703 DownloadShelf::kProgressIndicatorSize, kTextWidth); | 706 2 * kProgressPadding + DownloadShelf::kProgressIndicatorSize, |
| 707 kTextWidth); |
704 // Add font_list_.height() to compensate for title, which is drawn later. | 708 // Add font_list_.height() to compensate for title, which is drawn later. |
705 int y = box_y_ + kVerticalPadding + font_list_.GetHeight() + | 709 int y = box_y_ + kVerticalPadding + font_list_.GetHeight() + |
706 kVerticalTextPadding; | 710 kVerticalTextPadding; |
707 SkColor file_name_color = GetThemeProvider()->GetColor( | 711 SkColor file_name_color = GetThemeProvider()->GetColor( |
708 ThemeProperties::COLOR_BOOKMARK_TEXT); | 712 ThemeProperties::COLOR_BOOKMARK_TEXT); |
709 // If text is light-on-dark, lightening it alone will do nothing. | 713 // If text is light-on-dark, lightening it alone will do nothing. |
710 // Therefore we mute luminance a wee bit before drawing in this case. | 714 // Therefore we mute luminance a wee bit before drawing in this case. |
711 if (color_utils::RelativeLuminance(file_name_color) > 0.5) | 715 if (color_utils::RelativeLuminance(file_name_color) > 0.5) |
712 file_name_color = SkColorSetRGB( | 716 file_name_color = SkColorSetRGB( |
713 static_cast<int>(kDownloadItemLuminanceMod * | 717 static_cast<int>(kDownloadItemLuminanceMod * |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 // Then, elide the file name. | 823 // Then, elide the file name. |
820 base::string16 filename_string = | 824 base::string16 filename_string = |
821 gfx::ElideFilename(download()->GetFileNameToReportUser(), font_list_, | 825 gfx::ElideFilename(download()->GetFileNameToReportUser(), font_list_, |
822 kTextWidth - status_string_width); | 826 kTextWidth - status_string_width); |
823 // Last, concat the whole string. | 827 // Last, concat the whole string. |
824 filename = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, | 828 filename = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, |
825 filename_string); | 829 filename_string); |
826 } | 830 } |
827 | 831 |
828 int mirrored_x = GetMirroredXWithWidthInView( | 832 int mirrored_x = GetMirroredXWithWidthInView( |
829 DownloadShelf::kProgressIndicatorSize, kTextWidth); | 833 2 * kProgressPadding + DownloadShelf::kProgressIndicatorSize, |
| 834 kTextWidth); |
830 SkColor file_name_color = GetThemeProvider()->GetColor( | 835 SkColor file_name_color = GetThemeProvider()->GetColor( |
831 ThemeProperties::COLOR_BOOKMARK_TEXT); | 836 ThemeProperties::COLOR_BOOKMARK_TEXT); |
832 int y = | 837 int y = |
833 box_y_ + (status_text_.empty() ? | 838 box_y_ + (status_text_.empty() ? |
834 ((box_height_ - font_list_.GetHeight()) / 2) : kVerticalPadding); | 839 ((box_height_ - font_list_.GetHeight()) / 2) : kVerticalPadding); |
835 | 840 |
836 // Draw the file's name. | 841 // Draw the file's name. |
837 canvas->DrawStringRect( | 842 canvas->DrawStringRect( |
838 filename, font_list_, | 843 filename, font_list_, |
839 enabled() ? file_name_color : kFileNameDisabledColor, | 844 enabled() ? file_name_color : kFileNameDisabledColor, |
840 gfx::Rect(mirrored_x, y, kTextWidth, font_list_.GetHeight())); | 845 gfx::Rect(mirrored_x, y, kTextWidth, font_list_.GetHeight())); |
841 } | 846 } |
842 | 847 |
843 // Load the icon. | 848 // Load the icon. |
844 IconManager* im = g_browser_process->icon_manager(); | 849 IconManager* im = g_browser_process->icon_manager(); |
845 gfx::Image* image = im->LookupIconFromFilepath( | 850 gfx::Image* image = im->LookupIconFromFilepath( |
846 download()->GetTargetFilePath(), IconLoader::SMALL); | 851 download()->GetTargetFilePath(), IconLoader::SMALL); |
847 const gfx::ImageSkia* icon = NULL; | 852 const gfx::ImageSkia* icon = NULL; |
848 if (IsShowingWarningDialog()) | 853 if (IsShowingWarningDialog()) |
849 icon = warning_icon_; | 854 icon = warning_icon_; |
850 else if (image) | 855 else if (image) |
851 icon = image->ToImageSkia(); | 856 icon = image->ToImageSkia(); |
852 | 857 |
853 // We count on the fact that the icon manager will cache the icons and if one | 858 // We count on the fact that the icon manager will cache the icons and if one |
854 // is available, it will be cached here. We *don't* want to request the icon | 859 // is available, it will be cached here. We *don't* want to request the icon |
855 // to be loaded here, since this will also get called if the icon can't be | 860 // to be loaded here, since this will also get called if the icon can't be |
856 // loaded, in which case LookupIcon will always be NULL. The loading will be | 861 // loaded, in which case LookupIcon will always be NULL. The loading will be |
857 // triggered only when we think the status might change. | 862 // triggered only when we think the status might change. |
858 if (icon) { | 863 if (icon) { |
| 864 int progress_x = |
| 865 base::i18n::IsRTL() |
| 866 ? width() - kProgressPadding - DownloadShelf::kProgressIndicatorSize |
| 867 : kProgressPadding; |
| 868 int progress_y = kProgressPadding; |
| 869 |
859 if (!IsShowingWarningDialog()) { | 870 if (!IsShowingWarningDialog()) { |
| 871 canvas->Save(); |
| 872 canvas->Translate(gfx::Vector2d(progress_x, progress_y)); |
| 873 |
860 DownloadItem::DownloadState state = download()->GetState(); | 874 DownloadItem::DownloadState state = download()->GetState(); |
861 canvas->Save(); | |
862 if (base::i18n::IsRTL()) | |
863 canvas->Translate( | |
864 gfx::Vector2d(width() - DownloadShelf::kProgressIndicatorSize, 0)); | |
865 | |
866 if (state == DownloadItem::IN_PROGRESS) { | 875 if (state == DownloadItem::IN_PROGRESS) { |
867 base::TimeDelta progress_time = previous_progress_elapsed_; | 876 base::TimeDelta progress_time = previous_progress_elapsed_; |
868 if (!download()->IsPaused()) | 877 if (!download()->IsPaused()) |
869 progress_time += base::TimeTicks::Now() - progress_start_time_; | 878 progress_time += base::TimeTicks::Now() - progress_start_time_; |
870 DownloadShelf::PaintDownloadProgress(canvas, *GetThemeProvider(), | 879 DownloadShelf::PaintDownloadProgress(canvas, *GetThemeProvider(), |
871 progress_time, | 880 progress_time, |
872 model_.PercentComplete()); | 881 model_.PercentComplete()); |
873 } else if (complete_animation_.get() && | 882 } else if (complete_animation_.get() && |
874 complete_animation_->is_animating()) { | 883 complete_animation_->is_animating()) { |
875 if (state == DownloadItem::INTERRUPTED) { | 884 if (state == DownloadItem::INTERRUPTED) { |
876 DownloadShelf::PaintDownloadInterrupted( | 885 DownloadShelf::PaintDownloadInterrupted( |
877 canvas, *GetThemeProvider(), | 886 canvas, *GetThemeProvider(), |
878 complete_animation_->GetCurrentValue()); | 887 complete_animation_->GetCurrentValue()); |
879 } else { | 888 } else { |
880 DCHECK_EQ(DownloadItem::COMPLETE, state); | 889 DCHECK_EQ(DownloadItem::COMPLETE, state); |
881 DownloadShelf::PaintDownloadComplete( | 890 DownloadShelf::PaintDownloadComplete( |
882 canvas, *GetThemeProvider(), | 891 canvas, *GetThemeProvider(), |
883 complete_animation_->GetCurrentValue()); | 892 complete_animation_->GetCurrentValue()); |
884 } | 893 } |
885 } | 894 } |
886 canvas->Restore(); | 895 canvas->Restore(); |
887 } | 896 } |
888 | 897 |
889 // Draw the icon image. | 898 // Draw the icon image. |
890 int icon_x, icon_y; | 899 int icon_x, icon_y; |
891 | 900 |
892 if (IsShowingWarningDialog()) { | 901 if (IsShowingWarningDialog()) { |
893 icon_x = kLeftPadding + body_image_set->top_left->width(); | 902 icon_x = kLeftPadding + body_image_set->top_left->width(); |
| 903 icon_x = GetMirroredXWithWidthInView(icon_x, icon->width()); |
894 icon_y = (height() - icon->height()) / 2; | 904 icon_y = (height() - icon->height()) / 2; |
895 } else { | 905 } else { |
896 icon_x = DownloadShelf::kFiletypeIconOffset; | 906 icon_x = progress_x + DownloadShelf::kFiletypeIconOffset; |
897 icon_y = DownloadShelf::kFiletypeIconOffset; | 907 icon_y = progress_y + DownloadShelf::kFiletypeIconOffset; |
898 } | 908 } |
899 icon_x = GetMirroredXWithWidthInView(icon_x, icon->width()); | |
900 if (enabled()) { | 909 if (enabled()) { |
901 canvas->DrawImageInt(*icon, icon_x, icon_y); | 910 canvas->DrawImageInt(*icon, icon_x, icon_y); |
902 } else { | 911 } else { |
903 // Use an alpha to make the image look disabled. | 912 // Use an alpha to make the image look disabled. |
904 SkPaint paint; | 913 SkPaint paint; |
905 paint.setAlpha(120); | 914 paint.setAlpha(120); |
906 canvas->DrawImageInt(*icon, icon_x, icon_y, paint); | 915 canvas->DrawImageInt(*icon, icon_x, icon_y, paint); |
907 } | 916 } |
908 } | 917 } |
909 } | 918 } |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 void DownloadItemView::AnimateStateTransition(State from, State to, | 1388 void DownloadItemView::AnimateStateTransition(State from, State to, |
1380 gfx::SlideAnimation* animation) { | 1389 gfx::SlideAnimation* animation) { |
1381 if (from == NORMAL && to == HOT) { | 1390 if (from == NORMAL && to == HOT) { |
1382 animation->Show(); | 1391 animation->Show(); |
1383 } else if (from == HOT && to == NORMAL) { | 1392 } else if (from == HOT && to == NORMAL) { |
1384 animation->Hide(); | 1393 animation->Hide(); |
1385 } else if (from != to) { | 1394 } else if (from != to) { |
1386 animation->Reset((to == HOT) ? 1.0 : 0.0); | 1395 animation->Reset((to == HOT) ? 1.0 : 0.0); |
1387 } | 1396 } |
1388 } | 1397 } |
OLD | NEW |