Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: ui/message_center/views/message_list_view.h

Issue 2554903003: Add unittest for MessageListView (Closed)
Patch Set: fixed the build failrue on win Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_MESSAGE_CENTER_VIEWS_MESSAGE_LIST_VIEW_H_ 5 #ifndef UI_MESSAGE_CENTER_VIEWS_MESSAGE_LIST_VIEW_H_
6 #define UI_MESSAGE_CENTER_VIEWS_MESSAGE_LIST_VIEW_H_ 6 #define UI_MESSAGE_CENTER_VIEWS_MESSAGE_LIST_VIEW_H_
7 7
8 #include <list> 8 #include <list>
9 #include <set> 9 #include <set>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "ui/compositor/paint_context.h" 12 #include "ui/compositor/paint_context.h"
13 #include "ui/gfx/geometry/rect.h" 13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/size.h" 14 #include "ui/gfx/geometry/size.h"
15 #include "ui/message_center/message_center_export.h" 15 #include "ui/message_center/message_center_export.h"
16 #include "ui/message_center/notification.h" 16 #include "ui/message_center/notification.h"
17 #include "ui/views/animation/bounds_animator.h" 17 #include "ui/views/animation/bounds_animator.h"
18 #include "ui/views/animation/bounds_animator_observer.h" 18 #include "ui/views/animation/bounds_animator_observer.h"
19 #include "ui/views/view.h" 19 #include "ui/views/view.h"
20 20
21 namespace ui { 21 namespace ui {
22 class Layer; 22 class Layer;
23 } 23 }
24 24
25 namespace message_center { 25 namespace message_center {
26 26
27 class MessageCenterView;
28 class MessageView; 27 class MessageView;
29 28
30 // Displays a list of messages for rich notifications. Functions as an array of 29 // Displays a list of messages for rich notifications. Functions as an array of
31 // MessageViews and animates them on transitions. It also supports 30 // MessageViews and animates them on transitions. It also supports
32 // repositioning. 31 // repositioning.
33 class MessageListView : public views::View, 32 class MESSAGE_CENTER_EXPORT MessageListView
34 public views::BoundsAnimatorObserver { 33 : public views::View,
34 public views::BoundsAnimatorObserver {
35 public: 35 public:
36 explicit MessageListView(MessageCenterView* message_center_view, 36 class Observer {
37 bool top_down); 37 public:
38 virtual void OnAllNotificationsCleared() = 0;
39 };
40
41 explicit MessageListView(bool top_down);
38 ~MessageListView() override; 42 ~MessageListView() override;
39 43
40 void AddNotificationAt(MessageView* view, int i); 44 void AddNotificationAt(MessageView* view, int i);
41 void RemoveNotification(MessageView* view); 45 void RemoveNotification(MessageView* view);
42 void UpdateNotification(MessageView* view, const Notification& notification); 46 void UpdateNotification(MessageView* view, const Notification& notification);
43 void SetRepositionTarget(const gfx::Rect& target_rect); 47 void SetRepositionTarget(const gfx::Rect& target_rect);
44 void ResetRepositionSession(); 48 void ResetRepositionSession();
45 void ClearAllClosableNotifications(const gfx::Rect& visible_scroll_rect); 49 void ClearAllClosableNotifications(const gfx::Rect& visible_scroll_rect);
46 50
47 MESSAGE_CENTER_EXPORT void SetRepositionTargetForTest( 51 void AddObserver(Observer* observer);
52 void RemoveObserver(Observer* observer);
53
54 void SetRepositionTargetForTest(
48 const gfx::Rect& target_rect); 55 const gfx::Rect& target_rect);
49 56
50 protected: 57 protected:
51 // Overridden from views::View. 58 // Overridden from views::View.
52 void Layout() override; 59 void Layout() override;
53 gfx::Size GetPreferredSize() const override; 60 gfx::Size GetPreferredSize() const override;
54 int GetHeightForWidth(int width) const override; 61 int GetHeightForWidth(int width) const override;
55 void PaintChildren(const ui::PaintContext& context) override; 62 void PaintChildren(const ui::PaintContext& context) override;
56 void ReorderChildLayers(ui::Layer* parent_layer) override; 63 void ReorderChildLayers(ui::Layer* parent_layer) override;
57 64
58 // Overridden from views::BoundsAnimatorObserver. 65 // Overridden from views::BoundsAnimatorObserver.
59 void OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) override; 66 void OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) override;
60 void OnBoundsAnimatorDone(views::BoundsAnimator* animator) override; 67 void OnBoundsAnimatorDone(views::BoundsAnimator* animator) override;
61 68
62 private: 69 private:
63 friend class MessageCenterViewTest; 70 friend class MessageCenterViewTest;
71 friend class MessageListViewTest;
64 72
65 bool IsValidChild(const views::View* child) const; 73 bool IsValidChild(const views::View* child) const;
66 void DoUpdateIfPossible(); 74 void DoUpdateIfPossible();
67 75
68 // Animates all notifications below target upwards to align with the top of 76 // Animates all notifications below target upwards to align with the top of
69 // the last closed notification. 77 // the last closed notification.
70 void AnimateNotificationsBelowTarget(); 78 void AnimateNotificationsBelowTarget();
71 // Animates all notifications above target downwards to align with the top of 79 // Animates all notifications above target downwards to align with the top of
72 // the last closed notification. 80 // the last closed notification.
73 void AnimateNotificationsAboveTarget(); 81 void AnimateNotificationsAboveTarget();
74 82
75 // Schedules animation for a child to the specified position. Returns false 83 // Schedules animation for a child to the specified position. Returns false
76 // if |child| will disappear after the animation. 84 // if |child| will disappear after the animation.
77 bool AnimateChild(views::View* child, 85 bool AnimateChild(views::View* child,
78 int top, 86 int top,
79 int height, 87 int height,
80 bool animate_even_on_move); 88 bool animate_even_on_move);
81 89
82 // Animate clearing one notification. 90 // Animate clearing one notification.
83 void AnimateClearingOneNotification(); 91 void AnimateClearingOneNotification();
84 MessageCenterView* message_center_view() const {
85 return message_center_view_;
86 }
87 92
88 MessageCenterView* message_center_view_; // Weak reference. 93 // List of MessageListView::Observer
94 base::ObserverList<Observer> observers_;
95
89 // The top position of the reposition target rectangle. 96 // The top position of the reposition target rectangle.
90 int reposition_top_; 97 int reposition_top_;
91 int fixed_height_; 98 int fixed_height_;
92 bool has_deferred_task_; 99 bool has_deferred_task_;
93 bool clear_all_started_; 100 bool clear_all_started_;
94 bool top_down_; 101 bool top_down_;
95 std::set<views::View*> adding_views_; 102 std::set<views::View*> adding_views_;
96 std::set<views::View*> deleting_views_; 103 std::set<views::View*> deleting_views_;
97 std::set<views::View*> deleted_when_done_; 104 std::set<views::View*> deleted_when_done_;
98 std::list<views::View*> clearing_all_views_; 105 std::list<views::View*> clearing_all_views_;
99 views::BoundsAnimator animator_; 106 views::BoundsAnimator animator_;
100 107
101 // If true, the message loop will be quitted after the animation finishes. 108 // If true, the message loop will be quitted after the animation finishes.
102 // This is just for tests and has no setter. 109 // This is just for tests and has no setter.
103 bool quit_message_loop_after_animation_for_test_; 110 bool quit_message_loop_after_animation_for_test_;
104 111
105 base::WeakPtrFactory<MessageListView> weak_ptr_factory_; 112 base::WeakPtrFactory<MessageListView> weak_ptr_factory_;
106 DISALLOW_COPY_AND_ASSIGN(MessageListView); 113 DISALLOW_COPY_AND_ASSIGN(MessageListView);
107 }; 114 };
108 115
109 } // namespace message_center 116 } // namespace message_center
117
110 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_LIST_VIEW_H_ 118 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_LIST_VIEW_H_
OLDNEW
« no previous file with comments | « ui/message_center/views/message_center_view.cc ('k') | ui/message_center/views/message_list_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698