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

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: 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
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 27 matching lines...) Expand all
38 const int kTextLeftPadding = kIconSize + message_center::kIconToTextPadding; 38 const int kTextLeftPadding = kIconSize + message_center::kIconToTextPadding;
39 const int kTextBottomPadding = 12; 39 const int kTextBottomPadding = 12;
40 const int kTextRightPadding = 23; 40 const int kTextRightPadding = 23;
41 const int kItemTitleToMessagePadding = 3; 41 const int kItemTitleToMessagePadding = 3;
42 const int kProgressBarWidth = message_center::kNotificationWidth - 42 const int kProgressBarWidth = message_center::kNotificationWidth -
43 kTextLeftPadding - kTextRightPadding; 43 kTextLeftPadding - kTextRightPadding;
44 const int kProgressBarBottomPadding = 0; 44 const int kProgressBarBottomPadding = 0;
45 const int kButtonVecticalPadding = 0; 45 const int kButtonVecticalPadding = 0;
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 ine limits above,
jianli 2013/08/28 21:30:54 ine?
dewittj 2013/08/29 17:40:10 Done.
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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::kDimTextColor,
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 LOG(INFO) << "Context message: " << notification.context_message();
503 if (!notification.context_message().empty()) {
504 gfx::Font font = views::Label().font().DeriveFont(0, gfx::Font::ITALIC);
505 int padding = kContextMessageLineHeight - views::Label().font().GetHeight();
506 context_message_view_ =
507 new BoundedLabel(ui::TruncateString(notification.context_message(),
508 kContextMessageCharacterLimit),
509 font);
510 context_message_view_->SetLineLimit(
511 message_center::kContextMessageLineLimit);
512 context_message_view_->SetLineHeight(kContextMessageLineHeight);
513 context_message_view_->SetColors(message_center::kContextTextColor,
514 kContextTextBackgroundColor);
515 context_message_view_->set_border(MakeTextBorder(padding, 4, 0));
516 top_view_->AddChildView(context_message_view_);
517 accessible_lines.push_back(notification.context_message());
518 }
519
496 // Create the progress bar view. 520 // Create the progress bar view.
497 progress_bar_view_ = NULL; 521 progress_bar_view_ = NULL;
498 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) { 522 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) {
499 progress_bar_view_ = new NotificationProgressBar(); 523 progress_bar_view_ = new NotificationProgressBar();
500 progress_bar_view_->set_border(MakeProgressBarBorder( 524 progress_bar_view_->set_border(MakeProgressBarBorder(
501 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); 525 message_center::kProgressBarTopPadding, kProgressBarBottomPadding));
502 progress_bar_view_->SetValue(notification.progress() / 100.0); 526 progress_bar_view_->SetValue(notification.progress() / 100.0);
503 top_view_->AddChildView(progress_bar_view_); 527 top_view_->AddChildView(progress_bar_view_);
504 } 528 }
505 529
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 return message_view_ ? 781 return message_view_ ?
758 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; 782 message_view_->GetLinesForWidthAndLimit(width, limit) : 0;
759 } 783 }
760 784
761 int NotificationView::GetMessageHeight(int width, int limit) { 785 int NotificationView::GetMessageHeight(int width, int limit) {
762 return message_view_ ? 786 return message_view_ ?
763 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; 787 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0;
764 } 788 }
765 789
766 } // namespace message_center 790 } // namespace message_center
OLDNEW
« ui/message_center/views/notification_view.h ('K') | « 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