message_center_view.h 7.17 KB
Newer Older
1 2 3 4
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef ASH_MESSAGE_CENTER_MESSAGE_CENTER_VIEW_H_
#define ASH_MESSAGE_CENTER_MESSAGE_CENTER_VIEW_H_
7

8 9
#include <stddef.h>

10 11
#include "ash/ash_export.h"
#include "ash/message_center/message_list_view.h"
12
#include "ash/session/session_observer.h"
13
#include "base/macros.h"
14
#include "ui/gfx/animation/animation_delegate.h"
15
#include "ui/message_center/message_center_observer.h"
16
#include "ui/message_center/notification_list.h"
17
#include "ui/message_center/views/message_view_context_menu_controller.h"
Evan Stade's avatar
Evan Stade committed
18
#include "ui/message_center/views/message_view_delegate.h"
19
#include "ui/views/focus/focus_manager.h"
20
#include "ui/views/view.h"
21

22
namespace gfx {
23
class SlideAnimation;
24
}  // namespace gfx
25

26 27
namespace message_center {

28
class MessageCenter;
29
class MessageCenterTray;
30
class MessageView;
31 32 33 34 35 36

}  // namespace message_center

namespace ash {

class MessageCenterButtonBar;
37
class NotifierSettingsView;
38

39 40
// Container for all the top-level views in the notification center, such as the
// button bar, settings view, scrol view, and message list view.  Acts as a
Evan Stade's avatar
Evan Stade committed
41 42
// controller/delegate for the message list view, passing data back and forth to
// message center.
43
class ASH_EXPORT MessageCenterView
yoshiki's avatar
yoshiki committed
44
    : public views::View,
45
      public message_center::MessageCenterObserver,
Evan Stade's avatar
Evan Stade committed
46
      public message_center::MessageViewDelegate,
47
      public SessionObserver,
yoshiki's avatar
yoshiki committed
48
      public MessageListView::Observer,
49 50
      public gfx::AnimationDelegate,
      public views::FocusChangeListener {
51
 public:
52
  MessageCenterView(message_center::MessageCenter* message_center,
53
                    message_center::MessageCenterTray* tray,
54
                    int max_height,
55
                    bool initially_settings_visible);
56
  ~MessageCenterView() override;
57

58 59
  void Init();

60 61
  void SetNotifications(
      const message_center::NotificationList::Notifications& notifications);
62

63
  void ClearAllClosableNotifications();
64

65 66
  size_t NumMessageViewsForTest() const;

67
  void SetSettingsVisible(bool visible);
68
  void OnSettingsChanged();
69
  bool settings_visible() const { return settings_visible_; }
70
  message_center::MessageCenterTray* tray() { return tray_; }
71

72 73
  void SetIsClosing(bool is_closing);

74 75 76 77
  // Overridden from views::FocusChangeListener
  void OnWillChangeFocus(views::View* before, views::View* now) override {}
  void OnDidChangeFocus(views::View* before, views::View* now) override;

78
  // Fallback background color when the device does not support blur.
79
  static const SkColor kBackgroundColor;
80

81 82
  static const size_t kMaxVisibleNotifications;

83
 protected:
84 85 86 87
  // Potentially sets the reposition target, and then returns whether or not it
  // was was set.
  virtual bool SetRepositionTarget();

88
  // Overridden from views::View:
89
  void Layout() override;
90
  gfx::Size CalculatePreferredSize() const override;
91 92 93
  int GetHeightForWidth(int width) const override;
  bool OnMouseWheel(const ui::MouseWheelEvent& event) override;
  void OnMouseExited(const ui::MouseEvent& event) override;
94
  void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
95

96
  // Overridden from MessageCenterObserver:
97 98 99
  void OnNotificationAdded(const std::string& id) override;
  void OnNotificationRemoved(const std::string& id, bool by_user) override;
  void OnNotificationUpdated(const std::string& id) override;
100
  void OnQuietModeChanged(bool is_quiet_mode) override;
101

Evan Stade's avatar
Evan Stade committed
102
  // Overridden from MessageViewDelegate:
103 104 105
  void ClickOnNotification(const std::string& notification_id) override;
  void RemoveNotification(const std::string& notification_id,
                          bool by_user) override;
106
  std::unique_ptr<ui::MenuModel> CreateMenuModel(
107
      const message_center::Notification& notification) override;
108 109
  void ClickOnNotificationButton(const std::string& notification_id,
                                 int button_index) override;
110
  void ClickOnSettingsButton(const std::string& notification_id) override;
111
  void UpdateNotificationSize(const std::string& notification_id) override;
112

113 114 115
  // Overridden from SessionObserver:
  void OnLockStateChanged(bool locked) override;

yoshiki's avatar
yoshiki committed
116 117 118
  // Overridden from MessageListView::Observer:
  void OnAllNotificationsCleared() override;

119
  // Overridden from gfx::AnimationDelegate:
120 121 122
  void AnimationEnded(const gfx::Animation* animation) override;
  void AnimationProgressed(const gfx::Animation* animation) override;
  void AnimationCanceled(const gfx::Animation* animation) override;
123

124 125 126
 private:
  friend class MessageCenterViewTest;

127 128 129 130 131 132 133
  // NOTIFICATIONS: Normal notification list (MessageListView) is shown.
  //   There should be at least one notification.
  // SETTINGS: Notifier settings (NotifierSettingsView) is shown.
  // LOCKED: The computer is in the lock screen. No content view is shown.
  // NO_NOTIFICATIONS: "All done" message (EmptyNotifcationView) is shown.
  //   There should be no notification.
  enum class Mode { NOTIFICATIONS, SETTINGS, LOCKED, NO_NOTIFICATIONS };
134

135 136
  static bool disable_animation_for_testing;

137 138
  void AddNotificationAt(const message_center::Notification& notification,
                         int index);
139
  base::string16 GetButtonBarTitle() const;
140 141 142
  void Update(bool animate);
  void SetVisibilityMode(Mode mode, bool animate);
  void UpdateButtonBarStatus();
143
  void EnableCloseAllIfAppropriate();
144
  void SetNotificationViewForTest(message_center::MessageView* view);
145
  void UpdateNotification(const std::string& notification_id);
146

147 148 149 150 151 152 153 154
  // There are three patterns for animation.
  // - Only MessageCenterView height changes.
  // - Both MessageCenterview and NotifierSettingsView moves at same velocity.
  // - Only NotifierSettingsView moves.
  // Thus, these two methods are needed.
  int GetSettingsHeightForWidth(int width) const;
  int GetContentHeightDuringAnimation(int width) const;

155
  message_center::MessageCenter* message_center_;
156
  message_center::MessageCenterTray* tray_;
157

158
  // Child views.
159
  views::ScrollView* scroller_ = nullptr;
160
  std::unique_ptr<MessageListView> message_list_view_;
161 162 163
  NotifierSettingsView* settings_view_ = nullptr;
  views::View* no_notifications_view_ = nullptr;
  MessageCenterButtonBar* button_bar_ = nullptr;
164

165 166
  // Data for transition animation between settings view and message list.
  bool settings_visible_;
167 168 169

  // Animation managing transition between message center and settings (and vice
  // versa).
170
  std::unique_ptr<gfx::SlideAnimation> settings_transition_animation_;
171 172 173

  // Helper data to keep track of the transition between settings and
  // message center views.
174 175 176 177
  views::View* source_view_ = nullptr;
  int source_height_ = 0;
  views::View* target_view_ = nullptr;
  int target_height_ = 0;
178

179 180
  // True when the widget is closing so that further operations should be
  // ignored.
181
  bool is_closing_ = false;
182

183
  bool is_clearing_all_notifications_ = false;
184
  bool is_locked_;
185 186

  // Current view mode. During animation, it is the target mode.
187
  Mode mode_ = Mode::NO_NOTIFICATIONS;
188

189 190
  message_center::MessageViewContextMenuController context_menu_controller_{
      this};
191

192 193
  views::FocusManager* focus_manager_ = nullptr;

194 195
  ScopedSessionObserver session_observer_{this};

196 197 198
  DISALLOW_COPY_AND_ASSIGN(MessageCenterView);
};

199
}  // namespace ash
200

201
#endif  // ASH_MESSAGE_CENTER_MESSAGE_CENTER_VIEW_H_