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

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

Issue 14139014: Reposition toasts to align the closed one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 8 months 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 | Annotate | Revision Log
OLDNEW
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 <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "ui/gfx/native_widget_types.h" 14 #include "ui/gfx/native_widget_types.h"
15 #include "ui/gfx/rect.h"
15 #include "ui/message_center/message_center_export.h" 16 #include "ui/message_center/message_center_export.h"
17 #include "ui/message_center/message_center_observer.h"
16 #include "ui/views/widget/widget_observer.h" 18 #include "ui/views/widget/widget_observer.h"
17 19
18 namespace views { 20 namespace views {
19 class Widget; 21 class Widget;
20 } 22 }
21 23
22 namespace ash { 24 namespace ash {
23 FORWARD_DECLARE_TEST(WebNotificationTrayTest, ManyPopupNotifications); 25 FORWARD_DECLARE_TEST(WebNotificationTrayTest, ManyPopupNotifications);
24 } 26 }
25 27
26 namespace message_center { 28 namespace message_center {
29 namespace test {
30 class MessagePopupCollectionTest;
31 }
27 32
28 class MessageCenter; 33 class MessageCenter;
29 class ToastContentsView; 34 class ToastContentsView;
30 35
31 // Container for popup toasts. Because each toast is a frameless window rather 36 // Container for popup toasts. Because each toast is a frameless window rather
32 // than a view in a bubble, now the container just manages all of those windows. 37 // than a view in a bubble, now the container just manages all of those windows.
33 // This is similar to chrome/browser/notifications/balloon_collection, but the 38 // This is similar to chrome/browser/notifications/balloon_collection, but the
34 // contents of each toast are for the message center and layout strategy would 39 // contents of each toast are for the message center and layout strategy would
35 // be slightly different. 40 // be slightly different.
36 class MESSAGE_CENTER_EXPORT MessagePopupCollection 41 class MESSAGE_CENTER_EXPORT MessagePopupCollection
37 : public views::WidgetObserver, 42 : public MessageCenterObserver,
38 public base::SupportsWeakPtr<MessagePopupCollection> { 43 public base::SupportsWeakPtr<MessagePopupCollection> {
39 public: 44 public:
40 // |parent| specifies the parent widget of the toast windows. The default 45 // |parent| specifies the parent widget of the toast windows. The default
41 // parent will be used for NULL. 46 // parent will be used for NULL.
42 MessagePopupCollection(gfx::NativeView parent, 47 MessagePopupCollection(gfx::NativeView parent,
43 MessageCenter* message_center); 48 MessageCenter* message_center);
44 virtual ~MessagePopupCollection(); 49 virtual ~MessagePopupCollection();
45 50
46 void UpdatePopups();
47
48 void OnMouseEntered(); 51 void OnMouseEntered();
49 void OnMouseExited(); 52 void OnMouseExited();
50 53
51 private: 54 private:
52 FRIEND_TEST_ALL_PREFIXES(ash::WebNotificationTrayTest, 55 FRIEND_TEST_ALL_PREFIXES(ash::WebNotificationTrayTest,
53 ManyPopupNotifications); 56 ManyPopupNotifications);
57 friend class test::MessagePopupCollectionTest;
54 typedef std::map<std::string, ToastContentsView*> ToastContainer; 58 typedef std::map<std::string, ToastContentsView*> ToastContainer;
55 59
56 void CloseAllWidgets(); 60 void CloseAllWidgets();
57 61
58 // Overridden from views::WidgetObserver: 62 // Returns the bottom-right position of the current work area.
59 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 63 gfx::Point GetWorkAreaBottomRight();
64
65 // Creates new widgets for new toast notifications, and updates |toasts_| and
66 // |widgets_| correctly.
67 void UpdateWidgets();
68
69 // Repositions all of the widgets based on the current work area.
70 void RepositionWidgets();
71
72 // Repositions widgets. |target_rrect| denotes the region of the notification
73 // recently removed, and this attempts to slide widgets so that the user can
74 // click close-button without mouse moves. See crbug.com/224089
75 void RepositionWidgetsWithTarget(const gfx::Rect& target_rect);
76
77 // Overridden from MessageCenterObserver:
78 virtual void OnNotificationAdded(const std::string& notification_id) OVERRIDE;
79 virtual void OnNotificationRemoved(const std::string& notification_id,
80 bool by_user) OVERRIDE;
81 virtual void OnNotificationUpdated(
82 const std::string& notification_id) OVERRIDE;
83
84 void SetWorkAreaForTest(const gfx::Rect& work_area);
60 85
61 gfx::NativeView parent_; 86 gfx::NativeView parent_;
62 MessageCenter* message_center_; 87 MessageCenter* message_center_;
63 ToastContainer toasts_; 88 ToastContainer toasts_;
89 std::list<views::Widget*> widgets_;
90 gfx::Rect work_area_;
64 91
65 DISALLOW_COPY_AND_ASSIGN(MessagePopupCollection); 92 DISALLOW_COPY_AND_ASSIGN(MessagePopupCollection);
66 }; 93 };
67 94
68 } // namespace message_center 95 } // namespace message_center
69 96
70 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_POPUP_COLLECTION_H_ 97 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_POPUP_COLLECTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698