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

Side by Side Diff: ash/system/tiles/tiles_default_view.cc

Issue 2857103007: [Night Light] CL2: Ash and system tray work (Closed)
Patch Set: Update comment Created 3 years, 7 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
« no previous file with comments | « ash/system/tiles/tiles_default_view.h ('k') | ash/system/tiles/tray_tiles_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
54 box_layout->set_main_axis_alignment( 56 box_layout->set_main_axis_alignment(
55 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); 57 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
56 box_layout->set_cross_axis_alignment( 58 box_layout->set_cross_axis_alignment(
57 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 59 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
58 SetLayoutManager(box_layout); 60 SetLayoutManager(box_layout);
59 61
60 // Show the buttons in this row as disabled if the user is at the login 62 // Show the buttons in this row as disabled if the user is at the login
61 // screen, lock screen, or in a secondary account flow. The exception is 63 // screen, lock screen, or in a secondary account flow. The exception is
62 // |power_button_| which is always shown as enabled. 64 // |power_button_| which is always shown as enabled.
63 const bool disable_buttons = !TrayPopupUtils::CanOpenWebUISettings(); 65 const bool can_show_web_ui = TrayPopupUtils::CanOpenWebUISettings();
64 66
65 settings_button_ = new SystemMenuButton( 67 settings_button_ = new SystemMenuButton(
66 this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuSettingsIcon, 68 this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuSettingsIcon,
67 IDS_ASH_STATUS_TRAY_SETTINGS); 69 IDS_ASH_STATUS_TRAY_SETTINGS);
68 if (disable_buttons) 70 settings_button_->SetEnabled(can_show_web_ui);
69 settings_button_->SetEnabled(false);
70 AddChildView(settings_button_); 71 AddChildView(settings_button_);
71 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); 72 AddChildView(TrayPopupUtils::CreateVerticalSeparator());
72 73
73 help_button_ = 74 help_button_ =
74 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, 75 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED,
75 kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP); 76 kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP);
76 if (base::i18n::IsRTL() && 77 if (base::i18n::IsRTL() &&
77 base::i18n::GetConfiguredLocale() == kHebrewLocale) { 78 base::i18n::GetConfiguredLocale() == kHebrewLocale) {
78 // The asset for the help button is a question mark '?'. Normally this asset 79 // 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 80 // is flipped in RTL locales, however Hebrew uses the LTR '?'. So the
80 // flipping must be disabled. (crbug.com/475237) 81 // flipping must be disabled. (crbug.com/475237)
81 help_button_->EnableCanvasFlippingForRTLUI(false); 82 help_button_->EnableCanvasFlippingForRTLUI(false);
82 } 83 }
83 if (disable_buttons) 84 help_button_->SetEnabled(can_show_web_ui);
84 help_button_->SetEnabled(false);
85 AddChildView(help_button_); 85 AddChildView(help_button_);
86 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); 86 AddChildView(TrayPopupUtils::CreateVerticalSeparator());
87 87
88 night_light_button_ =
89 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED,
90 Shell::Get()->night_light_controller()->enabled()
91 ? kSystemMenuNightLightOnIcon
92 : kSystemMenuNightLightOffIcon,
93 IDS_ASH_STATUS_TRAY_NIGHT_LIGHT);
94 night_light_button_->SetEnabled(can_show_web_ui);
95 AddChildView(night_light_button_);
96 AddChildView(TrayPopupUtils::CreateVerticalSeparator());
97
88 lock_button_ = 98 lock_button_ =
89 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, 99 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED,
90 kSystemMenuLockIcon, IDS_ASH_STATUS_TRAY_LOCK); 100 kSystemMenuLockIcon, IDS_ASH_STATUS_TRAY_LOCK);
91 if (disable_buttons || !Shell::Get()->session_controller()->CanLockScreen()) 101 lock_button_->SetEnabled(can_show_web_ui &&
92 lock_button_->SetEnabled(false); 102 Shell::Get()->session_controller()->CanLockScreen());
93 103
94 AddChildView(lock_button_); 104 AddChildView(lock_button_);
95 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); 105 AddChildView(TrayPopupUtils::CreateVerticalSeparator());
96 106
97 power_button_ = 107 power_button_ =
98 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, 108 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED,
99 kSystemMenuPowerIcon, IDS_ASH_STATUS_TRAY_SHUTDOWN); 109 kSystemMenuPowerIcon, IDS_ASH_STATUS_TRAY_SHUTDOWN);
100 AddChildView(power_button_); 110 AddChildView(power_button_);
101 // This object is recreated every time the menu opens. Don't bother updating 111 // 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. 112 // the tooltip if the shutdown policy changes while the menu is open.
103 bool reboot = Shell::Get()->shutdown_controller()->reboot_on_shutdown(); 113 bool reboot = Shell::Get()->shutdown_controller()->reboot_on_shutdown();
104 power_button_->SetTooltipText(l10n_util::GetStringUTF16( 114 power_button_->SetTooltipText(l10n_util::GetStringUTF16(
105 reboot ? IDS_ASH_STATUS_TRAY_REBOOT : IDS_ASH_STATUS_TRAY_SHUTDOWN)); 115 reboot ? IDS_ASH_STATUS_TRAY_REBOOT : IDS_ASH_STATUS_TRAY_SHUTDOWN));
106 } 116 }
107 117
108 void TilesDefaultView::ButtonPressed(views::Button* sender, 118 void TilesDefaultView::ButtonPressed(views::Button* sender,
109 const ui::Event& event) { 119 const ui::Event& event) {
110 DCHECK(sender); 120 DCHECK(sender);
111 if (sender == settings_button_) { 121 if (sender == settings_button_) {
112 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SETTINGS); 122 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SETTINGS);
113 Shell::Get()->system_tray_controller()->ShowSettings(); 123 Shell::Get()->system_tray_controller()->ShowSettings();
114 } else if (sender == help_button_) { 124 } else if (sender == help_button_) {
115 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_HELP); 125 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_HELP);
116 Shell::Get()->system_tray_controller()->ShowHelp(); 126 Shell::Get()->system_tray_controller()->ShowHelp();
127 } else if (sender == night_light_button_) {
128 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_NIGHT_LIGHT);
129 Shell::Get()->night_light_controller()->Toggle();
117 } else if (sender == lock_button_) { 130 } else if (sender == lock_button_) {
118 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN); 131 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN);
119 chromeos::DBusThreadManager::Get() 132 chromeos::DBusThreadManager::Get()
120 ->GetSessionManagerClient() 133 ->GetSessionManagerClient()
121 ->RequestLockScreen(); 134 ->RequestLockScreen();
122 } else if (sender == power_button_) { 135 } else if (sender == power_button_) {
123 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SHUT_DOWN); 136 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SHUT_DOWN);
124 Shell::Get()->lock_state_controller()->RequestShutdown(); 137 Shell::Get()->lock_state_controller()->RequestShutdown();
125 } 138 }
126 139
127 owner_->system_tray()->CloseSystemBubble(); 140 owner_->system_tray()->CloseSystemBubble();
128 } 141 }
129 142
130 views::View* TilesDefaultView::GetHelpButtonView() const { 143 views::View* TilesDefaultView::GetHelpButtonView() const {
131 return help_button_; 144 return help_button_;
132 } 145 }
133 146
134 const views::CustomButton* TilesDefaultView::GetShutdownButtonViewForTest() 147 const views::CustomButton* TilesDefaultView::GetShutdownButtonViewForTest()
135 const { 148 const {
136 return power_button_; 149 return power_button_;
137 } 150 }
138 151
139 } // namespace ash 152 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tiles/tiles_default_view.h ('k') | ash/system/tiles/tray_tiles_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698