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; |
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 Loading... |
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_); |
69 view->SetUpView(); | 69 view->SetUpView(); |
70 content_->AddChildView(view); | 70 content_->AddChildView(view); |
71 } | 71 } |
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::PopupNotifications 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::PopupNotifications::const_iterator iter = |
| 174 popups.begin(); |
174 iter != popups.end(); ++iter) { | 175 iter != popups.end(); ++iter) { |
| 176 std::string id = (*iter)->id(); |
175 std::map<std::string, AutocloseTimer*>::const_iterator timer_iter = | 177 std::map<std::string, AutocloseTimer*>::const_iterator timer_iter = |
176 autoclose_timers_.find(iter->id); | 178 autoclose_timers_.find(id); |
177 if (timer_iter == autoclose_timers_.end()) { | 179 if (timer_iter == autoclose_timers_.end()) { |
178 AutocloseTimer *timer = new AutocloseTimer(*iter, this); | 180 AutocloseTimer *timer = new AutocloseTimer(*iter, this); |
179 autoclose_timers_[iter->id] = timer; | 181 autoclose_timers_[id] = timer; |
180 timer->Start(); | 182 timer->Start(); |
181 } | 183 } |
182 popup_ids_.insert(iter->id); | 184 popup_ids_.insert(id); |
183 old_popup_ids.erase(iter->id); | 185 old_popup_ids.erase(id); |
184 } | 186 } |
185 | 187 |
186 // Stops timers whose notifications are gone. | 188 // Stops timers whose notifications are gone. |
187 for (std::set<std::string>::const_iterator iter = old_popup_ids.begin(); | 189 for (std::set<std::string>::const_iterator iter = old_popup_ids.begin(); |
188 iter != old_popup_ids.end(); ++iter) { | 190 iter != old_popup_ids.end(); ++iter) { |
189 DeleteTimer(*iter); | 191 DeleteTimer(*iter); |
190 } | 192 } |
191 } | 193 } |
192 | 194 |
193 void MessagePopupBubble::OnMouseEnteredView() { | 195 void MessagePopupBubble::OnMouseEnteredView() { |
(...skipping 23 matching lines...) Expand all Loading... |
217 scoped_ptr<AutocloseTimer> release_timer(iter->second); | 219 scoped_ptr<AutocloseTimer> release_timer(iter->second); |
218 autoclose_timers_.erase(iter); | 220 autoclose_timers_.erase(iter); |
219 } | 221 } |
220 } | 222 } |
221 | 223 |
222 size_t MessagePopupBubble::NumMessageViewsForTest() const { | 224 size_t MessagePopupBubble::NumMessageViewsForTest() const { |
223 return contents_view_->NumMessageViews(); | 225 return contents_view_->NumMessageViews(); |
224 } | 226 } |
225 | 227 |
226 } // namespace message_center | 228 } // namespace message_center |
OLD | NEW |