OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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_POPUP_COLLECTION_H_ | 5 #ifndef UI_MESSAGE_CENTER_VIEWS_MESSAGE_POPUP_COLLECTION_H_ |
6 #define UI_MESSAGE_CENTER_VIEWS_MESSAGE_POPUP_COLLECTION_H_ | 6 #define UI_MESSAGE_CENTER_VIEWS_MESSAGE_POPUP_COLLECTION_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
11 #include <map> | 11 #include <map> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
17 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
18 #include "ui/gfx/native_widget_types.h" | |
19 #include "ui/message_center/message_center_export.h" | 18 #include "ui/message_center/message_center_export.h" |
20 #include "ui/message_center/message_center_observer.h" | 19 #include "ui/message_center/message_center_observer.h" |
21 #include "ui/message_center/views/message_center_controller.h" | 20 #include "ui/message_center/views/message_center_controller.h" |
22 #include "ui/message_center/views/toast_contents_view.h" | 21 #include "ui/message_center/views/toast_contents_view.h" |
23 #include "ui/views/widget/widget_observer.h" | 22 #include "ui/views/widget/widget_observer.h" |
24 | 23 |
25 namespace base { | 24 namespace base { |
26 class RunLoop; | 25 class RunLoop; |
27 } | 26 } |
28 | 27 |
(...skipping 17 matching lines...) Expand all Loading... |
46 | 45 |
47 // Container for popup toasts. Because each toast is a frameless window rather | 46 // Container for popup toasts. Because each toast is a frameless window rather |
48 // than a view in a bubble, now the container just manages all of those toasts. | 47 // than a view in a bubble, now the container just manages all of those toasts. |
49 // This is similar to chrome/browser/notifications/balloon_collection, but the | 48 // This is similar to chrome/browser/notifications/balloon_collection, but the |
50 // contents of each toast are for the message center and layout strategy would | 49 // contents of each toast are for the message center and layout strategy would |
51 // be slightly different. | 50 // be slightly different. |
52 class MESSAGE_CENTER_EXPORT MessagePopupCollection | 51 class MESSAGE_CENTER_EXPORT MessagePopupCollection |
53 : public MessageCenterController, | 52 : public MessageCenterController, |
54 public MessageCenterObserver { | 53 public MessageCenterObserver { |
55 public: | 54 public: |
56 // |parent| specifies the parent widget of the toast windows. The default | 55 MessagePopupCollection(MessageCenter* message_center, |
57 // parent will be used for NULL. Usually each icon is spacing against its | |
58 // predecessor. | |
59 MessagePopupCollection(gfx::NativeView parent, | |
60 MessageCenter* message_center, | |
61 MessageCenterTray* tray, | 56 MessageCenterTray* tray, |
62 PopupAlignmentDelegate* alignment_delegate); | 57 PopupAlignmentDelegate* alignment_delegate); |
63 ~MessagePopupCollection() override; | 58 ~MessagePopupCollection() override; |
64 | 59 |
65 // Overridden from MessageCenterController: | 60 // Overridden from MessageCenterController: |
66 void ClickOnNotification(const std::string& notification_id) override; | 61 void ClickOnNotification(const std::string& notification_id) override; |
67 void RemoveNotification(const std::string& notification_id, | 62 void RemoveNotification(const std::string& notification_id, |
68 bool by_user) override; | 63 bool by_user) override; |
69 std::unique_ptr<ui::MenuModel> CreateMenuModel( | 64 std::unique_ptr<ui::MenuModel> CreateMenuModel( |
70 const NotifierId& notifier_id, | 65 const NotifierId& notifier_id, |
(...skipping 22 matching lines...) Expand all Loading... |
93 // zero. Otherwise, simply waits when it becomes zero. | 88 // zero. Otherwise, simply waits when it becomes zero. |
94 void DoUpdateIfPossible(); | 89 void DoUpdateIfPossible(); |
95 | 90 |
96 // Removes the toast from our internal list of toasts; this is called when the | 91 // Removes the toast from our internal list of toasts; this is called when the |
97 // toast is irrevocably closed (such as within RemoveToast). | 92 // toast is irrevocably closed (such as within RemoveToast). |
98 void ForgetToast(ToastContentsView* toast); | 93 void ForgetToast(ToastContentsView* toast); |
99 | 94 |
100 // Called when the display bounds has been changed. Used in Windows only. | 95 // Called when the display bounds has been changed. Used in Windows only. |
101 void OnDisplayMetricsChanged(const display::Display& display); | 96 void OnDisplayMetricsChanged(const display::Display& display); |
102 | 97 |
103 // Used by ToastContentsView to locate itself. | |
104 gfx::NativeView parent() const { return parent_; } | |
105 | |
106 private: | 98 private: |
107 friend class test::MessagePopupCollectionTest; | 99 friend class test::MessagePopupCollectionTest; |
108 typedef std::list<ToastContentsView*> Toasts; | 100 typedef std::list<ToastContentsView*> Toasts; |
109 | 101 |
110 // Iterates toasts and starts closing them. | 102 // Iterates toasts and starts closing them. |
111 std::set<std::string> CloseAllWidgets(); | 103 std::set<std::string> CloseAllWidgets(); |
112 | 104 |
113 // Called by ToastContentsView when its window is closed. | 105 // Called by ToastContentsView when its window is closed. |
114 void RemoveToast(ToastContentsView* toast, bool mark_as_shown); | 106 void RemoveToast(ToastContentsView* toast, bool mark_as_shown); |
115 | 107 |
(...skipping 26 matching lines...) Expand all Loading... |
142 // done. This method is run when defer counter is zero, may initiate next | 134 // done. This method is run when defer counter is zero, may initiate next |
143 // update/animation step. | 135 // update/animation step. |
144 void OnDeferTimerExpired(); | 136 void OnDeferTimerExpired(); |
145 | 137 |
146 // "ForTest" methods. | 138 // "ForTest" methods. |
147 views::Widget* GetWidgetForTest(const std::string& id) const; | 139 views::Widget* GetWidgetForTest(const std::string& id) const; |
148 void CreateRunLoopForTest(); | 140 void CreateRunLoopForTest(); |
149 void WaitForTest(); | 141 void WaitForTest(); |
150 gfx::Rect GetToastRectAt(size_t index) const; | 142 gfx::Rect GetToastRectAt(size_t index) const; |
151 | 143 |
152 gfx::NativeView parent_; | |
153 MessageCenter* message_center_; | 144 MessageCenter* message_center_; |
154 MessageCenterTray* tray_; | 145 MessageCenterTray* tray_; |
155 Toasts toasts_; | 146 Toasts toasts_; |
156 | 147 |
157 PopupAlignmentDelegate* alignment_delegate_; | 148 PopupAlignmentDelegate* alignment_delegate_; |
158 | 149 |
159 int defer_counter_; | 150 int defer_counter_; |
160 | 151 |
161 // This is only used to compare with incoming events, do not assume that | 152 // This is only used to compare with incoming events, do not assume that |
162 // the toast will be valid if this pointer is non-NULL. | 153 // the toast will be valid if this pointer is non-NULL. |
(...skipping 18 matching lines...) Expand all Loading... |
181 // Gives out weak pointers to toast contents views which have an unrelated | 172 // Gives out weak pointers to toast contents views which have an unrelated |
182 // lifetime. Must remain the last member variable. | 173 // lifetime. Must remain the last member variable. |
183 base::WeakPtrFactory<MessagePopupCollection> weak_factory_; | 174 base::WeakPtrFactory<MessagePopupCollection> weak_factory_; |
184 | 175 |
185 DISALLOW_COPY_AND_ASSIGN(MessagePopupCollection); | 176 DISALLOW_COPY_AND_ASSIGN(MessagePopupCollection); |
186 }; | 177 }; |
187 | 178 |
188 } // namespace message_center | 179 } // namespace message_center |
189 | 180 |
190 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_POPUP_COLLECTION_H_ | 181 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_POPUP_COLLECTION_H_ |
OLD | NEW |