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

Side by Side Diff: ash/system/night_light/night_light_toggle_button.cc

Issue 2907503002: Use correct theme for the off icon of NightLight, fix tooltip and a11y (Closed)
Patch Set: Expose button for tests. 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/system/night_light/night_light_toggle_button.h"
6
7 #include "ash/shell.h"
8 #include "ash/strings/grit/ash_strings.h"
9 #include "ash/system/night_light/night_light_controller.h"
10 #include "ash/system/tray/tray_constants.h"
11 #include "ash/system/tray/tray_popup_item_style.h"
12 #include "ui/accessibility/ax_node_data.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/gfx/paint_vector_icon.h"
15 #include "ui/gfx/vector_icon_types.h"
16
17 namespace ash {
18
19 namespace {
20
21 gfx::ImageSkia GetNightLightNormalStateIcon(bool night_light_enabled) {
22 if (night_light_enabled)
23 return gfx::CreateVectorIcon(kSystemMenuNightLightOnIcon, kMenuIconColor);
24
25 // Use the same icon theme used for inactive items in the tray when
26 // NightLight is not active.
27 return gfx::CreateVectorIcon(kSystemMenuNightLightOffIcon,
28 TrayPopupItemStyle::GetIconColor(
29 TrayPopupItemStyle::ColorStyle::INACTIVE));
30 }
31
32 gfx::ImageSkia GetNightLightDisabledStateIcon(bool night_light_enabled) {
33 return gfx::CreateVectorIcon(night_light_enabled
34 ? kSystemMenuNightLightOnIcon
35 : kSystemMenuNightLightOffIcon,
36 kMenuIconColorDisabled);
37 }
38
39 } // namespace
40
41 NightLightToggleButton::NightLightToggleButton(views::ButtonListener* listener)
42 : SystemMenuButton(listener,
43 TrayPopupInkDropStyle::HOST_CENTERED,
44 kSystemMenuNightLightOffIcon,
45 IDS_ASH_STATUS_TRAY_NIGHT_LIGHT) {
46 Update();
47 }
48
49 void NightLightToggleButton::Update() {
50 const bool night_light_enabled =
51 Shell::Get()->night_light_controller()->GetEnabled();
52
53 SetImage(views::Button::STATE_NORMAL,
54 GetNightLightNormalStateIcon(night_light_enabled));
55 SetImage(views::Button::STATE_DISABLED,
56 GetNightLightDisabledStateIcon(night_light_enabled));
57 }
58
59 void NightLightToggleButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
60 node_data->SetName(
61 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NIGHT_LIGHT));
62 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON;
63 if (Shell::Get()->night_light_controller()->GetEnabled())
64 node_data->AddState(ui::AX_STATE_PRESSED);
65 }
66
67 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698