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

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 by default 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"
25 #include "ash/common/wm/container_finder.h"
26 #include "ash/common/wm_activation_observer.h"
24 #include "ash/common/wm_lookup.h" 27 #include "ash/common/wm_lookup.h"
25 #include "ash/common/wm_root_window_controller.h" 28 #include "ash/common/wm_root_window_controller.h"
26 #include "ash/common/wm_shell.h" 29 #include "ash/common/wm_shell.h"
27 #include "ash/common/wm_window.h" 30 #include "ash/common/wm_window.h"
28 #include "base/logging.h" 31 #include "base/logging.h"
29 #include "base/metrics/histogram.h" 32 #include "base/metrics/histogram.h"
30 #include "base/strings/utf_string_conversions.h" 33 #include "base/strings/utf_string_conversions.h"
31 #include "base/timer/timer.h" 34 #include "base/timer/timer.h"
32 #include "grit/ash_strings.h" 35 #include "grit/ash_strings.h"
36 #include "ui/base/accelerators/accelerator.h"
33 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/compositor/layer.h" 38 #include "ui/compositor/layer.h"
35 #include "ui/display/display.h" 39 #include "ui/display/display.h"
36 #include "ui/display/screen.h" 40 #include "ui/display/screen.h"
37 #include "ui/events/event_constants.h" 41 #include "ui/events/event_constants.h"
38 #include "ui/gfx/canvas.h" 42 #include "ui/gfx/canvas.h"
39 #include "ui/gfx/skia_util.h" 43 #include "ui/gfx/skia_util.h"
40 #include "ui/views/border.h" 44 #include "ui/views/border.h"
41 #include "ui/views/controls/label.h" 45 #include "ui/views/controls/label.h"
42 #include "ui/views/view.h" 46 #include "ui/views/view.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 bool is_persistent() const { return is_persistent_; } 116 bool is_persistent() const { return is_persistent_; }
113 117
114 private: 118 private:
115 std::unique_ptr<SystemTrayBubble> bubble_; 119 std::unique_ptr<SystemTrayBubble> bubble_;
116 std::unique_ptr<TrayBubbleWrapper> bubble_wrapper_; 120 std::unique_ptr<TrayBubbleWrapper> bubble_wrapper_;
117 bool is_persistent_; 121 bool is_persistent_;
118 122
119 DISALLOW_COPY_AND_ASSIGN(SystemBubbleWrapper); 123 DISALLOW_COPY_AND_ASSIGN(SystemBubbleWrapper);
120 }; 124 };
121 125
126 // An activation observer to close the bubble if the window other
127 // than system bubble nor popup notification is activated.
128 class SystemTray::ActivationObserver : public WmActivationObserver {
129 public:
130 explicit ActivationObserver(SystemTray* tray) : tray_(tray) {
131 WmShell::Get()->AddActivationObserver(this);
James Cook 2016/09/23 16:32:28 optional: DCHECK(tray_). (I've started using DCHE
oshima 2016/09/23 19:19:54 Done.
132 }
133
134 ~ActivationObserver() override {
135 WmShell::Get()->RemoveActivationObserver(this);
136 }
137
138 // WmActivationObserver:
139 void OnWindowActivated(WmWindow* gained_active,
140 WmWindow* lost_active) override {
141 if (!tray_->HasSystemBubble() || !gained_active)
142 return;
143
144 int container_id =
145 wm::GetContainerForWindow(gained_active)->GetShellWindowId();
146
147 // Don't close the bubble if a popup notification is activated.
148 if (container_id == kShellWindowId_StatusContainer)
149 return;
150
151 if (tray_->GetSystemBubble()->bubble_view()->GetWidget() !=
152 gained_active->GetInternalWidget()) {
153 tray_->CloseSystemBubble();
154 }
155 }
156 void OnAttemptToReactivateWindow(WmWindow* request_active,
157 WmWindow* actual_active) override {}
158
159 private:
160 SystemTray* tray_;
161
162 DISALLOW_COPY_AND_ASSIGN(ActivationObserver);
163 };
164
122 // SystemTray 165 // SystemTray
123 166
124 SystemTray::SystemTray(WmShelf* wm_shelf) 167 SystemTray::SystemTray(WmShelf* wm_shelf)
125 : TrayBackgroundView(wm_shelf), 168 : TrayBackgroundView(wm_shelf),
126 web_notification_tray_(nullptr), 169 web_notification_tray_(nullptr),
127 detailed_item_(nullptr), 170 detailed_item_(nullptr),
128 default_bubble_height_(0), 171 default_bubble_height_(0),
129 hide_notifications_(false), 172 hide_notifications_(false),
130 full_system_tray_menu_(false), 173 full_system_tray_menu_(false),
131 tray_accessibility_(nullptr), 174 tray_accessibility_(nullptr),
132 tray_audio_(nullptr), 175 tray_audio_(nullptr),
133 tray_cast_(nullptr), 176 tray_cast_(nullptr),
134 tray_date_(nullptr), 177 tray_date_(nullptr),
135 tray_update_(nullptr), 178 tray_update_(nullptr),
136 screen_capture_tray_item_(nullptr), 179 screen_capture_tray_item_(nullptr),
137 screen_share_tray_item_(nullptr) { 180 screen_share_tray_item_(nullptr) {
138 SetContentsBackground(); 181 SetContentsBackground();
139 } 182 }
140 183
141 SystemTray::~SystemTray() { 184 SystemTray::~SystemTray() {
142 // Destroy any child views that might have back pointers before ~View(). 185 // Destroy any child views that might have back pointers before ~View().
186 activation_observer_.reset();
187 key_event_watcher_.reset();
143 system_bubble_.reset(); 188 system_bubble_.reset();
144 notification_bubble_.reset(); 189 notification_bubble_.reset();
145 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); 190 for (std::vector<SystemTrayItem*>::iterator it = items_.begin();
146 it != items_.end(); ++it) { 191 it != items_.end(); ++it) {
147 (*it)->DestroyTrayView(); 192 (*it)->DestroyTrayView();
148 } 193 }
149 } 194 }
150 195
151 void SystemTray::InitializeTrayItems( 196 void SystemTray::InitializeTrayItems(
152 SystemTrayDelegate* delegate, 197 SystemTrayDelegate* delegate,
153 WebNotificationTray* web_notification_tray) { 198 WebNotificationTray* web_notification_tray) {
154 DCHECK(web_notification_tray); 199 DCHECK(web_notification_tray);
155 web_notification_tray_ = web_notification_tray; 200 web_notification_tray_ = web_notification_tray;
156 TrayBackgroundView::Initialize(); 201 TrayBackgroundView::Initialize();
157 CreateItems(delegate); 202 CreateItems(delegate);
158 } 203 }
159 204
160 void SystemTray::Shutdown() { 205 void SystemTray::Shutdown() {
161 DCHECK(web_notification_tray_); 206 DCHECK(web_notification_tray_);
207 activation_observer_.reset();
208 key_event_watcher_.reset();
162 web_notification_tray_ = nullptr; 209 web_notification_tray_ = nullptr;
163 } 210 }
164 211
165 void SystemTray::CreateItems(SystemTrayDelegate* delegate) { 212 void SystemTray::CreateItems(SystemTrayDelegate* delegate) {
166 WmShell* wm_shell = WmShell::Get(); 213 WmShell* wm_shell = WmShell::Get();
167 #if !defined(OS_WIN) 214 #if !defined(OS_WIN)
168 // Create user items for each possible user. 215 // Create user items for each possible user.
169 int maximum_user_profiles = 216 int maximum_user_profiles =
170 wm_shell->GetSessionStateDelegate()->GetMaximumNumberOfLoggedInUsers(); 217 wm_shell->GetSessionStateDelegate()->GetMaximumNumberOfLoggedInUsers();
171 for (int i = 0; i < maximum_user_profiles; i++) 218 for (int i = 0; i < maximum_user_profiles; i++)
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 // The menu width is fixed, and it is a per language setting. 538 // The menu width is fixed, and it is a per language setting.
492 int menu_width = std::max( 539 int menu_width = std::max(
493 MaterialDesignController::IsSystemTrayMenuMaterial() 540 MaterialDesignController::IsSystemTrayMenuMaterial()
494 ? kMinimumSystemTrayMenuWidthMd 541 ? kMinimumSystemTrayMenuWidthMd
495 : kMinimumSystemTrayMenuWidth, 542 : kMinimumSystemTrayMenuWidth,
496 WmShell::Get()->system_tray_delegate()->GetSystemTrayMenuWidth()); 543 WmShell::Get()->system_tray_delegate()->GetSystemTrayMenuWidth());
497 544
498 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, 545 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY,
499 GetAnchorAlignment(), menu_width, 546 GetAnchorAlignment(), menu_width,
500 kTrayPopupMaxWidth); 547 kTrayPopupMaxWidth);
501 init_params.can_activate = can_activate; 548 // TODO(oshima): Change TrayBubbleView itself.
549 init_params.can_activate = false;
502 init_params.first_item_has_no_margin = true; 550 init_params.first_item_has_no_margin = true;
503 if (detailed) { 551 if (detailed) {
504 // This is the case where a volume control or brightness control bubble 552 // This is the case where a volume control or brightness control bubble
505 // is created. 553 // is created.
506 init_params.max_height = default_bubble_height_; 554 init_params.max_height = default_bubble_height_;
507 init_params.arrow_color = kBackgroundColor; 555 init_params.arrow_color = kBackgroundColor;
508 } else { 556 } else {
509 init_params.arrow_color = kHeaderBackgroundColor; 557 init_params.arrow_color = kHeaderBackgroundColor;
510 } 558 }
511 init_params.arrow_offset = arrow_offset; 559 init_params.arrow_offset = arrow_offset;
512 if (bubble_type == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) 560 if (bubble_type == SystemTrayBubble::BUBBLE_TYPE_DEFAULT)
513 init_params.close_on_deactivate = !persistent; 561 init_params.close_on_deactivate = !persistent;
514 // For Volume and Brightness we don't want to show an arrow when 562 // For Volume and Brightness we don't want to show an arrow when
515 // they are shown in a bubble by themselves. 563 // they are shown in a bubble by themselves.
516 init_params.arrow_paint_type = views::BubbleBorder::PAINT_NORMAL; 564 init_params.arrow_paint_type = views::BubbleBorder::PAINT_NORMAL;
517 if (items.size() == 1 && items[0]->ShouldHideArrow()) 565 if (items.size() == 1 && items[0]->ShouldHideArrow())
518 init_params.arrow_paint_type = views::BubbleBorder::PAINT_TRANSPARENT; 566 init_params.arrow_paint_type = views::BubbleBorder::PAINT_TRANSPARENT;
519 SystemTrayBubble* bubble = new SystemTrayBubble(this, items, bubble_type); 567 SystemTrayBubble* bubble = new SystemTrayBubble(this, items, bubble_type);
520 568
521 system_bubble_.reset(new SystemBubbleWrapper(bubble)); 569 system_bubble_.reset(new SystemBubbleWrapper(bubble));
522 system_bubble_->InitView(this, tray_container(), &init_params, persistent); 570 system_bubble_->InitView(this, tray_container(), &init_params, persistent);
523 571
572 activation_observer_.reset(persistent ? nullptr
573 : new ActivationObserver(this));
574
524 // Record metrics for the system menu when the default view is invoked. 575 // Record metrics for the system menu when the default view is invoked.
525 if (!detailed) 576 if (!detailed)
526 RecordSystemMenuMetrics(); 577 RecordSystemMenuMetrics();
527 } 578 }
528 // Save height of default view for creating detailed views directly. 579 // Save height of default view for creating detailed views directly.
529 if (!detailed) 580 if (!detailed)
530 default_bubble_height_ = system_bubble_->bubble_view()->height(); 581 default_bubble_height_ = system_bubble_->bubble_view()->height();
531 582
583 key_event_watcher_.reset();
584 if (can_activate)
585 CreateKeyEventWatcher();
586
532 if (detailed && items.size() > 0) 587 if (detailed && items.size() > 0)
533 detailed_item_ = items[0]; 588 detailed_item_ = items[0];
534 else 589 else
535 detailed_item_ = NULL; 590 detailed_item_ = NULL;
536 591
537 UpdateNotificationBubble(); // State changed, re-create notifications. 592 UpdateNotificationBubble(); // State changed, re-create notifications.
538 if (!notification_bubble_) 593 if (!notification_bubble_)
539 UpdateWebNotifications(); 594 UpdateWebNotifications();
540 shelf()->UpdateAutoHideState(); 595 shelf()->UpdateAutoHideState();
541 596
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 } 779 }
725 780
726 TrayDate* SystemTray::GetTrayDateForTesting() const { 781 TrayDate* SystemTray::GetTrayDateForTesting() const {
727 return tray_date_; 782 return tray_date_;
728 } 783 }
729 784
730 TrayUpdate* SystemTray::GetTrayUpdateForTesting() const { 785 TrayUpdate* SystemTray::GetTrayUpdateForTesting() const {
731 return tray_update_; 786 return tray_update_;
732 } 787 }
733 788
789 void SystemTray::CloseBubble(const ui::KeyEvent& key_event) {
790 CloseSystemBubble();
791 }
792
793 void SystemTray::ActivateAndStartNavigation(const ui::KeyEvent& key_event) {
794 if (!system_bubble_)
795 return;
796 ActivateBubble();
797 views::Widget* widget = GetSystemBubble()->bubble_view()->GetWidget();
798 widget->GetFocusManager()->OnKeyEvent(key_event);
799 }
800
801 void SystemTray::CreateKeyEventWatcher() {
802 key_event_watcher_ = WmShell::Get()->CreateKeyEventWatcher();
803 key_event_watcher_->AddKeyEventCallback(
804 ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE),
805 base::Bind(&SystemTray::CloseBubble, base::Unretained(this)));
806 key_event_watcher_->AddKeyEventCallback(
807 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE),
808 base::Bind(&SystemTray::ActivateAndStartNavigation,
809 base::Unretained(this)));
810 key_event_watcher_->AddKeyEventCallback(
811 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN),
812 base::Bind(&SystemTray::ActivateAndStartNavigation,
813 base::Unretained(this)));
814 }
815
816 void SystemTray::ActivateBubble() {
817 TrayBubbleView* bubble_view = GetSystemBubble()->bubble_view();
818 bubble_view->set_can_activate(true);
819 bubble_view->GetWidget()->Activate();
820 }
821
734 bool SystemTray::PerformAction(const ui::Event& event) { 822 bool SystemTray::PerformAction(const ui::Event& event) {
735 // If we're already showing the default view, hide it; otherwise, show it 823 // If we're already showing the default view, hide it; otherwise, show it
736 // (and hide any popup that's currently shown). 824 // (and hide any popup that's currently shown).
737 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { 825 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) {
738 system_bubble_->bubble()->Close(); 826 system_bubble_->bubble()->Close();
739 } else { 827 } else {
740 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; 828 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset;
741 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { 829 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) {
742 const ui::LocatedEvent& located_event = 830 const ui::LocatedEvent& located_event =
743 static_cast<const ui::LocatedEvent&>(event); 831 static_cast<const ui::LocatedEvent&>(event);
744 if (IsHorizontalAlignment(shelf_alignment())) { 832 if (IsHorizontalAlignment(shelf_alignment())) {
745 gfx::Point point(located_event.x(), 0); 833 gfx::Point point(located_event.x(), 0);
746 ConvertPointToWidget(this, &point); 834 ConvertPointToWidget(this, &point);
747 arrow_offset = point.x(); 835 arrow_offset = point.x();
748 } 836 }
749 } 837 }
750 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset, false); 838 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset, false);
751 } 839 }
752 return true; 840 return true;
753 } 841 }
754 842
755 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { 843 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() {
844 activation_observer_.reset();
845 key_event_watcher_.reset();
756 system_bubble_.reset(); 846 system_bubble_.reset();
757 // When closing a system bubble with the alternate shelf layout, we need to 847 // When closing a system bubble with the alternate shelf layout, we need to
758 // turn off the active tinting of the shelf. 848 // turn off the active tinting of the shelf.
759 if (full_system_tray_menu_) { 849 if (full_system_tray_menu_) {
760 SetDrawBackgroundAsActive(false); 850 SetDrawBackgroundAsActive(false);
761 full_system_tray_menu_ = false; 851 full_system_tray_menu_ = false;
762 } 852 }
763 } 853 }
764 854
765 void SystemTray::RecordSystemMenuMetrics() { 855 void SystemTray::RecordSystemMenuMetrics() {
(...skipping 17 matching lines...) Expand all
783 .work_area() 873 .work_area()
784 .height(); 874 .height();
785 if (work_area_height > 0) { 875 if (work_area_height > 0) {
786 UMA_HISTOGRAM_CUSTOM_COUNTS( 876 UMA_HISTOGRAM_CUSTOM_COUNTS(
787 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", 877 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu",
788 100 * bubble_view->height() / work_area_height, 1, 300, 100); 878 100 * bubble_view->height() / work_area_height, 1, 300, 100);
789 } 879 }
790 } 880 }
791 881
792 } // namespace ash 882 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698