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_VIEWS_MESSAGE_CENTER_VIEW_H_ 6 #define UI_MESSAGE_CENTER_VIEWS_MESSAGE_CENTER_VIEW_H_ 7 8 9 #include "ui/gfx/animation/animation_delegate.h" 10 #include "ui/message_center/message_center_export.h" 11 #include "ui/message_center/message_center_observer.h" 12 #include "ui/message_center/notification_list.h" 13 #include "ui/message_center/views/message_center_controller.h" 14 #include "ui/message_center/views/message_view.h" 15 #include "ui/views/controls/button/button.h" 16 #include "ui/views/view.h" 17 18 namespace gfx { 19 class MultiAnimation; 20 } // namespace gfx 21 22 namespace views { 23 class Button; 24 } // namespace views 25 26 namespace message_center { 27 28 class MessageCenter; 29 class MessageCenterBubble; 30 class NotificationCenterButton; 31 class MessageCenterButtonBar; 32 class MessageCenterTray; 33 class MessageCenterView; 34 class MessageView; 35 class MessageViewContextMenuController; 36 class MessageListView; 37 class NotificationView; 38 class NotifierSettingsView; 39 40 // MessageCenterView /////////////////////////////////////////////////////////// 41 42 class MESSAGE_CENTER_EXPORT MessageCenterView : public views::View, 43 public MessageCenterObserver, 44 public MessageCenterController, 45 public gfx::AnimationDelegate { 46 public: 47 MessageCenterView(MessageCenter* message_center, 48 MessageCenterTray* tray, 49 int max_height, 50 bool initially_settings_visible, 51 bool top_down, 52 const base::string16& title); 53 virtual ~MessageCenterView(); 54 55 void SetNotifications(const NotificationList::Notifications& notifications); 56 57 void ClearAllNotifications(); 58 void OnAllNotificationsCleared(); 59 60 size_t NumMessageViewsForTest() const; 61 62 void SetSettingsVisible(bool visible); 63 void OnSettingsChanged(); 64 bool settings_visible() const { return settings_visible_; } 65 MessageCenterTray* tray() { return tray_; } 66 67 void SetIsClosing(bool is_closing); 68 69 protected: 70 // Overridden from views::View: 71 virtual void Layout() OVERRIDE; 72 virtual gfx::Size GetPreferredSize() const OVERRIDE; 73 virtual int GetHeightForWidth(int width) const OVERRIDE; 74 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; 75 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 76 77 // Overridden from MessageCenterObserver: 78 virtual void OnNotificationAdded(const std::string& id) OVERRIDE; 79 virtual void OnNotificationRemoved(const std::string& id, 80 bool by_user) OVERRIDE; 81 virtual void OnNotificationUpdated(const std::string& id) OVERRIDE; 82 83 // Overridden from MessageCenterController: 84 virtual void ClickOnNotification(const std::string& notification_id) OVERRIDE; 85 virtual void RemoveNotification(const std::string& notification_id, 86 bool by_user) OVERRIDE; 87 virtual scoped_ptr<ui::MenuModel> CreateMenuModel( 88 const NotifierId& notifier_id, 89 const base::string16& display_source) OVERRIDE; 90 virtual bool HasClickedListener(const std::string& notification_id) OVERRIDE; 91 virtual void ClickOnNotificationButton(const std::string& notification_id, 92 int button_index) OVERRIDE; 93 94 // Overridden from gfx::AnimationDelegate: 95 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; 96 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; 97 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE; 98 99 private: 100 friend class MessageCenterViewTest; 101 102 void AddNotificationAt(const Notification& notification, int index); 103 void NotificationsChanged(); 104 void SetNotificationViewForTest(MessageView* view); 105 106 MessageCenter* message_center_; // Weak reference. 107 MessageCenterTray* tray_; // Weak reference. 108 109 // Map notification_id->NotificationView*. It contains all NotificationViews 110 // currently displayed in MessageCenter. 111 typedef std::map<std::string, NotificationView*> NotificationViewsMap; 112 NotificationViewsMap notification_views_; // Weak. 113 114 // Child views. 115 views::ScrollView* scroller_; 116 scoped_ptr<MessageListView> message_list_view_; 117 scoped_ptr<views::View> empty_list_view_; 118 NotifierSettingsView* settings_view_; 119 MessageCenterButtonBar* button_bar_; 120 bool top_down_; 121 122 // Data for transition animation between settings view and message list. 123 bool settings_visible_; 124 125 // Animation managing transition between message center and settings (and vice 126 // versa). 127 scoped_ptr<gfx::MultiAnimation> settings_transition_animation_; 128 129 // Helper data to keep track of the transition between settings and 130 // message center views. 131 views::View* source_view_; 132 int source_height_; 133 views::View* target_view_; 134 int target_height_; 135 136 // True when the widget is closing so that further operations should be 137 // ignored. 138 bool is_closing_; 139 140 scoped_ptr<MessageViewContextMenuController> context_menu_controller_; 141 142 DISALLOW_COPY_AND_ASSIGN(MessageCenterView); 143 }; 144 145 } // namespace message_center 146 147 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_CENTER_VIEW_H_ 148