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

Side by Side Diff: ui/message_center/message_popup_bubble.cc

Issue 12277024: Notificaitons refactor step 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: steven's feedback 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/message_popup_bubble.h" 5 #include "ui/message_center/message_popup_bubble.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "ui/message_center/message_view.h" 9 #include "ui/message_center/message_view.h"
10 #include "ui/message_center/notification.h" 10 #include "ui/message_center/notification.h"
11 #include "ui/message_center/notification_types.h"
11 #include "ui/message_center/notification_view.h" 12 #include "ui/message_center/notification_view.h"
12 #include "ui/notifications/notification_types.h"
13 #include "ui/views/bubble/tray_bubble_view.h" 13 #include "ui/views/bubble/tray_bubble_view.h"
14 #include "ui/views/layout/box_layout.h" 14 #include "ui/views/layout/box_layout.h"
15 #include "ui/views/view.h" 15 #include "ui/views/view.h"
16 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
17 17
18 namespace message_center { 18 namespace message_center {
19 namespace { 19 namespace {
20 20
21 const int kAutocloseHighPriorityDelaySeconds = 25; 21 const int kAutocloseHighPriorityDelaySeconds = 25;
22 const int kAutocloseDefaultDelaySeconds = 8; 22 const int kAutocloseDefaultDelaySeconds = 8;
23 23
24 } // namespace 24 } // namespace
25 25
26 // Popup notifications contents. 26 // Popup notifications contents.
27 class PopupBubbleContentsView : public views::View { 27 class PopupBubbleContentsView : public views::View {
28 public: 28 public:
29 explicit PopupBubbleContentsView(NotificationList::Delegate* list_delegate); 29 explicit PopupBubbleContentsView(NotificationList::Delegate* list_delegate);
30 30
31 void Update(const NotificationList::Notifications& popup_notifications); 31 void Update(const NotificationList::PopupNotifications& popup_notifications);
32 32
33 size_t NumMessageViews() const { 33 size_t NumMessageViews() const {
34 return content_->child_count(); 34 return content_->child_count();
35 } 35 }
36 36
37 private: 37 private:
38 NotificationList::Delegate* list_delegate_; 38 NotificationList::Delegate* list_delegate_;
39 views::View* content_; 39 views::View* content_;
40 40
41 DISALLOW_COPY_AND_ASSIGN(PopupBubbleContentsView); 41 DISALLOW_COPY_AND_ASSIGN(PopupBubbleContentsView);
(...skipping 10 matching lines...) Expand all
52 AddChildView(content_); 52 AddChildView(content_);
53 53
54 if (get_use_acceleration_when_possible()) { 54 if (get_use_acceleration_when_possible()) {
55 content_->SetPaintToLayer(true); 55 content_->SetPaintToLayer(true);
56 content_->SetFillsBoundsOpaquely(false); 56 content_->SetFillsBoundsOpaquely(false);
57 content_->layer()->SetMasksToBounds(true); 57 content_->layer()->SetMasksToBounds(true);
58 } 58 }
59 } 59 }
60 60
61 void PopupBubbleContentsView::Update( 61 void PopupBubbleContentsView::Update(
62 const NotificationList::Notifications& popup_notifications) { 62 const NotificationList::PopupNotifications& popup_notifications) {
63 content_->RemoveAllChildViews(true); 63 content_->RemoveAllChildViews(true);
64 for (NotificationList::Notifications::const_iterator iter = 64 for (NotificationList::PopupNotifications::const_iterator iter =
65 popup_notifications.begin(); 65 popup_notifications.begin();
66 iter != popup_notifications.end(); ++iter) { 66 iter != popup_notifications.end(); ++iter) {
67 MessageView* view = 67 MessageView* view =
68 NotificationView::ViewForNotification(*iter, list_delegate_); 68 NotificationView::ViewForNotification(*(*iter), list_delegate_);
stevenjb 2013/02/25 23:55:56 NULL view?
Dmitry Titov 2013/02/26 01:01:51 Never returns NULL, always creates. Will rename in
69 view->SetUpView();
70 content_->AddChildView(view); 69 content_->AddChildView(view);
71 } 70 }
72 content_->SizeToPreferredSize(); 71 content_->SizeToPreferredSize();
73 content_->InvalidateLayout(); 72 content_->InvalidateLayout();
74 Layout(); 73 Layout();
75 if (GetWidget()) 74 if (GetWidget())
76 GetWidget()->GetRootView()->SchedulePaint(); 75 GetWidget()->GetRootView()->SchedulePaint();
77 } 76 }
78 77
79 // The timer to call OnAutoClose for |notification|. 78 // The timer to call OnAutoClose for |notification|.
80 class MessagePopupBubble::AutocloseTimer { 79 class MessagePopupBubble::AutocloseTimer {
81 public: 80 public:
82 AutocloseTimer(const Notification& notification, MessagePopupBubble* bubble); 81 AutocloseTimer(Notification* notification, MessagePopupBubble* bubble);
83 82
84 void Start(); 83 void Start();
85 84
86 void Suspend(); 85 void Suspend();
87 86
88 private: 87 private:
89 const std::string id_; 88 const std::string id_;
90 base::TimeDelta delay_; 89 base::TimeDelta delay_;
91 base::Time start_time_; 90 base::Time start_time_;
92 MessagePopupBubble* bubble_; 91 MessagePopupBubble* bubble_;
93 base::OneShotTimer<MessagePopupBubble> timer_; 92 base::OneShotTimer<MessagePopupBubble> timer_;
94 93
95 DISALLOW_COPY_AND_ASSIGN(AutocloseTimer); 94 DISALLOW_COPY_AND_ASSIGN(AutocloseTimer);
96 }; 95 };
97 96
98 MessagePopupBubble::AutocloseTimer::AutocloseTimer( 97 MessagePopupBubble::AutocloseTimer::AutocloseTimer(
99 const Notification& notification, 98 Notification* notification,
100 MessagePopupBubble* bubble) 99 MessagePopupBubble* bubble)
101 : id_(notification.id), 100 : id_(notification->id()),
102 bubble_(bubble) { 101 bubble_(bubble) {
103 int seconds = kAutocloseDefaultDelaySeconds; 102 int seconds = kAutocloseDefaultDelaySeconds;
104 if (notification.priority > ui::notifications::DEFAULT_PRIORITY) 103 if (notification->priority() > DEFAULT_PRIORITY)
105 seconds = kAutocloseHighPriorityDelaySeconds; 104 seconds = kAutocloseHighPriorityDelaySeconds;
106 delay_ = base::TimeDelta::FromSeconds(seconds); 105 delay_ = base::TimeDelta::FromSeconds(seconds);
107 } 106 }
108 107
109 void MessagePopupBubble::AutocloseTimer::Start() { 108 void MessagePopupBubble::AutocloseTimer::Start() {
110 start_time_ = base::Time::Now(); 109 start_time_ = base::Time::Now();
111 timer_.Start(FROM_HERE, 110 timer_.Start(FROM_HERE,
112 delay_, 111 delay_,
113 base::Bind(&MessagePopupBubble::OnAutoClose, 112 base::Bind(&MessagePopupBubble::OnAutoClose,
114 base::Unretained(bubble_), id_)); 113 base::Unretained(bubble_), id_));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 contents_view_ = new PopupBubbleContentsView(list_delegate()); 145 contents_view_ = new PopupBubbleContentsView(list_delegate());
147 bubble_view()->AddChildView(contents_view_); 146 bubble_view()->AddChildView(contents_view_);
148 UpdateBubbleView(); 147 UpdateBubbleView();
149 } 148 }
150 149
151 void MessagePopupBubble::OnBubbleViewDestroyed() { 150 void MessagePopupBubble::OnBubbleViewDestroyed() {
152 contents_view_ = NULL; 151 contents_view_ = NULL;
153 } 152 }
154 153
155 void MessagePopupBubble::UpdateBubbleView() { 154 void MessagePopupBubble::UpdateBubbleView() {
156 NotificationList::Notifications popups; 155 NotificationList::PopupNotifications popups =
157 list_delegate()->GetNotificationList()->GetPopupNotifications(&popups); 156 list_delegate()->GetNotificationList()->GetPopupNotifications();
158 157
159 if (popups.size() == 0) { 158 if (popups.size() == 0) {
160 if (bubble_view()) 159 if (bubble_view())
161 bubble_view()->delegate()->HideBubble(bubble_view()); // deletes |this| 160 bubble_view()->delegate()->HideBubble(bubble_view()); // deletes |this|
162 return; 161 return;
163 } 162 }
164 163
165 contents_view_->Update(popups); 164 contents_view_->Update(popups);
166 bubble_view()->Show(); 165 bubble_view()->Show();
167 bubble_view()->UpdateBubble(); 166 bubble_view()->UpdateBubble();
168 167
169 std::set<std::string> old_popup_ids; 168 std::set<std::string> old_popup_ids;
170 old_popup_ids.swap(popup_ids_); 169 old_popup_ids.swap(popup_ids_);
171 170
172 // Start autoclose timers. 171 // Start autoclose timers.
173 for (NotificationList::Notifications::const_iterator iter = popups.begin(); 172 for (NotificationList::PopupNotifications::const_iterator iter =
173 popups.begin();
174 iter != popups.end(); ++iter) { 174 iter != popups.end(); ++iter) {
175 std::string id = (*iter)->id();
175 std::map<std::string, AutocloseTimer*>::const_iterator timer_iter = 176 std::map<std::string, AutocloseTimer*>::const_iterator timer_iter =
176 autoclose_timers_.find(iter->id); 177 autoclose_timers_.find(id);
177 if (timer_iter == autoclose_timers_.end()) { 178 if (timer_iter == autoclose_timers_.end()) {
178 AutocloseTimer *timer = new AutocloseTimer(*iter, this); 179 AutocloseTimer *timer = new AutocloseTimer(*iter, this);
179 autoclose_timers_[iter->id] = timer; 180 autoclose_timers_[id] = timer;
180 timer->Start(); 181 timer->Start();
181 } 182 }
182 popup_ids_.insert(iter->id); 183 popup_ids_.insert(id);
183 old_popup_ids.erase(iter->id); 184 old_popup_ids.erase(id);
184 } 185 }
185 186
186 // Stops timers whose notifications are gone. 187 // Stops timers whose notifications are gone.
187 for (std::set<std::string>::const_iterator iter = old_popup_ids.begin(); 188 for (std::set<std::string>::const_iterator iter = old_popup_ids.begin();
188 iter != old_popup_ids.end(); ++iter) { 189 iter != old_popup_ids.end(); ++iter) {
189 DeleteTimer(*iter); 190 DeleteTimer(*iter);
190 } 191 }
191 } 192 }
192 193
193 void MessagePopupBubble::OnMouseEnteredView() { 194 void MessagePopupBubble::OnMouseEnteredView() {
(...skipping 23 matching lines...) Expand all
217 scoped_ptr<AutocloseTimer> release_timer(iter->second); 218 scoped_ptr<AutocloseTimer> release_timer(iter->second);
218 autoclose_timers_.erase(iter); 219 autoclose_timers_.erase(iter);
219 } 220 }
220 } 221 }
221 222
222 size_t MessagePopupBubble::NumMessageViewsForTest() const { 223 size_t MessagePopupBubble::NumMessageViewsForTest() const {
223 return contents_view_->NumMessageViews(); 224 return contents_view_->NumMessageViews();
224 } 225 }
225 226
226 } // namespace message_center 227 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698