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

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: Address comments from #1 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..ae38c54a41bd6d1b2662d6288e30e22c35db6a23 100644
--- a/ui/message_center/cocoa/status_item_view.mm
+++ b/ui/message_center/cocoa/status_item_view.mm
@@ -31,13 +31,12 @@ 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;
+- (int)getTrayResourceId;
+
@end
@implementation MCStatusItemView
-@synthesize unreadCount = unreadCount_;
@synthesize highlight = highlight_;
- (id)init {
@@ -65,21 +64,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];
@@ -127,10 +117,10 @@ const CGFloat kUnreadCountMinY = 4;
[statusItem_ drawStatusBarBackgroundInRect:frame
withHighlight:highlight];
+ int resource_id = [self getTrayResourceId];
// 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 +130,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 +151,28 @@ 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];
+- (int)getTrayResourceId {
+ BOOL highlight = [self shouldHighlight];
+ BOOL hasUnreadItems = unreadCount_ > 0;
Nico 2013/07/31 02:40:56 optional nit: What do you think about making this
dewittj 2013/07/31 21:58:41 Done.
+
+ if (quietMode_) {
+ if (hasUnreadItems) {
+ if (highlight)
+ return IDR_TRAY_DO_NOT_DISTURB_ATTENTION_PRESSED;
+ return IDR_TRAY_DO_NOT_DISTURB_ATTENTION;
+ }
+ if (highlight)
+ return IDR_TRAY_DO_NOT_DISTURB_EMPTY_PRESSED;
+ return IDR_TRAY_DO_NOT_DISTURB_EMPTY;
+ }
+ if (hasUnreadItems) {
+ if (highlight)
+ return IDR_TRAY_ATTENTION_PRESSED;
+ return IDR_TRAY_ATTENTION;
+ }
+ if (highlight)
+ return IDR_TRAY_EMPTY_PRESSED;
+ return IDR_TRAY_EMPTY;
}
@end

Powered by Google App Engine
This is Rietveld 408576698