OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/system/tiles/tiles_default_view.h" | 5 #include "ash/system/tiles/tiles_default_view.h" |
6 | 6 |
7 #include "ash/metrics/user_metrics_action.h" | 7 #include "ash/metrics/user_metrics_action.h" |
8 #include "ash/resources/vector_icons/vector_icons.h" | 8 #include "ash/resources/vector_icons/vector_icons.h" |
9 #include "ash/session/session_controller.h" | 9 #include "ash/session/session_controller.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/shell_port.h" | 11 #include "ash/shell_port.h" |
12 #include "ash/shutdown_controller.h" | 12 #include "ash/shutdown_controller.h" |
13 #include "ash/strings/grit/ash_strings.h" | 13 #include "ash/strings/grit/ash_strings.h" |
| 14 #include "ash/system/night_light/night_light_controller.h" |
14 #include "ash/system/tray/system_menu_button.h" | 15 #include "ash/system/tray/system_menu_button.h" |
15 #include "ash/system/tray/system_tray.h" | 16 #include "ash/system/tray/system_tray.h" |
16 #include "ash/system/tray/system_tray_controller.h" | 17 #include "ash/system/tray/system_tray_controller.h" |
17 #include "ash/system/tray/system_tray_item.h" | 18 #include "ash/system/tray/system_tray_item.h" |
18 #include "ash/system/tray/tray_constants.h" | 19 #include "ash/system/tray/tray_constants.h" |
19 #include "ash/system/tray/tray_popup_utils.h" | 20 #include "ash/system/tray/tray_popup_utils.h" |
20 #include "ash/wm/lock_state_controller.h" | 21 #include "ash/wm/lock_state_controller.h" |
21 #include "chromeos/dbus/dbus_thread_manager.h" | 22 #include "chromeos/dbus/dbus_thread_manager.h" |
22 #include "chromeos/dbus/session_manager_client.h" | 23 #include "chromeos/dbus/session_manager_client.h" |
23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
(...skipping 10 matching lines...) Expand all Loading... |
34 const char kHebrewLocale[] = "he"; | 35 const char kHebrewLocale[] = "he"; |
35 | 36 |
36 } // namespace | 37 } // namespace |
37 | 38 |
38 namespace ash { | 39 namespace ash { |
39 | 40 |
40 TilesDefaultView::TilesDefaultView(SystemTrayItem* owner) | 41 TilesDefaultView::TilesDefaultView(SystemTrayItem* owner) |
41 : owner_(owner), | 42 : owner_(owner), |
42 settings_button_(nullptr), | 43 settings_button_(nullptr), |
43 help_button_(nullptr), | 44 help_button_(nullptr), |
| 45 night_light_button_(nullptr), |
44 lock_button_(nullptr), | 46 lock_button_(nullptr), |
45 power_button_(nullptr) { | 47 power_button_(nullptr) { |
46 DCHECK(owner_); | 48 DCHECK(owner_); |
47 } | 49 } |
48 | 50 |
49 TilesDefaultView::~TilesDefaultView() = default; | 51 TilesDefaultView::~TilesDefaultView() = default; |
50 | 52 |
51 void TilesDefaultView::Init() { | 53 void TilesDefaultView::Init() { |
52 views::BoxLayout* box_layout = | 54 views::BoxLayout* box_layout = |
53 new views::BoxLayout(views::BoxLayout::kHorizontal, 4, 0, 0); | 55 new views::BoxLayout(views::BoxLayout::kHorizontal, 4, 0, 0); |
(...skipping 24 matching lines...) Expand all Loading... |
78 // The asset for the help button is a question mark '?'. Normally this asset | 80 // The asset for the help button is a question mark '?'. Normally this asset |
79 // is flipped in RTL locales, however Hebrew uses the LTR '?'. So the | 81 // is flipped in RTL locales, however Hebrew uses the LTR '?'. So the |
80 // flipping must be disabled. (crbug.com/475237) | 82 // flipping must be disabled. (crbug.com/475237) |
81 help_button_->EnableCanvasFlippingForRTLUI(false); | 83 help_button_->EnableCanvasFlippingForRTLUI(false); |
82 } | 84 } |
83 if (disable_buttons) | 85 if (disable_buttons) |
84 help_button_->SetEnabled(false); | 86 help_button_->SetEnabled(false); |
85 AddChildView(help_button_); | 87 AddChildView(help_button_); |
86 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); | 88 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); |
87 | 89 |
| 90 night_light_button_ = |
| 91 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, |
| 92 Shell::Get()->night_light_controller()->enabled() |
| 93 ? kSystemMenuNightLightOnIcon |
| 94 : kSystemMenuNightLightOffIcon, |
| 95 IDS_ASH_STATUS_TRAY_NIGHT_LIGHT); |
| 96 night_light_button_->SetEnabled(!disable_buttons); |
| 97 AddChildView(night_light_button_); |
| 98 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); |
| 99 |
88 lock_button_ = | 100 lock_button_ = |
89 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, | 101 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, |
90 kSystemMenuLockIcon, IDS_ASH_STATUS_TRAY_LOCK); | 102 kSystemMenuLockIcon, IDS_ASH_STATUS_TRAY_LOCK); |
91 if (disable_buttons || !Shell::Get()->session_controller()->CanLockScreen()) | 103 if (disable_buttons || !Shell::Get()->session_controller()->CanLockScreen()) |
92 lock_button_->SetEnabled(false); | 104 lock_button_->SetEnabled(false); |
93 | 105 |
94 AddChildView(lock_button_); | 106 AddChildView(lock_button_); |
95 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); | 107 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); |
96 | 108 |
97 power_button_ = | 109 power_button_ = |
98 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, | 110 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, |
99 kSystemMenuPowerIcon, IDS_ASH_STATUS_TRAY_SHUTDOWN); | 111 kSystemMenuPowerIcon, IDS_ASH_STATUS_TRAY_SHUTDOWN); |
100 AddChildView(power_button_); | 112 AddChildView(power_button_); |
101 // This object is recreated every time the menu opens. Don't bother updating | 113 // This object is recreated every time the menu opens. Don't bother updating |
102 // the tooltip if the shutdown policy changes while the menu is open. | 114 // the tooltip if the shutdown policy changes while the menu is open. |
103 bool reboot = Shell::Get()->shutdown_controller()->reboot_on_shutdown(); | 115 bool reboot = Shell::Get()->shutdown_controller()->reboot_on_shutdown(); |
104 power_button_->SetTooltipText(l10n_util::GetStringUTF16( | 116 power_button_->SetTooltipText(l10n_util::GetStringUTF16( |
105 reboot ? IDS_ASH_STATUS_TRAY_REBOOT : IDS_ASH_STATUS_TRAY_SHUTDOWN)); | 117 reboot ? IDS_ASH_STATUS_TRAY_REBOOT : IDS_ASH_STATUS_TRAY_SHUTDOWN)); |
106 } | 118 } |
107 | 119 |
108 void TilesDefaultView::ButtonPressed(views::Button* sender, | 120 void TilesDefaultView::ButtonPressed(views::Button* sender, |
109 const ui::Event& event) { | 121 const ui::Event& event) { |
110 DCHECK(sender); | 122 DCHECK(sender); |
111 if (sender == settings_button_) { | 123 if (sender == settings_button_) { |
112 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SETTINGS); | 124 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SETTINGS); |
113 Shell::Get()->system_tray_controller()->ShowSettings(); | 125 Shell::Get()->system_tray_controller()->ShowSettings(); |
114 } else if (sender == help_button_) { | 126 } else if (sender == help_button_) { |
115 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_HELP); | 127 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_HELP); |
116 Shell::Get()->system_tray_controller()->ShowHelp(); | 128 Shell::Get()->system_tray_controller()->ShowHelp(); |
| 129 } else if (sender == night_light_button_) { |
| 130 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_NIGHT_LIGHT); |
| 131 Shell::Get()->night_light_controller()->Toggle(); |
117 } else if (sender == lock_button_) { | 132 } else if (sender == lock_button_) { |
118 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN); | 133 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN); |
119 chromeos::DBusThreadManager::Get() | 134 chromeos::DBusThreadManager::Get() |
120 ->GetSessionManagerClient() | 135 ->GetSessionManagerClient() |
121 ->RequestLockScreen(); | 136 ->RequestLockScreen(); |
122 } else if (sender == power_button_) { | 137 } else if (sender == power_button_) { |
123 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SHUT_DOWN); | 138 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SHUT_DOWN); |
124 Shell::Get()->lock_state_controller()->RequestShutdown(); | 139 Shell::Get()->lock_state_controller()->RequestShutdown(); |
125 } | 140 } |
126 | 141 |
127 owner_->system_tray()->CloseSystemBubble(); | 142 owner_->system_tray()->CloseSystemBubble(); |
128 } | 143 } |
129 | 144 |
130 views::View* TilesDefaultView::GetHelpButtonView() const { | 145 views::View* TilesDefaultView::GetHelpButtonView() const { |
131 return help_button_; | 146 return help_button_; |
132 } | 147 } |
133 | 148 |
134 const views::CustomButton* TilesDefaultView::GetShutdownButtonViewForTest() | 149 const views::CustomButton* TilesDefaultView::GetShutdownButtonViewForTest() |
135 const { | 150 const { |
136 return power_button_; | 151 return power_button_; |
137 } | 152 } |
138 | 153 |
139 } // namespace ash | 154 } // namespace ash |
OLD | NEW |