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 "ui/message_center/views/notification_view.h" | 5 #include "ui/message_center/views/notification_view.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 const int kButtonTitleTopPadding = 0; | 46 const int kButtonTitleTopPadding = 0; |
47 | 47 |
48 // Character limits: Displayed text will be subject to the line limits above, | 48 // Character limits: Displayed text will be subject to the line limits above, |
49 // but we also remove trailing characters from text to reduce processing cost. | 49 // but we also remove trailing characters from text to reduce processing cost. |
50 // Character limit = pixels per line * line limit / min. pixels per character. | 50 // Character limit = pixels per line * line limit / min. pixels per character. |
51 const size_t kTitleCharacterLimit = | 51 const size_t kTitleCharacterLimit = |
52 message_center::kNotificationWidth * message_center::kTitleLineLimit / 4; | 52 message_center::kNotificationWidth * message_center::kTitleLineLimit / 4; |
53 const size_t kMessageCharacterLimit = | 53 const size_t kMessageCharacterLimit = |
54 message_center::kNotificationWidth * | 54 message_center::kNotificationWidth * |
55 message_center::kMessageExpandedLineLimit / 3; | 55 message_center::kMessageExpandedLineLimit / 3; |
56 const size_t kContextMessageCharacterLimit = | |
57 message_center::kNotificationWidth * | |
58 message_center::kContextMessageLineLimit / 3; | |
59 | 56 |
60 // Notification colors. The text background colors below are used only to keep | 57 // Notification colors. The text background colors below are used only to keep |
61 // view::Label from modifying the text color and will not actually be drawn. | 58 // view::Label from modifying the text color and will not actually be drawn. |
62 // See view::Label's RecalculateColors() for details. | 59 // See view::Label's RecalculateColors() for details. |
63 const SkColor kRegularTextBackgroundColor = SK_ColorWHITE; | 60 const SkColor kRegularTextBackgroundColor = SK_ColorWHITE; |
64 const SkColor kDimTextBackgroundColor = SK_ColorWHITE; | 61 const SkColor kDimTextBackgroundColor = SK_ColorWHITE; |
65 const SkColor kContextTextBackgroundColor = SK_ColorWHITE; | |
66 | 62 |
67 // static | 63 // static |
68 views::Background* MakeBackground( | 64 views::Background* MakeBackground( |
69 SkColor color = message_center::kNotificationBackgroundColor) { | 65 SkColor color = message_center::kNotificationBackgroundColor) { |
70 return views::Background::CreateSolidBackground(color); | 66 return views::Background::CreateSolidBackground(color); |
71 } | 67 } |
72 | 68 |
73 // static | 69 // static |
74 views::Border* MakeEmptyBorder(int top, int left, int bottom, int right) { | 70 views::Border* MakeEmptyBorder(int top, int left, int bottom, int right) { |
75 return views::Border::CreateEmptyBorder(top, left, bottom, right); | 71 return views::Border::CreateEmptyBorder(top, left, bottom, right); |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 } | 479 } |
484 | 480 |
485 // Create the message view if appropriate. | 481 // Create the message view if appropriate. |
486 message_view_ = NULL; | 482 message_view_ = NULL; |
487 if (!notification.message().empty()) { | 483 if (!notification.message().empty()) { |
488 int padding = kMessageLineHeight - views::Label().font().GetHeight(); | 484 int padding = kMessageLineHeight - views::Label().font().GetHeight(); |
489 message_view_ = new BoundedLabel( | 485 message_view_ = new BoundedLabel( |
490 ui::TruncateString(notification.message(), kMessageCharacterLimit)); | 486 ui::TruncateString(notification.message(), kMessageCharacterLimit)); |
491 message_view_->SetLineHeight(kMessageLineHeight); | 487 message_view_->SetLineHeight(kMessageLineHeight); |
492 message_view_->SetVisible(!is_expanded() || !notification.items().size()); | 488 message_view_->SetVisible(!is_expanded() || !notification.items().size()); |
493 message_view_->SetColors(message_center::kRegularTextColor, | 489 message_view_->SetColors(message_center::kDimTextColor, |
494 kDimTextBackgroundColor); | 490 kDimTextBackgroundColor); |
495 message_view_->set_border(MakeTextBorder(padding, 4, 0)); | 491 message_view_->set_border(MakeTextBorder(padding, 4, 0)); |
496 top_view_->AddChildView(message_view_); | 492 top_view_->AddChildView(message_view_); |
497 accessible_lines.push_back(notification.message()); | 493 accessible_lines.push_back(notification.message()); |
498 } | 494 } |
499 | 495 |
500 // Create the context message view if appropriate. | |
501 context_message_view_ = NULL; | |
502 if (!notification.context_message().empty()) { | |
503 gfx::Font font = views::Label().font(); | |
504 int padding = kMessageLineHeight - font.GetHeight(); | |
505 context_message_view_ = | |
506 new BoundedLabel(ui::TruncateString(notification.context_message(), | |
507 kContextMessageCharacterLimit), | |
508 font); | |
509 context_message_view_->SetLineLimit( | |
510 message_center::kContextMessageLineLimit); | |
511 context_message_view_->SetLineHeight(kMessageLineHeight); | |
512 context_message_view_->SetColors(message_center::kDimTextColor, | |
513 kContextTextBackgroundColor); | |
514 context_message_view_->set_border(MakeTextBorder(padding, 4, 0)); | |
515 top_view_->AddChildView(context_message_view_); | |
516 accessible_lines.push_back(notification.context_message()); | |
517 } | |
518 | |
519 // Create the progress bar view. | 496 // Create the progress bar view. |
520 progress_bar_view_ = NULL; | 497 progress_bar_view_ = NULL; |
521 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) { | 498 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) { |
522 progress_bar_view_ = new NotificationProgressBar(); | 499 progress_bar_view_ = new NotificationProgressBar(); |
523 progress_bar_view_->set_border(MakeProgressBarBorder( | 500 progress_bar_view_->set_border(MakeProgressBarBorder( |
524 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); | 501 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); |
525 progress_bar_view_->SetValue(notification.progress() / 100.0); | 502 progress_bar_view_->SetValue(notification.progress() / 100.0); |
526 top_view_->AddChildView(progress_bar_view_); | 503 top_view_->AddChildView(progress_bar_view_); |
527 } | 504 } |
528 | 505 |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 return message_view_ ? | 757 return message_view_ ? |
781 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; | 758 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; |
782 } | 759 } |
783 | 760 |
784 int NotificationView::GetMessageHeight(int width, int limit) { | 761 int NotificationView::GetMessageHeight(int width, int limit) { |
785 return message_view_ ? | 762 return message_view_ ? |
786 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 763 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
787 } | 764 } |
788 | 765 |
789 } // namespace message_center | 766 } // namespace message_center |
OLD | NEW |