Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: ui/message_center/views/notification_view.cc

Issue 23462005: Adds the contextMessage field to notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adjust unit test due to bugfix in toast layout. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/message_center/views/notification_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
56 59
57 // Notification colors. The text background colors below are used only to keep 60 // Notification colors. The text background colors below are used only to keep
58 // view::Label from modifying the text color and will not actually be drawn. 61 // view::Label from modifying the text color and will not actually be drawn.
59 // See view::Label's RecalculateColors() for details. 62 // See view::Label's RecalculateColors() for details.
60 const SkColor kRegularTextBackgroundColor = SK_ColorWHITE; 63 const SkColor kRegularTextBackgroundColor = SK_ColorWHITE;
61 const SkColor kDimTextBackgroundColor = SK_ColorWHITE; 64 const SkColor kDimTextBackgroundColor = SK_ColorWHITE;
65 const SkColor kContextTextBackgroundColor = SK_ColorWHITE;
62 66
63 // static 67 // static
64 views::Background* MakeBackground( 68 views::Background* MakeBackground(
65 SkColor color = message_center::kNotificationBackgroundColor) { 69 SkColor color = message_center::kNotificationBackgroundColor) {
66 return views::Background::CreateSolidBackground(color); 70 return views::Background::CreateSolidBackground(color);
67 } 71 }
68 72
69 // static 73 // static
70 views::Border* MakeEmptyBorder(int top, int left, int bottom, int right) { 74 views::Border* MakeEmptyBorder(int top, int left, int bottom, int right) {
71 return views::Border::CreateEmptyBorder(top, left, bottom, right); 75 return views::Border::CreateEmptyBorder(top, left, bottom, right);
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 483 }
480 484
481 // Create the message view if appropriate. 485 // Create the message view if appropriate.
482 message_view_ = NULL; 486 message_view_ = NULL;
483 if (!notification.message().empty()) { 487 if (!notification.message().empty()) {
484 int padding = kMessageLineHeight - views::Label().font().GetHeight(); 488 int padding = kMessageLineHeight - views::Label().font().GetHeight();
485 message_view_ = new BoundedLabel( 489 message_view_ = new BoundedLabel(
486 ui::TruncateString(notification.message(), kMessageCharacterLimit)); 490 ui::TruncateString(notification.message(), kMessageCharacterLimit));
487 message_view_->SetLineHeight(kMessageLineHeight); 491 message_view_->SetLineHeight(kMessageLineHeight);
488 message_view_->SetVisible(!is_expanded() || !notification.items().size()); 492 message_view_->SetVisible(!is_expanded() || !notification.items().size());
489 message_view_->SetColors(message_center::kDimTextColor, 493 message_view_->SetColors(message_center::kRegularTextColor,
490 kDimTextBackgroundColor); 494 kDimTextBackgroundColor);
491 message_view_->set_border(MakeTextBorder(padding, 4, 0)); 495 message_view_->set_border(MakeTextBorder(padding, 4, 0));
492 top_view_->AddChildView(message_view_); 496 top_view_->AddChildView(message_view_);
493 accessible_lines.push_back(notification.message()); 497 accessible_lines.push_back(notification.message());
494 } 498 }
495 499
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
496 // Create the progress bar view. 519 // Create the progress bar view.
497 progress_bar_view_ = NULL; 520 progress_bar_view_ = NULL;
498 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) { 521 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) {
499 progress_bar_view_ = new NotificationProgressBar(); 522 progress_bar_view_ = new NotificationProgressBar();
500 progress_bar_view_->set_border(MakeProgressBarBorder( 523 progress_bar_view_->set_border(MakeProgressBarBorder(
501 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); 524 message_center::kProgressBarTopPadding, kProgressBarBottomPadding));
502 progress_bar_view_->SetValue(notification.progress() / 100.0); 525 progress_bar_view_->SetValue(notification.progress() / 100.0);
503 top_view_->AddChildView(progress_bar_view_); 526 top_view_->AddChildView(progress_bar_view_);
504 } 527 }
505 528
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 return message_view_ ? 780 return message_view_ ?
758 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; 781 message_view_->GetLinesForWidthAndLimit(width, limit) : 0;
759 } 782 }
760 783
761 int NotificationView::GetMessageHeight(int width, int limit) { 784 int NotificationView::GetMessageHeight(int width, int limit) {
762 return message_view_ ? 785 return message_view_ ?
763 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; 786 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0;
764 } 787 }
765 788
766 } // namespace message_center 789 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/notification_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698