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 3 // found in the LICENSE file. 4 5 #ifndef UI_MESSAGE_CENTER_MESSAGE_CENTER_TRAY_H_ 6 #define UI_MESSAGE_CENTER_MESSAGE_CENTER_TRAY_H_ 7 8 #include "base/observer_list.h" 9 #include "ui/base/models/simple_menu_model.h" 10 #include "ui/message_center/message_center_export.h" 11 #include "ui/message_center/message_center_observer.h" 12 #include "ui/message_center/message_center_tray_delegate.h" 13 14 namespace message_center { 15 16 class MessageCenter; 17 class MessageBubbleBase; 18 class MessagePopupBubble; 19 class QuietModeBubble; 20 21 // Implementation found with each supported platform's implementation of 22 // MessageCenterTrayDelegate. 23 MessageCenterTrayDelegate* CreateMessageCenterTray(); 24 25 // Class that observes a MessageCenter. Manages the popup and message center 26 // bubbles. Tells the MessageCenterTrayHost when the tray is changed, as well 27 // as when bubbles are shown and hidden. 28 class MESSAGE_CENTER_EXPORT MessageCenterTray 29 : public MessageCenterObserver, 30 public ui::SimpleMenuModel::Delegate { 31 public: 32 MessageCenterTray(MessageCenterTrayDelegate* delegate, 33 message_center::MessageCenter* message_center); 34 virtual ~MessageCenterTray(); 35 36 // Shows or updates the message center bubble and hides the popup bubble. 37 // Returns whether the message center is visible after the call, whether or 38 // not it was visible before. 39 bool ShowMessageCenterBubble(); 40 41 // Hides the message center if visible and returns whether the message center 42 // was visible before. 43 bool HideMessageCenterBubble(); 44 45 // Marks the message center as "not visible" (this method will not hide the 46 // message center). 47 void MarkMessageCenterHidden(); 48 49 void ToggleMessageCenterBubble(); 50 51 // Causes an update if the popup bubble is already shown. 52 void ShowPopupBubble(); 53 54 // Returns whether the popup was visible before. 55 bool HidePopupBubble(); 56 57 // Toggles the visibility of the settings view in the message center bubble. 58 void ShowNotifierSettingsBubble(); 59 60 // Creates the menu model for quiet mode and returns it. The caller must 61 // take the ownership of the return value. 62 ui::MenuModel* CreateQuietModeMenu(); 63 64 bool message_center_visible() { return message_center_visible_; } 65 bool popups_visible() { return popups_visible_; } 66 MessageCenterTrayDelegate* delegate() { return delegate_; } 67 const message_center::MessageCenter* message_center() const { 68 return message_center_; 69 } 70 message_center::MessageCenter* message_center() { return message_center_; } 71 72 // Overridden from MessageCenterObserver: 73 virtual void OnNotificationAdded(const std::string& notification_id) OVERRIDE; 74 virtual void OnNotificationRemoved(const std::string& notification_id, 75 bool by_user) OVERRIDE; 76 virtual void OnNotificationUpdated( 77 const std::string& notification_id) OVERRIDE; 78 virtual void OnNotificationClicked( 79 const std::string& notification_id) OVERRIDE; 80 virtual void OnNotificationButtonClicked( 81 const std::string& notification_id, 82 int button_index) OVERRIDE; 83 virtual void OnNotificationDisplayed( 84 const std::string& notification_id) OVERRIDE; 85 86 // Overridden from SimpleMenuModel::Delegate. 87 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; 88 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 89 virtual bool GetAcceleratorForCommandId( 90 int command_id, 91 ui::Accelerator* accelerator) OVERRIDE; 92 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; 93 94 private: 95 void OnMessageCenterChanged(); 96 void NotifyMessageCenterTrayChanged(); 97 98 // |message_center_| is a weak pointer that must live longer than 99 // MessageCenterTray. 100 message_center::MessageCenter* message_center_; 101 bool message_center_visible_; 102 bool popups_visible_; 103 // |delegate_| is a weak pointer that must live longer than MessageCenterTray. 104 MessageCenterTrayDelegate* delegate_; 105 106 DISALLOW_COPY_AND_ASSIGN(MessageCenterTray); 107 }; 108 109 } // namespace message_center 110 111 #endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_TRAY_H_ 112