cast_feature_pod_controller.cc 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2018 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/cast/cast_feature_pod_controller.h"
  5. #include "ash/public/cpp/ash_view_ids.h"
  6. #include "ash/public/cpp/system_tray_client.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/model/system_tray_model.h"
  11. #include "ash/system/unified/feature_pod_button.h"
  12. #include "ash/system/unified/unified_system_tray_controller.h"
  13. #include "components/access_code_cast/common/access_code_cast_metrics.h"
  14. #include "ui/base/l10n/l10n_util.h"
  15. namespace ash {
  16. CastFeaturePodController::CastFeaturePodController(
  17. UnifiedSystemTrayController* tray_controller)
  18. : tray_controller_(tray_controller) {
  19. }
  20. CastFeaturePodController::~CastFeaturePodController() {
  21. if (CastConfigController::Get() && button_)
  22. CastConfigController::Get()->RemoveObserver(this);
  23. }
  24. FeaturePodButton* CastFeaturePodController::CreateButton() {
  25. button_ = new FeaturePodButton(this);
  26. button_->SetVectorIcon(kUnifiedMenuCastIcon);
  27. button_->SetLabel(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_CAST_SHORT));
  28. button_->SetIconAndLabelTooltips(
  29. l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_CAST_TOOLTIP));
  30. button_->ShowDetailedViewArrow();
  31. button_->DisableLabelButtonFocus();
  32. button_->SetID(VIEW_ID_CAST_MAIN_VIEW);
  33. if (CastConfigController::Get()) {
  34. CastConfigController::Get()->AddObserver(this);
  35. CastConfigController::Get()->RequestDeviceRefresh();
  36. }
  37. Update();
  38. return button_;
  39. }
  40. void CastFeaturePodController::OnIconPressed() {
  41. auto* cast_config = CastConfigController::Get();
  42. // If there are no devices currently available for the user, and they have
  43. // access code casting available, don't bother displaying an empty list.
  44. // Instead, launch directly into the access code UI so that they can begin
  45. // casting immediately.
  46. if (cast_config && !cast_config->HasSinksAndRoutes() &&
  47. cast_config->AccessCodeCastingEnabled()) {
  48. Shell::Get()->system_tray_model()->client()->ShowAccessCodeCastingDialog(
  49. AccessCodeCastDialogOpenLocation::kSystemTrayCastFeaturePod);
  50. } else {
  51. tray_controller_->ShowCastDetailedView();
  52. }
  53. }
  54. void CastFeaturePodController::OnLabelPressed() {
  55. // Clicking on the label should always launch the full UI.
  56. tray_controller_->ShowCastDetailedView();
  57. }
  58. SystemTrayItemUmaType CastFeaturePodController::GetUmaType() const {
  59. return SystemTrayItemUmaType::UMA_CAST;
  60. }
  61. void CastFeaturePodController::OnDevicesUpdated(
  62. const std::vector<SinkAndRoute>& devices) {
  63. Update();
  64. }
  65. void CastFeaturePodController::Update() {
  66. auto* cast_config = CastConfigController::Get();
  67. button_->SetVisible(cast_config &&
  68. (cast_config->HasSinksAndRoutes() ||
  69. cast_config->AccessCodeCastingEnabled()) &&
  70. !cast_config->HasActiveRoute());
  71. }
  72. } // namespace ash