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 #include "ui/views/view.h" 9 10 #include "ui/gfx/animation/animation_delegate.h" 11 #include "ui/message_center/message_center_export.h" 12 #include "ui/message_center/message_center_observer.h" 13 #include "ui/message_center/notification_list.h" 14 #include "ui/message_center/views/message_center_controller.h" 15 #include "ui/message_center/views/message_view.h" 16 #include "ui/views/controls/button/button.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 GroupView; 29 class MessageCenter; 30 class MessageCenterBubble; 31 class NotificationCenterButton; 32 class MessageCenterButtonBar; 33 class MessageCenterTray; 34 class MessageCenterView; 35 class MessageView; 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 virtual ~MessageCenterView(); 53 54 void SetNotifications(const NotificationList::Notifications& notifications); 55 56 void ClearAllNotifications(); 57 void OnAllNotificationsCleared(); 58 59 size_t NumMessageViewsForTest() const; 60 61 void SetSettingsVisible(bool visible); 62 void OnSettingsChanged(); 63 bool settings_visible() const { return settings_visible_; } 64 65 void SetIsClosing(bool is_closing); 66 67 protected: 68 // Overridden from views::View: 69 virtual void Layout() OVERRIDE; 70 virtual gfx::Size GetPreferredSize() OVERRIDE; 71 virtual int GetHeightForWidth(int width) OVERRIDE; 72 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; 73 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 74 75 // Overridden from MessageCenterObserver: 76 virtual void OnNotificationAdded(const std::string& id) OVERRIDE; 77 virtual void OnNotificationRemoved(const std::string& id, 78 bool by_user) OVERRIDE; 79 virtual void OnNotificationUpdated(const std::string& id) OVERRIDE; 80 81 // Overridden from MessageCenterController: 82 virtual void ClickOnNotification(const std::string& notification_id) OVERRIDE; 83 virtual void RemoveNotification(const std::string& notification_id, 84 bool by_user) OVERRIDE; 85 virtual void DisableNotificationsFromThisSource( 86 const NotifierId& notifier_id) OVERRIDE; 87 virtual void ShowNotifierSettingsBubble() OVERRIDE; 88 virtual bool HasClickedListener(const std::string& notification_id) OVERRIDE; 89 virtual void ClickOnNotificationButton(const std::string& notification_id, 90 int button_index) OVERRIDE; 91 virtual void ExpandNotification(const std::string& notification_id) OVERRIDE; 92 virtual void GroupBodyClicked(const std::string& last_notification_id) 93 OVERRIDE; 94 virtual void ExpandGroup(const NotifierId& notifier_id) OVERRIDE; 95 virtual void RemoveGroup(const NotifierId& notifier_id) OVERRIDE; 96 97 // Overridden from gfx::AnimationDelegate: 98 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; 99 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; 100 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE; 101 102 private: 103 friend class MessageCenterViewTest; 104 105 void AddMessageViewAt(MessageView* view, int index); 106 void AddGroupPlaceholder(const NotifierId& group_id, 107 const Notification& notification, 108 const gfx::ImageSkia& group_icon, 109 int group_size, 110 int index); 111 void AddNotificationAt(const Notification& notification, int index); 112 void NotificationsChanged(); 113 void SetNotificationViewForTest(MessageView* view); 114 115 MessageCenter* message_center_; // Weak reference. 116 MessageCenterTray* tray_; // Weak reference. 117 118 // Map notification_id->NotificationView*. It contains all NotificaitonViews 119 // currently displayed in MessageCenter. 120 typedef std::map<std::string, NotificationView*> NotificationViewsMap; 121 NotificationViewsMap notification_views_; // Weak. 122 123 // List of all GroupViews. GroupView is responsible for multiple Notifications 124 // from the same source. 125 typedef std::list<GroupView*> GroupViews; 126 GroupViews group_views_; // Weak. 127 128 // Child views. 129 views::ScrollView* scroller_; 130 scoped_ptr<MessageListView> message_list_view_; 131 scoped_ptr<views::View> empty_list_view_; 132 NotifierSettingsView* settings_view_; 133 MessageCenterButtonBar* button_bar_; 134 bool top_down_; 135 136 // Data for transition animation between settings view and message list. 137 bool settings_visible_; 138 139 // Animation managing transition between message center and settings (and vice 140 // versa). 141 scoped_ptr<gfx::MultiAnimation> settings_transition_animation_; 142 143 // Helper data to keep track of the transition between settings and 144 // message center views. 145 views::View* source_view_; 146 int source_height_; 147 views::View* target_view_; 148 int target_height_; 149 150 // True when the widget is closing so that further operations should be 151 // ignored. 152 bool is_closing_; 153 154 DISALLOW_COPY_AND_ASSIGN(MessageCenterView); 155 }; 156 157 } // namespace message_center 158 159 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_CENTER_VIEW_H_ 160