| 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/common/system/tray/system_tray.h" | 5 #include "ash/common/system/tray/system_tray.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/common/key_event_watcher.h" | 11 #include "ash/common/key_event_watcher.h" |
| 12 #include "ash/common/login_status.h" | 12 #include "ash/common/login_status.h" |
| 13 #include "ash/common/material_design/material_design_controller.h" | 13 #include "ash/common/material_design/material_design_controller.h" |
| 14 #include "ash/common/session/session_state_delegate.h" | 14 #include "ash/common/session/session_state_delegate.h" |
| 15 #include "ash/common/shelf/wm_shelf.h" | 15 #include "ash/common/shelf/wm_shelf.h" |
| 16 #include "ash/common/shelf/wm_shelf_util.h" | 16 #include "ash/common/shelf/wm_shelf_util.h" |
| 17 #include "ash/common/system/chromeos/audio/tray_audio.h" |
| 18 #include "ash/common/system/chromeos/bluetooth/tray_bluetooth.h" |
| 19 #include "ash/common/system/chromeos/brightness/tray_brightness.h" |
| 20 #include "ash/common/system/chromeos/cast/tray_cast.h" |
| 21 #include "ash/common/system/chromeos/enterprise/tray_enterprise.h" |
| 22 #include "ash/common/system/chromeos/media_security/multi_profile_media_tray_ite
m.h" |
| 23 #include "ash/common/system/chromeos/network/tray_network.h" |
| 24 #include "ash/common/system/chromeos/network/tray_sms.h" |
| 25 #include "ash/common/system/chromeos/network/tray_vpn.h" |
| 26 #include "ash/common/system/chromeos/power/power_status.h" |
| 27 #include "ash/common/system/chromeos/power/tray_power.h" |
| 28 #include "ash/common/system/chromeos/screen_security/screen_capture_tray_item.h" |
| 29 #include "ash/common/system/chromeos/screen_security/screen_share_tray_item.h" |
| 30 #include "ash/common/system/chromeos/session/tray_session_length_limit.h" |
| 31 #include "ash/common/system/chromeos/settings/tray_settings.h" |
| 32 #include "ash/common/system/chromeos/supervised/tray_supervised_user.h" |
| 33 #include "ash/common/system/chromeos/tray_caps_lock.h" |
| 34 #include "ash/common/system/chromeos/tray_tracing.h" |
| 17 #include "ash/common/system/date/tray_date.h" | 35 #include "ash/common/system/date/tray_date.h" |
| 18 #include "ash/common/system/date/tray_system_info.h" | 36 #include "ash/common/system/date/tray_system_info.h" |
| 37 #include "ash/common/system/ime/tray_ime_chromeos.h" |
| 19 #include "ash/common/system/tiles/tray_tiles.h" | 38 #include "ash/common/system/tiles/tray_tiles.h" |
| 20 #include "ash/common/system/tray/system_tray_controller.h" | 39 #include "ash/common/system/tray/system_tray_controller.h" |
| 21 #include "ash/common/system/tray/system_tray_delegate.h" | 40 #include "ash/common/system/tray/system_tray_delegate.h" |
| 22 #include "ash/common/system/tray/system_tray_item.h" | 41 #include "ash/common/system/tray/system_tray_item.h" |
| 23 #include "ash/common/system/tray/tray_bubble_wrapper.h" | 42 #include "ash/common/system/tray/tray_bubble_wrapper.h" |
| 24 #include "ash/common/system/tray/tray_constants.h" | 43 #include "ash/common/system/tray/tray_constants.h" |
| 25 #include "ash/common/system/tray_accessibility.h" | 44 #include "ash/common/system/tray_accessibility.h" |
| 26 #include "ash/common/system/update/tray_update.h" | 45 #include "ash/common/system/update/tray_update.h" |
| 27 #include "ash/common/system/user/tray_user.h" | 46 #include "ash/common/system/user/tray_user.h" |
| 28 #include "ash/common/system/user/tray_user_separator.h" | 47 #include "ash/common/system/user/tray_user_separator.h" |
| 29 #include "ash/common/system/web_notification/web_notification_tray.h" | 48 #include "ash/common/system/web_notification/web_notification_tray.h" |
| 30 #include "ash/common/wm/container_finder.h" | 49 #include "ash/common/wm/container_finder.h" |
| 31 #include "ash/common/wm_activation_observer.h" | 50 #include "ash/common/wm_activation_observer.h" |
| 32 #include "ash/common/wm_lookup.h" | 51 #include "ash/common/wm_lookup.h" |
| 33 #include "ash/common/wm_root_window_controller.h" | 52 #include "ash/common/wm_root_window_controller.h" |
| 34 #include "ash/common/wm_shell.h" | 53 #include "ash/common/wm_shell.h" |
| 35 #include "ash/common/wm_window.h" | 54 #include "ash/common/wm_window.h" |
| 36 #include "ash/public/cpp/shell_window_ids.h" | 55 #include "ash/public/cpp/shell_window_ids.h" |
| 37 #include "base/logging.h" | 56 #include "base/logging.h" |
| 38 #include "base/metrics/histogram.h" | 57 #include "base/metrics/histogram.h" |
| 39 #include "base/strings/utf_string_conversions.h" | |
| 40 #include "base/timer/timer.h" | 58 #include "base/timer/timer.h" |
| 41 #include "grit/ash_strings.h" | 59 #include "grit/ash_strings.h" |
| 42 #include "ui/base/accelerators/accelerator.h" | 60 #include "ui/base/accelerators/accelerator.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 61 #include "ui/base/l10n/l10n_util.h" |
| 44 #include "ui/compositor/layer.h" | 62 #include "ui/compositor/layer.h" |
| 45 #include "ui/display/display.h" | 63 #include "ui/display/display.h" |
| 46 #include "ui/display/screen.h" | 64 #include "ui/display/screen.h" |
| 47 #include "ui/events/event_constants.h" | 65 #include "ui/events/event_constants.h" |
| 48 #include "ui/gfx/canvas.h" | 66 #include "ui/gfx/canvas.h" |
| 49 #include "ui/gfx/skia_util.h" | 67 #include "ui/gfx/skia_util.h" |
| 68 #include "ui/message_center/message_center.h" |
| 50 #include "ui/message_center/message_center_style.h" | 69 #include "ui/message_center/message_center_style.h" |
| 51 #include "ui/views/border.h" | 70 #include "ui/views/border.h" |
| 52 #include "ui/views/controls/label.h" | 71 #include "ui/views/controls/label.h" |
| 53 #include "ui/views/view.h" | 72 #include "ui/views/view.h" |
| 54 #include "ui/views/widget/widget.h" | 73 #include "ui/views/widget/widget.h" |
| 55 | 74 |
| 56 #if defined(OS_CHROMEOS) | |
| 57 #include "ash/common/system/chromeos/audio/tray_audio.h" | |
| 58 #include "ash/common/system/chromeos/bluetooth/tray_bluetooth.h" | |
| 59 #include "ash/common/system/chromeos/brightness/tray_brightness.h" | |
| 60 #include "ash/common/system/chromeos/cast/tray_cast.h" | |
| 61 #include "ash/common/system/chromeos/enterprise/tray_enterprise.h" | |
| 62 #include "ash/common/system/chromeos/media_security/multi_profile_media_tray_ite
m.h" | |
| 63 #include "ash/common/system/chromeos/network/tray_network.h" | |
| 64 #include "ash/common/system/chromeos/network/tray_sms.h" | |
| 65 #include "ash/common/system/chromeos/network/tray_vpn.h" | |
| 66 #include "ash/common/system/chromeos/power/power_status.h" | |
| 67 #include "ash/common/system/chromeos/power/tray_power.h" | |
| 68 #include "ash/common/system/chromeos/screen_security/screen_capture_tray_item.h" | |
| 69 #include "ash/common/system/chromeos/screen_security/screen_share_tray_item.h" | |
| 70 #include "ash/common/system/chromeos/session/tray_session_length_limit.h" | |
| 71 #include "ash/common/system/chromeos/settings/tray_settings.h" | |
| 72 #include "ash/common/system/chromeos/supervised/tray_supervised_user.h" | |
| 73 #include "ash/common/system/chromeos/tray_caps_lock.h" | |
| 74 #include "ash/common/system/chromeos/tray_tracing.h" | |
| 75 #include "ash/common/system/ime/tray_ime_chromeos.h" | |
| 76 #include "ui/message_center/message_center.h" | |
| 77 #endif | |
| 78 | |
| 79 using views::TrayBubbleView; | 75 using views::TrayBubbleView; |
| 80 | 76 |
| 81 namespace ash { | 77 namespace ash { |
| 82 | 78 |
| 83 namespace { | 79 namespace { |
| 84 | 80 |
| 85 // A tray item that just reserves space in the tray. | 81 // A tray item that just reserves space in the tray. |
| 86 class PaddingTrayItem : public SystemTrayItem { | 82 class PaddingTrayItem : public SystemTrayItem { |
| 87 public: | 83 public: |
| 88 PaddingTrayItem() : SystemTrayItem(nullptr, UMA_NOT_RECORDED) {} | 84 PaddingTrayItem() : SystemTrayItem(nullptr, UMA_NOT_RECORDED) {} |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 CreateItems(delegate); | 247 CreateItems(delegate); |
| 252 } | 248 } |
| 253 | 249 |
| 254 void SystemTray::Shutdown() { | 250 void SystemTray::Shutdown() { |
| 255 DCHECK(web_notification_tray_); | 251 DCHECK(web_notification_tray_); |
| 256 web_notification_tray_ = nullptr; | 252 web_notification_tray_ = nullptr; |
| 257 } | 253 } |
| 258 | 254 |
| 259 void SystemTray::CreateItems(SystemTrayDelegate* delegate) { | 255 void SystemTray::CreateItems(SystemTrayDelegate* delegate) { |
| 260 const bool use_md = MaterialDesignController::IsSystemTrayMenuMaterial(); | 256 const bool use_md = MaterialDesignController::IsSystemTrayMenuMaterial(); |
| 261 #if !defined(OS_WIN) | 257 |
| 262 // Create user items for each possible user. | 258 // Create user items for each possible user. |
| 263 int maximum_user_profiles = WmShell::Get() | 259 int maximum_user_profiles = WmShell::Get() |
| 264 ->GetSessionStateDelegate() | 260 ->GetSessionStateDelegate() |
| 265 ->GetMaximumNumberOfLoggedInUsers(); | 261 ->GetMaximumNumberOfLoggedInUsers(); |
| 266 for (int i = 0; i < maximum_user_profiles; i++) | 262 for (int i = 0; i < maximum_user_profiles; i++) |
| 267 AddTrayItem(new TrayUser(this, i)); | 263 AddTrayItem(new TrayUser(this, i)); |
| 268 | 264 |
| 269 // Crucially, this trailing padding has to be inside the user item(s). | 265 // Crucially, this trailing padding has to be inside the user item(s). |
| 270 // Otherwise it could be a main axis margin on the tray's box layout. | 266 // Otherwise it could be a main axis margin on the tray's box layout. |
| 271 if (use_md) | 267 if (use_md) |
| 272 AddTrayItem(new PaddingTrayItem()); | 268 AddTrayItem(new PaddingTrayItem()); |
| 273 | 269 |
| 274 if (!use_md && maximum_user_profiles > 1) { | 270 if (!use_md && maximum_user_profiles > 1) { |
| 275 // Add a special double line separator between users and the rest of the | 271 // Add a special double line separator between users and the rest of the |
| 276 // menu if more than one user is logged in. | 272 // menu if more than one user is logged in. |
| 277 AddTrayItem(new TrayUserSeparator(this)); | 273 AddTrayItem(new TrayUserSeparator(this)); |
| 278 } | 274 } |
| 279 #endif | |
| 280 | 275 |
| 281 tray_accessibility_ = new TrayAccessibility(this); | 276 tray_accessibility_ = new TrayAccessibility(this); |
| 282 if (!use_md) | 277 if (!use_md) |
| 283 tray_date_ = new TrayDate(this); | 278 tray_date_ = new TrayDate(this); |
| 284 tray_update_ = new TrayUpdate(this); | 279 tray_update_ = new TrayUpdate(this); |
| 285 | 280 |
| 286 #if defined(OS_CHROMEOS) | |
| 287 AddTrayItem(new TraySessionLengthLimit(this)); | 281 AddTrayItem(new TraySessionLengthLimit(this)); |
| 288 AddTrayItem(new TrayEnterprise(this)); | 282 AddTrayItem(new TrayEnterprise(this)); |
| 289 AddTrayItem(new TraySupervisedUser(this)); | 283 AddTrayItem(new TraySupervisedUser(this)); |
| 290 AddTrayItem(new TrayIME(this)); | 284 AddTrayItem(new TrayIME(this)); |
| 291 AddTrayItem(tray_accessibility_); | 285 AddTrayItem(tray_accessibility_); |
| 292 AddTrayItem(new TrayTracing(this)); | 286 AddTrayItem(new TrayTracing(this)); |
| 293 AddTrayItem(new TrayPower(this, message_center::MessageCenter::Get())); | 287 AddTrayItem(new TrayPower(this, message_center::MessageCenter::Get())); |
| 294 tray_network_ = new TrayNetwork(this); | 288 tray_network_ = new TrayNetwork(this); |
| 295 AddTrayItem(tray_network_); | 289 AddTrayItem(tray_network_); |
| 296 AddTrayItem(new TrayVPN(this)); | 290 AddTrayItem(new TrayVPN(this)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 314 if (tray_rotation_lock) | 308 if (tray_rotation_lock) |
| 315 AddTrayItem(tray_rotation_lock.release()); | 309 AddTrayItem(tray_rotation_lock.release()); |
| 316 if (!use_md) | 310 if (!use_md) |
| 317 AddTrayItem(new TraySettings(this)); | 311 AddTrayItem(new TraySettings(this)); |
| 318 AddTrayItem(tray_update_); | 312 AddTrayItem(tray_update_); |
| 319 if (use_md) { | 313 if (use_md) { |
| 320 tray_tiles_ = new TrayTiles(this); | 314 tray_tiles_ = new TrayTiles(this); |
| 321 AddTrayItem(tray_tiles_); | 315 AddTrayItem(tray_tiles_); |
| 322 tray_system_info_ = new TraySystemInfo(this); | 316 tray_system_info_ = new TraySystemInfo(this); |
| 323 AddTrayItem(tray_system_info_); | 317 AddTrayItem(tray_system_info_); |
| 318 // Leading padding. |
| 319 AddTrayItem(new PaddingTrayItem()); |
| 324 } else { | 320 } else { |
| 325 AddTrayItem(tray_date_); | 321 AddTrayItem(tray_date_); |
| 326 } | 322 } |
| 327 #elif defined(OS_WIN) | |
| 328 AddTrayItem(tray_accessibility_); | |
| 329 AddTrayItem(tray_update_); | |
| 330 if (!use_md) | |
| 331 AddTrayItem(tray_date_); | |
| 332 #endif | |
| 333 // Leading padding. | |
| 334 if (use_md) | |
| 335 AddTrayItem(new PaddingTrayItem()); | |
| 336 } | 323 } |
| 337 | 324 |
| 338 void SystemTray::AddTrayItem(SystemTrayItem* item) { | 325 void SystemTray::AddTrayItem(SystemTrayItem* item) { |
| 339 items_.push_back(item); | 326 items_.push_back(item); |
| 340 | 327 |
| 341 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 328 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 342 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus()); | 329 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus()); |
| 343 item->UpdateAfterShelfAlignmentChange(shelf_alignment()); | 330 item->UpdateAfterShelfAlignmentChange(shelf_alignment()); |
| 344 | 331 |
| 345 if (tray_item) { | 332 if (tray_item) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 507 |
| 521 void SystemTray::DestroyNotificationBubble() { | 508 void SystemTray::DestroyNotificationBubble() { |
| 522 if (notification_bubble_) { | 509 if (notification_bubble_) { |
| 523 notification_bubble_.reset(); | 510 notification_bubble_.reset(); |
| 524 UpdateWebNotifications(); | 511 UpdateWebNotifications(); |
| 525 } | 512 } |
| 526 } | 513 } |
| 527 | 514 |
| 528 base::string16 SystemTray::GetAccessibleNameForTray() { | 515 base::string16 SystemTray::GetAccessibleNameForTray() { |
| 529 base::string16 time = GetAccessibleTimeString(base::Time::Now()); | 516 base::string16 time = GetAccessibleTimeString(base::Time::Now()); |
| 530 base::string16 battery = base::ASCIIToUTF16(""); | 517 base::string16 battery = PowerStatus::Get()->GetAccessibleNameString(false); |
| 531 #if defined(OS_CHROMEOS) | |
| 532 battery = PowerStatus::Get()->GetAccessibleNameString(false); | |
| 533 #endif | |
| 534 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBLE_DESCRIPTION, | 518 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBLE_DESCRIPTION, |
| 535 time, battery); | 519 time, battery); |
| 536 } | 520 } |
| 537 | 521 |
| 538 void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items, | 522 void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items, |
| 539 bool detailed, | 523 bool detailed, |
| 540 bool can_activate, | 524 bool can_activate, |
| 541 BubbleCreationType creation_type, | 525 BubbleCreationType creation_type, |
| 542 bool persistent) { | 526 bool persistent) { |
| 543 // No system tray bubbles in kiosk mode. | 527 // No system tray bubbles in kiosk mode. |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 .work_area() | 895 .work_area() |
| 912 .height(); | 896 .height(); |
| 913 if (work_area_height > 0) { | 897 if (work_area_height > 0) { |
| 914 UMA_HISTOGRAM_CUSTOM_COUNTS( | 898 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 915 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", | 899 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", |
| 916 100 * bubble_view->height() / work_area_height, 1, 300, 100); | 900 100 * bubble_view->height() / work_area_height, 1, 300, 100); |
| 917 } | 901 } |
| 918 } | 902 } |
| 919 | 903 |
| 920 } // namespace ash | 904 } // namespace ash |
| OLD | NEW |