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

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

Issue 12326091: Made notification center notifications collapsed and expandable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, rebase, and rebase again! Created 7 years, 9 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 #include "ui/message_center/views/message_popup_collection.h" 5 #include "ui/message_center/views/message_popup_collection.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/timer.h" 10 #include "base/timer.h"
11 #include "ui/gfx/screen.h" 11 #include "ui/gfx/screen.h"
12 #include "ui/message_center/message_center.h"
12 #include "ui/message_center/message_center_constants.h" 13 #include "ui/message_center/message_center_constants.h"
13 #include "ui/message_center/notification.h" 14 #include "ui/message_center/notification.h"
14 #include "ui/message_center/notification_list.h" 15 #include "ui/message_center/notification_list.h"
15 #include "ui/message_center/views/message_view.h" 16 #include "ui/message_center/views/message_view.h"
16 #include "ui/message_center/views/notification_view.h" 17 #include "ui/message_center/views/notification_view.h"
17 #include "ui/views/background.h" 18 #include "ui/views/background.h"
18 #include "ui/views/layout/fill_layout.h" 19 #include "ui/views/layout/fill_layout.h"
19 #include "ui/views/view.h" 20 #include "ui/views/view.h"
20 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
22 #include "ui/views/widget/widget_delegate.h"
21 23
22 namespace message_center { 24 namespace message_center {
23 25
24 class ToastContentsView : public views::WidgetDelegateView { 26 class ToastContentsView : public views::WidgetDelegateView {
25 public: 27 public:
26 ToastContentsView(const Notification* notification, 28 ToastContentsView(const Notification* notification,
27 MessagePopupCollection* collection) 29 MessagePopupCollection* collection)
28 : collection_(collection) { 30 : collection_(collection) {
29 DCHECK(collection_); 31 DCHECK(collection_);
30 32
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 80 }
79 81
80 void StartTimer() { 82 void StartTimer() {
81 start_time_ = base::Time::Now(); 83 start_time_ = base::Time::Now();
82 timer_.Start(FROM_HERE, 84 timer_.Start(FROM_HERE,
83 delay_, 85 delay_,
84 base::Bind(&views::Widget::Close, 86 base::Bind(&views::Widget::Close,
85 base::Unretained(GetWidget()))); 87 base::Unretained(GetWidget())));
86 } 88 }
87 89
88 // views::WidgetDelegate overrides: 90 // Overridden from views::WidgetDelegate:
89 virtual views::View* GetContentsView() OVERRIDE { 91 virtual views::View* GetContentsView() OVERRIDE {
90 return this; 92 return this;
91 } 93 }
92 94
93 virtual void WindowClosing() OVERRIDE { 95 virtual void WindowClosing() OVERRIDE {
94 if (timer_.IsRunning()) 96 if (timer_.IsRunning())
95 SuspendTimer(); 97 SuspendTimer();
96 } 98 }
97 99
98 virtual bool CanActivate() const OVERRIDE { 100 virtual bool CanActivate() const OVERRIDE {
99 return false; 101 return false;
100 } 102 }
101 103
102 // views::View overrides: 104 // Overridden from views::View:
103 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { 105 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE {
104 collection_->OnMouseEntered(); 106 collection_->OnMouseEntered();
105 } 107 }
106 108
107 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE { 109 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE {
108 collection_->OnMouseExited(); 110 collection_->OnMouseExited();
109 } 111 }
110 112
111 private: 113 private:
112 base::TimeDelta delay_; 114 base::TimeDelta delay_;
113 base::Time start_time_; 115 base::Time start_time_;
114 base::OneShotTimer<views::Widget> timer_; 116 base::OneShotTimer<views::Widget> timer_;
115 MessagePopupCollection* collection_; 117 MessagePopupCollection* collection_;
116 118
117 DISALLOW_COPY_AND_ASSIGN(ToastContentsView); 119 DISALLOW_COPY_AND_ASSIGN(ToastContentsView);
118 }; 120 };
119 121
120 MessagePopupCollection::MessagePopupCollection( 122 MessagePopupCollection::MessagePopupCollection(gfx::NativeView context,
121 gfx::NativeView context, 123 MessageCenter* message_center)
122 NotificationList::Delegate* list_delegate)
123 : context_(context), 124 : context_(context),
124 list_delegate_(list_delegate) { 125 message_center_(message_center) {
125 DCHECK(list_delegate_); 126 DCHECK(message_center_);
126 } 127 }
127 128
128 MessagePopupCollection::~MessagePopupCollection() { 129 MessagePopupCollection::~MessagePopupCollection() {
129 CloseAllWidgets(); 130 CloseAllWidgets();
130 } 131 }
131 132
132 void MessagePopupCollection::UpdatePopups() { 133 void MessagePopupCollection::UpdatePopups() {
133 NotificationList::PopupNotifications popups = 134 NotificationList::PopupNotifications popups =
134 list_delegate_->GetNotificationList()->GetPopupNotifications(); 135 message_center_->notification_list()->GetPopupNotifications();
135 136
136 if (popups.empty()) { 137 if (popups.empty()) {
137 CloseAllWidgets(); 138 CloseAllWidgets();
138 return; 139 return;
139 } 140 }
140 141
141 gfx::Screen* screen = gfx::Screen::GetScreenFor(context_); 142 gfx::Screen* screen = gfx::Screen::GetScreenFor(context_);
142 gfx::Rect work_area = screen->GetDisplayNearestWindow(context_).work_area(); 143 gfx::Rect work_area = screen->GetDisplayNearestWindow(context_).work_area();
143 144
144 std::set<std::string> old_toast_ids; 145 std::set<std::string> old_toast_ids;
145 for (ToastContainer::iterator iter = toasts_.begin(); iter != toasts_.end(); 146 for (ToastContainer::iterator iter = toasts_.begin(); iter != toasts_.end();
146 ++iter) { 147 ++iter) {
147 old_toast_ids.insert(iter->first); 148 old_toast_ids.insert(iter->first);
148 } 149 }
149 150
150 int total_height = 0; 151 int total_height = 0;
151 std::vector<views::Widget*> widgets; 152 std::vector<views::Widget*> widgets;
152 for (NotificationList::PopupNotifications::const_iterator iter = 153 for (NotificationList::PopupNotifications::const_iterator iter =
153 popups.begin(); iter != popups.end(); ++iter) { 154 popups.begin(); iter != popups.end(); ++iter) {
154 ToastContainer::iterator toast_iter = toasts_.find((*iter)->id()); 155 ToastContainer::iterator toast_iter = toasts_.find((*iter)->id());
155 views::Widget* widget = NULL; 156 views::Widget* widget = NULL;
156 MessageView* view = NotificationView::Create(*(*iter), list_delegate_); 157 // NotificationViews are expanded by default here because
158 // MessagePopupCollection hasn't been tested yet with changing subview
159 // sizes, and such changes could come if those subviews were initially
160 // collapsed and allowed to be expanded by users. TODO(dharcourt): Fix.
161 MessageView* view = NotificationView::Create(*(*iter), message_center_,
162 true);
157 if (toast_iter != toasts_.end()) { 163 if (toast_iter != toasts_.end()) {
158 widget = toast_iter->second->GetWidget(); 164 widget = toast_iter->second->GetWidget();
159 old_toast_ids.erase((*iter)->id()); 165 old_toast_ids.erase((*iter)->id());
160 // Need to replace the contents because |view| can be updated, like 166 // Need to replace the contents because |view| can be updated, like
161 // image loads. 167 // image loads.
162 toast_iter->second->SetContents(view); 168 toast_iter->second->SetContents(view);
163 } else { 169 } else {
164 ToastContentsView* toast = new ToastContentsView(*iter, this); 170 ToastContentsView* toast = new ToastContentsView(*iter, this);
165 toast->SetContents(view); 171 toast->SetContents(view);
166 widget = toast->CreateWidget(context_); 172 widget = toast->CreateWidget(context_);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 widget->Close(); 239 widget->Close();
234 } 240 }
235 toasts_.clear(); 241 toasts_.clear();
236 } 242 }
237 243
238 void MessagePopupCollection::OnWidgetDestroying(views::Widget* widget) { 244 void MessagePopupCollection::OnWidgetDestroying(views::Widget* widget) {
239 widget->RemoveObserver(this); 245 widget->RemoveObserver(this);
240 for (ToastContainer::iterator iter = toasts_.begin(); 246 for (ToastContainer::iterator iter = toasts_.begin();
241 iter != toasts_.end(); ++iter) { 247 iter != toasts_.end(); ++iter) {
242 if (iter->second->GetWidget() == widget) { 248 if (iter->second->GetWidget() == widget) {
243 list_delegate_->GetNotificationList()->MarkSinglePopupAsShown( 249 message_center_->notification_list()->MarkSinglePopupAsShown(
244 iter->first, false); 250 iter->first, false);
245 toasts_.erase(iter); 251 toasts_.erase(iter);
246 break; 252 break;
247 } 253 }
248 } 254 }
249 UpdatePopups(); 255 UpdatePopups();
250 } 256 }
251 257
252 } // namespace message_center 258 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/message_popup_collection.h ('k') | ui/message_center/views/message_simple_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698