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

Unified Diff: ui/message_center/cocoa/status_item_view.mm

Issue 21308002: Update Mac notification tray behavior. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
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 c0efa075d1f6bdf2e8ae71b3169ef46f368f2377..a3e4dd634b8a165c65f356863ed3a04380c9f245 100644
--- a/ui/message_center/cocoa/status_item_view.mm
+++ b/ui/message_center/cocoa/status_item_view.mm
@@ -31,13 +31,10 @@ const CGFloat kUnreadCountMinY = 4;
// Whether or not the status item should be drawn highlighted.
- (BOOL)shouldHighlight;
-// Returns an autoreleased, styled string for the unread count.
-- (NSAttributedString*)unreadCountString;
@end
@implementation MCStatusItemView
-@synthesize unreadCount = unreadCount_;
@synthesize highlight = highlight_;
- (id)init {
@@ -65,21 +62,12 @@ const CGFloat kUnreadCountMinY = 4;
callback_.reset(Block_copy(callback));
}
-- (void)setUnreadCount:(size_t)unreadCount {
+- (void)setUnreadCount:(size_t)unreadCount withQuietMode:(BOOL)quietMode {
unreadCount_ = unreadCount;
+ quietMode_ = quietMode;
NSRect frame = [self frame];
frame.size.width = kStatusItemLength;
- NSAttributedString* countString = [self unreadCountString];
- if (countString) {
- // Get the subpixel bounding rectangle for the string. -size doesn't yield
- // correct results for pixel-precise drawing, since it doesn't use the
- // device metrics.
- NSRect boundingRect =
- [countString boundingRectWithSize:NSZeroSize
- options:NSStringDrawingUsesDeviceMetrics];
- frame.size.width += roundf(NSWidth(boundingRect)) + kMargin;
- }
[self setFrame:frame];
[self setNeedsDisplay:YES];
@@ -126,11 +114,34 @@ const CGFloat kUnreadCountMinY = 4;
BOOL highlight = [self shouldHighlight];
[statusItem_ drawStatusBarBackgroundInRect:frame
withHighlight:highlight];
+ BOOL hasUnreadItems = unreadCount_ > 0;
+
+ int resource_id = IDR_TRAY_EMPTY;
+ if (highlight) {
Nico 2013/07/31 00:09:41 This whole block looks like something that would l
dewittj 2013/07/31 00:37:09 Done. I also reordered the boolean checks to matc
+ if (hasUnreadItems) {
+ if (quietMode_)
+ resource_id = IDR_TRAY_DO_NOT_DISTURB_ATTENTION_PRESSED;
+ else
+ resource_id = IDR_TRAY_ATTENTION_PRESSED;
+ } else if (quietMode_) {
+ resource_id = IDR_TRAY_DO_NOT_DISTURB_EMPTY_PRESSED;
+ } else {
+ resource_id = IDR_TRAY_EMPTY_PRESSED;
+ }
+ } else {
+ if (hasUnreadItems) {
+ if (quietMode_)
+ resource_id = IDR_TRAY_DO_NOT_DISTURB_ATTENTION;
+ else
+ resource_id = IDR_TRAY_ATTENTION;
+ } else if (quietMode_) {
+ resource_id = IDR_TRAY_DO_NOT_DISTURB_EMPTY;
+ }
+ }
// Draw the icon.
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- NSImage* image = rb.GetNativeImageNamed(
- highlight ? IDR_TRAY_ICON_PRESSED : IDR_TRAY_ICON_REGULAR).ToNSImage();
+ NSImage* image = rb.GetNativeImageNamed(resource_id).ToNSImage();
NSSize size = [image size];
NSRect drawRect = NSMakeRect(kMargin,
floorf((NSHeight(frame) - size.height) / 2),
@@ -140,14 +151,6 @@ const CGFloat kUnreadCountMinY = 4;
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0];
-
- // Draw the unread count.
- NSAttributedString* countString = [self unreadCountString];
- if (countString) {
- NSPoint countPoint = NSMakePoint(
- NSMaxX(drawRect) + kUnreadCountPadding, kUnreadCountMinY);
- [countString drawAtPoint:countPoint];
- }
}
- (NSArray*)accessibilityActionNames {
@@ -169,24 +172,4 @@ const CGFloat kUnreadCountMinY = 4;
return highlight_ || inMouseEventSequence_;
}
-- (NSAttributedString*)unreadCountString {
- if (unreadCount_ == 0)
- return nil;
-
- NSString* count = nil;
- if (unreadCount_ > 9)
- count = @"9+";
- else
- count = [NSString stringWithFormat:@"%" PRIuS, unreadCount_];
-
- NSColor* fontColor = [self shouldHighlight] ? [NSColor whiteColor]
- : [NSColor blackColor];
- NSDictionary* attributes = @{
- NSFontAttributeName: [NSFont fontWithName:@"Helvetica-Bold" size:12],
- NSForegroundColorAttributeName: fontColor,
- };
- return [[[NSAttributedString alloc] initWithString:count
- attributes:attributes] autorelease];
-}
-
@end

Powered by Google App Engine
This is Rietveld 408576698