Chromium Code Reviews| Index: ash/system/tiles/tiles_default_view.cc |
| diff --git a/ash/system/tiles/tiles_default_view.cc b/ash/system/tiles/tiles_default_view.cc |
| index b67d34e8f7c7892197edd54d860fa00eb9eb8a08..9487a21653612b05a7c76af3da225f2e0b1cd144 100644 |
| --- a/ash/system/tiles/tiles_default_view.cc |
| +++ b/ash/system/tiles/tiles_default_view.cc |
| @@ -17,12 +17,15 @@ |
| #include "ash/system/tray/system_tray_controller.h" |
| #include "ash/system/tray/system_tray_item.h" |
| #include "ash/system/tray/tray_constants.h" |
| +#include "ash/system/tray/tray_popup_item_style.h" |
| #include "ash/system/tray/tray_popup_utils.h" |
| #include "ash/wm/lock_state_controller.h" |
| #include "chromeos/dbus/dbus_thread_manager.h" |
| #include "chromeos/dbus/session_manager_client.h" |
| +#include "ui/accessibility/ax_node_data.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/gfx/geometry/insets.h" |
| +#include "ui/gfx/paint_vector_icon.h" |
| #include "ui/views/border.h" |
| #include "ui/views/controls/button/custom_button.h" |
| #include "ui/views/controls/separator.h" |
| @@ -36,14 +39,62 @@ namespace { |
| // not mirrored in this locale. |
| const char kHebrewLocale[] = "he"; |
| -const gfx::VectorIcon& GetNightLightButtonIcon() { |
| - return Shell::Get()->night_light_controller()->GetEnabled() |
| - ? kSystemMenuNightLightOnIcon |
| - : kSystemMenuNightLightOffIcon; |
| +gfx::ImageSkia GetNightLightNormalStateIcon(bool night_light_enabled) { |
| + if (night_light_enabled) |
| + return gfx::CreateVectorIcon(kSystemMenuNightLightOnIcon, kMenuIconColor); |
| + |
| + // Use the same icon theme used for inactive items in the tray when |
| + // NightLight is not active. |
| + return gfx::CreateVectorIcon(kSystemMenuNightLightOffIcon, |
| + TrayPopupItemStyle::GetIconColor( |
| + TrayPopupItemStyle::ColorStyle::INACTIVE)); |
| +} |
| + |
| +gfx::ImageSkia GetNightLightDisabledStateIcon(bool night_light_enabled) { |
| + return gfx::CreateVectorIcon(night_light_enabled |
| + ? kSystemMenuNightLightOnIcon |
| + : kSystemMenuNightLightOffIcon, |
| + kMenuIconColorDisabled); |
| } |
| } // namespace |
| +// The NightLight toggle button in the system tray. |
| +class NightLightToggleButton : public SystemMenuButton { |
| + public: |
| + 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
|
| + : SystemMenuButton(listener, |
| + TrayPopupInkDropStyle::HOST_CENTERED, |
| + kSystemMenuNightLightOffIcon, |
| + IDS_ASH_STATUS_TRAY_NIGHT_LIGHT) { |
| + Update(); |
| + } |
| + ~NightLightToggleButton() override = default; |
| + |
| + // Updates the icon and its style based on the status of NightLight. |
| + void Update() { |
| + const bool night_light_enabled = |
| + Shell::Get()->night_light_controller()->GetEnabled(); |
| + |
| + SetImage(views::Button::STATE_NORMAL, |
| + GetNightLightNormalStateIcon(night_light_enabled)); |
| + SetImage(views::Button::STATE_DISABLED, |
| + GetNightLightDisabledStateIcon(night_light_enabled)); |
| + } |
| + |
| + private: |
| + // views::View: |
| + void GetAccessibleNodeData(ui::AXNodeData* node_data) override { |
| + node_data->SetName( |
| + l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NIGHT_LIGHT)); |
| + node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; |
| + if (Shell::Get()->night_light_controller()->GetEnabled()) |
| + node_data->AddState(ui::AX_STATE_PRESSED); |
| + } |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NightLightToggleButton); |
| +}; |
| + |
| TilesDefaultView::TilesDefaultView(SystemTrayItem* owner) |
| : owner_(owner), |
| settings_button_(nullptr), |
| @@ -91,9 +142,7 @@ void TilesDefaultView::Init() { |
| AddChildView(help_button_); |
| AddChildView(TrayPopupUtils::CreateVerticalSeparator()); |
| - night_light_button_ = new SystemMenuButton( |
| - this, TrayPopupInkDropStyle::HOST_CENTERED, GetNightLightButtonIcon(), |
| - IDS_ASH_STATUS_TRAY_NIGHT_LIGHT); |
| + night_light_button_ = new NightLightToggleButton(this); |
| night_light_button_->SetEnabled(can_show_web_ui); |
| AddChildView(night_light_button_); |
| AddChildView(TrayPopupUtils::CreateVerticalSeparator()); |
| @@ -130,7 +179,7 @@ void TilesDefaultView::ButtonPressed(views::Button* sender, |
| } else if (sender == night_light_button_) { |
| ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_NIGHT_LIGHT); |
| Shell::Get()->night_light_controller()->Toggle(); |
| - night_light_button_->SetVectorIcon(GetNightLightButtonIcon()); |
| + night_light_button_->Update(); |
| } else if (sender == lock_button_) { |
| ShellPort::Get()->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN); |
| chromeos::DBusThreadManager::Get() |