diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 12:56:46 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 12:56:46 +0000 |
commit | 642b33573d2b5cc1bf83c17877f2d1869eb9b721 (patch) | |
tree | 1248d34f51c40b5a919d2e5aeeeb7028d90e9973 /ui/message_center | |
parent | 630f022b8df5e96ee43300ee6fd15a479c344c37 (diff) | |
download | chromium_src-642b33573d2b5cc1bf83c17877f2d1869eb9b721.zip chromium_src-642b33573d2b5cc1bf83c17877f2d1869eb9b721.tar.gz chromium_src-642b33573d2b5cc1bf83c17877f2d1869eb9b721.tar.bz2 |
[Mac][MC] Only show the status item when there are notifications in the tray.
This also cleans up the MCStatusItem interface to have a simple designated
initializer.
BUG=248319
TEST=No icon visible at launch. Show some notifications and the icon appears. Close the notifications in the tray and the icon disappears.
R=dewittj@chromium.org, thakis@chromium.org
Review URL: https://codereview.chromium.org/16836003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206058 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/message_center')
-rw-r--r-- | ui/message_center/cocoa/status_item_view.h | 9 | ||||
-rw-r--r-- | ui/message_center/cocoa/status_item_view.mm | 13 | ||||
-rw-r--r-- | ui/message_center/cocoa/status_item_view_unittest.mm | 16 |
3 files changed, 22 insertions, 16 deletions
diff --git a/ui/message_center/cocoa/status_item_view.h b/ui/message_center/cocoa/status_item_view.h index f1f186a..29a26eb 100644 --- a/ui/message_center/cocoa/status_item_view.h +++ b/ui/message_center/cocoa/status_item_view.h @@ -47,9 +47,12 @@ MESSAGE_CENTER_EXPORT @property(nonatomic) size_t unreadCount; @property(nonatomic) BOOL highlight; -// Designated initializer. This will take ownership of |item| and set self as -// its view. -- (id)initWithStatusItem:(NSStatusItem*)item; +// Designated initializer. Creates a new NSStatusItem in the system menubar. +- (id)init; + +// Removes the status item from the menubar. Must be called to break the +// retain cycle between self and the NSStatusItem view. +- (void)removeItem; @end diff --git a/ui/message_center/cocoa/status_item_view.mm b/ui/message_center/cocoa/status_item_view.mm index 4a76d931..085fa61 100644 --- a/ui/message_center/cocoa/status_item_view.mm +++ b/ui/message_center/cocoa/status_item_view.mm @@ -40,16 +40,23 @@ const CGFloat kUnreadCountMinY = 4; @synthesize unreadCount = unreadCount_; @synthesize highlight = highlight_; -- (id)initWithStatusItem:(NSStatusItem*)item { - CGFloat thickness = [[item statusBar] thickness]; +- (id)init { + statusItem_.reset([[[NSStatusBar systemStatusBar] statusItemWithLength: + NSVariableStatusItemLength] retain]); + CGFloat thickness = [[statusItem_ statusBar] thickness]; + NSRect frame = NSMakeRect(0, 0, kStatusItemLength, thickness); if ((self = [super initWithFrame:frame])) { - statusItem_.reset([item retain]); [statusItem_ setView:self]; } return self; } +- (void)removeItem { + [[NSStatusBar systemStatusBar] removeStatusItem:statusItem_]; + statusItem_.reset(); +} + - (message_center::StatusItemClickedCallack)callback { return callback_.get(); } diff --git a/ui/message_center/cocoa/status_item_view_unittest.mm b/ui/message_center/cocoa/status_item_view_unittest.mm index e276be1..7e9dc45 100644 --- a/ui/message_center/cocoa/status_item_view_unittest.mm +++ b/ui/message_center/cocoa/status_item_view_unittest.mm @@ -10,24 +10,20 @@ class StatusItemViewTest : public ui::CocoaTest { public: StatusItemViewTest() - : status_item_([[NSStatusBar systemStatusBar] statusItemWithLength: - NSVariableStatusItemLength]), - view_([[MCStatusItemView alloc] initWithStatusItem:status_item_]) { + : view_([[MCStatusItemView alloc] init]) { } virtual void SetUp() OVERRIDE { - // CocoaTest keeps a list of windows that were open at the time of its - // construction, and it will attempt to close all new ones. Using - // NSStatusBar creates a non-closeable window. Call Init() again after - // creating the NSStatusItem to exclude the status bar window from the - // list of windows to attempt to close. - ui::CocoaTest::Init(); ui::CocoaTest::SetUp(); [[test_window() contentView] addSubview:view_]; } + virtual void TearDown() OVERRIDE { + [view_ removeItem]; + ui::CocoaTest::TearDown(); + } + protected: - NSStatusItem* status_item_; // Weak, owned by |view_|. scoped_nsobject<MCStatusItemView> view_; }; |