1 // Copyright (c) 2015 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.
5 #ifndef UI_MESSAGE_CENTER_VIEWS_MESSAGE_LIST_VIEW_H_
6 #define UI_MESSAGE_CENTER_VIEWS_MESSAGE_LIST_VIEW_H_
11 #include "ui/compositor/paint_context.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/geometry/size.h"
14 #include "ui/message_center/notification.h"
15 #include "ui/views/animation/bounds_animator.h"
16 #include "ui/views/animation/bounds_animator_observer.h"
17 #include "ui/views/view.h"
27 namespace message_center
{
29 class MessageCenterView
;
32 // Displays a list of messages for rich notifications. Functions as an array of
33 // MessageViews and animates them on transitions. It also supports
35 class MessageListView
: public views::View
,
36 public views::BoundsAnimatorObserver
{
38 explicit MessageListView(MessageCenterView
* message_center_view
,
40 ~MessageListView() override
;
42 void AddNotificationAt(MessageView
* view
, int i
);
43 void RemoveNotification(MessageView
* view
);
44 void UpdateNotification(MessageView
* view
, const Notification
& notification
);
45 void SetRepositionTarget(const gfx::Rect
& target_rect
);
46 void ResetRepositionSession();
47 void ClearAllNotifications(const gfx::Rect
& visible_scroll_rect
);
50 // Overridden from views::View.
51 void Layout() override
;
52 gfx::Size
GetPreferredSize() const override
;
53 int GetHeightForWidth(int width
) const override
;
54 void PaintChildren(const ui::PaintContext
& context
) override
;
55 void ReorderChildLayers(ui::Layer
* parent_layer
) override
;
57 // Overridden from views::BoundsAnimatorObserver.
58 void OnBoundsAnimatorProgressed(views::BoundsAnimator
* animator
) override
;
59 void OnBoundsAnimatorDone(views::BoundsAnimator
* animator
) override
;
62 bool IsValidChild(const views::View
* child
) const;
63 void DoUpdateIfPossible();
65 // Animates all notifications below target upwards to align with the top of
66 // the last closed notification.
67 void AnimateNotificationsBelowTarget();
68 // Animates all notifications above target downwards to align with the top of
69 // the last closed notification.
70 void AnimateNotificationsAboveTarget();
72 // Schedules animation for a child to the specified position. Returns false
73 // if |child| will disappear after the animation.
74 bool AnimateChild(views::View
* child
, int top
, int height
);
76 // Animate clearing one notification.
77 void AnimateClearingOneNotification();
78 MessageCenterView
* message_center_view() const {
79 return message_center_view_
;
82 MessageCenterView
* message_center_view_
; // Weak reference.
83 // The top position of the reposition target rectangle.
86 bool has_deferred_task_
;
87 bool clear_all_started_
;
89 std::set
<views::View
*> adding_views_
;
90 std::set
<views::View
*> deleting_views_
;
91 std::set
<views::View
*> deleted_when_done_
;
92 std::list
<views::View
*> clearing_all_views_
;
93 views::BoundsAnimator animator_
;
94 base::WeakPtrFactory
<MessageListView
> weak_ptr_factory_
;
96 DISALLOW_COPY_AND_ASSIGN(MessageListView
);
99 } // namespace message_center
100 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_LIST_VIEW_H_