Chromium Code Reviews| 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/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" |
| 25 #include "ui/accessibility/ax_node_data.h" | |
| 24 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/gfx/geometry/insets.h" | 27 #include "ui/gfx/geometry/insets.h" |
| 28 #include "ui/gfx/paint_vector_icon.h" | |
| 26 #include "ui/views/border.h" | 29 #include "ui/views/border.h" |
| 27 #include "ui/views/controls/button/custom_button.h" | 30 #include "ui/views/controls/button/custom_button.h" |
| 28 #include "ui/views/controls/separator.h" | 31 #include "ui/views/controls/separator.h" |
| 29 #include "ui/views/layout/box_layout.h" | 32 #include "ui/views/layout/box_layout.h" |
| 30 | 33 |
| 31 namespace ash { | 34 namespace ash { |
| 32 | 35 |
| 33 namespace { | 36 namespace { |
| 34 | 37 |
| 35 // The ISO-639 code for the Hebrew locale. The help icon asset is a '?' which is | 38 // The ISO-639 code for the Hebrew locale. The help icon asset is a '?' which is |
| 36 // not mirrored in this locale. | 39 // not mirrored in this locale. |
| 37 const char kHebrewLocale[] = "he"; | 40 const char kHebrewLocale[] = "he"; |
| 38 | 41 |
| 39 const gfx::VectorIcon& GetNightLightButtonIcon() { | 42 gfx::ImageSkia GetNightLightNormalStateIcon(bool night_light_enabled) { |
| 40 return Shell::Get()->night_light_controller()->GetEnabled() | 43 if (night_light_enabled) |
| 41 ? kSystemMenuNightLightOnIcon | 44 return gfx::CreateVectorIcon(kSystemMenuNightLightOnIcon, kMenuIconColor); |
| 42 : kSystemMenuNightLightOffIcon; | 45 |
| 46 // Use the same icon theme used for inactive items in the tray when | |
| 47 // NightLight is not active. | |
| 48 return gfx::CreateVectorIcon(kSystemMenuNightLightOffIcon, | |
| 49 TrayPopupItemStyle::GetIconColor( | |
| 50 TrayPopupItemStyle::ColorStyle::INACTIVE)); | |
| 51 } | |
| 52 | |
| 53 gfx::ImageSkia GetNightLightDisabledStateIcon(bool night_light_enabled) { | |
| 54 return gfx::CreateVectorIcon(night_light_enabled | |
| 55 ? kSystemMenuNightLightOnIcon | |
| 56 : kSystemMenuNightLightOffIcon, | |
| 57 kMenuIconColorDisabled); | |
| 43 } | 58 } |
| 44 | 59 |
| 45 } // namespace | 60 } // namespace |
| 46 | 61 |
| 62 // The NightLight toggle button in the system tray. | |
| 63 class NightLightToggleButton : public SystemMenuButton { | |
| 64 public: | |
| 65 NightLightToggleButton(views::ButtonListener* listener) | |
|
Daniel Erat
2017/05/25 16:17:34
explicit
afakhry
2017/05/25 16:31:38
Done.
I remember the presubmit script used to catc
| |
| 66 : SystemMenuButton(listener, | |
| 67 TrayPopupInkDropStyle::HOST_CENTERED, | |
| 68 kSystemMenuNightLightOffIcon, | |
| 69 IDS_ASH_STATUS_TRAY_NIGHT_LIGHT) { | |
| 70 Update(); | |
| 71 } | |
| 72 ~NightLightToggleButton() override = default; | |
| 73 | |
| 74 // Updates the icon and its style based on the status of NightLight. | |
| 75 void Update() { | |
| 76 const bool night_light_enabled = | |
| 77 Shell::Get()->night_light_controller()->GetEnabled(); | |
| 78 | |
| 79 SetImage(views::Button::STATE_NORMAL, | |
| 80 GetNightLightNormalStateIcon(night_light_enabled)); | |
| 81 SetImage(views::Button::STATE_DISABLED, | |
| 82 GetNightLightDisabledStateIcon(night_light_enabled)); | |
| 83 } | |
| 84 | |
| 85 private: | |
| 86 // views::View: | |
| 87 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { | |
| 88 node_data->SetName( | |
| 89 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NIGHT_LIGHT)); | |
| 90 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; | |
| 91 if (Shell::Get()->night_light_controller()->GetEnabled()) | |
| 92 node_data->AddState(ui::AX_STATE_PRESSED); | |
| 93 } | |
| 94 | |
| 95 DISALLOW_COPY_AND_ASSIGN(NightLightToggleButton); | |
| 96 }; | |
| 97 | |
| 47 TilesDefaultView::TilesDefaultView(SystemTrayItem* owner) | 98 TilesDefaultView::TilesDefaultView(SystemTrayItem* owner) |
| 48 : owner_(owner), | 99 : owner_(owner), |
| 49 settings_button_(nullptr), | 100 settings_button_(nullptr), |
| 50 help_button_(nullptr), | 101 help_button_(nullptr), |
| 51 night_light_button_(nullptr), | 102 night_light_button_(nullptr), |
| 52 lock_button_(nullptr), | 103 lock_button_(nullptr), |
| 53 power_button_(nullptr) { | 104 power_button_(nullptr) { |
| 54 DCHECK(owner_); | 105 DCHECK(owner_); |
| 55 } | 106 } |
| 56 | 107 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 84 base::i18n::GetConfiguredLocale() == kHebrewLocale) { | 135 base::i18n::GetConfiguredLocale() == kHebrewLocale) { |
| 85 // The asset for the help button is a question mark '?'. Normally this asset | 136 // 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 | 137 // is flipped in RTL locales, however Hebrew uses the LTR '?'. So the |
| 87 // flipping must be disabled. (crbug.com/475237) | 138 // flipping must be disabled. (crbug.com/475237) |
| 88 help_button_->EnableCanvasFlippingForRTLUI(false); | 139 help_button_->EnableCanvasFlippingForRTLUI(false); |
| 89 } | 140 } |
| 90 help_button_->SetEnabled(can_show_web_ui); | 141 help_button_->SetEnabled(can_show_web_ui); |
| 91 AddChildView(help_button_); | 142 AddChildView(help_button_); |
| 92 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); | 143 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); |
| 93 | 144 |
| 94 night_light_button_ = new SystemMenuButton( | 145 night_light_button_ = new NightLightToggleButton(this); |
| 95 this, TrayPopupInkDropStyle::HOST_CENTERED, GetNightLightButtonIcon(), | |
| 96 IDS_ASH_STATUS_TRAY_NIGHT_LIGHT); | |
| 97 night_light_button_->SetEnabled(can_show_web_ui); | 146 night_light_button_->SetEnabled(can_show_web_ui); |
| 98 AddChildView(night_light_button_); | 147 AddChildView(night_light_button_); |
| 99 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); | 148 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); |
| 100 | 149 |
| 101 lock_button_ = | 150 lock_button_ = |
| 102 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, | 151 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, |
| 103 kSystemMenuLockIcon, IDS_ASH_STATUS_TRAY_LOCK); | 152 kSystemMenuLockIcon, IDS_ASH_STATUS_TRAY_LOCK); |
| 104 lock_button_->SetEnabled(can_show_web_ui && | 153 lock_button_->SetEnabled(can_show_web_ui && |
| 105 Shell::Get()->session_controller()->CanLockScreen()); | 154 Shell::Get()->session_controller()->CanLockScreen()); |
| 106 | 155 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 123 DCHECK(sender); | 172 DCHECK(sender); |
| 124 if (sender == settings_button_) { | 173 if (sender == settings_button_) { |
| 125 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SETTINGS); | 174 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SETTINGS); |
| 126 Shell::Get()->system_tray_controller()->ShowSettings(); | 175 Shell::Get()->system_tray_controller()->ShowSettings(); |
| 127 } else if (sender == help_button_) { | 176 } else if (sender == help_button_) { |
| 128 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_HELP); | 177 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_HELP); |
| 129 Shell::Get()->system_tray_controller()->ShowHelp(); | 178 Shell::Get()->system_tray_controller()->ShowHelp(); |
| 130 } else if (sender == night_light_button_) { | 179 } else if (sender == night_light_button_) { |
| 131 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_NIGHT_LIGHT); | 180 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_NIGHT_LIGHT); |
| 132 Shell::Get()->night_light_controller()->Toggle(); | 181 Shell::Get()->night_light_controller()->Toggle(); |
| 133 night_light_button_->SetVectorIcon(GetNightLightButtonIcon()); | 182 night_light_button_->Update(); |
| 134 } else if (sender == lock_button_) { | 183 } else if (sender == lock_button_) { |
| 135 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN); | 184 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN); |
| 136 chromeos::DBusThreadManager::Get() | 185 chromeos::DBusThreadManager::Get() |
| 137 ->GetSessionManagerClient() | 186 ->GetSessionManagerClient() |
| 138 ->RequestLockScreen(); | 187 ->RequestLockScreen(); |
| 139 } else if (sender == power_button_) { | 188 } else if (sender == power_button_) { |
| 140 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SHUT_DOWN); | 189 ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_SHUT_DOWN); |
| 141 Shell::Get()->lock_state_controller()->RequestShutdown(); | 190 Shell::Get()->lock_state_controller()->RequestShutdown(); |
| 142 } | 191 } |
| 143 } | 192 } |
| 144 | 193 |
| 145 views::View* TilesDefaultView::GetHelpButtonView() const { | 194 views::View* TilesDefaultView::GetHelpButtonView() const { |
| 146 return help_button_; | 195 return help_button_; |
| 147 } | 196 } |
| 148 | 197 |
| 149 const views::CustomButton* TilesDefaultView::GetShutdownButtonViewForTest() | 198 const views::CustomButton* TilesDefaultView::GetShutdownButtonViewForTest() |
| 150 const { | 199 const { |
| 151 return power_button_; | 200 return power_button_; |
| 152 } | 201 } |
| 153 | 202 |
| 154 } // namespace ash | 203 } // namespace ash |
| OLD | NEW |