OLD | NEW |
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; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 content_->SizeToPreferredSize(); | 72 content_->SizeToPreferredSize(); |
73 content_->InvalidateLayout(); | 73 content_->InvalidateLayout(); |
74 Layout(); | 74 Layout(); |
75 if (GetWidget()) | 75 if (GetWidget()) |
76 GetWidget()->GetRootView()->SchedulePaint(); | 76 GetWidget()->GetRootView()->SchedulePaint(); |
77 } | 77 } |
78 | 78 |
79 // The timer to call OnAutoClose for |notification|. | 79 // The timer to call OnAutoClose for |notification|. |
80 class MessagePopupBubble::AutocloseTimer { | 80 class MessagePopupBubble::AutocloseTimer { |
81 public: | 81 public: |
82 AutocloseTimer(const Notification& notification, MessagePopupBubble* bubble); | 82 AutocloseTimer(Notification* notification, MessagePopupBubble* bubble); |
83 | 83 |
84 void Start(); | 84 void Start(); |
85 | 85 |
86 void Suspend(); | 86 void Suspend(); |
87 | 87 |
88 private: | 88 private: |
89 const std::string id_; | 89 const std::string id_; |
90 base::TimeDelta delay_; | 90 base::TimeDelta delay_; |
91 base::Time start_time_; | 91 base::Time start_time_; |
92 MessagePopupBubble* bubble_; | 92 MessagePopupBubble* bubble_; |
93 base::OneShotTimer<MessagePopupBubble> timer_; | 93 base::OneShotTimer<MessagePopupBubble> timer_; |
94 | 94 |
95 DISALLOW_COPY_AND_ASSIGN(AutocloseTimer); | 95 DISALLOW_COPY_AND_ASSIGN(AutocloseTimer); |
96 }; | 96 }; |
97 | 97 |
98 MessagePopupBubble::AutocloseTimer::AutocloseTimer( | 98 MessagePopupBubble::AutocloseTimer::AutocloseTimer( |
99 const Notification& notification, | 99 Notification* notification, |
100 MessagePopupBubble* bubble) | 100 MessagePopupBubble* bubble) |
101 : id_(notification.id), | 101 : id_(notification->id()), |
102 bubble_(bubble) { | 102 bubble_(bubble) { |
103 int seconds = kAutocloseDefaultDelaySeconds; | 103 int seconds = kAutocloseDefaultDelaySeconds; |
104 if (notification.priority > ui::notifications::DEFAULT_PRIORITY) | 104 if (notification->priority() > DEFAULT_PRIORITY) |
105 seconds = kAutocloseHighPriorityDelaySeconds; | 105 seconds = kAutocloseHighPriorityDelaySeconds; |
106 delay_ = base::TimeDelta::FromSeconds(seconds); | 106 delay_ = base::TimeDelta::FromSeconds(seconds); |
107 } | 107 } |
108 | 108 |
109 void MessagePopupBubble::AutocloseTimer::Start() { | 109 void MessagePopupBubble::AutocloseTimer::Start() { |
110 start_time_ = base::Time::Now(); | 110 start_time_ = base::Time::Now(); |
111 timer_.Start(FROM_HERE, | 111 timer_.Start(FROM_HERE, |
112 delay_, | 112 delay_, |
113 base::Bind(&MessagePopupBubble::OnAutoClose, | 113 base::Bind(&MessagePopupBubble::OnAutoClose, |
114 base::Unretained(bubble_), id_)); | 114 base::Unretained(bubble_), id_)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 contents_view_ = new PopupBubbleContentsView(list_delegate()); | 146 contents_view_ = new PopupBubbleContentsView(list_delegate()); |
147 bubble_view()->AddChildView(contents_view_); | 147 bubble_view()->AddChildView(contents_view_); |
148 UpdateBubbleView(); | 148 UpdateBubbleView(); |
149 } | 149 } |
150 | 150 |
151 void MessagePopupBubble::OnBubbleViewDestroyed() { | 151 void MessagePopupBubble::OnBubbleViewDestroyed() { |
152 contents_view_ = NULL; | 152 contents_view_ = NULL; |
153 } | 153 } |
154 | 154 |
155 void MessagePopupBubble::UpdateBubbleView() { | 155 void MessagePopupBubble::UpdateBubbleView() { |
156 NotificationList::Notifications popups; | 156 NotificationList::Notifications popups = |
157 list_delegate()->GetNotificationList()->GetPopupNotifications(&popups); | 157 list_delegate()->GetNotificationList()->GetPopupNotifications(); |
158 | 158 |
159 if (popups.size() == 0) { | 159 if (popups.size() == 0) { |
160 if (bubble_view()) | 160 if (bubble_view()) |
161 bubble_view()->delegate()->HideBubble(bubble_view()); // deletes |this| | 161 bubble_view()->delegate()->HideBubble(bubble_view()); // deletes |this| |
162 return; | 162 return; |
163 } | 163 } |
164 | 164 |
165 contents_view_->Update(popups); | 165 contents_view_->Update(popups); |
166 bubble_view()->Show(); | 166 bubble_view()->Show(); |
167 bubble_view()->UpdateBubble(); | 167 bubble_view()->UpdateBubble(); |
168 | 168 |
169 std::set<std::string> old_popup_ids; | 169 std::set<std::string> old_popup_ids; |
170 old_popup_ids.swap(popup_ids_); | 170 old_popup_ids.swap(popup_ids_); |
171 | 171 |
172 // Start autoclose timers. | 172 // Start autoclose timers. |
173 for (NotificationList::Notifications::const_iterator iter = popups.begin(); | 173 for (NotificationList::Notifications::const_iterator iter = 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 Loading... |
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 |
OLD | NEW |