| 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 | |
| 83 // SystemTray | 54 // SystemTray |
| 84 | 55 |
| 85 using internal::SystemTrayBubble; | 56 using internal::SystemTrayBubble; |
| 86 using internal::SystemTrayLayerAnimationObserver; | |
| 87 using internal::TrayBubbleView; | 57 using internal::TrayBubbleView; |
| 88 | 58 |
| 89 SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) | 59 SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) |
| 90 : internal::TrayBackgroundView(status_area_widget), | 60 : internal::TrayBackgroundView(status_area_widget), |
| 91 items_(), | 61 items_(), |
| 92 accessibility_observer_(NULL), | 62 accessibility_observer_(NULL), |
| 93 audio_observer_(NULL), | 63 audio_observer_(NULL), |
| 94 bluetooth_observer_(NULL), | 64 bluetooth_observer_(NULL), |
| 95 brightness_observer_(NULL), | 65 brightness_observer_(NULL), |
| 96 caps_lock_observer_(NULL), | 66 caps_lock_observer_(NULL), |
| 97 clock_observer_(NULL), | 67 clock_observer_(NULL), |
| 98 drive_observer_(NULL), | 68 drive_observer_(NULL), |
| 99 ime_observer_(NULL), | 69 ime_observer_(NULL), |
| 100 locale_observer_(NULL), | 70 locale_observer_(NULL), |
| 101 network_observer_(NULL), | 71 network_observer_(NULL), |
| 102 update_observer_(NULL), | 72 update_observer_(NULL), |
| 103 user_observer_(NULL), | 73 user_observer_(NULL), |
| 104 should_show_launcher_(false), | 74 should_show_launcher_(false), |
| 105 default_bubble_height_(0), | 75 default_bubble_height_(0), |
| 106 hide_notifications_(false) { | 76 hide_notifications_(false) { |
| 107 } | 77 } |
| 108 | 78 |
| 109 SystemTray::~SystemTray() { | 79 SystemTray::~SystemTray() { |
| 110 bubble_.reset(); | 80 bubble_.reset(); |
| 111 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); | 81 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); |
| 112 it != items_.end(); | 82 it != items_.end(); |
| 113 ++it) { | 83 ++it) { |
| 114 (*it)->DestroyTrayView(); | 84 (*it)->DestroyTrayView(); |
| 115 } | 85 } |
| 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()); | |
| 124 } | 86 } |
| 125 | 87 |
| 126 void SystemTray::CreateItems() { | 88 void SystemTray::CreateItems() { |
| 127 internal::TrayVolume* tray_volume = new internal::TrayVolume(); | 89 internal::TrayVolume* tray_volume = new internal::TrayVolume(); |
| 128 internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth(); | 90 internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth(); |
| 129 internal::TrayBrightness* tray_brightness = new internal::TrayBrightness(); | 91 internal::TrayBrightness* tray_brightness = new internal::TrayBrightness(); |
| 130 internal::TrayDate* tray_date = new internal::TrayDate(); | 92 internal::TrayDate* tray_date = new internal::TrayDate(); |
| 131 internal::TrayPower* tray_power = new internal::TrayPower(); | 93 internal::TrayPower* tray_power = new internal::TrayPower(); |
| 132 internal::TrayNetwork* tray_network = new internal::TrayNetwork; | 94 internal::TrayNetwork* tray_network = new internal::TrayNetwork; |
| 133 internal::TraySms* tray_sms = new internal::TraySms(); | 95 internal::TraySms* tray_sms = new internal::TraySms(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 AddTrayItem(tray_date); | 136 AddTrayItem(tray_date); |
| 175 SetVisible(ash::Shell::GetInstance()->tray_delegate()-> | 137 SetVisible(ash::Shell::GetInstance()->tray_delegate()-> |
| 176 GetTrayVisibilityOnStartup()); | 138 GetTrayVisibilityOnStartup()); |
| 177 } | 139 } |
| 178 | 140 |
| 179 void SystemTray::AddTrayItem(SystemTrayItem* item) { | 141 void SystemTray::AddTrayItem(SystemTrayItem* item) { |
| 180 items_.push_back(item); | 142 items_.push_back(item); |
| 181 | 143 |
| 182 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 144 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
| 183 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus()); | 145 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus()); |
| 184 item->UpdateAfterShelfAlignmentChange( | 146 item->UpdateAfterShelfAlignmentChange(shelf_alignment()); |
| 185 ash::Shell::GetInstance()->system_tray()->shelf_alignment()); | |
| 186 | 147 |
| 187 if (tray_item) { | 148 if (tray_item) { |
| 188 tray_container()->AddChildViewAt(tray_item, 0); | 149 tray_container()->AddChildViewAt(tray_item, 0); |
| 189 PreferredSizeChanged(); | 150 PreferredSizeChanged(); |
| 190 tray_item_map_[item] = tray_item; | 151 tray_item_map_[item] = tray_item; |
| 191 } | 152 } |
| 192 } | 153 } |
| 193 | 154 |
| 194 void SystemTray::RemoveTrayItem(SystemTrayItem* item) { | 155 void SystemTray::RemoveTrayItem(SystemTrayItem* item) { |
| 195 NOTIMPLEMENTED(); | 156 NOTIMPLEMENTED(); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 init_params.arrow_color = kBackgroundColor; | 389 init_params.arrow_color = kBackgroundColor; |
| 429 user::LoginStatus login_status = | 390 user::LoginStatus login_status = |
| 430 Shell::GetInstance()->tray_delegate()->GetUserLoginStatus(); | 391 Shell::GetInstance()->tray_delegate()->GetUserLoginStatus(); |
| 431 notification_bubble_->InitView(anchor, init_params, login_status); | 392 notification_bubble_->InitView(anchor, init_params, login_status); |
| 432 if (hide_notifications_) | 393 if (hide_notifications_) |
| 433 notification_bubble_->SetVisible(false); | 394 notification_bubble_->SetVisible(false); |
| 434 else | 395 else |
| 435 status_area_widget()->HideNonSystemNotifications(); | 396 status_area_widget()->HideNonSystemNotifications(); |
| 436 } | 397 } |
| 437 | 398 |
| 438 void SystemTray::UpdateNotificationAnchor() { | 399 void SystemTray::Initialize() { |
| 439 if (!notification_bubble_.get()) | 400 internal::TrayBackgroundView::Initialize(); |
| 440 return; | 401 CreateItems(); |
| 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(); | |
| 444 } | 402 } |
| 445 | 403 |
| 446 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { | 404 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 447 if (alignment == shelf_alignment()) | 405 if (alignment == shelf_alignment()) |
| 448 return; | 406 return; |
| 449 internal::TrayBackgroundView::SetShelfAlignment(alignment); | 407 internal::TrayBackgroundView::SetShelfAlignment(alignment); |
| 450 UpdateAfterShelfAlignmentChange(alignment); | 408 UpdateAfterShelfAlignmentChange(alignment); |
| 451 // Destroy any existing bubble so that it is rebuilt correctly. | 409 // Destroy any existing bubble so that it is rebuilt correctly. |
| 452 bubble_.reset(); | 410 bubble_.reset(); |
| 453 // Rebuild any notification bubble. | 411 // Rebuild any notification bubble. |
| 454 if (notification_bubble_.get()) { | 412 if (notification_bubble_.get()) { |
| 455 notification_bubble_.reset(); | 413 notification_bubble_.reset(); |
| 456 UpdateNotificationBubble(); | 414 UpdateNotificationBubble(); |
| 457 } | 415 } |
| 458 } | 416 } |
| 459 | 417 |
| 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 |
| 460 bool SystemTray::PerformAction(const ui::Event& event) { | 428 bool SystemTray::PerformAction(const ui::Event& event) { |
| 461 // If we're already showing the default view, hide it; otherwise, show it | 429 // If we're already showing the default view, hide it; otherwise, show it |
| 462 // (and hide any popup that's currently shown). | 430 // (and hide any popup that's currently shown). |
| 463 if (bubble_.get() && | 431 if (bubble_.get() && |
| 464 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { | 432 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { |
| 465 bubble_->Close(); | 433 bubble_->Close(); |
| 466 } else { | 434 } else { |
| 467 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; | 435 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; |
| 468 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { | 436 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { |
| 469 const ui::LocatedEvent& located_event = | 437 const ui::LocatedEvent& located_event = |
| (...skipping 14 matching lines...) Expand all Loading... |
| 484 should_show_launcher_ = true; | 452 should_show_launcher_ = true; |
| 485 } | 453 } |
| 486 | 454 |
| 487 void SystemTray::OnMouseExited(const ui::MouseEvent& event) { | 455 void SystemTray::OnMouseExited(const ui::MouseEvent& event) { |
| 488 TrayBackgroundView::OnMouseExited(event); | 456 TrayBackgroundView::OnMouseExited(event); |
| 489 // When the popup closes we'll update |should_show_launcher_|. | 457 // When the popup closes we'll update |should_show_launcher_|. |
| 490 if (!bubble_.get()) | 458 if (!bubble_.get()) |
| 491 should_show_launcher_ = false; | 459 should_show_launcher_ = false; |
| 492 } | 460 } |
| 493 | 461 |
| 494 void SystemTray::AboutToRequestFocusFromTabTraversal(bool reverse) { | |
| 495 views::View* v = GetNextFocusableView(); | |
| 496 if (v) | |
| 497 v->AboutToRequestFocusFromTabTraversal(reverse); | |
| 498 } | |
| 499 | |
| 500 void SystemTray::GetAccessibleState(ui::AccessibleViewState* state) { | 462 void SystemTray::GetAccessibleState(ui::AccessibleViewState* state) { |
| 501 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 463 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 502 state->name = l10n_util::GetStringUTF16( | 464 state->name = l10n_util::GetStringUTF16( |
| 503 IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); | 465 IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); |
| 504 } | 466 } |
| 505 | 467 |
| 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 | |
| 514 } // namespace ash | 468 } // namespace ash |
| OLD | NEW |