| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "ui/gfx/screen.h" | 44 #include "ui/gfx/screen.h" |
| 45 #include "ui/gfx/skia_util.h" | 45 #include "ui/gfx/skia_util.h" |
| 46 #include "ui/views/border.h" | 46 #include "ui/views/border.h" |
| 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 namespace internal { |
| 55 |
| 56 // Observe the tray layer animation and update the anchor when it changes. |
| 57 // TODO(stevenjb): Observe or mirror the actual animation, not just the start |
| 58 // and end points. |
| 59 class SystemTrayLayerAnimationObserver : public ui::LayerAnimationObserver { |
| 60 public: |
| 61 explicit SystemTrayLayerAnimationObserver(SystemTray* host) : host_(host) {} |
| 62 |
| 63 virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) { |
| 64 host_->UpdateNotificationAnchor(); |
| 65 } |
| 66 |
| 67 virtual void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) { |
| 68 host_->UpdateNotificationAnchor(); |
| 69 } |
| 70 |
| 71 virtual void OnLayerAnimationScheduled(ui::LayerAnimationSequence* sequence) { |
| 72 host_->UpdateNotificationAnchor(); |
| 73 } |
| 74 |
| 75 private: |
| 76 SystemTray* host_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(SystemTrayLayerAnimationObserver); |
| 79 }; |
| 80 |
| 81 } // namespace internal |
| 82 |
| 54 // SystemTray | 83 // SystemTray |
| 55 | 84 |
| 56 using internal::SystemTrayBubble; | 85 using internal::SystemTrayBubble; |
| 86 using internal::SystemTrayLayerAnimationObserver; |
| 57 using internal::TrayBubbleView; | 87 using internal::TrayBubbleView; |
| 58 | 88 |
| 59 SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) | 89 SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) |
| 60 : internal::TrayBackgroundView(status_area_widget), | 90 : internal::TrayBackgroundView(status_area_widget), |
| 61 items_(), | 91 items_(), |
| 62 accessibility_observer_(NULL), | 92 accessibility_observer_(NULL), |
| 63 audio_observer_(NULL), | 93 audio_observer_(NULL), |
| 64 bluetooth_observer_(NULL), | 94 bluetooth_observer_(NULL), |
| 65 brightness_observer_(NULL), | 95 brightness_observer_(NULL), |
| 66 caps_lock_observer_(NULL), | 96 caps_lock_observer_(NULL), |
| 67 clock_observer_(NULL), | 97 clock_observer_(NULL), |
| 68 drive_observer_(NULL), | 98 drive_observer_(NULL), |
| 69 ime_observer_(NULL), | 99 ime_observer_(NULL), |
| 70 locale_observer_(NULL), | 100 locale_observer_(NULL), |
| 71 network_observer_(NULL), | 101 network_observer_(NULL), |
| 72 update_observer_(NULL), | 102 update_observer_(NULL), |
| 73 user_observer_(NULL), | 103 user_observer_(NULL), |
| 74 should_show_launcher_(false), | 104 should_show_launcher_(false), |
| 75 default_bubble_height_(0), | 105 default_bubble_height_(0), |
| 76 hide_notifications_(false) { | 106 hide_notifications_(false) { |
| 77 } | 107 } |
| 78 | 108 |
| 79 SystemTray::~SystemTray() { | 109 SystemTray::~SystemTray() { |
| 80 bubble_.reset(); | 110 bubble_.reset(); |
| 81 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); | 111 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); |
| 82 it != items_.end(); | 112 it != items_.end(); |
| 83 ++it) { | 113 ++it) { |
| 84 (*it)->DestroyTrayView(); | 114 (*it)->DestroyTrayView(); |
| 85 } | 115 } |
| 116 GetWidget()->GetNativeView()->layer()->GetAnimator()->RemoveObserver( |
| 117 layer_animation_observer_.get()); |
| 118 } |
| 119 |
| 120 void SystemTray::Initialize() { |
| 121 layer_animation_observer_.reset(new SystemTrayLayerAnimationObserver(this)); |
| 122 GetWidget()->GetNativeView()->layer()->GetAnimator()->AddObserver( |
| 123 layer_animation_observer_.get()); |
| 86 } | 124 } |
| 87 | 125 |
| 88 void SystemTray::CreateItems() { | 126 void SystemTray::CreateItems() { |
| 89 internal::TrayVolume* tray_volume = new internal::TrayVolume(); | 127 internal::TrayVolume* tray_volume = new internal::TrayVolume(); |
| 90 internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth(); | 128 internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth(); |
| 91 internal::TrayBrightness* tray_brightness = new internal::TrayBrightness(); | 129 internal::TrayBrightness* tray_brightness = new internal::TrayBrightness(); |
| 92 internal::TrayDate* tray_date = new internal::TrayDate(); | 130 internal::TrayDate* tray_date = new internal::TrayDate(); |
| 93 internal::TrayPower* tray_power = new internal::TrayPower(); | 131 internal::TrayPower* tray_power = new internal::TrayPower(); |
| 94 internal::TrayNetwork* tray_network = new internal::TrayNetwork; | 132 internal::TrayNetwork* tray_network = new internal::TrayNetwork; |
| 95 internal::TraySms* tray_sms = new internal::TraySms(); | 133 internal::TraySms* tray_sms = new internal::TraySms(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 AddTrayItem(tray_date); | 174 AddTrayItem(tray_date); |
| 137 SetVisible(ash::Shell::GetInstance()->tray_delegate()-> | 175 SetVisible(ash::Shell::GetInstance()->tray_delegate()-> |
| 138 GetTrayVisibilityOnStartup()); | 176 GetTrayVisibilityOnStartup()); |
| 139 } | 177 } |
| 140 | 178 |
| 141 void SystemTray::AddTrayItem(SystemTrayItem* item) { | 179 void SystemTray::AddTrayItem(SystemTrayItem* item) { |
| 142 items_.push_back(item); | 180 items_.push_back(item); |
| 143 | 181 |
| 144 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 182 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
| 145 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus()); | 183 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus()); |
| 146 item->UpdateAfterShelfAlignmentChange(shelf_alignment()); | 184 item->UpdateAfterShelfAlignmentChange( |
| 185 ash::Shell::GetInstance()->system_tray()->shelf_alignment()); |
| 147 | 186 |
| 148 if (tray_item) { | 187 if (tray_item) { |
| 149 tray_container()->AddChildViewAt(tray_item, 0); | 188 tray_container()->AddChildViewAt(tray_item, 0); |
| 150 PreferredSizeChanged(); | 189 PreferredSizeChanged(); |
| 151 tray_item_map_[item] = tray_item; | 190 tray_item_map_[item] = tray_item; |
| 152 } | 191 } |
| 153 } | 192 } |
| 154 | 193 |
| 155 void SystemTray::RemoveTrayItem(SystemTrayItem* item) { | 194 void SystemTray::RemoveTrayItem(SystemTrayItem* item) { |
| 156 NOTIMPLEMENTED(); | 195 NOTIMPLEMENTED(); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 init_params.arrow_color = kBackgroundColor; | 428 init_params.arrow_color = kBackgroundColor; |
| 390 user::LoginStatus login_status = | 429 user::LoginStatus login_status = |
| 391 Shell::GetInstance()->tray_delegate()->GetUserLoginStatus(); | 430 Shell::GetInstance()->tray_delegate()->GetUserLoginStatus(); |
| 392 notification_bubble_->InitView(anchor, init_params, login_status); | 431 notification_bubble_->InitView(anchor, init_params, login_status); |
| 393 if (hide_notifications_) | 432 if (hide_notifications_) |
| 394 notification_bubble_->SetVisible(false); | 433 notification_bubble_->SetVisible(false); |
| 395 else | 434 else |
| 396 status_area_widget()->HideNonSystemNotifications(); | 435 status_area_widget()->HideNonSystemNotifications(); |
| 397 } | 436 } |
| 398 | 437 |
| 399 void SystemTray::Initialize() { | 438 void SystemTray::UpdateNotificationAnchor() { |
| 400 internal::TrayBackgroundView::Initialize(); | 439 if (!notification_bubble_.get()) |
| 401 CreateItems(); | 440 return; |
| 441 notification_bubble_->bubble_view()->UpdateBubble(); |
| 442 // Ensure that the notification buble is above the launcher/status area. |
| 443 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); |
| 402 } | 444 } |
| 403 | 445 |
| 404 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { | 446 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 405 if (alignment == shelf_alignment()) | 447 if (alignment == shelf_alignment()) |
| 406 return; | 448 return; |
| 407 internal::TrayBackgroundView::SetShelfAlignment(alignment); | 449 internal::TrayBackgroundView::SetShelfAlignment(alignment); |
| 408 UpdateAfterShelfAlignmentChange(alignment); | 450 UpdateAfterShelfAlignmentChange(alignment); |
| 409 // Destroy any existing bubble so that it is rebuilt correctly. | 451 // Destroy any existing bubble so that it is rebuilt correctly. |
| 410 bubble_.reset(); | 452 bubble_.reset(); |
| 411 // Rebuild any notification bubble. | 453 // Rebuild any notification bubble. |
| 412 if (notification_bubble_.get()) { | 454 if (notification_bubble_.get()) { |
| 413 notification_bubble_.reset(); | 455 notification_bubble_.reset(); |
| 414 UpdateNotificationBubble(); | 456 UpdateNotificationBubble(); |
| 415 } | 457 } |
| 416 } | 458 } |
| 417 | 459 |
| 418 void SystemTray::AnchorUpdated() { | |
| 419 if (notification_bubble_.get()) { | |
| 420 notification_bubble_->bubble_view()->UpdateBubble(); | |
| 421 // Ensure that the notification buble is above the launcher/status area. | |
| 422 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); | |
| 423 } | |
| 424 if (bubble_.get()) | |
| 425 bubble_->bubble_view()->UpdateBubble(); | |
| 426 } | |
| 427 | |
| 428 bool SystemTray::PerformAction(const ui::Event& event) { | 460 bool SystemTray::PerformAction(const ui::Event& event) { |
| 429 // If we're already showing the default view, hide it; otherwise, show it | 461 // If we're already showing the default view, hide it; otherwise, show it |
| 430 // (and hide any popup that's currently shown). | 462 // (and hide any popup that's currently shown). |
| 431 if (bubble_.get() && | 463 if (bubble_.get() && |
| 432 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { | 464 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { |
| 433 bubble_->Close(); | 465 bubble_->Close(); |
| 434 } else { | 466 } else { |
| 435 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; | 467 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; |
| 436 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { | 468 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { |
| 437 const ui::LocatedEvent& located_event = | 469 const ui::LocatedEvent& located_event = |
| (...skipping 14 matching lines...) Expand all Loading... |
| 452 should_show_launcher_ = true; | 484 should_show_launcher_ = true; |
| 453 } | 485 } |
| 454 | 486 |
| 455 void SystemTray::OnMouseExited(const ui::MouseEvent& event) { | 487 void SystemTray::OnMouseExited(const ui::MouseEvent& event) { |
| 456 TrayBackgroundView::OnMouseExited(event); | 488 TrayBackgroundView::OnMouseExited(event); |
| 457 // When the popup closes we'll update |should_show_launcher_|. | 489 // When the popup closes we'll update |should_show_launcher_|. |
| 458 if (!bubble_.get()) | 490 if (!bubble_.get()) |
| 459 should_show_launcher_ = false; | 491 should_show_launcher_ = false; |
| 460 } | 492 } |
| 461 | 493 |
| 494 void SystemTray::AboutToRequestFocusFromTabTraversal(bool reverse) { |
| 495 views::View* v = GetNextFocusableView(); |
| 496 if (v) |
| 497 v->AboutToRequestFocusFromTabTraversal(reverse); |
| 498 } |
| 499 |
| 462 void SystemTray::GetAccessibleState(ui::AccessibleViewState* state) { | 500 void SystemTray::GetAccessibleState(ui::AccessibleViewState* state) { |
| 463 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 501 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 464 state->name = l10n_util::GetStringUTF16( | 502 state->name = l10n_util::GetStringUTF16( |
| 465 IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); | 503 IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); |
| 466 } | 504 } |
| 467 | 505 |
| 506 void SystemTray::OnPaintFocusBorder(gfx::Canvas* canvas) { |
| 507 // The tray itself expands to the right and bottom edge of the screen to make |
| 508 // sure clicking on the edges brings up the popup. However, the focus border |
| 509 // should be only around the container. |
| 510 if (GetWidget() && GetWidget()->IsActive()) |
| 511 DrawBorder(canvas, GetContentsBounds()); |
| 512 } |
| 513 |
| 468 } // namespace ash | 514 } // namespace ash |
| OLD | NEW |