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/string_util.h" | 8 #include "base/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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // Character limit = pixels per line * line limit / min. pixels per character. | 52 // Character limit = pixels per line * line limit / min. pixels per character. |
53 const size_t kTitleCharacterLimit = | 53 const size_t kTitleCharacterLimit = |
54 message_center::kNotificationWidth * kTitleLineLimit / 4; | 54 message_center::kNotificationWidth * kTitleLineLimit / 4; |
55 const size_t kMessageCharacterLimit = | 55 const size_t kMessageCharacterLimit = |
56 message_center::kNotificationWidth * kMessageExpandedLineLimit / 3; | 56 message_center::kNotificationWidth * kMessageExpandedLineLimit / 3; |
57 | 57 |
58 // Notification colors. The text background colors below are used only to keep | 58 // Notification colors. The text background colors below are used only to keep |
59 // view::Label from modifying the text color and will not actually be drawn. | 59 // view::Label from modifying the text color and will not actually be drawn. |
60 // See view::Label's RecalculateColors() for details. | 60 // See view::Label's RecalculateColors() for details. |
61 const SkColor kRegularTextBackgroundColor = SK_ColorWHITE; | 61 const SkColor kRegularTextBackgroundColor = SK_ColorWHITE; |
62 const SkColor kDimTextColor = SkColorSetRGB(102, 102, 102); | |
63 const SkColor kDimTextBackgroundColor = SK_ColorWHITE; | 62 const SkColor kDimTextBackgroundColor = SK_ColorWHITE; |
64 | 63 |
65 // static | 64 // static |
66 views::Background* MakeBackground( | 65 views::Background* MakeBackground( |
67 SkColor color = message_center::kNotificationBackgroundColor) { | 66 SkColor color = message_center::kNotificationBackgroundColor) { |
68 return views::Background::CreateSolidBackground(color); | 67 return views::Background::CreateSolidBackground(color); |
69 } | 68 } |
70 | 69 |
71 // static | 70 // static |
72 views::Border* MakeEmptyBorder(int top, int left, int bottom, int right) { | 71 views::Border* MakeEmptyBorder(int top, int left, int bottom, int right) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 views::Label* title = new views::Label(item.title); | 137 views::Label* title = new views::Label(item.title); |
139 title->set_collapse_when_hidden(true); | 138 title->set_collapse_when_hidden(true); |
140 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 139 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
141 title->SetEnabledColor(message_center::kRegularTextColor); | 140 title->SetEnabledColor(message_center::kRegularTextColor); |
142 title->SetBackgroundColor(kRegularTextBackgroundColor); | 141 title->SetBackgroundColor(kRegularTextBackgroundColor); |
143 AddChildView(title); | 142 AddChildView(title); |
144 | 143 |
145 views::Label* message = new views::Label(item.message); | 144 views::Label* message = new views::Label(item.message); |
146 message->set_collapse_when_hidden(true); | 145 message->set_collapse_when_hidden(true); |
147 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 146 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
148 message->SetEnabledColor(kDimTextColor); | 147 message->SetEnabledColor(message_center::kDimTextColor); |
149 message->SetBackgroundColor(kDimTextBackgroundColor); | 148 message->SetBackgroundColor(kDimTextBackgroundColor); |
150 AddChildView(message); | 149 AddChildView(message); |
151 | 150 |
152 PreferredSizeChanged(); | 151 PreferredSizeChanged(); |
153 SchedulePaint(); | 152 SchedulePaint(); |
154 } | 153 } |
155 | 154 |
156 ItemView::~ItemView() { | 155 ItemView::~ItemView() { |
157 } | 156 } |
158 | 157 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 } | 407 } |
409 | 408 |
410 // Create the message view if appropriate. | 409 // Create the message view if appropriate. |
411 message_view_ = NULL; | 410 message_view_ = NULL; |
412 if (!notification.message().empty()) { | 411 if (!notification.message().empty()) { |
413 int padding = kMessageLineHeight - views::Label().font().GetHeight(); | 412 int padding = kMessageLineHeight - views::Label().font().GetHeight(); |
414 message_view_ = new BoundedLabel( | 413 message_view_ = new BoundedLabel( |
415 ui::TruncateString(notification.message(), kMessageCharacterLimit)); | 414 ui::TruncateString(notification.message(), kMessageCharacterLimit)); |
416 message_view_->SetLineHeight(kMessageLineHeight); | 415 message_view_->SetLineHeight(kMessageLineHeight); |
417 message_view_->SetVisible(!is_expanded() || !notification.items().size()); | 416 message_view_->SetVisible(!is_expanded() || !notification.items().size()); |
418 message_view_->SetColors(kDimTextColor, kDimTextBackgroundColor); | 417 message_view_->SetColors(message_center::kDimTextColor, |
| 418 kDimTextBackgroundColor); |
419 message_view_->set_border(MakeTextBorder(padding, 4, 0)); | 419 message_view_->set_border(MakeTextBorder(padding, 4, 0)); |
420 top_view_->AddChildView(message_view_); | 420 top_view_->AddChildView(message_view_); |
421 accessible_lines.push_back(notification.message()); | 421 accessible_lines.push_back(notification.message()); |
422 } | 422 } |
423 | 423 |
424 // Create the list item views (up to a maximum). | 424 // Create the list item views (up to a maximum). |
425 int padding = kMessageLineHeight - views::Label().font().GetHeight(); | 425 int padding = kMessageLineHeight - views::Label().font().GetHeight(); |
426 std::vector<NotificationItem> items = notification.items(); | 426 std::vector<NotificationItem> items = notification.items(); |
427 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { | 427 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { |
428 ItemView* item_view = new ItemView(items[i]); | 428 ItemView* item_view = new ItemView(items[i]); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 return message_view_ ? | 665 return message_view_ ? |
666 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; | 666 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; |
667 } | 667 } |
668 | 668 |
669 int NotificationView::GetMessageHeight(int width, int limit) { | 669 int NotificationView::GetMessageHeight(int width, int limit) { |
670 return message_view_ ? | 670 return message_view_ ? |
671 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 671 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
672 } | 672 } |
673 | 673 |
674 } // namespace message_center | 674 } // namespace message_center |
OLD | NEW |