Home | History | Annotate | Download | only in views
      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/base/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/views/controls/button/button.h"
     15 
     16 namespace ui {
     17 class MultiAnimation;
     18 }  // namespace ui
     19 
     20 namespace views {
     21 class Button;
     22 }  // namespace views
     23 
     24 namespace message_center {
     25 
     26 class MessageCenter;
     27 class MessageCenterBubble;
     28 class NotificationCenterButton;
     29 class MessageCenterButtonBar;
     30 class MessageCenterTray;
     31 class MessageCenterView;
     32 class MessageView;
     33 class MessageListView;
     34 class NotifierSettingsView;
     35 
     36 // MessageCenterView ///////////////////////////////////////////////////////////
     37 
     38 class MESSAGE_CENTER_EXPORT MessageCenterView : public views::View,
     39                                                 public MessageCenterObserver,
     40                                                 public ui::AnimationDelegate {
     41  public:
     42   MessageCenterView(MessageCenter* message_center,
     43                     MessageCenterTray* tray,
     44                     int max_height,
     45                     bool initially_settings_visible,
     46                     bool top_down);
     47   virtual ~MessageCenterView();
     48 
     49   void SetNotifications(const NotificationList::Notifications& notifications);
     50 
     51   void ClearAllNotifications();
     52   void OnAllNotificationsCleared();
     53 
     54   size_t NumMessageViewsForTest() const;
     55 
     56   void SetSettingsVisible(bool visible);
     57   void OnSettingsChanged();
     58   bool settings_visible() const { return settings_visible_; }
     59 
     60   void SetIsClosing(bool is_closing);
     61 
     62  protected:
     63   // Overridden from views::View:
     64   virtual void Layout() OVERRIDE;
     65   virtual gfx::Size GetPreferredSize() OVERRIDE;
     66   virtual int GetHeightForWidth(int width) OVERRIDE;
     67   virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE;
     68   virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
     69 
     70   // Overridden from MessageCenterObserver:
     71   virtual void OnNotificationAdded(const std::string& id) OVERRIDE;
     72   virtual void OnNotificationRemoved(const std::string& id,
     73                                      bool by_user) OVERRIDE;
     74   virtual void OnNotificationUpdated(const std::string& id) OVERRIDE;
     75 
     76   // Overridden from ui::AnimationDelegate:
     77   virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
     78   virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
     79   virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE;
     80 
     81  private:
     82   friend class MessageCenterViewTest;
     83 
     84   void AddNotificationAt(const Notification& notification, int index);
     85   void NotificationsChanged();
     86   void SetNotificationViewForTest(views::View* view);
     87 
     88   MessageCenter* message_center_;  // Weak reference.
     89   MessageCenterTray* tray_;  // Weak reference.
     90   std::vector<MessageView*> message_views_;  // Weak references.
     91 
     92   // Child views.
     93   views::ScrollView* scroller_;
     94   MessageListView* message_list_view_;
     95   NotifierSettingsView* settings_view_;
     96   MessageCenterButtonBar* button_bar_;
     97   views::View* no_notifications_message_view_;
     98   bool top_down_;
     99 
    100   // Data for transition animation between settings view and message list.
    101   bool settings_visible_;
    102 
    103   // Animation managing transition between message center and settings (and vice
    104   // versa).
    105   scoped_ptr<ui::MultiAnimation> settings_transition_animation_;
    106 
    107   // Helper data to keep track of the transition between settings and
    108   // message center views.
    109   views::View* source_view_;
    110   int source_height_;
    111   views::View* target_view_;
    112   int target_height_;
    113 
    114   // True when the widget is closing so that further operations should be
    115   // ignored.
    116   bool is_closing_;
    117 
    118   DISALLOW_COPY_AND_ASSIGN(MessageCenterView);
    119 };
    120 
    121 }  // namespace message_center
    122 
    123 #endif  // UI_MESSAGE_CENTER_VIEWS_MESSAGE_CENTER_VIEW_H_
    124