privacy_screen_feature_pod_controller.cc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2020 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. #include "ash/system/privacy_screen/privacy_screen_feature_pod_controller.h"
  5. #include <utility>
  6. #include "ash/display/privacy_screen_controller.h"
  7. #include "ash/resources/vector_icons/vector_icons.h"
  8. #include "ash/shell.h"
  9. #include "ash/strings/grit/ash_strings.h"
  10. #include "ash/system/unified/feature_pod_button.h"
  11. #include "ui/base/l10n/l10n_util.h"
  12. #include "ui/views/layout/box_layout.h"
  13. namespace ash {
  14. PrivacyScreenFeaturePodController::PrivacyScreenFeaturePodController() {
  15. Shell::Get()->privacy_screen_controller()->AddObserver(this);
  16. }
  17. PrivacyScreenFeaturePodController::~PrivacyScreenFeaturePodController() {
  18. Shell::Get()->privacy_screen_controller()->RemoveObserver(this);
  19. }
  20. FeaturePodButton* PrivacyScreenFeaturePodController::CreateButton() {
  21. DCHECK(!button_);
  22. button_ = new FeaturePodButton(this);
  23. UpdateButton();
  24. return button_;
  25. }
  26. void PrivacyScreenFeaturePodController::OnIconPressed() {
  27. TogglePrivacyScreen();
  28. }
  29. void PrivacyScreenFeaturePodController::OnLabelPressed() {
  30. TogglePrivacyScreen();
  31. }
  32. SystemTrayItemUmaType PrivacyScreenFeaturePodController::GetUmaType() const {
  33. return SystemTrayItemUmaType::UMA_PRIVACY_SCREEN;
  34. }
  35. void PrivacyScreenFeaturePodController::TogglePrivacyScreen() {
  36. auto* privacy_screen_controller = Shell::Get()->privacy_screen_controller();
  37. DCHECK(privacy_screen_controller->IsSupported());
  38. privacy_screen_controller->SetEnabled(
  39. !privacy_screen_controller->GetEnabled(),
  40. PrivacyScreenController::kToggleUISurfaceFeaturePod);
  41. }
  42. void PrivacyScreenFeaturePodController::UpdateButton() {
  43. auto* privacy_screen_controller = Shell::Get()->privacy_screen_controller();
  44. bool is_supported = privacy_screen_controller->IsSupported();
  45. button_->SetVisible(is_supported);
  46. if (!is_supported)
  47. return;
  48. bool is_enabled = privacy_screen_controller->GetEnabled();
  49. bool is_managed = privacy_screen_controller->IsManaged();
  50. button_->SetVectorIcon(kPrivacyScreenIcon);
  51. button_->SetToggled(is_enabled);
  52. button_->SetLabel(
  53. l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_LABEL));
  54. std::u16string tooltip_state;
  55. if (is_enabled) {
  56. button_->SetSubLabel(l10n_util::GetStringUTF16(
  57. IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_ON_SUBLABEL));
  58. tooltip_state =
  59. l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_ON_STATE);
  60. } else {
  61. button_->SetSubLabel(l10n_util::GetStringUTF16(
  62. IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_OFF_SUBLABEL));
  63. tooltip_state =
  64. l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_OFF_STATE);
  65. }
  66. if (is_managed) {
  67. button_->SetSubLabel(l10n_util::GetStringUTF16(
  68. IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_MANAGED_SUBLABEL));
  69. }
  70. button_->SetIconAndLabelTooltips(l10n_util::GetStringFUTF16(
  71. IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_TOOLTIP, tooltip_state));
  72. }
  73. void PrivacyScreenFeaturePodController::OnPrivacyScreenSettingChanged(
  74. bool enabled,
  75. bool notify_ui) {
  76. if (notify_ui)
  77. UpdateButton();
  78. }
  79. } // namespace ash