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

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

Issue 2330403002: Do not activate system tray bubble by default (Closed)
Patch Set: Do not activate system tray bubble Created 4 years, 3 months 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 "ash/common/key_event_watcher.h"
7 #include "ash/common/login_status.h" 8 #include "ash/common/login_status.h"
8 #include "ash/common/material_design/material_design_controller.h" 9 #include "ash/common/material_design/material_design_controller.h"
9 #include "ash/common/session/session_state_delegate.h" 10 #include "ash/common/session/session_state_delegate.h"
10 #include "ash/common/shelf/wm_shelf.h" 11 #include "ash/common/shelf/wm_shelf.h"
11 #include "ash/common/shelf/wm_shelf_util.h" 12 #include "ash/common/shelf/wm_shelf_util.h"
12 #include "ash/common/shell_window_ids.h" 13 #include "ash/common/shell_window_ids.h"
13 #include "ash/common/system/cast/tray_cast.h" 14 #include "ash/common/system/cast/tray_cast.h"
14 #include "ash/common/system/date/tray_date.h" 15 #include "ash/common/system/date/tray_date.h"
15 #include "ash/common/system/tray/system_tray_delegate.h" 16 #include "ash/common/system/tray/system_tray_delegate.h"
16 #include "ash/common/system/tray/system_tray_item.h" 17 #include "ash/common/system/tray/system_tray_item.h"
17 #include "ash/common/system/tray/tray_bubble_wrapper.h" 18 #include "ash/common/system/tray/tray_bubble_wrapper.h"
18 #include "ash/common/system/tray/tray_constants.h" 19 #include "ash/common/system/tray/tray_constants.h"
19 #include "ash/common/system/tray_accessibility.h" 20 #include "ash/common/system/tray_accessibility.h"
20 #include "ash/common/system/update/tray_update.h" 21 #include "ash/common/system/update/tray_update.h"
21 #include "ash/common/system/user/tray_user.h" 22 #include "ash/common/system/user/tray_user.h"
22 #include "ash/common/system/user/tray_user_separator.h" 23 #include "ash/common/system/user/tray_user_separator.h"
23 #include "ash/common/system/web_notification/web_notification_tray.h" 24 #include "ash/common/system/web_notification/web_notification_tray.h"
24 #include "ash/common/wm_lookup.h" 25 #include "ash/common/wm_lookup.h"
25 #include "ash/common/wm_root_window_controller.h" 26 #include "ash/common/wm_root_window_controller.h"
26 #include "ash/common/wm_shell.h" 27 #include "ash/common/wm_shell.h"
27 #include "ash/common/wm_window.h" 28 #include "ash/common/wm_window.h"
28 #include "base/logging.h" 29 #include "base/logging.h"
29 #include "base/metrics/histogram.h" 30 #include "base/metrics/histogram.h"
30 #include "base/strings/utf_string_conversions.h" 31 #include "base/strings/utf_string_conversions.h"
31 #include "base/timer/timer.h" 32 #include "base/timer/timer.h"
32 #include "grit/ash_strings.h" 33 #include "grit/ash_strings.h"
34 #include "ui/base/accelerators/accelerator.h"
33 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/compositor/layer.h" 36 #include "ui/compositor/layer.h"
35 #include "ui/display/display.h" 37 #include "ui/display/display.h"
36 #include "ui/display/screen.h" 38 #include "ui/display/screen.h"
37 #include "ui/events/event_constants.h" 39 #include "ui/events/event_constants.h"
38 #include "ui/gfx/canvas.h" 40 #include "ui/gfx/canvas.h"
39 #include "ui/gfx/skia_util.h" 41 #include "ui/gfx/skia_util.h"
40 #include "ui/views/border.h" 42 #include "ui/views/border.h"
41 #include "ui/views/controls/label.h" 43 #include "ui/views/controls/label.h"
42 #include "ui/views/view.h" 44 #include "ui/views/view.h"
(...skipping 14 matching lines...) Expand all
57 #include "ash/common/system/chromeos/screen_security/screen_share_tray_item.h" 59 #include "ash/common/system/chromeos/screen_security/screen_share_tray_item.h"
58 #include "ash/common/system/chromeos/session/tray_session_length_limit.h" 60 #include "ash/common/system/chromeos/session/tray_session_length_limit.h"
59 #include "ash/common/system/chromeos/settings/tray_settings.h" 61 #include "ash/common/system/chromeos/settings/tray_settings.h"
60 #include "ash/common/system/chromeos/supervised/tray_supervised_user.h" 62 #include "ash/common/system/chromeos/supervised/tray_supervised_user.h"
61 #include "ash/common/system/chromeos/tray_caps_lock.h" 63 #include "ash/common/system/chromeos/tray_caps_lock.h"
62 #include "ash/common/system/chromeos/tray_tracing.h" 64 #include "ash/common/system/chromeos/tray_tracing.h"
63 #include "ash/common/system/ime/tray_ime_chromeos.h" 65 #include "ash/common/system/ime/tray_ime_chromeos.h"
64 #include "ui/message_center/message_center.h" 66 #include "ui/message_center/message_center.h"
65 #endif 67 #endif
66 68
69 #include "base/debug/stack_trace.h"
James Cook 2016/09/22 21:17:16 remove
oshima 2016/09/23 09:37:20 Oops, done.
70
67 using views::TrayBubbleView; 71 using views::TrayBubbleView;
68 72
69 namespace ash { 73 namespace ash {
70 74
71 // The minimum width of the system tray menu. 75 // The minimum width of the system tray menu.
72 const int kMinimumSystemTrayMenuWidth = 300; 76 const int kMinimumSystemTrayMenuWidth = 300;
73 const int kMinimumSystemTrayMenuWidthMd = 332; 77 const int kMinimumSystemTrayMenuWidthMd = 332;
74 78
75 // Class to initialize and manage the SystemTrayBubble and TrayBubbleWrapper 79 // Class to initialize and manage the SystemTrayBubble and TrayBubbleWrapper
76 // instances for a bubble. 80 // instances for a bubble.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 tray_cast_(nullptr), 137 tray_cast_(nullptr),
134 tray_date_(nullptr), 138 tray_date_(nullptr),
135 tray_update_(nullptr), 139 tray_update_(nullptr),
136 screen_capture_tray_item_(nullptr), 140 screen_capture_tray_item_(nullptr),
137 screen_share_tray_item_(nullptr) { 141 screen_share_tray_item_(nullptr) {
138 SetContentsBackground(); 142 SetContentsBackground();
139 } 143 }
140 144
141 SystemTray::~SystemTray() { 145 SystemTray::~SystemTray() {
142 // Destroy any child views that might have back pointers before ~View(). 146 // Destroy any child views that might have back pointers before ~View().
147 key_event_watcher_.reset();
143 system_bubble_.reset(); 148 system_bubble_.reset();
144 notification_bubble_.reset(); 149 notification_bubble_.reset();
145 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); 150 for (std::vector<SystemTrayItem*>::iterator it = items_.begin();
146 it != items_.end(); ++it) { 151 it != items_.end(); ++it) {
147 (*it)->DestroyTrayView(); 152 (*it)->DestroyTrayView();
148 } 153 }
149 } 154 }
150 155
151 void SystemTray::InitializeTrayItems( 156 void SystemTray::InitializeTrayItems(
152 SystemTrayDelegate* delegate, 157 SystemTrayDelegate* delegate,
153 WebNotificationTray* web_notification_tray) { 158 WebNotificationTray* web_notification_tray) {
154 DCHECK(web_notification_tray); 159 DCHECK(web_notification_tray);
155 web_notification_tray_ = web_notification_tray; 160 web_notification_tray_ = web_notification_tray;
156 TrayBackgroundView::Initialize(); 161 TrayBackgroundView::Initialize();
157 CreateItems(delegate); 162 CreateItems(delegate);
158 } 163 }
159 164
160 void SystemTray::Shutdown() { 165 void SystemTray::Shutdown() {
161 DCHECK(web_notification_tray_); 166 DCHECK(web_notification_tray_);
167 key_event_watcher_.reset();
James Cook 2016/09/22 21:17:16 Does this need to be both here and in destructor?
oshima 2016/09/23 09:37:19 Yes, it is in dtor too.
James Cook 2016/09/23 16:32:28 I meant, does it have to be in the destructor? In
oshima 2016/09/23 19:19:53 It should actually be dtor, where the bubble is re
162 web_notification_tray_ = nullptr; 168 web_notification_tray_ = nullptr;
163 } 169 }
164 170
165 void SystemTray::CreateItems(SystemTrayDelegate* delegate) { 171 void SystemTray::CreateItems(SystemTrayDelegate* delegate) {
166 WmShell* wm_shell = WmShell::Get(); 172 WmShell* wm_shell = WmShell::Get();
167 #if !defined(OS_WIN) 173 #if !defined(OS_WIN)
168 // Create user items for each possible user. 174 // Create user items for each possible user.
169 int maximum_user_profiles = 175 int maximum_user_profiles =
170 wm_shell->GetSessionStateDelegate()->GetMaximumNumberOfLoggedInUsers(); 176 wm_shell->GetSessionStateDelegate()->GetMaximumNumberOfLoggedInUsers();
171 for (int i = 0; i < maximum_user_profiles; i++) 177 for (int i = 0; i < maximum_user_profiles; i++)
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 void SystemTray::ShowDefaultViewWithOffset(BubbleCreationType creation_type, 452 void SystemTray::ShowDefaultViewWithOffset(BubbleCreationType creation_type,
447 int arrow_offset, 453 int arrow_offset,
448 bool persistent) { 454 bool persistent) {
449 if (creation_type != BUBBLE_USE_EXISTING) 455 if (creation_type != BUBBLE_USE_EXISTING)
450 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_MENU_OPENED); 456 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_MENU_OPENED);
451 ShowItems(items_.get(), false, true, creation_type, arrow_offset, persistent); 457 ShowItems(items_.get(), false, true, creation_type, arrow_offset, persistent);
452 } 458 }
453 459
454 void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items, 460 void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items,
455 bool detailed, 461 bool detailed,
456 bool can_activate, 462 bool can_activate,
James Cook 2016/09/22 21:17:16 This needs to be renamed. It no longer means "can
oshima 2016/09/23 09:37:20 The name should have been "activate", and that's w
457 BubbleCreationType creation_type, 463 BubbleCreationType creation_type,
458 int arrow_offset, 464 int arrow_offset,
459 bool persistent) { 465 bool persistent) {
460 // No system tray bubbles in kiosk mode. 466 // No system tray bubbles in kiosk mode.
461 if (WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() == 467 if (WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() ==
462 LoginStatus::KIOSK_APP) { 468 LoginStatus::KIOSK_APP) {
463 return; 469 return;
464 } 470 }
465 471
466 // Destroy any existing bubble and create a new one. 472 // Destroy any existing bubble and create a new one.
(...skipping 24 matching lines...) Expand all
491 // The menu width is fixed, and it is a per language setting. 497 // The menu width is fixed, and it is a per language setting.
492 int menu_width = std::max( 498 int menu_width = std::max(
493 MaterialDesignController::IsSystemTrayMenuMaterial() 499 MaterialDesignController::IsSystemTrayMenuMaterial()
494 ? kMinimumSystemTrayMenuWidthMd 500 ? kMinimumSystemTrayMenuWidthMd
495 : kMinimumSystemTrayMenuWidth, 501 : kMinimumSystemTrayMenuWidth,
496 WmShell::Get()->system_tray_delegate()->GetSystemTrayMenuWidth()); 502 WmShell::Get()->system_tray_delegate()->GetSystemTrayMenuWidth());
497 503
498 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, 504 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY,
499 GetAnchorAlignment(), menu_width, 505 GetAnchorAlignment(), menu_width,
500 kTrayPopupMaxWidth); 506 kTrayPopupMaxWidth);
501 init_params.can_activate = can_activate; 507 // TODO(oshima): Change TrayBubbleView itself.
508 init_params.can_activate = false;
502 init_params.first_item_has_no_margin = true; 509 init_params.first_item_has_no_margin = true;
503 if (detailed) { 510 if (detailed) {
504 // This is the case where a volume control or brightness control bubble 511 // This is the case where a volume control or brightness control bubble
505 // is created. 512 // is created.
506 init_params.max_height = default_bubble_height_; 513 init_params.max_height = default_bubble_height_;
507 init_params.arrow_color = kBackgroundColor; 514 init_params.arrow_color = kBackgroundColor;
508 } else { 515 } else {
509 init_params.arrow_color = kHeaderBackgroundColor; 516 init_params.arrow_color = kHeaderBackgroundColor;
510 } 517 }
511 init_params.arrow_offset = arrow_offset; 518 init_params.arrow_offset = arrow_offset;
(...skipping 10 matching lines...) Expand all
522 system_bubble_->InitView(this, tray_container(), &init_params, persistent); 529 system_bubble_->InitView(this, tray_container(), &init_params, persistent);
523 530
524 // Record metrics for the system menu when the default view is invoked. 531 // Record metrics for the system menu when the default view is invoked.
525 if (!detailed) 532 if (!detailed)
526 RecordSystemMenuMetrics(); 533 RecordSystemMenuMetrics();
527 } 534 }
528 // Save height of default view for creating detailed views directly. 535 // Save height of default view for creating detailed views directly.
529 if (!detailed) 536 if (!detailed)
530 default_bubble_height_ = system_bubble_->bubble_view()->height(); 537 default_bubble_height_ = system_bubble_->bubble_view()->height();
531 538
539 key_event_watcher_.reset();
James Cook 2016/09/22 21:17:16 optional: This might be clearer in an else{} claus
oshima 2016/09/23 09:37:19 I prefer this way because this can avoid potential
540 if (can_activate) {
James Cook 2016/09/22 21:17:16 Document what you are doing in this block of code
oshima 2016/09/23 09:37:20 Done.
541 key_event_watcher_ = WmShell::Get()->CreateKeyEventWatcher();
542 key_event_watcher_->AddKeyEventCallback(
543 ui::Accelerator(ui::VKEY_ESCAPE, 0),
James Cook 2016/09/22 21:17:16 0 -> EF_NONE
oshima 2016/09/23 09:37:19 Done.
544 base::Bind(&SystemTray::CloseBubble, base::Unretained(this)));
545 key_event_watcher_->AddKeyEventCallback(
546 ui::Accelerator(ui::VKEY_TAB, 0),
547 base::Bind(&SystemTray::ActivateAndStartNavigation,
548 base::Unretained(this)));
549 key_event_watcher_->AddKeyEventCallback(
550 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN),
551 base::Bind(&SystemTray::ActivateAndStartNavigation,
552 base::Unretained(this)));
553 }
554
532 if (detailed && items.size() > 0) 555 if (detailed && items.size() > 0)
533 detailed_item_ = items[0]; 556 detailed_item_ = items[0];
534 else 557 else
535 detailed_item_ = NULL; 558 detailed_item_ = NULL;
536 559
537 UpdateNotificationBubble(); // State changed, re-create notifications. 560 UpdateNotificationBubble(); // State changed, re-create notifications.
538 if (!notification_bubble_) 561 if (!notification_bubble_)
539 UpdateWebNotifications(); 562 UpdateWebNotifications();
540 shelf()->UpdateAutoHideState(); 563 shelf()->UpdateAutoHideState();
541 564
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 } 747 }
725 748
726 TrayDate* SystemTray::GetTrayDateForTesting() const { 749 TrayDate* SystemTray::GetTrayDateForTesting() const {
727 return tray_date_; 750 return tray_date_;
728 } 751 }
729 752
730 TrayUpdate* SystemTray::GetTrayUpdateForTesting() const { 753 TrayUpdate* SystemTray::GetTrayUpdateForTesting() const {
731 return tray_update_; 754 return tray_update_;
732 } 755 }
733 756
757 void SystemTray::CloseBubble(const ui::KeyEvent& key_event) {
758 CloseSystemBubble();
759 }
760
761 void SystemTray::ActivateAndStartNavigation(const ui::KeyEvent& key_event) {
762 if (!system_bubble_)
763 return;
764 ActivateBubble();
765 views::Widget* widget = GetSystemBubble()->bubble_view()->GetWidget();
766 widget->GetFocusManager()->OnKeyEvent(key_event);
767 }
768
769 void SystemTray::ActivateBubble() {
770 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view();
771 bubble_view->set_can_activate(true);
772 bubble_view->GetWidget()->Activate();
773 }
774
734 bool SystemTray::PerformAction(const ui::Event& event) { 775 bool SystemTray::PerformAction(const ui::Event& event) {
735 // If we're already showing the default view, hide it; otherwise, show it 776 // If we're already showing the default view, hide it; otherwise, show it
736 // (and hide any popup that's currently shown). 777 // (and hide any popup that's currently shown).
737 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { 778 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) {
738 system_bubble_->bubble()->Close(); 779 system_bubble_->bubble()->Close();
739 } else { 780 } else {
740 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; 781 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset;
741 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { 782 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) {
742 const ui::LocatedEvent& located_event = 783 const ui::LocatedEvent& located_event =
743 static_cast<const ui::LocatedEvent&>(event); 784 static_cast<const ui::LocatedEvent&>(event);
744 if (IsHorizontalAlignment(shelf_alignment())) { 785 if (IsHorizontalAlignment(shelf_alignment())) {
745 gfx::Point point(located_event.x(), 0); 786 gfx::Point point(located_event.x(), 0);
746 ConvertPointToWidget(this, &point); 787 ConvertPointToWidget(this, &point);
747 arrow_offset = point.x(); 788 arrow_offset = point.x();
748 } 789 }
749 } 790 }
750 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset, false); 791 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset, false);
751 } 792 }
752 return true; 793 return true;
753 } 794 }
754 795
755 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { 796 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() {
797 key_event_watcher_.reset();
756 system_bubble_.reset(); 798 system_bubble_.reset();
757 // When closing a system bubble with the alternate shelf layout, we need to 799 // When closing a system bubble with the alternate shelf layout, we need to
758 // turn off the active tinting of the shelf. 800 // turn off the active tinting of the shelf.
759 if (full_system_tray_menu_) { 801 if (full_system_tray_menu_) {
760 SetDrawBackgroundAsActive(false); 802 SetDrawBackgroundAsActive(false);
761 full_system_tray_menu_ = false; 803 full_system_tray_menu_ = false;
762 } 804 }
763 } 805 }
764 806
765 void SystemTray::RecordSystemMenuMetrics() { 807 void SystemTray::RecordSystemMenuMetrics() {
(...skipping 17 matching lines...) Expand all
783 .work_area() 825 .work_area()
784 .height(); 826 .height();
785 if (work_area_height > 0) { 827 if (work_area_height > 0) {
786 UMA_HISTOGRAM_CUSTOM_COUNTS( 828 UMA_HISTOGRAM_CUSTOM_COUNTS(
787 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", 829 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu",
788 100 * bubble_view->height() / work_area_height, 1, 300, 100); 830 100 * bubble_view->height() / work_area_height, 1, 300, 100);
789 } 831 }
790 } 832 }
791 833
792 } // namespace ash 834 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698