Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: ash/common/system/tray/system_tray.cc

Issue 2576133002: chromeos: Remove OS ifdefs from ash/common/system/tray (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 20 matching lines...) Expand all
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_);
324 } else { 318 } else {
325 AddTrayItem(tray_date_); 319 AddTrayItem(tray_date_);
326 } 320 }
327 #elif defined(OS_WIN) 321
328 AddTrayItem(tray_accessibility_);
329 AddTrayItem(tray_update_);
330 if (!use_md)
331 AddTrayItem(tray_date_);
332 #endif
333 // Leading padding. 322 // Leading padding.
334 if (use_md) 323 if (use_md)
335 AddTrayItem(new PaddingTrayItem()); 324 AddTrayItem(new PaddingTrayItem());
msw 2016/12/14 22:51:00 optional nit: fold into the end of the |if (use_md
James Cook 2016/12/14 23:46:08 Done.
336 } 325 }
337 326
338 void SystemTray::AddTrayItem(SystemTrayItem* item) { 327 void SystemTray::AddTrayItem(SystemTrayItem* item) {
339 items_.push_back(item); 328 items_.push_back(item);
340 329
341 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 330 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
342 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus()); 331 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus());
343 item->UpdateAfterShelfAlignmentChange(shelf_alignment()); 332 item->UpdateAfterShelfAlignmentChange(shelf_alignment());
344 333
345 if (tray_item) { 334 if (tray_item) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 } 508 }
520 509
521 void SystemTray::DestroyNotificationBubble() { 510 void SystemTray::DestroyNotificationBubble() {
522 if (notification_bubble_) { 511 if (notification_bubble_) {
523 notification_bubble_.reset(); 512 notification_bubble_.reset();
524 UpdateWebNotifications(); 513 UpdateWebNotifications();
525 } 514 }
526 } 515 }
527 516
528 base::string16 SystemTray::GetAccessibleNameForTray() { 517 base::string16 SystemTray::GetAccessibleNameForTray() {
529 base::string16 time = GetAccessibleTimeString(base::Time::Now()); 518 base::string16 time = GetAccessibleTimeString(base::Time::Now());
msw 2016/12/14 22:51:00 optional nit: inline locals into the function call
James Cook 2016/12/14 23:46:08 I tried it and it seemed less readable (the wrappi
530 base::string16 battery = base::ASCIIToUTF16(""); 519 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, 520 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBLE_DESCRIPTION,
535 time, battery); 521 time, battery);
536 } 522 }
537 523
538 void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items, 524 void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items,
539 bool detailed, 525 bool detailed,
540 bool can_activate, 526 bool can_activate,
541 BubbleCreationType creation_type, 527 BubbleCreationType creation_type,
542 bool persistent) { 528 bool persistent) {
543 // No system tray bubbles in kiosk mode. 529 // No system tray bubbles in kiosk mode.
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 .work_area() 897 .work_area()
912 .height(); 898 .height();
913 if (work_area_height > 0) { 899 if (work_area_height > 0) {
914 UMA_HISTOGRAM_CUSTOM_COUNTS( 900 UMA_HISTOGRAM_CUSTOM_COUNTS(
915 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", 901 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu",
916 100 * bubble_view->height() / work_area_height, 1, 300, 100); 902 100 * bubble_view->height() / work_area_height, 1, 300, 100);
917 } 903 }
918 } 904 }
919 905
920 } // namespace ash 906 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698