| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.h" | 5 #include "chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/i18n/number_formatting.h" | 8 #include "base/i18n/number_formatting.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 base::MessageLoop::current()->PostTask(FROM_HERE, | 69 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 70 base::Bind(&MessageCenterTrayBridge::OpenTrayWindow, | 70 base::Bind(&MessageCenterTrayBridge::OpenTrayWindow, |
| 71 weak_ptr_factory_.GetWeakPtr())); | 71 weak_ptr_factory_.GetWeakPtr())); |
| 72 return true; | 72 return true; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void MessageCenterTrayBridge::HideMessageCenter() { | 75 void MessageCenterTrayBridge::HideMessageCenter() { |
| 76 [status_item_view_ setHighlight:NO]; | 76 [status_item_view_ setHighlight:NO]; |
| 77 [tray_controller_ close]; | 77 [tray_controller_ close]; |
| 78 tray_controller_.autorelease(); | 78 tray_controller_.autorelease(); |
| 79 UpdateStatusItem(); |
| 79 } | 80 } |
| 80 | 81 |
| 81 bool MessageCenterTrayBridge::ShowNotifierSettings() { | 82 bool MessageCenterTrayBridge::ShowNotifierSettings() { |
| 82 // This method needs to be implemented when the context menu of each | 83 // This method needs to be implemented when the context menu of each |
| 83 // notification is ready and it contains 'settings' menu item. | 84 // notification is ready and it contains 'settings' menu item. |
| 84 return false; | 85 return false; |
| 85 } | 86 } |
| 86 | 87 |
| 87 void MessageCenterTrayBridge::UpdateStatusItem() { | 88 void MessageCenterTrayBridge::UpdateStatusItem() { |
| 88 // Only show the status item if there are notifications. | |
| 89 if (message_center_->NotificationCount() == 0) { | |
| 90 [status_item_view_ removeItem]; | |
| 91 status_item_view_.reset(); | |
| 92 return; | |
| 93 } | |
| 94 | |
| 95 if (!status_item_view_) { | 89 if (!status_item_view_) { |
| 96 status_item_view_.reset([[MCStatusItemView alloc] init]); | 90 status_item_view_.reset([[MCStatusItemView alloc] init]); |
| 97 [status_item_view_ setCallback:^{ tray_->ToggleMessageCenterBubble(); }]; | 91 [status_item_view_ setCallback:^{ tray_->ToggleMessageCenterBubble(); }]; |
| 98 } | 92 } |
| 99 | 93 |
| 94 // We want a static message center icon while it's visible. |
| 95 if (message_center()->IsMessageCenterVisible()) |
| 96 return; |
| 97 |
| 100 size_t unread_count = message_center_->UnreadNotificationCount(); | 98 size_t unread_count = message_center_->UnreadNotificationCount(); |
| 101 [status_item_view_ setUnreadCount:unread_count]; | 99 bool quiet_mode = message_center_->IsQuietMode(); |
| 100 [status_item_view_ setUnreadCount:unread_count withQuietMode:quiet_mode]; |
| 102 | 101 |
| 103 string16 product_name = l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); | 102 string16 product_name = l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); |
| 104 if (unread_count > 0) { | 103 if (unread_count > 0) { |
| 105 string16 unread_count_string = base::FormatNumber(unread_count); | 104 string16 unread_count_string = base::FormatNumber(unread_count); |
| 106 [status_item_view_ setToolTip: | 105 [status_item_view_ setToolTip: |
| 107 l10n_util::GetNSStringF(IDS_MESSAGE_CENTER_TOOLTIP_UNREAD, | 106 l10n_util::GetNSStringF(IDS_MESSAGE_CENTER_TOOLTIP_UNREAD, |
| 108 product_name, unread_count_string)]; | 107 product_name, unread_count_string)]; |
| 109 } else { | 108 } else { |
| 110 [status_item_view_ setToolTip: | 109 [status_item_view_ setToolTip: |
| 111 l10n_util::GetNSStringF(IDS_MESSAGE_CENTER_TOOLTIP, product_name)]; | 110 l10n_util::GetNSStringF(IDS_MESSAGE_CENTER_TOOLTIP, product_name)]; |
| 112 } | 111 } |
| 113 } | 112 } |
| 114 | 113 |
| 115 void MessageCenterTrayBridge::OpenTrayWindow() { | 114 void MessageCenterTrayBridge::OpenTrayWindow() { |
| 116 DCHECK(!tray_controller_); | 115 DCHECK(!tray_controller_); |
| 117 tray_controller_.reset( | 116 tray_controller_.reset( |
| 118 [[MCTrayController alloc] initWithMessageCenterTray:tray_.get()]); | 117 [[MCTrayController alloc] initWithMessageCenterTray:tray_.get()]); |
| 119 | 118 |
| 120 UpdateStatusItem(); | 119 UpdateStatusItem(); |
| 121 | 120 |
| 122 [status_item_view_ setHighlight:YES]; | 121 [status_item_view_ setHighlight:YES]; |
| 123 NSRect frame = [[status_item_view_ window] frame]; | 122 NSRect frame = [[status_item_view_ window] frame]; |
| 124 [tray_controller_ showTrayAtRightOf:NSMakePoint(NSMinX(frame), | 123 [tray_controller_ showTrayAtRightOf:NSMakePoint(NSMinX(frame), |
| 125 NSMinY(frame)) | 124 NSMinY(frame)) |
| 126 atLeftOf:NSMakePoint(NSMaxX(frame), | 125 atLeftOf:NSMakePoint(NSMaxX(frame), |
| 127 NSMinY(frame))]; | 126 NSMinY(frame))]; |
| 128 } | 127 } |
| OLD | NEW |