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 "ash/system/tray/system_tray.h" | 5 #include "ash/system/tray/system_tray.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell/panel_window.h" | 8 #include "ash/shell/panel_window.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/system/audio/tray_volume.h" | 10 #include "ash/system/audio/tray_volume.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "ui/views/controls/label.h" | 47 #include "ui/views/controls/label.h" |
48 #include "ui/views/layout/box_layout.h" | 48 #include "ui/views/layout/box_layout.h" |
49 #include "ui/views/layout/fill_layout.h" | 49 #include "ui/views/layout/fill_layout.h" |
50 #include "ui/views/view.h" | 50 #include "ui/views/view.h" |
51 | 51 |
52 namespace ash { | 52 namespace ash { |
53 | 53 |
54 // SystemTray | 54 // SystemTray |
55 | 55 |
56 using internal::SystemTrayBubble; | 56 using internal::SystemTrayBubble; |
57 using internal::TrayBubbleView; | |
58 | 57 |
59 SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) | 58 SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) |
60 : internal::TrayBackgroundView(status_area_widget), | 59 : internal::TrayBackgroundView(status_area_widget), |
61 items_(), | 60 items_(), |
62 accessibility_observer_(NULL), | 61 accessibility_observer_(NULL), |
63 audio_observer_(NULL), | 62 audio_observer_(NULL), |
64 bluetooth_observer_(NULL), | 63 bluetooth_observer_(NULL), |
65 brightness_observer_(NULL), | 64 brightness_observer_(NULL), |
66 caps_lock_observer_(NULL), | 65 caps_lock_observer_(NULL), |
67 clock_observer_(NULL), | 66 clock_observer_(NULL), |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 void SystemTray::DestroyBubble() { | 262 void SystemTray::DestroyBubble() { |
264 bubble_.reset(); | 263 bubble_.reset(); |
265 detailed_item_ = NULL; | 264 detailed_item_ = NULL; |
266 } | 265 } |
267 | 266 |
268 void SystemTray::DestroyNotificationBubble() { | 267 void SystemTray::DestroyNotificationBubble() { |
269 notification_bubble_.reset(); | 268 notification_bubble_.reset(); |
270 status_area_widget()->SetHideWebNotifications(false); | 269 status_area_widget()->SetHideWebNotifications(false); |
271 } | 270 } |
272 | 271 |
273 void SystemTray::RemoveBubble(SystemTrayBubble* bubble) { | |
274 if (bubble == bubble_.get()) { | |
275 DestroyBubble(); | |
276 UpdateNotificationBubble(); // State changed, re-create notifications. | |
277 Shell::GetInstance()->shelf()->UpdateAutoHideState(); | |
278 } else if (bubble == notification_bubble_) { | |
279 DestroyNotificationBubble(); | |
280 } else { | |
281 NOTREACHED(); | |
282 } | |
283 } | |
284 | |
285 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const { | 272 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const { |
286 // Don't attempt to align the arrow if the shelf is on the left or right. | 273 // Don't attempt to align the arrow if the shelf is on the left or right. |
287 if (shelf_alignment() != SHELF_ALIGNMENT_BOTTOM) | 274 if (shelf_alignment() != SHELF_ALIGNMENT_BOTTOM) |
288 return TrayBubbleView::InitParams::kArrowDefaultOffset; | 275 return TrayBubbleView::InitParams::kArrowDefaultOffset; |
289 | 276 |
290 std::map<SystemTrayItem*, views::View*>::const_iterator it = | 277 std::map<SystemTrayItem*, views::View*>::const_iterator it = |
291 tray_item_map_.find(item); | 278 tray_item_map_.find(item); |
292 if (it == tray_item_map_.end()) | 279 if (it == tray_item_map_.end()) |
293 return TrayBubbleView::InitParams::kArrowDefaultOffset; | 280 return TrayBubbleView::InitParams::kArrowDefaultOffset; |
294 | 281 |
(...skipping 29 matching lines...) Expand all Loading... |
324 notification_bubble_.reset(); | 311 notification_bubble_.reset(); |
325 | 312 |
326 if (bubble_.get() && creation_type == BUBBLE_USE_EXISTING) { | 313 if (bubble_.get() && creation_type == BUBBLE_USE_EXISTING) { |
327 bubble_->UpdateView(items, bubble_type); | 314 bubble_->UpdateView(items, bubble_type); |
328 } else { | 315 } else { |
329 bubble_.reset(new SystemTrayBubble(this, items, bubble_type)); | 316 bubble_.reset(new SystemTrayBubble(this, items, bubble_type)); |
330 ash::SystemTrayDelegate* delegate = | 317 ash::SystemTrayDelegate* delegate = |
331 ash::Shell::GetInstance()->tray_delegate(); | 318 ash::Shell::GetInstance()->tray_delegate(); |
332 views::View* anchor = tray_container(); | 319 views::View* anchor = tray_container(); |
333 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, | 320 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, |
334 shelf_alignment()); | 321 GetAnchorAlignment(), |
| 322 kTrayPopupWidth); |
335 init_params.can_activate = can_activate; | 323 init_params.can_activate = can_activate; |
336 if (detailed) { | 324 if (detailed) { |
337 // This is the case where a volume control or brightness control bubble | 325 // This is the case where a volume control or brightness control bubble |
338 // is created. | 326 // is created. |
339 init_params.max_height = default_bubble_height_; | 327 init_params.max_height = default_bubble_height_; |
340 init_params.top_color = kBackgroundColor; | 328 init_params.top_color = kBackgroundColor; |
341 init_params.arrow_color = kBackgroundColor; | 329 init_params.arrow_color = kBackgroundColor; |
342 } else { | 330 } else { |
343 init_params.top_color = kBackgroundColor; | 331 init_params.top_color = kBackgroundColor; |
344 init_params.arrow_color = kHeaderBackgroundColorDark; | 332 init_params.arrow_color = kHeaderBackgroundColorDark; |
345 } | 333 } |
346 init_params.arrow_offset = arrow_offset; | 334 init_params.arrow_offset = arrow_offset; |
347 bubble_->InitView(anchor, init_params, delegate->GetUserLoginStatus()); | 335 bubble_->InitView(anchor, delegate->GetUserLoginStatus(), &init_params); |
348 } | 336 } |
349 // Save height of default view for creating detailed views directly. | 337 // Save height of default view for creating detailed views directly. |
350 if (!detailed) | 338 if (!detailed) |
351 default_bubble_height_ = bubble_->bubble_view()->height(); | 339 default_bubble_height_ = bubble_->bubble_view()->height(); |
352 | 340 |
353 if (detailed && items.size() > 0) | 341 if (detailed && items.size() > 0) |
354 detailed_item_ = items[0]; | 342 detailed_item_ = items[0]; |
355 else | 343 else |
356 detailed_item_ = NULL; | 344 detailed_item_ = NULL; |
357 | 345 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 } | 380 } |
393 views::View* anchor; | 381 views::View* anchor; |
394 TrayBubbleView::AnchorType anchor_type; | 382 TrayBubbleView::AnchorType anchor_type; |
395 if (bubble_.get()) { | 383 if (bubble_.get()) { |
396 anchor = bubble_->bubble_view(); | 384 anchor = bubble_->bubble_view(); |
397 anchor_type = TrayBubbleView::ANCHOR_TYPE_BUBBLE; | 385 anchor_type = TrayBubbleView::ANCHOR_TYPE_BUBBLE; |
398 } else { | 386 } else { |
399 anchor = tray_container(); | 387 anchor = tray_container(); |
400 anchor_type = TrayBubbleView::ANCHOR_TYPE_TRAY; | 388 anchor_type = TrayBubbleView::ANCHOR_TYPE_TRAY; |
401 } | 389 } |
402 TrayBubbleView::InitParams init_params(anchor_type, shelf_alignment()); | 390 TrayBubbleView::InitParams init_params(anchor_type, |
| 391 GetAnchorAlignment(), |
| 392 kTrayPopupWidth); |
403 init_params.top_color = kBackgroundColor; | 393 init_params.top_color = kBackgroundColor; |
404 init_params.arrow_color = kBackgroundColor; | 394 init_params.arrow_color = kBackgroundColor; |
405 init_params.arrow_offset = GetTrayXOffset(notification_items_[0]); | 395 init_params.arrow_offset = GetTrayXOffset(notification_items_[0]); |
406 user::LoginStatus login_status = | 396 user::LoginStatus login_status = |
407 Shell::GetInstance()->tray_delegate()->GetUserLoginStatus(); | 397 Shell::GetInstance()->tray_delegate()->GetUserLoginStatus(); |
408 notification_bubble_->InitView(anchor, init_params, login_status); | 398 notification_bubble_->InitView(anchor, login_status, &init_params); |
409 if (notification_bubble_->bubble_view()->child_count() == 0) { | 399 if (notification_bubble_->bubble_view()->child_count() == 0) { |
410 // It is possible that none of the items generated actual notifications. | 400 // It is possible that none of the items generated actual notifications. |
411 DestroyNotificationBubble(); | 401 DestroyNotificationBubble(); |
412 return; | 402 return; |
413 } | 403 } |
414 if (hide_notifications_) | 404 if (hide_notifications_) |
415 notification_bubble_->SetVisible(false); | 405 notification_bubble_->SetVisible(false); |
416 else | 406 else |
417 status_area_widget()->SetHideWebNotifications(true); | 407 status_area_widget()->SetHideWebNotifications(true); |
418 } | 408 } |
(...skipping 24 matching lines...) Expand all Loading... |
443 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); | 433 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); |
444 } | 434 } |
445 if (bubble_.get()) | 435 if (bubble_.get()) |
446 bubble_->bubble_view()->UpdateBubble(); | 436 bubble_->bubble_view()->UpdateBubble(); |
447 } | 437 } |
448 | 438 |
449 string16 SystemTray::GetAccessibleName() { | 439 string16 SystemTray::GetAccessibleName() { |
450 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); | 440 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); |
451 } | 441 } |
452 | 442 |
| 443 void SystemTray::HideBubbleWithView(const TrayBubbleView* bubble_view) { |
| 444 if (bubble_.get() && bubble_view == bubble_->bubble_view()) { |
| 445 DestroyBubble(); |
| 446 UpdateNotificationBubble(); // State changed, re-create notifications. |
| 447 Shell::GetInstance()->shelf()->UpdateAutoHideState(); |
| 448 } else if (notification_bubble_.get() && |
| 449 bubble_view == notification_bubble_->bubble_view()) { |
| 450 DestroyNotificationBubble(); |
| 451 } |
| 452 } |
| 453 |
| 454 bool SystemTray::ClickedOutsideBubble() { |
| 455 if (!bubble_.get() || |
| 456 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_NOTIFICATION) { |
| 457 return false; |
| 458 } |
| 459 HideBubbleWithView(bubble_->bubble_view()); |
| 460 return true; |
| 461 } |
| 462 |
453 bool SystemTray::PerformAction(const ui::Event& event) { | 463 bool SystemTray::PerformAction(const ui::Event& event) { |
454 // If we're already showing the default view, hide it; otherwise, show it | 464 // If we're already showing the default view, hide it; otherwise, show it |
455 // (and hide any popup that's currently shown). | 465 // (and hide any popup that's currently shown). |
456 if (bubble_.get() && | 466 if (bubble_.get() && |
457 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { | 467 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { |
458 bubble_->Close(); | 468 bubble_->Close(); |
459 } else { | 469 } else { |
460 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; | 470 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; |
461 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { | 471 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { |
462 const ui::LocatedEvent& located_event = | 472 const ui::LocatedEvent& located_event = |
463 static_cast<const ui::LocatedEvent&>(event); | 473 static_cast<const ui::LocatedEvent&>(event); |
464 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | 474 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
465 gfx::Point point(located_event.x(), 0); | 475 gfx::Point point(located_event.x(), 0); |
466 ConvertPointToWidget(this, &point); | 476 ConvertPointToWidget(this, &point); |
467 arrow_offset = point.x(); | 477 arrow_offset = point.x(); |
468 } | 478 } |
469 } | 479 } |
470 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); | 480 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); |
471 } | 481 } |
472 return true; | 482 return true; |
473 } | 483 } |
474 | 484 |
475 } // namespace ash | 485 } // namespace ash |
OLD | NEW |