Chromium Code Reviews| Index: ui/message_center/cocoa/notification_controller.mm |
| diff --git a/ui/message_center/cocoa/notification_controller.mm b/ui/message_center/cocoa/notification_controller.mm |
| index 965ba423f24432ae86ef611ed1cd5b7c649cbe9e..8b0b74842b1ee3fc770a664306acce3d27a7dd5f 100644 |
| --- a/ui/message_center/cocoa/notification_controller.mm |
| +++ b/ui/message_center/cocoa/notification_controller.mm |
| @@ -203,6 +203,9 @@ |
| // Initializes message_ in the given frame. |
| - (void)configureBodyInFrame:(NSRect)rootFrame; |
| +// Initializes contextMessage_ in the given frame. |
| +- (void)configureContextMessageInFrame:(NSRect)rootFrame; |
| + |
| // Creates a NSTextField that the caller owns configured as a label in a |
| // notification. |
| - (NSTextField*)newLabelWithFrame:(NSRect)frame; |
| @@ -260,6 +263,10 @@ |
| [self configureBodyInFrame:rootFrame]; |
| [rootView addSubview:message_]; |
| + // Create the context message body. |
| + [self configureContextMessageInFrame:rootFrame]; |
| + [rootView addSubview:contextMessage_]; |
| + |
| // Populate the data. |
| [self updateNotification:notification_]; |
| } |
| @@ -285,9 +292,15 @@ |
| CGFloat messageTopGap = |
| roundf([[message_ font] ascender] - [[message_ font] capHeight]); |
| + CGFloat messageBottomGap = roundf(fabs([[message_ font] descender])); |
| CGFloat messagePadding = |
| message_center::kTextTopPadding - titleBottomGap - messageTopGap; |
| + CGFloat contextMessageTopGap = roundf( |
| + [[contextMessage_ font] ascender] - [[contextMessage_ font] capHeight]); |
| + CGFloat contextMessagePadding = |
| + message_center::kTextTopPadding - messageBottomGap - contextMessageTopGap; |
| + |
| // Set the title and recalculate the frame. |
| [title_ setStringValue:base::SysUTF16ToNSString( |
| [self wrapText:notification_->title() |
| @@ -300,26 +313,51 @@ |
| // Set the message and recalculate the frame. |
| [message_ setStringValue:base::SysUTF16ToNSString( |
| [self wrapText:notification_->message() |
| - forField:title_ |
| + forField:message_ |
| maxNumberOfLines:message_center::kMessageExpandedLineLimit])]; |
| - [message_ setHidden:NO]; |
| [message_ sizeToFit]; |
| NSRect messageFrame = [message_ frame]; |
| - messageFrame.origin.y = |
| - NSMinY(titleFrame) - messagePadding - NSHeight(messageFrame); |
| - messageFrame.size.height = NSHeight([message_ frame]); |
| - // Create the list item views (up to a maximum). |
| - [listItemView_ removeFromSuperview]; |
| + // Need to hide the message if there are items. |
|
jianli
2013/08/28 21:30:54
Do we also do this on views?
dewittj
2013/08/29 17:40:10
Yes. This isn't new, just added a comment for fun
|
| const std::vector<message_center::NotificationItem>& items = |
| notification->items(); |
| - NSRect listFrame = NSZeroRect; |
| if (items.size() > 0) { |
| // If there are list items, then the message_ view should not be displayed. |
| [message_ setHidden:YES]; |
| messageFrame.origin.y = titleFrame.origin.y; |
| messageFrame.size.height = 0; |
| + } else { |
| + [message_ setHidden:NO]; |
| + messageFrame.origin.y = |
| + NSMinY(titleFrame) - messagePadding - NSHeight(messageFrame); |
| + messageFrame.size.height = NSHeight([message_ frame]); |
| + } |
| + |
| + // Set the context message and recalculate the frame. |
| + [contextMessage_ setStringValue:base::SysUTF16ToNSString( |
| + [self wrapText:notification_->context_message() |
| + forField:contextMessage_ |
| + maxNumberOfLines:message_center::kContextMessageLineLimit])]; |
| + [contextMessage_ sizeToFit]; |
| + NSRect contextMessageFrame = [contextMessage_ frame]; |
| + |
| + if (notification_->context_message().length() == 0) { |
|
jianli
2013/08/28 21:30:54
nit: empty()
dewittj
2013/08/29 17:40:10
Done.
|
| + [contextMessage_ setHidden:YES]; |
| + contextMessageFrame.origin.y = messageFrame.origin.y; |
| + contextMessageFrame.size.height = 0; |
| + } else { |
| + [contextMessage_ setHidden:NO]; |
| + contextMessageFrame.origin.y = |
| + NSMinY(messageFrame) - |
| + contextMessagePadding - |
| + NSHeight(contextMessageFrame); |
| + contextMessageFrame.size.height = NSHeight([contextMessage_ frame]); |
| + } |
| + // Create the list item views (up to a maximum). |
| + [listItemView_ removeFromSuperview]; |
| + NSRect listFrame = NSZeroRect; |
| + if (items.size() > 0) { |
| listFrame = [self currentContentRect]; |
| listFrame.origin.y = 0; |
| listFrame.size.height = 0; |
| @@ -348,10 +386,10 @@ |
| } |
| // TODO(thakis): The spacing is not completely right. |
| CGFloat listTopPadding = |
| - message_center::kTextTopPadding - messageTopGap; |
| + message_center::kTextTopPadding - contextMessageTopGap; |
| listFrame.size.height = y; |
| listFrame.origin.y = |
| - NSMinY(titleFrame) - listTopPadding - NSHeight(listFrame); |
| + NSMinY(contextMessageFrame) - listTopPadding - NSHeight(listFrame); |
| [listItemView_ setFrame:listFrame]; |
| [[self view] addSubview:listItemView_]; |
| } |
| @@ -361,7 +399,7 @@ |
| NSRect progressBarFrame = NSZeroRect; |
| if (notification->type() == message_center::NOTIFICATION_TYPE_PROGRESS) { |
| progressBarFrame = [self currentContentRect]; |
| - progressBarFrame.origin.y = NSMinY(messageFrame) - |
| + progressBarFrame.origin.y = NSMinY(contextMessageFrame) - |
| message_center::kProgressBarTopPadding - |
| message_center::kProgressBarThickness; |
| progressBarFrame.size.height = message_center::kProgressBarThickness; |
| @@ -376,7 +414,7 @@ |
| // If the bottom-most element so far is out of the rootView's bounds, resize |
| // the view. |
| - CGFloat minY = NSMinY(messageFrame); |
| + CGFloat minY = NSMinY(contextMessageFrame); |
| if (listItemView_ && NSMinY(listFrame) < minY) |
| minY = NSMinY(listFrame); |
| if (progressBarView_ && NSMinY(progressBarFrame) < minY) |
| @@ -386,6 +424,7 @@ |
| rootFrame.size.height += delta; |
| titleFrame.origin.y += delta; |
| messageFrame.origin.y += delta; |
| + contextMessageFrame.origin.y += delta; |
| listFrame.origin.y += delta; |
| progressBarFrame.origin.y += delta; |
| } |
| @@ -456,6 +495,7 @@ |
| rootFrame.size.height += NSHeight(frame); |
| titleFrame.origin.y += NSHeight(frame); |
| messageFrame.origin.y += NSHeight(frame); |
| + contextMessageFrame.origin.y += NSHeight(frame); |
| listFrame.origin.y += NSHeight(frame); |
| progressBarFrame.origin.y += NSHeight(frame); |
| @@ -467,6 +507,7 @@ |
| rootFrame.size.height += bottomAdjust; |
| titleFrame.origin.y += bottomAdjust; |
| messageFrame.origin.y += bottomAdjust; |
| + contextMessageFrame.origin.y += bottomAdjust; |
| listFrame.origin.y += bottomAdjust; |
| progressBarFrame.origin.y += bottomAdjust; |
| } |
| @@ -474,6 +515,7 @@ |
| [[self view] setFrame:rootFrame]; |
| [title_ setFrame:titleFrame]; |
| [message_ setFrame:messageFrame]; |
| + [contextMessage_ setFrame:contextMessageFrame]; |
| [listItemView_ setFrame:listFrame]; |
| [progressBarView_ setFrame:progressBarFrame]; |
| @@ -616,6 +658,20 @@ |
| [NSFont messageFontOfSize:message_center::kMessageFontSize]]; |
| } |
| +- (void)configureContextMessageInFrame:(NSRect)rootFrame { |
| + NSRect frame = [self currentContentRect]; |
| + frame.size.height = 0; |
| + contextMessage_.reset([self newLabelWithFrame:frame]); |
| + [contextMessage_ setAutoresizingMask:NSViewMinYMargin]; |
| + [contextMessage_ setTextColor:gfx::SkColorToCalibratedNSColor( |
| + message_center::kContextTextColor)]; |
| + NSFont* messageFont = |
| + [NSFont messageFontOfSize:message_center::kMessageFontSize]; |
| + [contextMessage_ setFont: |
| + [[NSFontManager sharedFontManager] convertFont:messageFont |
| + toHaveTrait:NSBoldFontMask]]; |
| +} |
| + |
| - (NSTextField*)newLabelWithFrame:(NSRect)frame { |
| NSTextField* label = [[NSTextField alloc] initWithFrame:frame]; |
| [label setDrawsBackground:NO]; |