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

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

Issue 2857103007: [Night Light] CL2: Ash and system tray work (Closed)
Patch Set: Exclude one test from mash 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
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);
(...skipping 24 matching lines...) Expand all
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_ = new SystemMenuButton(
91 this, TrayPopupInkDropStyle::HOST_CENTERED,
92 ash::Shell::Get()->night_light_controller()->enabled()
James Cook 2017/05/05 17:12:32 nit: no ash::
afakhry 2017/05/05 20:04:12 Done.
93 ? kSystemMenuNightLightOnIcon
94 : kSystemMenuNightLightOffIcon,
95 IDS_ASH_STATUS_TRAY_NIGHT_LIGHT);
96 night_light_button_->SetEnabled(!disable_buttons);
James Cook 2017/05/05 17:12:32 Is this button going to be a toggle, or will it op
afakhry 2017/05/05 20:04:12 It's a toggle button, but this |disable_buttons| i
James Cook 2017/05/05 20:47:43 |disable_buttons| currently means "I can show webu
afakhry 2017/05/06 00:49:34 According to this comment: https://cs.chromium.org
97 AddChildView(night_light_button_);
98 AddChildView(TrayPopupUtils::CreateVerticalSeparator());
James Cook 2017/05/05 17:12:32 Please add a test that the night light icon is cre
afakhry 2017/05/05 20:04:12 Done. I updated TrayTilesTest.
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698