| 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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/common/shelf/wm_shelf_util.h" | 8 #include "ash/common/shelf/wm_shelf_util.h" |
| 9 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
| 10 #include "ash/common/system/tray/system_tray_delegate.h" | 10 #include "ash/common/system/tray/system_tray_delegate.h" |
| 11 #include "ash/common/system/tray/tray_constants.h" | 11 #include "ash/common/system/tray/tray_constants.h" |
| 12 #include "ash/common/wm_shell.h" |
| 12 #include "ash/metrics/user_metrics_recorder.h" | 13 #include "ash/metrics/user_metrics_recorder.h" |
| 13 #include "ash/shelf/shelf_layout_manager.h" | 14 #include "ash/shelf/shelf_layout_manager.h" |
| 14 #include "ash/shelf/shelf_util.h" | 15 #include "ash/shelf/shelf_util.h" |
| 15 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 16 #include "ash/system/audio/tray_audio.h" | 17 #include "ash/system/audio/tray_audio.h" |
| 17 #include "ash/system/cast/tray_cast.h" | 18 #include "ash/system/cast/tray_cast.h" |
| 18 #include "ash/system/date/tray_date.h" | 19 #include "ash/system/date/tray_date.h" |
| 19 #include "ash/system/status_area_widget.h" | 20 #include "ash/system/status_area_widget.h" |
| 20 #include "ash/system/tray/system_tray_item.h" | 21 #include "ash/system/tray/system_tray_item.h" |
| 21 #include "ash/system/tray/tray_bubble_wrapper.h" | 22 #include "ash/system/tray/tray_bubble_wrapper.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 explicit SystemBubbleWrapper(SystemTrayBubble* bubble) | 88 explicit SystemBubbleWrapper(SystemTrayBubble* bubble) |
| 88 : bubble_(bubble), is_persistent_(false) {} | 89 : bubble_(bubble), is_persistent_(false) {} |
| 89 | 90 |
| 90 // Initializes the bubble view and creates |bubble_wrapper_|. | 91 // Initializes the bubble view and creates |bubble_wrapper_|. |
| 91 void InitView(TrayBackgroundView* tray, | 92 void InitView(TrayBackgroundView* tray, |
| 92 views::View* anchor, | 93 views::View* anchor, |
| 93 TrayBubbleView::InitParams* init_params, | 94 TrayBubbleView::InitParams* init_params, |
| 94 bool is_persistent) { | 95 bool is_persistent) { |
| 95 DCHECK(anchor); | 96 DCHECK(anchor); |
| 96 LoginStatus login_status = | 97 LoginStatus login_status = |
| 97 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus(); | 98 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus(); |
| 98 bubble_->InitView(anchor, login_status, init_params); | 99 bubble_->InitView(anchor, login_status, init_params); |
| 99 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_->bubble_view())); | 100 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_->bubble_view())); |
| 100 // The system bubble should not have an arrow. | 101 // The system bubble should not have an arrow. |
| 101 bubble_->bubble_view()->SetArrowPaintType( | 102 bubble_->bubble_view()->SetArrowPaintType( |
| 102 views::BubbleBorder::PAINT_NONE); | 103 views::BubbleBorder::PAINT_NONE); |
| 103 is_persistent_ = is_persistent; | 104 is_persistent_ = is_persistent; |
| 104 | 105 |
| 105 // If ChromeVox is enabled, focus the default item if no item is focused and | 106 // If ChromeVox is enabled, focus the default item if no item is focused and |
| 106 // there isn't a delayed close. | 107 // there isn't a delayed close. |
| 107 if (Shell::GetInstance() | 108 if (Shell::GetInstance() |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 AddTrayItem(new TrayUpdate(this)); | 210 AddTrayItem(new TrayUpdate(this)); |
| 210 AddTrayItem(tray_date_); | 211 AddTrayItem(tray_date_); |
| 211 #elif defined(OS_WIN) | 212 #elif defined(OS_WIN) |
| 212 AddTrayItem(tray_accessibility_); | 213 AddTrayItem(tray_accessibility_); |
| 213 if (media::CoreAudioUtil::IsSupported()) | 214 if (media::CoreAudioUtil::IsSupported()) |
| 214 AddTrayItem(new TrayAudioWin(this)); | 215 AddTrayItem(new TrayAudioWin(this)); |
| 215 AddTrayItem(new TrayUpdate(this)); | 216 AddTrayItem(new TrayUpdate(this)); |
| 216 AddTrayItem(tray_date_); | 217 AddTrayItem(tray_date_); |
| 217 #endif | 218 #endif |
| 218 | 219 |
| 219 SetVisible(ash::Shell::GetInstance()->system_tray_delegate()-> | 220 SetVisible(ash::WmShell::Get() |
| 220 GetTrayVisibilityOnStartup()); | 221 ->system_tray_delegate() |
| 222 ->GetTrayVisibilityOnStartup()); |
| 221 } | 223 } |
| 222 | 224 |
| 223 void SystemTray::AddTrayItem(SystemTrayItem* item) { | 225 void SystemTray::AddTrayItem(SystemTrayItem* item) { |
| 224 items_.push_back(item); | 226 items_.push_back(item); |
| 225 | 227 |
| 226 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 228 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 227 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus()); | 229 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus()); |
| 228 item->UpdateAfterShelfAlignmentChange(shelf_alignment()); | 230 item->UpdateAfterShelfAlignmentChange(shelf_alignment()); |
| 229 | 231 |
| 230 if (tray_item) { | 232 if (tray_item) { |
| 231 tray_container()->AddChildViewAt(tray_item, 0); | 233 tray_container()->AddChildViewAt(tray_item, 0); |
| 232 PreferredSizeChanged(); | 234 PreferredSizeChanged(); |
| 233 tray_item_map_[item] = tray_item; | 235 tray_item_map_[item] = tray_item; |
| 234 } | 236 } |
| 235 } | 237 } |
| 236 | 238 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 ShowItems(items_.get(), false, true, creation_type, arrow_offset, persistent); | 447 ShowItems(items_.get(), false, true, creation_type, arrow_offset, persistent); |
| 446 } | 448 } |
| 447 | 449 |
| 448 void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items, | 450 void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items, |
| 449 bool detailed, | 451 bool detailed, |
| 450 bool can_activate, | 452 bool can_activate, |
| 451 BubbleCreationType creation_type, | 453 BubbleCreationType creation_type, |
| 452 int arrow_offset, | 454 int arrow_offset, |
| 453 bool persistent) { | 455 bool persistent) { |
| 454 // No system tray bubbles in kiosk mode. | 456 // No system tray bubbles in kiosk mode. |
| 455 if (Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus() == | 457 if (WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() == |
| 456 LoginStatus::KIOSK_APP) { | 458 LoginStatus::KIOSK_APP) { |
| 457 return; | 459 return; |
| 458 } | 460 } |
| 459 | 461 |
| 460 // Destroy any existing bubble and create a new one. | 462 // Destroy any existing bubble and create a new one. |
| 461 SystemTrayBubble::BubbleType bubble_type = detailed ? | 463 SystemTrayBubble::BubbleType bubble_type = detailed ? |
| 462 SystemTrayBubble::BUBBLE_TYPE_DETAILED : | 464 SystemTrayBubble::BUBBLE_TYPE_DETAILED : |
| 463 SystemTrayBubble::BUBBLE_TYPE_DEFAULT; | 465 SystemTrayBubble::BUBBLE_TYPE_DEFAULT; |
| 464 | 466 |
| 465 // Destroy the notification bubble here so that it doesn't get rebuilt | 467 // Destroy the notification bubble here so that it doesn't get rebuilt |
| (...skipping 12 matching lines...) Expand all Loading... |
| 478 // destruction, leading to subtle errors/crashes such as crbug.com/545166. | 480 // destruction, leading to subtle errors/crashes such as crbug.com/545166. |
| 479 DestroySystemBubble(); | 481 DestroySystemBubble(); |
| 480 | 482 |
| 481 // Remember if the menu is a single property (like e.g. volume) or the | 483 // Remember if the menu is a single property (like e.g. volume) or the |
| 482 // full tray menu. Note that in case of the |BUBBLE_USE_EXISTING| case | 484 // full tray menu. Note that in case of the |BUBBLE_USE_EXISTING| case |
| 483 // above, |full_system_tray_menu_| does not get changed since the fact that | 485 // above, |full_system_tray_menu_| does not get changed since the fact that |
| 484 // the menu is full (or not) doesn't change even if a "single property" | 486 // the menu is full (or not) doesn't change even if a "single property" |
| 485 // (like network) replaces most of the menu. | 487 // (like network) replaces most of the menu. |
| 486 full_system_tray_menu_ = items.size() > 1; | 488 full_system_tray_menu_ = items.size() > 1; |
| 487 // The menu width is fixed, and it is a per language setting. | 489 // The menu width is fixed, and it is a per language setting. |
| 488 int menu_width = std::max(kMinimumSystemTrayMenuWidth, | 490 int menu_width = std::max( |
| 489 Shell::GetInstance()->system_tray_delegate()->GetSystemTrayMenuWidth()); | 491 kMinimumSystemTrayMenuWidth, |
| 492 WmShell::Get()->system_tray_delegate()->GetSystemTrayMenuWidth()); |
| 490 | 493 |
| 491 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, | 494 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, |
| 492 GetAnchorAlignment(), | 495 GetAnchorAlignment(), |
| 493 menu_width, | 496 menu_width, |
| 494 kTrayPopupMaxWidth); | 497 kTrayPopupMaxWidth); |
| 495 init_params.can_activate = can_activate; | 498 init_params.can_activate = can_activate; |
| 496 init_params.first_item_has_no_margin = true; | 499 init_params.first_item_has_no_margin = true; |
| 497 if (detailed) { | 500 if (detailed) { |
| 498 // This is the case where a volume control or brightness control bubble | 501 // This is the case where a volume control or brightness control bubble |
| 499 // is created. | 502 // is created. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 .work_area(); | 604 .work_area(); |
| 602 height = | 605 height = |
| 603 std::max(0, work_area.height() - bubble_view->GetBoundsInScreen().y()); | 606 std::max(0, work_area.height() - bubble_view->GetBoundsInScreen().y()); |
| 604 } | 607 } |
| 605 status_area_widget()->web_notification_tray()->SetSystemTrayHeight(height); | 608 status_area_widget()->web_notification_tray()->SetSystemTrayHeight(height); |
| 606 } | 609 } |
| 607 | 610 |
| 608 base::string16 SystemTray::GetAccessibleTimeString( | 611 base::string16 SystemTray::GetAccessibleTimeString( |
| 609 const base::Time& now) const { | 612 const base::Time& now) const { |
| 610 base::HourClockType hour_type = | 613 base::HourClockType hour_type = |
| 611 ash::Shell::GetInstance()->system_tray_delegate()->GetHourClockType(); | 614 ash::WmShell::Get()->system_tray_delegate()->GetHourClockType(); |
| 612 return base::TimeFormatTimeOfDayWithHourClockType( | 615 return base::TimeFormatTimeOfDayWithHourClockType( |
| 613 now, hour_type, base::kKeepAmPm); | 616 now, hour_type, base::kKeepAmPm); |
| 614 } | 617 } |
| 615 | 618 |
| 616 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { | 619 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 617 if (alignment == shelf_alignment()) | 620 if (alignment == shelf_alignment()) |
| 618 return; | 621 return; |
| 619 TrayBackgroundView::SetShelfAlignment(alignment); | 622 TrayBackgroundView::SetShelfAlignment(alignment); |
| 620 UpdateAfterShelfAlignmentChange(alignment); | 623 UpdateAfterShelfAlignmentChange(alignment); |
| 621 // Destroy any existing bubble so that it is rebuilt correctly. | 624 // Destroy any existing bubble so that it is rebuilt correctly. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 .work_area() | 759 .work_area() |
| 757 .height(); | 760 .height(); |
| 758 if (work_area_height > 0) { | 761 if (work_area_height > 0) { |
| 759 UMA_HISTOGRAM_CUSTOM_COUNTS( | 762 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 760 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", | 763 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", |
| 761 100 * bubble_view->height() / work_area_height, 1, 300, 100); | 764 100 * bubble_view->height() / work_area_height, 1, 300, 100); |
| 762 } | 765 } |
| 763 } | 766 } |
| 764 | 767 |
| 765 } // namespace ash | 768 } // namespace ash |
| OLD | NEW |