shelf_party_feature_pod_controller.cc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2021 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/shelf/shelf_party_feature_pod_controller.h"
  5. #include "ash/public/cpp/shelf_model.h"
  6. #include "ash/resources/vector_icons/vector_icons.h"
  7. #include "ash/session/session_controller_impl.h"
  8. #include "ash/shelf/shelf_controller.h"
  9. #include "ash/shell.h"
  10. #include "ash/strings/grit/ash_strings.h"
  11. #include "ash/system/unified/feature_pod_button.h"
  12. #include "components/session_manager/session_manager_types.h"
  13. #include "ui/base/l10n/l10n_util.h"
  14. namespace ash {
  15. ShelfPartyFeaturePodController::ShelfPartyFeaturePodController() = default;
  16. ShelfPartyFeaturePodController::~ShelfPartyFeaturePodController() {
  17. Shell::Get()->session_controller()->RemoveObserver(this);
  18. Shell::Get()->shelf_controller()->model()->RemoveObserver(this);
  19. }
  20. FeaturePodButton* ShelfPartyFeaturePodController::CreateButton() {
  21. DCHECK(!button_);
  22. button_ = new FeaturePodButton(this);
  23. button_->DisableLabelButtonFocus();
  24. button_->SetVectorIcon(kShelfPartyIcon);
  25. button_->SetLabel(
  26. l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHELF_PARTY_LABEL));
  27. UpdateButton();
  28. Shell::Get()->session_controller()->AddObserver(this);
  29. Shell::Get()->shelf_controller()->model()->AddObserver(this);
  30. return button_;
  31. }
  32. void ShelfPartyFeaturePodController::OnIconPressed() {
  33. Shell::Get()->shelf_controller()->model()->ToggleShelfParty();
  34. }
  35. SystemTrayItemUmaType ShelfPartyFeaturePodController::GetUmaType() const {
  36. return SystemTrayItemUmaType::UMA_SHELF_PARTY;
  37. }
  38. void ShelfPartyFeaturePodController::OnSessionStateChanged(
  39. session_manager::SessionState state) {
  40. UpdateButton();
  41. }
  42. void ShelfPartyFeaturePodController::ShelfPartyToggled(bool in_shelf_party) {
  43. UpdateButton();
  44. }
  45. void ShelfPartyFeaturePodController::UpdateButton() {
  46. DCHECK(button_);
  47. const SessionControllerImpl* session_controller =
  48. Shell::Get()->session_controller();
  49. button_->SetVisible(session_controller->GetSessionState() ==
  50. session_manager::SessionState::ACTIVE &&
  51. !session_controller->IsEnterpriseManaged());
  52. const bool toggled =
  53. Shell::Get()->shelf_controller()->model()->in_shelf_party();
  54. button_->SetToggled(toggled);
  55. button_->SetSubLabel(l10n_util::GetStringUTF16(
  56. toggled ? IDS_ASH_STATUS_TRAY_SHELF_PARTY_ON_SUBLABEL
  57. : IDS_ASH_STATUS_TRAY_SHELF_PARTY_OFF_SUBLABEL));
  58. button_->SetIconAndLabelTooltips(l10n_util::GetStringFUTF16(
  59. IDS_ASH_STATUS_TRAY_SHELF_PARTY_TOGGLE_TOOLTIP,
  60. l10n_util::GetStringUTF16(
  61. toggled ? IDS_ASH_STATUS_TRAY_SHELF_PARTY_ENABLED_STATE_TOOLTIP
  62. : IDS_ASH_STATUS_TRAY_SHELF_PARTY_DISABLED_STATE_TOOLTIP)));
  63. }
  64. } // namespace ash