Chromium Code Reviews| Index: ui/message_center/cocoa/status_item_view.mm |
| diff --git a/ui/message_center/cocoa/status_item_view.mm b/ui/message_center/cocoa/status_item_view.mm |
| index 305929332416862e0c1b15271b206a200c659b18..dfdeb8b89812500a3c587f914fc0fca2d9a4d26e 100644 |
| --- a/ui/message_center/cocoa/status_item_view.mm |
| +++ b/ui/message_center/cocoa/status_item_view.mm |
| @@ -12,12 +12,24 @@ |
| namespace { |
| -// The width of the status bar. |
| -const CGFloat kStatusItemLength = 45; |
| +// The width of the status bar item when it's just the icon. |
| +const CGFloat kStatusItemLengthIcon = 27; |
| + |
| +// The width of the status bar item when it's the icon and a number. |
| +const CGFloat kStatusItemLengthNumber = 35; |
| + |
| +// The width of the status bar item when it's the icon, a number, and a + sign. |
|
sail
2013/05/28 19:40:22
I was a little surprised by this approach. I thoug
|
| +const CGFloat kStatusItemLengthNumberPlus = 43; |
| // The amount of space between the edge of the status item and where the icon |
| // should start drawing. |
| -const CGFloat kInset = 6; |
| +const CGFloat kInset = 5; |
| + |
| +// The amount of space between the icon and the unread count number. |
| +const CGFloat kUnreadCountLeftMargin = 3; |
| + |
| +// The lower-left Y coordinate of the unread count number. |
| +const CGFloat kUnreadCountMinY = 4; |
| } // namespace |
| @@ -28,7 +40,7 @@ const CGFloat kInset = 6; |
| - (id)initWithStatusItem:(NSStatusItem*)item { |
| CGFloat thickness = [[item statusBar] thickness]; |
| - NSRect frame = NSMakeRect(0, 0, kStatusItemLength, thickness); |
| + NSRect frame = NSMakeRect(0, 0, kStatusItemLengthIcon, thickness); |
| if ((self = [super initWithFrame:frame])) { |
| statusItem_.reset([item retain]); |
| [statusItem_ setView:self]; |
| @@ -46,6 +58,16 @@ const CGFloat kInset = 6; |
| - (void)setUnreadCount:(size_t)unreadCount { |
| unreadCount_ = unreadCount; |
| + |
| + NSRect frame = [self frame]; |
| + if (unreadCount_ == 0) |
| + frame.size.width = kStatusItemLengthIcon; |
| + else if (unreadCount_ < 10) |
| + frame.size.width = kStatusItemLengthNumber; |
| + else |
| + frame.size.width = kStatusItemLengthNumberPlus; |
| + [self setFrame:frame]; |
| + |
| [self setNeedsDisplay:YES]; |
| } |
| @@ -106,15 +128,8 @@ const CGFloat kInset = 6; |
| NSForegroundColorAttributeName: fontColor, |
| }; |
| - // Center the string inside the remaining space of the status item. |
| - NSSize stringSize = [count sizeWithAttributes:attributes]; |
| - NSRect iconSlice, textSlice; |
| - NSDivideRect(frame, &iconSlice, &textSlice, NSMaxX(drawRect), NSMinXEdge); |
| NSPoint countPoint = NSMakePoint( |
| - floorf(NSMinX(textSlice) + (NSWidth(textSlice) - stringSize.width) / 2), |
| - floorf(NSMinY(textSlice) + |
| - (NSHeight(textSlice) - stringSize.height) / 2)); |
| - |
| + NSMaxX(drawRect) + kUnreadCountLeftMargin, kUnreadCountMinY); |
| [count drawAtPoint:countPoint withAttributes:attributes]; |
| } |
| } |