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

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

Issue 2907503002: Use correct theme for the off icon of NightLight, fix tooltip and a11y (Closed)
Patch Set: 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 | « no previous file | no next file » | 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/night_light/night_light_controller.h"
15 #include "ash/system/tray/system_menu_button.h" 15 #include "ash/system/tray/system_menu_button.h"
16 #include "ash/system/tray/system_tray.h" 16 #include "ash/system/tray/system_tray.h"
17 #include "ash/system/tray/system_tray_controller.h" 17 #include "ash/system/tray/system_tray_controller.h"
18 #include "ash/system/tray/system_tray_item.h" 18 #include "ash/system/tray/system_tray_item.h"
19 #include "ash/system/tray/tray_constants.h" 19 #include "ash/system/tray/tray_constants.h"
20 #include "ash/system/tray/tray_popup_item_style.h"
20 #include "ash/system/tray/tray_popup_utils.h" 21 #include "ash/system/tray/tray_popup_utils.h"
21 #include "ash/wm/lock_state_controller.h" 22 #include "ash/wm/lock_state_controller.h"
22 #include "chromeos/dbus/dbus_thread_manager.h" 23 #include "chromeos/dbus/dbus_thread_manager.h"
23 #include "chromeos/dbus/session_manager_client.h" 24 #include "chromeos/dbus/session_manager_client.h"
24 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/gfx/geometry/insets.h" 26 #include "ui/gfx/geometry/insets.h"
27 #include "ui/gfx/paint_vector_icon.h"
26 #include "ui/views/border.h" 28 #include "ui/views/border.h"
27 #include "ui/views/controls/button/custom_button.h" 29 #include "ui/views/controls/button/custom_button.h"
28 #include "ui/views/controls/separator.h" 30 #include "ui/views/controls/separator.h"
29 #include "ui/views/layout/box_layout.h" 31 #include "ui/views/layout/box_layout.h"
30 32
31 namespace ash { 33 namespace ash {
32 34
33 namespace { 35 namespace {
34 36
35 // The ISO-639 code for the Hebrew locale. The help icon asset is a '?' which is 37 // The ISO-639 code for the Hebrew locale. The help icon asset is a '?' which is
36 // not mirrored in this locale. 38 // not mirrored in this locale.
37 const char kHebrewLocale[] = "he"; 39 const char kHebrewLocale[] = "he";
38 40
39 const gfx::VectorIcon& GetNightLightButtonIcon() { 41 // Updates the icon and its style of the NightLight toggle button based on the
40 return Shell::Get()->night_light_controller()->GetEnabled() 42 // status of NightLight.
41 ? kSystemMenuNightLightOnIcon 43 void UpdateNightLightButtonStyle(SystemMenuButton* night_light_button) {
42 : kSystemMenuNightLightOffIcon; 44 // Use the same icon theme used for inactive items in the tray when
45 // NightLight is not active.
46 SkColor normal_color = TrayPopupItemStyle::GetIconColor(
47 TrayPopupItemStyle::ColorStyle::INACTIVE);
48 const gfx::VectorIcon* icon = &kSystemMenuNightLightOffIcon;
49
50 if (Shell::Get()->night_light_controller()->GetEnabled()) {
51 normal_color = kMenuIconColor;
52 icon = &kSystemMenuNightLightOnIcon;
53 }
54
55 night_light_button->SetImage(views::Button::STATE_NORMAL,
56 gfx::CreateVectorIcon(*icon, normal_color));
57 night_light_button->SetImage(
58 views::Button::STATE_DISABLED,
59 gfx::CreateVectorIcon(*icon, kMenuIconColorDisabled));
James Cook 2017/05/25 02:08:45 I'm finding this hard to follow. How about creatin
afakhry 2017/05/25 03:17:54 Please take a look at the new code. I created a cl
43 } 60 }
44 61
45 } // namespace 62 } // namespace
46 63
47 TilesDefaultView::TilesDefaultView(SystemTrayItem* owner) 64 TilesDefaultView::TilesDefaultView(SystemTrayItem* owner)
48 : owner_(owner), 65 : owner_(owner),
49 settings_button_(nullptr), 66 settings_button_(nullptr),
50 help_button_(nullptr), 67 help_button_(nullptr),
51 night_light_button_(nullptr), 68 night_light_button_(nullptr),
52 lock_button_(nullptr), 69 lock_button_(nullptr),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 base::i18n::GetConfiguredLocale() == kHebrewLocale) { 101 base::i18n::GetConfiguredLocale() == kHebrewLocale) {
85 // The asset for the help button is a question mark '?'. Normally this asset 102 // The asset for the help button is a question mark '?'. Normally this asset
86 // is flipped in RTL locales, however Hebrew uses the LTR '?'. So the 103 // is flipped in RTL locales, however Hebrew uses the LTR '?'. So the
87 // flipping must be disabled. (crbug.com/475237) 104 // flipping must be disabled. (crbug.com/475237)
88 help_button_->EnableCanvasFlippingForRTLUI(false); 105 help_button_->EnableCanvasFlippingForRTLUI(false);
89 } 106 }
90 help_button_->SetEnabled(can_show_web_ui); 107 help_button_->SetEnabled(can_show_web_ui);
91 AddChildView(help_button_); 108 AddChildView(help_button_);
92 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); 109 AddChildView(TrayPopupUtils::CreateVerticalSeparator());
93 110
111 // Temporarily create the button with the "Off" icon. Calling
112 // UpdateNightLightButtonStyle() below will set the correct icon and its theme
113 // based on the current status of NightLight.
94 night_light_button_ = new SystemMenuButton( 114 night_light_button_ = new SystemMenuButton(
95 this, TrayPopupInkDropStyle::HOST_CENTERED, GetNightLightButtonIcon(), 115 this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuNightLightOffIcon,
96 IDS_ASH_STATUS_TRAY_NIGHT_LIGHT); 116 IDS_ASH_STATUS_TRAY_NIGHT_LIGHT);
117 UpdateNightLightButtonStyle(night_light_button_);
97 night_light_button_->SetEnabled(can_show_web_ui); 118 night_light_button_->SetEnabled(can_show_web_ui);
98 AddChildView(night_light_button_); 119 AddChildView(night_light_button_);
99 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); 120 AddChildView(TrayPopupUtils::CreateVerticalSeparator());
100 121
101 lock_button_ = 122 lock_button_ =
102 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, 123 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED,
103 kSystemMenuLockIcon, IDS_ASH_STATUS_TRAY_LOCK); 124 kSystemMenuLockIcon, IDS_ASH_STATUS_TRAY_LOCK);
104 lock_button_->SetEnabled(can_show_web_ui && 125 lock_button_->SetEnabled(can_show_web_ui &&
105 Shell::Get()->session_controller()->CanLockScreen()); 126 Shell::Get()->session_controller()->CanLockScreen());
106 127
(...skipping 16 matching lines...) Expand all
123 DCHECK(sender); 144 DCHECK(sender);
124 if (sender == settings_button_) { 145 if (sender == settings_button_) {
125 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SETTINGS); 146 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SETTINGS);
126 Shell::Get()->system_tray_controller()->ShowSettings(); 147 Shell::Get()->system_tray_controller()->ShowSettings();
127 } else if (sender == help_button_) { 148 } else if (sender == help_button_) {
128 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_HELP); 149 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_HELP);
129 Shell::Get()->system_tray_controller()->ShowHelp(); 150 Shell::Get()->system_tray_controller()->ShowHelp();
130 } else if (sender == night_light_button_) { 151 } else if (sender == night_light_button_) {
131 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_NIGHT_LIGHT); 152 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_NIGHT_LIGHT);
132 Shell::Get()->night_light_controller()->Toggle(); 153 Shell::Get()->night_light_controller()->Toggle();
133 night_light_button_->SetVectorIcon(GetNightLightButtonIcon()); 154 UpdateNightLightButtonStyle(night_light_button_);
134 } else if (sender == lock_button_) { 155 } else if (sender == lock_button_) {
135 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN); 156 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN);
136 chromeos::DBusThreadManager::Get() 157 chromeos::DBusThreadManager::Get()
137 ->GetSessionManagerClient() 158 ->GetSessionManagerClient()
138 ->RequestLockScreen(); 159 ->RequestLockScreen();
139 } else if (sender == power_button_) { 160 } else if (sender == power_button_) {
140 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SHUT_DOWN); 161 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SHUT_DOWN);
141 Shell::Get()->lock_state_controller()->RequestShutdown(); 162 Shell::Get()->lock_state_controller()->RequestShutdown();
142 } 163 }
143 } 164 }
144 165
145 views::View* TilesDefaultView::GetHelpButtonView() const { 166 views::View* TilesDefaultView::GetHelpButtonView() const {
146 return help_button_; 167 return help_button_;
147 } 168 }
148 169
149 const views::CustomButton* TilesDefaultView::GetShutdownButtonViewForTest() 170 const views::CustomButton* TilesDefaultView::GetShutdownButtonViewForTest()
150 const { 171 const {
151 return power_button_; 172 return power_button_;
152 } 173 }
153 174
154 } // namespace ash 175 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698