| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/night_light/night_light_toggle_button.h" | 5 #include "ash/system/night_light/night_light_toggle_button.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/strings/grit/ash_strings.h" | 8 #include "ash/strings/grit/ash_strings.h" |
| 9 #include "ash/system/night_light/night_light_controller.h" | 9 #include "ash/system/night_light/night_light_controller.h" |
| 10 #include "ash/system/tray/tray_constants.h" | 10 #include "ash/system/tray/tray_constants.h" |
| 11 #include "ash/system/tray/tray_popup_item_style.h" | 11 #include "ash/system/tray/tray_popup_item_style.h" |
| 12 #include "ui/accessibility/ax_enums.h" |
| 12 #include "ui/accessibility/ax_node_data.h" | 13 #include "ui/accessibility/ax_node_data.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/gfx/paint_vector_icon.h" | 15 #include "ui/gfx/paint_vector_icon.h" |
| 15 #include "ui/gfx/vector_icon_types.h" | 16 #include "ui/gfx/vector_icon_types.h" |
| 16 | 17 |
| 17 namespace ash { | 18 namespace ash { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 gfx::ImageSkia GetNightLightNormalStateIcon(bool night_light_enabled) { | 22 gfx::ImageSkia GetNightLightNormalStateIcon(bool night_light_enabled) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 49 NightLightToggleButton::NightLightToggleButton(views::ButtonListener* listener) | 50 NightLightToggleButton::NightLightToggleButton(views::ButtonListener* listener) |
| 50 : SystemMenuButton(listener, | 51 : SystemMenuButton(listener, |
| 51 TrayPopupInkDropStyle::HOST_CENTERED, | 52 TrayPopupInkDropStyle::HOST_CENTERED, |
| 52 kSystemMenuNightLightOffIcon, | 53 kSystemMenuNightLightOffIcon, |
| 53 IDS_ASH_STATUS_TRAY_NIGHT_LIGHT) { | 54 IDS_ASH_STATUS_TRAY_NIGHT_LIGHT) { |
| 54 Update(); | 55 Update(); |
| 55 } | 56 } |
| 56 | 57 |
| 58 void NightLightToggleButton::Toggle() { |
| 59 DCHECK(NightLightController::IsFeatureEnabled()); |
| 60 Shell::Get()->night_light_controller()->Toggle(); |
| 61 Update(); |
| 62 NotifyAccessibilityEvent(ui::AX_EVENT_ARIA_ATTRIBUTE_CHANGED, true); |
| 63 } |
| 64 |
| 57 void NightLightToggleButton::Update() { | 65 void NightLightToggleButton::Update() { |
| 58 const bool night_light_enabled = | 66 const bool night_light_enabled = |
| 59 Shell::Get()->night_light_controller()->GetEnabled(); | 67 Shell::Get()->night_light_controller()->GetEnabled(); |
| 60 | 68 |
| 61 SetTooltipText(GetNightLightTooltipText(night_light_enabled)); | 69 SetTooltipText(GetNightLightTooltipText(night_light_enabled)); |
| 62 SetImage(views::Button::STATE_NORMAL, | 70 SetImage(views::Button::STATE_NORMAL, |
| 63 GetNightLightNormalStateIcon(night_light_enabled)); | 71 GetNightLightNormalStateIcon(night_light_enabled)); |
| 64 SetImage(views::Button::STATE_DISABLED, | 72 SetImage(views::Button::STATE_DISABLED, |
| 65 GetNightLightDisabledStateIcon(night_light_enabled)); | 73 GetNightLightDisabledStateIcon(night_light_enabled)); |
| 66 } | 74 } |
| 67 | 75 |
| 68 void NightLightToggleButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 76 void NightLightToggleButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 69 node_data->SetName( | 77 node_data->SetName( |
| 70 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NIGHT_LIGHT)); | 78 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NIGHT_LIGHT)); |
| 71 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; | 79 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; |
| 72 const bool is_pressed = Shell::Get()->night_light_controller()->GetEnabled(); | 80 const bool is_pressed = Shell::Get()->night_light_controller()->GetEnabled(); |
| 73 node_data->AddIntAttribute( | 81 node_data->AddIntAttribute( |
| 74 ui::AX_ATTR_CHECKED_STATE, | 82 ui::AX_ATTR_CHECKED_STATE, |
| 75 is_pressed ? ui::AX_CHECKED_STATE_TRUE : ui::AX_CHECKED_STATE_FALSE); | 83 is_pressed ? ui::AX_CHECKED_STATE_TRUE : ui::AX_CHECKED_STATE_FALSE); |
| 76 } | 84 } |
| 77 | 85 |
| 78 } // namespace ash | 86 } // namespace ash |
| OLD | NEW |