Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: ash/system/web_notification/web_notification_tray.cc

Issue 11154022: Re-factor Ash Message Center code part 3/4 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits, fix clang error Created 8 years, 2 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 "ash/system/web_notification/web_notification_tray.h" 5 #include "ash/system/web_notification/web_notification_tray.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/status_area_widget.h" 8 #include "ash/system/status_area_widget.h"
9 #include "ash/system/tray/tray_bubble_view.h" 9 #include "ash/system/tray/tray_bubble_view.h"
10 #include "ash/system/tray/tray_bubble_wrapper.h"
10 #include "ash/system/tray/tray_constants.h" 11 #include "ash/system/tray/tray_constants.h"
11 #include "ash/system/tray/tray_views.h" 12 #include "ash/system/tray/tray_views.h"
12 #include "ash/system/web_notification/message_center_bubble.h" 13 #include "ash/system/web_notification/message_center_bubble.h"
13 #include "ash/system/web_notification/popup_bubble.h" 14 #include "ash/system/web_notification/popup_bubble.h"
14 #include "ash/system/web_notification/web_notification.h" 15 #include "ash/system/web_notification/web_notification.h"
15 #include "ash/system/web_notification/web_notification_bubble.h" 16 #include "ash/system/web_notification/web_notification_bubble.h"
16 #include "ash/system/web_notification/web_notification_list.h" 17 #include "ash/system/web_notification/web_notification_list.h"
17 #include "ash/system/web_notification/web_notification_view.h"
18 #include "ash/wm/shelf_layout_manager.h" 18 #include "ash/wm/shelf_layout_manager.h"
19 #include "base/message_loop.h" 19 #include "base/message_loop.h"
20 #include "base/stringprintf.h" 20 #include "base/stringprintf.h"
21 #include "grit/ash_resources.h" 21 #include "grit/ash_resources.h"
22 #include "grit/ash_strings.h" 22 #include "grit/ash_strings.h"
23 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
26 #include "ui/views/widget/widget_observer.h" 26 #include "ui/views/widget/widget_observer.h"
27 27
28 namespace { 28 namespace {
29 29
30 // Tray constants 30 // Tray constants
31 const int kTrayContainerVerticalPaddingBottomAlignment = 3; 31 const int kTrayContainerVerticalPaddingBottomAlignment = 3;
32 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; 32 const int kTrayContainerHorizontalPaddingBottomAlignment = 1;
33 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; 33 const int kTrayContainerVerticalPaddingVerticalAlignment = 1;
34 const int kTrayContainerHorizontalPaddingVerticalAlignment = 0; 34 const int kTrayContainerHorizontalPaddingVerticalAlignment = 0;
35 const int kPaddingFromLeftEdgeOfSystemTrayBottomAlignment = 8; 35 const int kPaddingFromLeftEdgeOfSystemTrayBottomAlignment = 8;
36 const int kPaddingFromTopEdgeOfSystemTrayVerticalAlignment = 10; 36 const int kPaddingFromTopEdgeOfSystemTrayVerticalAlignment = 10;
37 37
38 std::string GetNotificationText(int notification_count) { 38 std::string GetNotificationText(int notification_count) {
39 if (notification_count >= 100) 39 if (notification_count >= 100)
40 return "99+"; 40 return "99+";
41 return base::StringPrintf("%d", notification_count); 41 return base::StringPrintf("%d", notification_count);
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 namespace ash {
47
48 // WebNotificationTray statics (for unit tests)
49
50 // Limit the number of visible notifications.
51 const size_t WebNotificationTray::kMaxVisibleTrayNotifications = 100;
52 const size_t WebNotificationTray::kMaxVisiblePopupNotifications = 5;
53
54 using message_center::MessageCenterBubble; 46 using message_center::MessageCenterBubble;
55 using message_center::PopupBubble; 47 using message_center::PopupBubble;
48 using message_center::TrayBubbleView;
56 using message_center::WebNotification; 49 using message_center::WebNotification;
57 using message_center::WebNotificationBubble; 50 using message_center::WebNotificationBubble;
58 using message_center::WebNotificationList; 51 using message_center::WebNotificationList;
59 using message_center::WebNotificationView; 52
53 namespace ash {
54
55 namespace internal {
56
57 // Class to initialize and manage the WebNotificationBubble and
58 // TrayBubbleWrapper instances for a bubble.
59
60 class WebNotificationBubbleWrapper {
61 public:
62 // Takes ownership of |bubble| and creates |bubble_wrapper_|.
63 WebNotificationBubbleWrapper(WebNotificationTray* tray,
64 WebNotificationBubble* bubble) {
65 bubble_.reset(bubble);
66 TrayBubbleView::AnchorAlignment anchor_alignment =
67 tray->GetAnchorAlignment();
68 TrayBubbleView::InitParams init_params =
69 bubble->GetInitParams(anchor_alignment);
70 views::View* anchor = tray->tray_container();
71 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
72 gfx::Point bounds(anchor->width() / 2, 0);
73 views::View::ConvertPointToWidget(anchor, &bounds);
74 init_params.arrow_offset = bounds.x();
75 }
76 TrayBubbleView* bubble_view = TrayBubbleView::Create(
77 tray->GetBubbleWindowContainer(), anchor, tray, &init_params);
78 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view));
79 bubble->InitializeContents(bubble_view);
80 }
81
82 WebNotificationBubble* bubble() const { return bubble_.get(); }
83
84 // Convenience accessors.
85 TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); }
86
87 private:
88 scoped_ptr<WebNotificationBubble> bubble_;
89 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_;
90 };
91
92 } // namespace internal
60 93
61 WebNotificationTray::WebNotificationTray( 94 WebNotificationTray::WebNotificationTray(
62 internal::StatusAreaWidget* status_area_widget) 95 internal::StatusAreaWidget* status_area_widget)
63 : internal::TrayBackgroundView(status_area_widget), 96 : internal::TrayBackgroundView(status_area_widget),
64 notification_list_(new WebNotificationList()),
65 button_(NULL), 97 button_(NULL),
66 delegate_(NULL), 98 delegate_(NULL),
67 show_message_center_on_unlock_(false) { 99 show_message_center_on_unlock_(false) {
100 notification_list_.reset(new WebNotificationList(this));
101
68 button_ = new views::ImageButton(this); 102 button_ = new views::ImageButton(this);
69
70 tray_container()->AddChildView(button_); 103 tray_container()->AddChildView(button_);
71 104
72 UpdateTray(); 105 UpdateTray();
73 } 106 }
74 107
75 WebNotificationTray::~WebNotificationTray() { 108 WebNotificationTray::~WebNotificationTray() {
76 // Release any child views that might have back pointers before ~View(). 109 // Release any child views that might have back pointers before ~View().
77 notification_list_.reset(); 110 notification_list_.reset();
78 message_center_bubble_.reset(); 111 message_center_bubble_.reset();
79 popup_bubble_.reset(); 112 popup_bubble_.reset();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 if (!notification_list_->HasPopupNotifications()) 146 if (!notification_list_->HasPopupNotifications())
114 HidePopupBubble(); 147 HidePopupBubble();
115 UpdateTrayAndBubble(); 148 UpdateTrayAndBubble();
116 } 149 }
117 150
118 void WebNotificationTray::SetNotificationImage(const std::string& id, 151 void WebNotificationTray::SetNotificationImage(const std::string& id,
119 const gfx::ImageSkia& image) { 152 const gfx::ImageSkia& image) {
120 if (!notification_list_->SetNotificationImage(id, image)) 153 if (!notification_list_->SetNotificationImage(id, image))
121 return; 154 return;
122 UpdateTrayAndBubble(); 155 UpdateTrayAndBubble();
123 if (popup_bubble())
124 popup_bubble()->set_dirty(true);
125 ShowPopupBubble(); 156 ShowPopupBubble();
126 } 157 }
127 158
128 void WebNotificationTray::ShowMessageCenterBubble() { 159 void WebNotificationTray::ShowMessageCenterBubble() {
129 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) 160 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED)
130 return; 161 return;
131 if (message_center_bubble()) { 162 if (message_center_bubble()) {
132 UpdateTray(); 163 UpdateTray();
133 return; 164 return;
134 } 165 }
135 // Indicate that the message center is visible. Clears the unread count. 166 // Indicate that the message center is visible. Clears the unread count.
136 notification_list_->SetMessageCenterVisible(true); 167 notification_list_->SetMessageCenterVisible(true);
137 UpdateTray(); 168 UpdateTray();
138 HidePopupBubble(); 169 HidePopupBubble();
139 message_center_bubble_.reset(new MessageCenterBubble(this)); 170 MessageCenterBubble* bubble = new MessageCenterBubble(this);
171 message_center_bubble_.reset(
172 new internal::WebNotificationBubbleWrapper(this, bubble));
173
140 status_area_widget()->SetHideSystemNotifications(true); 174 status_area_widget()->SetHideSystemNotifications(true);
141 Shell::GetInstance()->shelf()->UpdateAutoHideState(); 175 Shell::GetInstance()->shelf()->UpdateAutoHideState();
142 } 176 }
143 177
144 void WebNotificationTray::HideMessageCenterBubble() { 178 void WebNotificationTray::HideMessageCenterBubble() {
145 if (!message_center_bubble()) 179 if (!message_center_bubble())
146 return; 180 return;
147 message_center_bubble_.reset(); 181 message_center_bubble_.reset();
148 show_message_center_on_unlock_ = false; 182 show_message_center_on_unlock_ = false;
149 notification_list_->SetMessageCenterVisible(false); 183 notification_list_->SetMessageCenterVisible(false);
(...skipping 11 matching lines...) Expand all
161 195
162 void WebNotificationTray::ShowPopupBubble() { 196 void WebNotificationTray::ShowPopupBubble() {
163 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) 197 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED)
164 return; 198 return;
165 if (message_center_bubble()) 199 if (message_center_bubble())
166 return; 200 return;
167 if (!status_area_widget()->ShouldShowWebNotifications()) 201 if (!status_area_widget()->ShouldShowWebNotifications())
168 return; 202 return;
169 UpdateTray(); 203 UpdateTray();
170 if (popup_bubble()) { 204 if (popup_bubble()) {
171 popup_bubble()->ScheduleUpdate(); 205 popup_bubble()->bubble()->ScheduleUpdate();
172 } else if (notification_list_->HasPopupNotifications()) { 206 } else if (notification_list_->HasPopupNotifications()) {
173 popup_bubble_.reset(new PopupBubble(this)); 207 popup_bubble_.reset(
208 new internal::WebNotificationBubbleWrapper(
209 this, new PopupBubble(this)));
174 } 210 }
175 } 211 }
176 212
177 void WebNotificationTray::HidePopupBubble() { 213 void WebNotificationTray::HidePopupBubble() {
178 popup_bubble_.reset(); 214 popup_bubble_.reset();
179 } 215 }
180 216
181 void WebNotificationTray::UpdateAfterLoginStatusChange( 217 void WebNotificationTray::UpdateAfterLoginStatusChange(
182 user::LoginStatus login_status) { 218 user::LoginStatus login_status) {
183 if (login_status == user::LOGGED_IN_LOCKED) { 219 if (login_status == user::LOGGED_IN_LOCKED) {
184 if (message_center_bubble()) { 220 if (message_center_bubble()) {
185 message_center_bubble_.reset(); 221 message_center_bubble_.reset();
186 show_message_center_on_unlock_ = true; 222 show_message_center_on_unlock_ = true;
187 } 223 }
188 HidePopupBubble(); 224 HidePopupBubble();
189 } else { 225 } else {
190 if (show_message_center_on_unlock_) 226 if (show_message_center_on_unlock_)
191 ShowMessageCenterBubble(); 227 ShowMessageCenterBubble();
192 show_message_center_on_unlock_ = false; 228 show_message_center_on_unlock_ = false;
193 } 229 }
194 UpdateTray(); 230 UpdateTray();
195 } 231 }
196 232
197 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { 233 bool WebNotificationTray::IsMessageCenterBubbleVisible() const {
198 return (message_center_bubble() && message_center_bubble_->IsVisible()); 234 return (message_center_bubble() &&
235 message_center_bubble_->bubble()->IsVisible());
199 } 236 }
200 237
201 bool WebNotificationTray::IsMouseInNotificationBubble() const { 238 bool WebNotificationTray::IsMouseInNotificationBubble() const {
202 if (!popup_bubble()) 239 if (!popup_bubble())
203 return false; 240 return false;
204 return popup_bubble_->bubble_view()->GetBoundsInScreen().Contains( 241 return popup_bubble_->bubble_view()->GetBoundsInScreen().Contains(
205 Shell::GetScreen()->GetCursorScreenPoint()); 242 Shell::GetScreen()->GetCursorScreenPoint());
206 } 243 }
207 244
208 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { 245 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) {
209 if (alignment == shelf_alignment()) 246 if (alignment == shelf_alignment())
210 return; 247 return;
211 internal::TrayBackgroundView::SetShelfAlignment(alignment); 248 internal::TrayBackgroundView::SetShelfAlignment(alignment);
212 // Destroy any existing bubble so that it will be rebuilt correctly. 249 // Destroy any existing bubble so that it will be rebuilt correctly.
213 HideMessageCenterBubble(); 250 HideMessageCenterBubble();
214 HidePopupBubble(); 251 HidePopupBubble();
215 } 252 }
216 253
217 void WebNotificationTray::AnchorUpdated() { 254 void WebNotificationTray::AnchorUpdated() {
218 if (popup_bubble_.get()) { 255 if (popup_bubble_.get()) {
219 popup_bubble_->bubble_view()->UpdateBubble(); 256 popup_bubble_->bubble_view()->UpdateBubble();
220 // Ensure that the notification buble is above the launcher/status area. 257 // Ensure that the notification buble is above the launcher/status area.
221 popup_bubble_->bubble_view()->GetWidget()->StackAtTop(); 258 popup_bubble_->bubble_view()->GetWidget()->StackAtTop();
222 } 259 }
223 if (message_center_bubble_.get()) 260 if (message_center_bubble_.get())
224 message_center_bubble_->bubble_view()->UpdateBubble(); 261 message_center_bubble_->bubble_view()->UpdateBubble();
225 } 262 }
226 263
227 string16 WebNotificationTray::GetAccessibleName() { 264 string16 WebNotificationTray::GetAccessibleNameForTray() {
228 return l10n_util::GetStringUTF16( 265 return l10n_util::GetStringUTF16(
229 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME); 266 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME);
230 } 267 }
231 268
232 // Private methods invoked by WebNotificationBubble and its child classes
233
234 void WebNotificationTray::SendRemoveNotification(const std::string& id) { 269 void WebNotificationTray::SendRemoveNotification(const std::string& id) {
235 // If this is the only notification in the list, close the bubble. 270 // If this is the only notification in the list, close the bubble.
236 if (notification_list_->notifications().size() == 1 && 271 if (notification_list_->notifications().size() == 1 &&
237 notification_list_->HasNotification(id)) { 272 notification_list_->HasNotification(id)) {
238 HideMessageCenterBubble(); 273 HideMessageCenterBubble();
239 } 274 }
240 if (delegate_) 275 if (delegate_)
241 delegate_->NotificationRemoved(id); 276 delegate_->NotificationRemoved(id);
242 } 277 }
243 278
244 void WebNotificationTray::SendRemoveAllNotifications() { 279 void WebNotificationTray::SendRemoveAllNotifications() {
245 HideMessageCenterBubble(); 280 HideMessageCenterBubble();
246 if (delegate_) { 281 if (delegate_) {
247 const WebNotificationList::Notifications& notifications = 282 const WebNotificationList::Notifications& notifications =
248 notification_list_->notifications(); 283 notification_list_->notifications();
249 for (WebNotificationList::Notifications::const_iterator loopiter = 284 for (WebNotificationList::Notifications::const_iterator loopiter =
250 notifications.begin(); 285 notifications.begin();
251 loopiter != notifications.end(); ) { 286 loopiter != notifications.end(); ) {
252 WebNotificationList::Notifications::const_iterator curiter = loopiter++; 287 WebNotificationList::Notifications::const_iterator curiter = loopiter++;
253 std::string notification_id = curiter->id; 288 std::string notification_id = curiter->id;
254 // May call RemoveNotification and erase curiter. 289 // May call RemoveNotification and erase curiter.
255 delegate_->NotificationRemoved(notification_id); 290 delegate_->NotificationRemoved(notification_id);
256 } 291 }
257 } 292 }
258 } 293 }
259 294
260 // When we disable notifications, we remove any existing matching 295 // When we disable notifications, we remove any existing matching
261 // notifications to avoid adding complicated UI to re-enable the source. 296 // notifications to avoid adding complicated UI to re-enable the source.
262 void WebNotificationTray::DisableByExtension(const std::string& id) { 297 void WebNotificationTray::DisableNotificationByExtension(
298 const std::string& id) {
263 if (delegate_) 299 if (delegate_)
264 delegate_->DisableExtension(id); 300 delegate_->DisableExtension(id);
265 // Will call SendRemoveNotification for each matching notification. 301 // Will call SendRemoveNotification for each matching notification.
266 notification_list_->SendRemoveNotificationsByExtension(this, id); 302 notification_list_->SendRemoveNotificationsByExtension(id);
267 } 303 }
268 304
269 void WebNotificationTray::DisableByUrl(const std::string& id) { 305 void WebNotificationTray::DisableNotificationByUrl(const std::string& id) {
270 if (delegate_) 306 if (delegate_)
271 delegate_->DisableNotificationsFromSource(id); 307 delegate_->DisableNotificationsFromSource(id);
272 // Will call SendRemoveNotification for each matching notification. 308 // Will call SendRemoveNotification for each matching notification.
273 notification_list_->SendRemoveNotificationsBySource(this, id); 309 notification_list_->SendRemoveNotificationsBySource(id);
310 }
311
312 void WebNotificationTray::ShowNotificationSettings(const std::string& id) {
313 if (delegate_)
314 delegate_->ShowSettings(id);
315 }
316
317 void WebNotificationTray::OnNotificationClicked(const std::string& id) {
318 if (delegate_)
319 delegate_->OnClicked(id);
320 }
321
322 message_center::WebNotificationList*
323 WebNotificationTray::GetNotificationList() {
jennyz 2012/10/16 23:09:39 Should line 323 indented for 4 blanks?
stevenjb 2012/10/17 00:52:50 It's not defined in the style guide, but I've seen
324 return notification_list_.get();
325 }
326
327 void WebNotificationTray::HideBubbleWithView(
328 const TrayBubbleView* bubble_view) {
329 if (message_center_bubble() &&
330 bubble_view == message_center_bubble()->bubble_view()) {
331 HideMessageCenterBubble();
332 } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) {
333 HidePopupBubble();
334 }
274 } 335 }
275 336
276 bool WebNotificationTray::PerformAction(const ui::Event& event) { 337 bool WebNotificationTray::PerformAction(const ui::Event& event) {
277 ToggleMessageCenterBubble(); 338 ToggleMessageCenterBubble();
278 return true; 339 return true;
279 } 340 }
280 341
342 void WebNotificationTray::BubbleViewDestroyed() {
343 if (message_center_bubble())
344 message_center_bubble()->bubble()->BubbleViewDestroyed();
345 if (popup_bubble())
346 popup_bubble()->bubble()->BubbleViewDestroyed();
347 }
348
349 void WebNotificationTray::OnMouseEnteredView() {
350 if (popup_bubble())
351 popup_bubble()->bubble()->OnMouseEnteredView();
352 }
353
354 void WebNotificationTray::OnMouseExitedView() {
355 if (popup_bubble())
356 popup_bubble()->bubble()->OnMouseExitedView();
357 }
358
359 string16 WebNotificationTray::GetAccessibleNameForBubble() {
360 return GetAccessibleNameForTray();
361 }
362
363 gfx::Rect WebNotificationTray::GetAnchorRect(views::Widget* anchor_widget,
364 AnchorType anchor_type,
365 AnchorAlignment anchor_alignment) {
366 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment);
367 }
368
369 void WebNotificationTray::HideBubble(const TrayBubbleView* bubble_view) {
370 HideBubbleWithView(bubble_view);
371 }
372
281 void WebNotificationTray::ButtonPressed(views::Button* sender, 373 void WebNotificationTray::ButtonPressed(views::Button* sender,
282 const ui::Event& event) { 374 const ui::Event& event) {
283 DCHECK(sender == button_); 375 DCHECK(sender == button_);
284 ToggleMessageCenterBubble(); 376 ToggleMessageCenterBubble();
285 } 377 }
286 378
287 void WebNotificationTray::ShowSettings(const std::string& id) { 379 // Private methods
288 if (delegate_)
289 delegate_->ShowSettings(id);
290 }
291
292 void WebNotificationTray::OnClicked(const std::string& id) {
293 if (delegate_)
294 delegate_->OnClicked(id);
295 }
296
297 // Other private methods
298 380
299 void WebNotificationTray::ToggleMessageCenterBubble() { 381 void WebNotificationTray::ToggleMessageCenterBubble() {
300 if (message_center_bubble()) 382 if (message_center_bubble())
301 HideMessageCenterBubble(); 383 HideMessageCenterBubble();
302 else 384 else
303 ShowMessageCenterBubble(); 385 ShowMessageCenterBubble();
304 UpdateTray(); 386 UpdateTray();
305 } 387 }
306 388
307 void WebNotificationTray::UpdateTray() { 389 void WebNotificationTray::UpdateTray() {
(...skipping 24 matching lines...) Expand all
332 SetVisible(is_visible); 414 SetVisible(is_visible);
333 Layout(); 415 Layout();
334 SchedulePaint(); 416 SchedulePaint();
335 } 417 }
336 418
337 void WebNotificationTray::UpdateTrayAndBubble() { 419 void WebNotificationTray::UpdateTrayAndBubble() {
338 if (message_center_bubble()) { 420 if (message_center_bubble()) {
339 if (notification_list_->notifications().size() == 0) 421 if (notification_list_->notifications().size() == 0)
340 HideMessageCenterBubble(); 422 HideMessageCenterBubble();
341 else 423 else
342 message_center_bubble()->ScheduleUpdate(); 424 message_center_bubble()->bubble()->ScheduleUpdate();
343 } 425 }
344 if (popup_bubble()) { 426 if (popup_bubble()) {
345 if (notification_list_->notifications().size() == 0) 427 if (notification_list_->notifications().size() == 0)
346 HidePopupBubble(); 428 HidePopupBubble();
347 else 429 else
348 popup_bubble()->ScheduleUpdate(); 430 popup_bubble()->bubble()->ScheduleUpdate();
349 } 431 }
350 UpdateTray(); 432 UpdateTray();
351 } 433 }
352 434
353 void WebNotificationTray::HideBubbleWithView(
354 const TrayBubbleView* bubble_view) {
355 if (message_center_bubble() &&
356 bubble_view == message_center_bubble()->bubble_view()) {
357 HideMessageCenterBubble();
358 } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) {
359 HidePopupBubble();
360 }
361 }
362
363 bool WebNotificationTray::ClickedOutsideBubble() { 435 bool WebNotificationTray::ClickedOutsideBubble() {
364 // Only hide the message center. 436 // Only hide the message center.
365 if (!message_center_bubble()) 437 if (!message_center_bubble())
366 return false; 438 return false;
367 HideMessageCenterBubble(); 439 HideMessageCenterBubble();
368 return true; 440 return true;
369 } 441 }
370 442
371 // Methods for testing 443 // Methods for testing
372 444
373 size_t WebNotificationTray::GetNotificationCountForTest() const { 445 MessageCenterBubble* WebNotificationTray::GetMessageCenterBubbleForTest() {
374 return notification_list_->notifications().size(); 446 if (!message_center_bubble_.get())
447 return NULL;
448 return static_cast<MessageCenterBubble*>(message_center_bubble_->bubble());
375 } 449 }
376 450
377 bool WebNotificationTray::HasNotificationForTest(const std::string& id) const { 451 PopupBubble* WebNotificationTray::GetPopupBubbleForTest() {
378 return notification_list_->HasNotification(id); 452 if (!popup_bubble_.get())
379 } 453 return NULL;
380 454 return static_cast<PopupBubble*>(popup_bubble_->bubble());
381 void WebNotificationTray::RemoveAllNotificationsForTest() {
382 notification_list_->RemoveAllNotifications();
383 }
384
385 size_t WebNotificationTray::GetMessageCenterNotificationCountForTest() const {
386 if (!message_center_bubble())
387 return 0;
388 return message_center_bubble()->NumMessageViewsForTest();
389 }
390
391 size_t WebNotificationTray::GetPopupNotificationCountForTest() const {
392 if (!popup_bubble())
393 return 0;
394 return popup_bubble()->NumMessageViewsForTest();
395 } 455 }
396 456
397 } // namespace ash 457 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698