Commit b09e000b authored by dewittj@chromium.org's avatar dewittj@chromium.org

Update notification style: allow 2-line titles if the message is blank.

This is to support longer text in simple notifications.

BUG=361890

Review URL: https://codereview.chromium.org/256883002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266767 0039d316-1c4b-4281-b951-d872f2087c98
parent b8af2d1b
......@@ -343,10 +343,13 @@
message_center::kTextTopPadding - messageBottomGap - contextMessageTopGap;
// Set the title and recalculate the frame.
int titleLineLimit = notification_->message().empty()
? message_center::kTitleNoMessageLineLimit
: message_center::kTitleLineLimit;
[title_ setString:base::SysUTF16ToNSString(
[self wrapText:notification_->title()
forFont:[title_ font]
maxNumberOfLines:message_center::kTitleLineLimit])];
maxNumberOfLines:titleLineLimit])];
[title_ sizeToFit];
NSRect titleFrame = [title_ frame];
titleFrame.origin.y = NSMaxY(rootFrame) - titlePadding - NSHeight(titleFrame);
......@@ -362,7 +365,10 @@
// If there are list items, then the message_ view should not be displayed.
const std::vector<message_center::NotificationItem>& items =
notification->items();
if (items.size() > 0) {
// If there are list items, don't show the main message. Also if the message
// is empty, mark it as hidden and set 0 height, so it doesn't take up any
// space (size to fit leaves it 15 px tall.
if (items.size() > 0 || notification_->message().empty()) {
[message_ setHidden:YES];
messageFrame.origin.y = titleFrame.origin.y;
messageFrame.size.height = 0;
......
......@@ -331,4 +331,31 @@ TEST_F(NotificationControllerTest, List) {
NSMinY([[controller titleView] frame]));
}
TEST_F(NotificationControllerTest, NoMessage) {
message_center::RichNotificationData optional;
optional.context_message = UTF8ToUTF16("Context Message");
scoped_ptr<message_center::Notification> notification(
new message_center::Notification(
message_center::NOTIFICATION_TYPE_BASE_FORMAT,
"an_id",
UTF8ToUTF16("Notification Title"),
UTF8ToUTF16(""),
gfx::Image(),
base::string16(),
DummyNotifierId(),
optional,
NULL));
MockMessageCenter message_center;
base::scoped_nsobject<MCNotificationController> controller(
[[MCNotificationController alloc] initWithNotification:notification.get()
messageCenter:&message_center]);
[controller view];
EXPECT_FALSE([[controller titleView] isHidden]);
EXPECT_TRUE([[controller messageView] isHidden]);
EXPECT_FALSE([[controller contextMessageView] isHidden]);
}
} // namespace message_center
......@@ -113,6 +113,7 @@ const SkColor kProgressBarSliceColor = SkColorSetRGB(120, 120, 120);
// Line limits.
const int kTitleLineLimit = 1;
const int kTitleNoMessageLineLimit = 2;
const int kMessageCollapsedLineLimit = 2;
const int kMessageExpandedLineLimit = 5;
const int kContextMessageLineLimit = 1;
......
......@@ -31,8 +31,7 @@ const int kButtonTitleTopPadding = 0;
// Character limits: Displayed text will be subject to the line limits above,
// but we also remove trailing characters from text to reduce processing cost.
// Character limit = pixels per line * line limit / min. pixels per character.
const size_t kTitleCharacterLimit =
message_center::kNotificationWidth * message_center::kTitleLineLimit / 4;
const int kMinPixelsPerTitleCharacter = 4;
const size_t kMessageCharacterLimit =
message_center::kNotificationWidth *
message_center::kMessageExpandedLineLimit / 3;
......
......@@ -318,11 +318,15 @@ NotificationView::NotificationView(MessageCenterController* controller,
const gfx::FontList& font_list =
default_label_font_list.DeriveWithSizeDelta(2);
int padding = kTitleLineHeight - font_list.GetHeight();
int title_lines = notification.message().empty() ? kTitleNoMessageLineLimit
: kTitleLineLimit;
int title_character_limit =
kNotificationWidth * title_lines / kMinPixelsPerTitleCharacter;
title_view_ = new BoundedLabel(
gfx::TruncateString(notification.title(), kTitleCharacterLimit),
gfx::TruncateString(notification.title(), title_character_limit),
font_list);
title_view_->SetLineHeight(kTitleLineHeight);
title_view_->SetLineLimit(message_center::kTitleLineLimit);
title_view_->SetLineLimit(title_lines);
title_view_->SetColors(message_center::kRegularTextColor,
kRegularTextBackgroundColor);
title_view_->SetBorder(MakeTextBorder(padding, 3, 0));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment