OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/download_item_view.h" | 5 #include "chrome/browser/views/download_item_view.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP_NO_DD), | 204 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP_NO_DD), |
205 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_NO_DD), | 205 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_NO_DD), |
206 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_NO_DD) | 206 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_NO_DD) |
207 }; | 207 }; |
208 dangerous_mode_body_image_set_ = dangerous_mode_body_image_set; | 208 dangerous_mode_body_image_set_ = dangerous_mode_body_image_set; |
209 | 209 |
210 LoadIcon(); | 210 LoadIcon(); |
211 tooltip_text_ = download_->GetFileName().ToWStringHack(); | 211 tooltip_text_ = download_->GetFileName().ToWStringHack(); |
212 | 212 |
213 font_ = ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); | 213 font_ = ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); |
214 box_height_ = std::max<int>(2 * kVerticalPadding + font_.height() + | 214 box_height_ = std::max<int>(2 * kVerticalPadding + font_.GetHeight() + |
215 kVerticalTextPadding + font_.height(), | 215 kVerticalTextPadding + font_.GetHeight(), |
216 2 * kVerticalPadding + | 216 2 * kVerticalPadding + |
217 normal_body_image_set_.top_left->height() + | 217 normal_body_image_set_.top_left->height() + |
218 normal_body_image_set_.bottom_left->height()); | 218 normal_body_image_set_.bottom_left->height()); |
219 | 219 |
220 if (download_util::kSmallProgressIconSize > box_height_) | 220 if (download_util::kSmallProgressIconSize > box_height_) |
221 box_y_ = (download_util::kSmallProgressIconSize - box_height_) / 2; | 221 box_y_ = (download_util::kSmallProgressIconSize - box_height_) / 2; |
222 else | 222 else |
223 box_y_ = kVerticalPadding; | 223 box_y_ = kVerticalPadding; |
224 | 224 |
225 gfx::Size size = GetPreferredSize(); | 225 gfx::Size size = GetPreferredSize(); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 // May be caused by animation. | 479 // May be caused by animation. |
480 if (center_width <= 0) | 480 if (center_width <= 0) |
481 return; | 481 return; |
482 | 482 |
483 // Draw status before button image to effectively lighten text. | 483 // Draw status before button image to effectively lighten text. |
484 if (!IsDangerousMode()) { | 484 if (!IsDangerousMode()) { |
485 if (show_status_text_) { | 485 if (show_status_text_) { |
486 int mirrored_x = MirroredXWithWidthInsideView( | 486 int mirrored_x = MirroredXWithWidthInsideView( |
487 download_util::kSmallProgressIconSize, kTextWidth); | 487 download_util::kSmallProgressIconSize, kTextWidth); |
488 // Add font_.height() to compensate for title, which is drawn later. | 488 // Add font_.height() to compensate for title, which is drawn later. |
489 int y = box_y_ + kVerticalPadding + font_.height() + | 489 int y = box_y_ + kVerticalPadding + font_.GetHeight() + |
490 kVerticalTextPadding; | 490 kVerticalTextPadding; |
491 SkColor file_name_color = GetThemeProvider()->GetColor( | 491 SkColor file_name_color = GetThemeProvider()->GetColor( |
492 BrowserThemeProvider::COLOR_BOOKMARK_TEXT); | 492 BrowserThemeProvider::COLOR_BOOKMARK_TEXT); |
493 // If text is light-on-dark, lightening it alone will do nothing. | 493 // If text is light-on-dark, lightening it alone will do nothing. |
494 // Therefore we mute luminance a wee bit before drawing in this case. | 494 // Therefore we mute luminance a wee bit before drawing in this case. |
495 if (color_utils::RelativeLuminance(file_name_color) > 0.5) | 495 if (color_utils::RelativeLuminance(file_name_color) > 0.5) |
496 file_name_color = SkColorSetRGB( | 496 file_name_color = SkColorSetRGB( |
497 static_cast<int>(kDownloadItemLuminanceMod * | 497 static_cast<int>(kDownloadItemLuminanceMod * |
498 SkColorGetR(file_name_color)), | 498 SkColorGetR(file_name_color)), |
499 static_cast<int>(kDownloadItemLuminanceMod * | 499 static_cast<int>(kDownloadItemLuminanceMod * |
500 SkColorGetG(file_name_color)), | 500 SkColorGetG(file_name_color)), |
501 static_cast<int>(kDownloadItemLuminanceMod * | 501 static_cast<int>(kDownloadItemLuminanceMod * |
502 SkColorGetB(file_name_color))); | 502 SkColorGetB(file_name_color))); |
503 canvas->DrawStringInt(status_text_, font_, file_name_color, | 503 canvas->DrawStringInt(status_text_, font_, file_name_color, |
504 mirrored_x, y, kTextWidth, font_.height()); | 504 mirrored_x, y, kTextWidth, font_.GetHeight()); |
505 } | 505 } |
506 } | 506 } |
507 | 507 |
508 // Paint the background images. | 508 // Paint the background images. |
509 int x = kLeftPadding; | 509 int x = kLeftPadding; |
510 bool rtl_ui = base::i18n::IsRTL(); | 510 bool rtl_ui = base::i18n::IsRTL(); |
511 if (rtl_ui) { | 511 if (rtl_ui) { |
512 // Since we do not have the mirrored images for | 512 // Since we do not have the mirrored images for |
513 // (hot_)body_image_set->top_left, (hot_)body_image_set->left, | 513 // (hot_)body_image_set->top_left, (hot_)body_image_set->left, |
514 // (hot_)body_image_set->bottom_left, and drop_down_image_set, | 514 // (hot_)body_image_set->bottom_left, and drop_down_image_set, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 kTextWidth - status_string_width); | 617 kTextWidth - status_string_width); |
618 // Last, concat the whole string. | 618 // Last, concat the whole string. |
619 filename = l10n_util::GetStringF(IDS_DOWNLOAD_STATUS_OPENING, | 619 filename = l10n_util::GetStringF(IDS_DOWNLOAD_STATUS_OPENING, |
620 filename_string); | 620 filename_string); |
621 } | 621 } |
622 | 622 |
623 int mirrored_x = MirroredXWithWidthInsideView( | 623 int mirrored_x = MirroredXWithWidthInsideView( |
624 download_util::kSmallProgressIconSize, kTextWidth); | 624 download_util::kSmallProgressIconSize, kTextWidth); |
625 SkColor file_name_color = GetThemeProvider()->GetColor( | 625 SkColor file_name_color = GetThemeProvider()->GetColor( |
626 BrowserThemeProvider::COLOR_BOOKMARK_TEXT); | 626 BrowserThemeProvider::COLOR_BOOKMARK_TEXT); |
627 int y = box_y_ + (show_status_text_ ? kVerticalPadding : | 627 int y = |
628 (box_height_ - font_.height()) / 2); | 628 box_y_ + (show_status_text_ ? kVerticalPadding : |
| 629 (box_height_ - font_.GetHeight()) / 2); |
629 | 630 |
630 // Draw the file's name. | 631 // Draw the file's name. |
631 canvas->DrawStringInt(filename, font_, | 632 canvas->DrawStringInt(filename, font_, |
632 IsEnabled() ? file_name_color : | 633 IsEnabled() ? file_name_color : |
633 kFileNameDisabledColor, | 634 kFileNameDisabledColor, |
634 mirrored_x, y, kTextWidth, font_.height()); | 635 mirrored_x, y, kTextWidth, font_.GetHeight()); |
635 } | 636 } |
636 | 637 |
637 // Paint the icon. | 638 // Paint the icon. |
638 IconManager* im = g_browser_process->icon_manager(); | 639 IconManager* im = g_browser_process->icon_manager(); |
639 SkBitmap* icon = IsDangerousMode() ? warning_icon_ : | 640 SkBitmap* icon = IsDangerousMode() ? warning_icon_ : |
640 im->LookupIcon(download_->full_path(), IconLoader::SMALL); | 641 im->LookupIcon(download_->full_path(), IconLoader::SMALL); |
641 | 642 |
642 // We count on the fact that the icon manager will cache the icons and if one | 643 // We count on the fact that the icon manager will cache the icons and if one |
643 // is available, it will be cached here. We *don't* want to request the icon | 644 // is available, it will be cached here. We *don't* want to request the icon |
644 // to be loaded here, since this will also get called if the icon can't be | 645 // to be loaded here, since this will also get called if the icon can't be |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 | 732 |
732 // Force the shelf to layout again as our size has changed. | 733 // Force the shelf to layout again as our size has changed. |
733 parent_->Layout(); | 734 parent_->Layout(); |
734 parent_->SchedulePaint(); | 735 parent_->SchedulePaint(); |
735 } | 736 } |
736 | 737 |
737 gfx::Size DownloadItemView::GetPreferredSize() { | 738 gfx::Size DownloadItemView::GetPreferredSize() { |
738 int width, height; | 739 int width, height; |
739 | 740 |
740 // First, we set the height to the height of two rows or text plus margins. | 741 // First, we set the height to the height of two rows or text plus margins. |
741 height = 2 * kVerticalPadding + 2 * font_.height() + kVerticalTextPadding; | 742 height = 2 * kVerticalPadding + 2 * font_.GetHeight() + kVerticalTextPadding; |
742 // Then we increase the size if the progress icon doesn't fit. | 743 // Then we increase the size if the progress icon doesn't fit. |
743 height = std::max<int>(height, download_util::kSmallProgressIconSize); | 744 height = std::max<int>(height, download_util::kSmallProgressIconSize); |
744 | 745 |
745 if (IsDangerousMode()) { | 746 if (IsDangerousMode()) { |
746 width = kLeftPadding + dangerous_mode_body_image_set_.top_left->width(); | 747 width = kLeftPadding + dangerous_mode_body_image_set_.top_left->width(); |
747 width += warning_icon_->width() + kLabelPadding; | 748 width += warning_icon_->width() + kLabelPadding; |
748 width += dangerous_download_label_->width() + kLabelPadding; | 749 width += dangerous_download_label_->width() + kLabelPadding; |
749 gfx::Size button_size = GetButtonSize(); | 750 gfx::Size button_size = GetButtonSize(); |
750 // Make sure the button fits. | 751 // Make sure the button fits. |
751 height = std::max<int>(height, 2 * kVerticalPadding + button_size.height()); | 752 height = std::max<int>(height, 2 * kVerticalPadding + button_size.height()); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 void DownloadItemView::Reenable() { | 1009 void DownloadItemView::Reenable() { |
1009 disabled_while_opening_ = false; | 1010 disabled_while_opening_ = false; |
1010 SetEnabled(true); // Triggers a repaint. | 1011 SetEnabled(true); // Triggers a repaint. |
1011 } | 1012 } |
1012 | 1013 |
1013 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) { | 1014 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) { |
1014 if (x > drop_down_x_left_ && x < drop_down_x_right_) | 1015 if (x > drop_down_x_left_ && x < drop_down_x_right_) |
1015 return true; | 1016 return true; |
1016 return false; | 1017 return false; |
1017 } | 1018 } |
OLD | NEW |