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_observer.h"
16 #include "ui/views/view.h"
30 namespace message_center
{
32 class MessageCenterView
;
35 // Displays a list of messages for rich notifications. Functions as an array of
36 // MessageViews and animates them on transitions. It also supports
38 class MessageListView
: public views::View
,
39 public views::BoundsAnimatorObserver
{
41 explicit MessageListView(MessageCenterView
* message_center_view
,
43 ~MessageListView() override
;
45 void AddNotificationAt(MessageView
* view
, int i
);
46 void RemoveNotification(MessageView
* view
);
47 void UpdateNotification(MessageView
* view
, const Notification
& notification
);
48 void SetRepositionTarget(const gfx::Rect
& target_rect
);
49 void ResetRepositionSession();
50 void ClearAllNotifications(const gfx::Rect
& visible_scroll_rect
);
53 // Overridden from views::View.
54 void Layout() override
;
55 gfx::Size
GetPreferredSize() const override
;
56 int GetHeightForWidth(int width
) const override
;
57 void PaintChildren(const ui::PaintContext
& context
) override
;
58 void ReorderChildLayers(ui::Layer
* parent_layer
) override
;
60 // Overridden from views::BoundsAnimatorObserver.
61 void OnBoundsAnimatorProgressed(views::BoundsAnimator
* animator
) override
;
62 void OnBoundsAnimatorDone(views::BoundsAnimator
* animator
) override
;
65 bool IsValidChild(const views::View
* child
) const;
66 void DoUpdateIfPossible();
68 // Animates all notifications below target upwards to align with the top of
69 // the last closed notification.
70 void AnimateNotificationsBelowTarget();
71 // Animates all notifications above target downwards to align with the top of
72 // the last closed notification.
73 void AnimateNotificationsAboveTarget();
75 // Schedules animation for a child to the specified position. Returns false
76 // if |child| will disappear after the animation.
77 bool AnimateChild(views::View
* child
, int top
, int height
);
79 // Animate clearing one notification.
80 void AnimateClearingOneNotification();
81 MessageCenterView
* message_center_view() const {
82 return message_center_view_
;
85 MessageCenterView
* message_center_view_
; // Weak reference.
86 // The top position of the reposition target rectangle.
89 bool has_deferred_task_
;
90 bool clear_all_started_
;
92 std::set
<views::View
*> adding_views_
;
93 std::set
<views::View
*> deleting_views_
;
94 std::set
<views::View
*> deleted_when_done_
;
95 std::list
<views::View
*> clearing_all_views_
;
96 scoped_ptr
<views::BoundsAnimator
> animator_
;
97 base::WeakPtrFactory
<MessageListView
> weak_ptr_factory_
;
99 DISALLOW_COPY_AND_ASSIGN(MessageListView
);
102 } // namespace message_center
103 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_LIST_VIEW_H_