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" | |
14 #include "ash/common/session/session_controller.h" | 13 #include "ash/common/session/session_controller.h" |
15 #include "ash/common/shelf/wm_shelf.h" | 14 #include "ash/common/shelf/wm_shelf.h" |
16 #include "ash/common/shelf/wm_shelf_util.h" | 15 #include "ash/common/shelf/wm_shelf_util.h" |
17 #include "ash/common/system/chromeos/audio/tray_audio.h" | 16 #include "ash/common/system/chromeos/audio/tray_audio.h" |
18 #include "ash/common/system/chromeos/bluetooth/tray_bluetooth.h" | 17 #include "ash/common/system/chromeos/bluetooth/tray_bluetooth.h" |
19 #include "ash/common/system/chromeos/brightness/tray_brightness.h" | 18 #include "ash/common/system/chromeos/brightness/tray_brightness.h" |
20 #include "ash/common/system/chromeos/cast/tray_cast.h" | 19 #include "ash/common/system/chromeos/cast/tray_cast.h" |
21 #include "ash/common/system/chromeos/enterprise/tray_enterprise.h" | 20 #include "ash/common/system/chromeos/enterprise/tray_enterprise.h" |
22 #include "ash/common/system/chromeos/media_security/multi_profile_media_tray_ite
m.h" | 21 #include "ash/common/system/chromeos/media_security/multi_profile_media_tray_ite
m.h" |
23 #include "ash/common/system/chromeos/network/tray_network.h" | 22 #include "ash/common/system/chromeos/network/tray_network.h" |
24 #include "ash/common/system/chromeos/network/tray_vpn.h" | 23 #include "ash/common/system/chromeos/network/tray_vpn.h" |
25 #include "ash/common/system/chromeos/power/power_status.h" | 24 #include "ash/common/system/chromeos/power/power_status.h" |
26 #include "ash/common/system/chromeos/power/tray_power.h" | 25 #include "ash/common/system/chromeos/power/tray_power.h" |
27 #include "ash/common/system/chromeos/screen_security/screen_capture_tray_item.h" | 26 #include "ash/common/system/chromeos/screen_security/screen_capture_tray_item.h" |
28 #include "ash/common/system/chromeos/screen_security/screen_share_tray_item.h" | 27 #include "ash/common/system/chromeos/screen_security/screen_share_tray_item.h" |
29 #include "ash/common/system/chromeos/session/tray_session_length_limit.h" | 28 #include "ash/common/system/chromeos/session/tray_session_length_limit.h" |
30 #include "ash/common/system/chromeos/supervised/tray_supervised_user.h" | 29 #include "ash/common/system/chromeos/supervised/tray_supervised_user.h" |
31 #include "ash/common/system/chromeos/tray_caps_lock.h" | 30 #include "ash/common/system/chromeos/tray_caps_lock.h" |
32 #include "ash/common/system/chromeos/tray_tracing.h" | 31 #include "ash/common/system/chromeos/tray_tracing.h" |
33 #include "ash/common/system/date/tray_date.h" | |
34 #include "ash/common/system/date/tray_system_info.h" | 32 #include "ash/common/system/date/tray_system_info.h" |
35 #include "ash/common/system/ime/tray_ime_chromeos.h" | 33 #include "ash/common/system/ime/tray_ime_chromeos.h" |
36 #include "ash/common/system/tiles/tray_tiles.h" | 34 #include "ash/common/system/tiles/tray_tiles.h" |
37 #include "ash/common/system/tray/system_tray_controller.h" | 35 #include "ash/common/system/tray/system_tray_controller.h" |
38 #include "ash/common/system/tray/system_tray_delegate.h" | 36 #include "ash/common/system/tray/system_tray_delegate.h" |
39 #include "ash/common/system/tray/system_tray_item.h" | 37 #include "ash/common/system/tray/system_tray_item.h" |
40 #include "ash/common/system/tray/tray_bubble_wrapper.h" | 38 #include "ash/common/system/tray/tray_bubble_wrapper.h" |
41 #include "ash/common/system/tray/tray_constants.h" | 39 #include "ash/common/system/tray/tray_constants.h" |
42 #include "ash/common/system/tray_accessibility.h" | 40 #include "ash/common/system/tray_accessibility.h" |
43 #include "ash/common/system/update/tray_update.h" | 41 #include "ash/common/system/update/tray_update.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 212 |
215 SystemTray::SystemTray(WmShelf* wm_shelf) | 213 SystemTray::SystemTray(WmShelf* wm_shelf) |
216 : TrayBackgroundView(wm_shelf, true), | 214 : TrayBackgroundView(wm_shelf, true), |
217 web_notification_tray_(nullptr), | 215 web_notification_tray_(nullptr), |
218 detailed_item_(nullptr), | 216 detailed_item_(nullptr), |
219 default_bubble_height_(0), | 217 default_bubble_height_(0), |
220 full_system_tray_menu_(false), | 218 full_system_tray_menu_(false), |
221 tray_accessibility_(nullptr), | 219 tray_accessibility_(nullptr), |
222 tray_audio_(nullptr), | 220 tray_audio_(nullptr), |
223 tray_cast_(nullptr), | 221 tray_cast_(nullptr), |
224 tray_date_(nullptr), | |
225 tray_network_(nullptr), | 222 tray_network_(nullptr), |
226 tray_tiles_(nullptr), | 223 tray_tiles_(nullptr), |
227 tray_system_info_(nullptr), | 224 tray_system_info_(nullptr), |
228 tray_update_(nullptr), | 225 tray_update_(nullptr), |
229 screen_capture_tray_item_(nullptr), | 226 screen_capture_tray_item_(nullptr), |
230 screen_share_tray_item_(nullptr) { | 227 screen_share_tray_item_(nullptr) { |
231 if (MaterialDesignController::IsShelfMaterial()) { | 228 SetInkDropMode(InkDropMode::ON); |
232 SetInkDropMode(InkDropMode::ON); | |
233 | 229 |
234 // Since user avatar is on the right hand side of System tray of a | 230 // Since user avatar is on the right hand side of System tray of a |
235 // horizontal shelf and that is sufficient to indicate separation, no | 231 // horizontal shelf and that is sufficient to indicate separation, no |
236 // separator is required. | 232 // separator is required. |
237 set_separator_visibility(false); | 233 set_separator_visibility(false); |
238 } | |
239 } | 234 } |
240 | 235 |
241 SystemTray::~SystemTray() { | 236 SystemTray::~SystemTray() { |
242 // Destroy any child views that might have back pointers before ~View(). | 237 // Destroy any child views that might have back pointers before ~View(). |
243 activation_observer_.reset(); | 238 activation_observer_.reset(); |
244 key_event_watcher_.reset(); | 239 key_event_watcher_.reset(); |
245 system_bubble_.reset(); | 240 system_bubble_.reset(); |
246 for (const auto& item : items_) | 241 for (const auto& item : items_) |
247 item->DestroyTrayView(); | 242 item->DestroyTrayView(); |
248 } | 243 } |
249 | 244 |
250 void SystemTray::InitializeTrayItems( | 245 void SystemTray::InitializeTrayItems( |
251 SystemTrayDelegate* delegate, | 246 SystemTrayDelegate* delegate, |
252 WebNotificationTray* web_notification_tray) { | 247 WebNotificationTray* web_notification_tray) { |
253 DCHECK(web_notification_tray); | 248 DCHECK(web_notification_tray); |
254 web_notification_tray_ = web_notification_tray; | 249 web_notification_tray_ = web_notification_tray; |
255 TrayBackgroundView::Initialize(); | 250 TrayBackgroundView::Initialize(); |
256 CreateItems(delegate); | 251 CreateItems(delegate); |
257 } | 252 } |
258 | 253 |
259 void SystemTray::Shutdown() { | 254 void SystemTray::Shutdown() { |
260 DCHECK(web_notification_tray_); | 255 DCHECK(web_notification_tray_); |
261 web_notification_tray_ = nullptr; | 256 web_notification_tray_ = nullptr; |
262 } | 257 } |
263 | 258 |
264 void SystemTray::CreateItems(SystemTrayDelegate* delegate) { | 259 void SystemTray::CreateItems(SystemTrayDelegate* delegate) { |
265 const bool use_md = MaterialDesignController::IsSystemTrayMenuMaterial(); | |
266 | |
267 // Create user items for each possible user. | 260 // Create user items for each possible user. |
268 const int maximum_user_profiles = | 261 const int maximum_user_profiles = |
269 Shell::Get()->session_controller()->GetMaximumNumberOfLoggedInUsers(); | 262 Shell::Get()->session_controller()->GetMaximumNumberOfLoggedInUsers(); |
270 for (int i = 0; i < maximum_user_profiles; i++) | 263 for (int i = 0; i < maximum_user_profiles; i++) |
271 AddTrayItem(base::MakeUnique<TrayUser>(this, i)); | 264 AddTrayItem(base::MakeUnique<TrayUser>(this, i)); |
272 | 265 |
273 // Crucially, this trailing padding has to be inside the user item(s). | 266 // Crucially, this trailing padding has to be inside the user item(s). |
274 // Otherwise it could be a main axis margin on the tray's box layout. | 267 // Otherwise it could be a main axis margin on the tray's box layout. |
275 AddTrayItem(base::MakeUnique<PaddingTrayItem>()); | 268 AddTrayItem(base::MakeUnique<PaddingTrayItem>()); |
276 | 269 |
277 tray_accessibility_ = new TrayAccessibility(this); | 270 tray_accessibility_ = new TrayAccessibility(this); |
278 if (!use_md) | |
279 tray_date_ = new TrayDate(this); | |
280 tray_update_ = new TrayUpdate(this); | 271 tray_update_ = new TrayUpdate(this); |
281 | 272 |
282 AddTrayItem(base::MakeUnique<TraySessionLengthLimit>(this)); | 273 AddTrayItem(base::MakeUnique<TraySessionLengthLimit>(this)); |
283 AddTrayItem(base::MakeUnique<TrayEnterprise>(this)); | 274 AddTrayItem(base::MakeUnique<TrayEnterprise>(this)); |
284 AddTrayItem(base::MakeUnique<TraySupervisedUser>(this)); | 275 AddTrayItem(base::MakeUnique<TraySupervisedUser>(this)); |
285 AddTrayItem(base::MakeUnique<TrayIME>(this)); | 276 AddTrayItem(base::MakeUnique<TrayIME>(this)); |
286 AddTrayItem(base::WrapUnique(tray_accessibility_)); | 277 AddTrayItem(base::WrapUnique(tray_accessibility_)); |
287 AddTrayItem(base::MakeUnique<TrayTracing>(this)); | 278 AddTrayItem(base::MakeUnique<TrayTracing>(this)); |
288 AddTrayItem( | 279 AddTrayItem( |
289 base::MakeUnique<TrayPower>(this, message_center::MessageCenter::Get())); | 280 base::MakeUnique<TrayPower>(this, message_center::MessageCenter::Get())); |
(...skipping 12 matching lines...) Expand all Loading... |
302 AddTrayItem(base::WrapUnique(tray_audio_)); | 293 AddTrayItem(base::WrapUnique(tray_audio_)); |
303 AddTrayItem(base::MakeUnique<TrayBrightness>(this)); | 294 AddTrayItem(base::MakeUnique<TrayBrightness>(this)); |
304 AddTrayItem(base::MakeUnique<TrayCapsLock>(this)); | 295 AddTrayItem(base::MakeUnique<TrayCapsLock>(this)); |
305 // TODO(jamescook): Remove this when mus has support for display management | 296 // TODO(jamescook): Remove this when mus has support for display management |
306 // and we have a DisplayManager equivalent. See http://crbug.com/548429 | 297 // and we have a DisplayManager equivalent. See http://crbug.com/548429 |
307 std::unique_ptr<SystemTrayItem> tray_rotation_lock = | 298 std::unique_ptr<SystemTrayItem> tray_rotation_lock = |
308 delegate->CreateRotationLockTrayItem(this); | 299 delegate->CreateRotationLockTrayItem(this); |
309 if (tray_rotation_lock) | 300 if (tray_rotation_lock) |
310 AddTrayItem(std::move(tray_rotation_lock)); | 301 AddTrayItem(std::move(tray_rotation_lock)); |
311 AddTrayItem(base::WrapUnique(tray_update_)); | 302 AddTrayItem(base::WrapUnique(tray_update_)); |
312 if (use_md) { | 303 tray_tiles_ = new TrayTiles(this); |
313 tray_tiles_ = new TrayTiles(this); | 304 AddTrayItem(base::WrapUnique(tray_tiles_)); |
314 AddTrayItem(base::WrapUnique(tray_tiles_)); | 305 tray_system_info_ = new TraySystemInfo(this); |
315 tray_system_info_ = new TraySystemInfo(this); | 306 AddTrayItem(base::WrapUnique(tray_system_info_)); |
316 AddTrayItem(base::WrapUnique(tray_system_info_)); | 307 // Leading padding. |
317 // Leading padding. | 308 AddTrayItem(base::MakeUnique<PaddingTrayItem>()); |
318 AddTrayItem(base::MakeUnique<PaddingTrayItem>()); | |
319 } else { | |
320 AddTrayItem(base::WrapUnique(tray_date_)); | |
321 } | |
322 } | 309 } |
323 | 310 |
324 void SystemTray::AddTrayItem(std::unique_ptr<SystemTrayItem> item) { | 311 void SystemTray::AddTrayItem(std::unique_ptr<SystemTrayItem> item) { |
325 SystemTrayItem* item_ptr = item.get(); | 312 SystemTrayItem* item_ptr = item.get(); |
326 items_.push_back(std::move(item)); | 313 items_.push_back(std::move(item)); |
327 | 314 |
328 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); | 315 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); |
329 views::View* tray_item = | 316 views::View* tray_item = |
330 item_ptr->CreateTrayView(delegate->GetUserLoginStatus()); | 317 item_ptr->CreateTrayView(delegate->GetUserLoginStatus()); |
331 item_ptr->UpdateAfterShelfAlignmentChange(shelf_alignment()); | 318 item_ptr->UpdateAfterShelfAlignmentChange(shelf_alignment()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 420 |
434 bool SystemTray::CloseSystemBubble() const { | 421 bool SystemTray::CloseSystemBubble() const { |
435 if (!system_bubble_) | 422 if (!system_bubble_) |
436 return false; | 423 return false; |
437 CHECK(!activating_); | 424 CHECK(!activating_); |
438 system_bubble_->bubble()->Close(); | 425 system_bubble_->bubble()->Close(); |
439 return true; | 426 return true; |
440 } | 427 } |
441 | 428 |
442 views::View* SystemTray::GetHelpButtonView() const { | 429 views::View* SystemTray::GetHelpButtonView() const { |
443 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | 430 return tray_tiles_->GetHelpButtonView(); |
444 return tray_tiles_->GetHelpButtonView(); | |
445 return tray_date_->GetHelpButtonView(); | |
446 } | 431 } |
447 | 432 |
448 TrayAudio* SystemTray::GetTrayAudio() const { | 433 TrayAudio* SystemTray::GetTrayAudio() const { |
449 return tray_audio_; | 434 return tray_audio_; |
450 } | 435 } |
451 | 436 |
452 // Private methods. | 437 // Private methods. |
453 | 438 |
454 bool SystemTray::HasSystemBubbleType(SystemTrayBubble::BubbleType type) { | 439 bool SystemTray::HasSystemBubbleType(SystemTrayBubble::BubbleType type) { |
455 return system_bubble_.get() && system_bubble_->bubble_type() == type; | 440 return system_bubble_.get() && system_bubble_->bubble_type() == type; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 // destruction, leading to subtle errors/crashes such as crbug.com/545166. | 485 // destruction, leading to subtle errors/crashes such as crbug.com/545166. |
501 DestroySystemBubble(); | 486 DestroySystemBubble(); |
502 | 487 |
503 // Remember if the menu is a single property (like e.g. volume) or the | 488 // Remember if the menu is a single property (like e.g. volume) or the |
504 // full tray menu. Note that in case of the |BUBBLE_USE_EXISTING| case | 489 // full tray menu. Note that in case of the |BUBBLE_USE_EXISTING| case |
505 // above, |full_system_tray_menu_| does not get changed since the fact that | 490 // above, |full_system_tray_menu_| does not get changed since the fact that |
506 // the menu is full (or not) doesn't change even if a "single property" | 491 // the menu is full (or not) doesn't change even if a "single property" |
507 // (like network) replaces most of the menu. | 492 // (like network) replaces most of the menu. |
508 full_system_tray_menu_ = items.size() > 1; | 493 full_system_tray_menu_ = items.size() > 1; |
509 | 494 |
510 // The menu width is fixed for all languages in material design. | 495 TrayBubbleView::InitParams init_params( |
511 int menu_width = kTrayMenuMinimumWidthMd; | 496 GetAnchorAlignment(), kTrayMenuMinimumWidthMd, kTrayPopupMaxWidth); |
512 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) { | |
513 // The menu width is fixed, and it is a per language setting. | |
514 menu_width = std::max( | |
515 kTrayMenuMinimumWidth, | |
516 Shell::Get()->system_tray_delegate()->GetSystemTrayMenuWidth()); | |
517 } | |
518 | |
519 TrayBubbleView::InitParams init_params(GetAnchorAlignment(), menu_width, | |
520 kTrayPopupMaxWidth); | |
521 // TODO(oshima): Change TrayBubbleView itself. | 497 // TODO(oshima): Change TrayBubbleView itself. |
522 init_params.can_activate = false; | 498 init_params.can_activate = false; |
523 if (detailed) { | 499 if (detailed) { |
524 // This is the case where a volume control or brightness control bubble | 500 // This is the case where a volume control or brightness control bubble |
525 // is created. | 501 // is created. |
526 init_params.max_height = default_bubble_height_; | 502 init_params.max_height = default_bubble_height_; |
527 init_params.bg_color = kBackgroundColor; | 503 init_params.bg_color = kBackgroundColor; |
528 } else { | 504 } else { |
529 init_params.bg_color = kHeaderBackgroundColor; | 505 init_params.bg_color = kHeaderBackgroundColor; |
530 } | 506 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 views::View* SystemTray::GetTrayItemViewForTest(SystemTrayItem* item) { | 641 views::View* SystemTray::GetTrayItemViewForTest(SystemTrayItem* item) { |
666 std::map<SystemTrayItem*, views::View*>::iterator it = | 642 std::map<SystemTrayItem*, views::View*>::iterator it = |
667 tray_item_map_.find(item); | 643 tray_item_map_.find(item); |
668 return it == tray_item_map_.end() ? NULL : it->second; | 644 return it == tray_item_map_.end() ? NULL : it->second; |
669 } | 645 } |
670 | 646 |
671 TrayCast* SystemTray::GetTrayCastForTesting() const { | 647 TrayCast* SystemTray::GetTrayCastForTesting() const { |
672 return tray_cast_; | 648 return tray_cast_; |
673 } | 649 } |
674 | 650 |
675 TrayDate* SystemTray::GetTrayDateForTesting() const { | |
676 return tray_date_; | |
677 } | |
678 | |
679 TrayNetwork* SystemTray::GetTrayNetworkForTesting() const { | 651 TrayNetwork* SystemTray::GetTrayNetworkForTesting() const { |
680 return tray_network_; | 652 return tray_network_; |
681 } | 653 } |
682 | 654 |
683 TraySystemInfo* SystemTray::GetTraySystemInfoForTesting() const { | 655 TraySystemInfo* SystemTray::GetTraySystemInfoForTesting() const { |
684 return tray_system_info_; | 656 return tray_system_info_; |
685 } | 657 } |
686 | 658 |
687 TrayTiles* SystemTray::GetTrayTilesForTesting() const { | 659 TrayTiles* SystemTray::GetTrayTilesForTesting() const { |
688 return tray_tiles_; | 660 return tray_tiles_; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 .work_area() | 749 .work_area() |
778 .height(); | 750 .height(); |
779 if (work_area_height > 0) { | 751 if (work_area_height > 0) { |
780 UMA_HISTOGRAM_CUSTOM_COUNTS( | 752 UMA_HISTOGRAM_CUSTOM_COUNTS( |
781 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", | 753 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", |
782 100 * bubble_view->height() / work_area_height, 1, 300, 100); | 754 100 * bubble_view->height() / work_area_height, 1, 300, 100); |
783 } | 755 } |
784 } | 756 } |
785 | 757 |
786 } // namespace ash | 758 } // namespace ash |
OLD | NEW |