phone_hub_tray.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #ifndef ASH_SYSTEM_PHONEHUB_PHONE_HUB_TRAY_H_
  5. #define ASH_SYSTEM_PHONEHUB_PHONE_HUB_TRAY_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/session/session_controller_impl.h"
  8. #include "ash/system/phonehub/onboarding_view.h"
  9. #include "ash/system/phonehub/phone_hub_content_view.h"
  10. #include "ash/system/phonehub/phone_hub_ui_controller.h"
  11. #include "ash/system/phonehub/phone_status_view.h"
  12. #include "ash/system/status_area_widget.h"
  13. #include "ash/system/tray/tray_background_view.h"
  14. #include "base/bind.h"
  15. #include "base/callback.h"
  16. #include "base/callback_forward.h"
  17. #include "base/callback_helpers.h"
  18. #include "base/scoped_observation.h"
  19. #include "ui/events/event.h"
  20. #include "ui/views/controls/button/image_button.h"
  21. namespace views {
  22. class ImageButton;
  23. }
  24. namespace ash {
  25. class EcheIconLoadingIndicatorView;
  26. class PhoneHubContentView;
  27. class TrayBubbleWrapper;
  28. class SessionControllerImpl;
  29. namespace phonehub {
  30. class PhoneHubManager;
  31. }
  32. // This class represents the Phone Hub tray button in the status area and
  33. // controls the bubble that is shown when the tray button is clicked.
  34. class ASH_EXPORT PhoneHubTray : public TrayBackgroundView,
  35. public OnboardingView::Delegate,
  36. public PhoneStatusView::Delegate,
  37. public PhoneHubUiController::Observer,
  38. public SessionObserver {
  39. public:
  40. explicit PhoneHubTray(Shelf* shelf);
  41. PhoneHubTray(const PhoneHubTray&) = delete;
  42. ~PhoneHubTray() override;
  43. PhoneHubTray& operator=(const PhoneHubTray&) = delete;
  44. // Sets the PhoneHubManager that provides the data to drive the UI.
  45. void SetPhoneHubManager(phonehub::PhoneHubManager* phone_hub_manager);
  46. // TrayBackgroundView:
  47. void ClickedOutsideBubble() override;
  48. std::u16string GetAccessibleNameForTray() override;
  49. void HandleLocaleChange() override;
  50. void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
  51. void AnchorUpdated() override;
  52. void Initialize() override;
  53. void CloseBubble() override;
  54. void ShowBubble() override;
  55. bool PerformAction(const ui::Event& event) override;
  56. TrayBubbleView* GetBubbleView() override;
  57. views::Widget* GetBubbleWidget() const override;
  58. const char* GetClassName() const override;
  59. void OnThemeChanged() override;
  60. // PhoneStatusView::Delegate:
  61. bool CanOpenConnectedDeviceSettings() override;
  62. void OpenConnectedDevicesSettings() override;
  63. // OnboardingView::Delegate:
  64. void HideStatusHeaderView() override;
  65. // Provides the Eche icon and Eche loading indicator to
  66. // `EcheTray` in order to let `EcheTray` control the visibiliity
  67. // of them. Please note that these views are in control of 'EcheTray'
  68. // and the phone hub area is "borrowed" by `EcheTray` for the
  69. // purpose of grouping the icons together.
  70. views::ImageButton* eche_icon_view() { return eche_icon_; }
  71. EcheIconLoadingIndicatorView* eche_loading_indicator() {
  72. return eche_loading_indicator_;
  73. }
  74. // Sets a callback that will be called when eche icon is activated.
  75. void SetEcheIconActivationCallback(
  76. base::RepeatingCallback<bool(const ui::Event&)> callback);
  77. views::View* content_view_for_testing() { return content_view_; }
  78. PhoneHubUiController* ui_controller_for_testing() {
  79. return ui_controller_.get();
  80. }
  81. private:
  82. // TrayBubbleView::Delegate:
  83. std::u16string GetAccessibleNameForBubble() override;
  84. bool ShouldEnableExtraKeyboardAccessibility() override;
  85. void HideBubble(const TrayBubbleView* bubble_view) override;
  86. // PhoneHubUiController::Observer:
  87. void OnPhoneHubUiStateChanged() override;
  88. // SessionObserver:
  89. void OnSessionStateChanged(session_manager::SessionState state) override;
  90. void OnActiveUserSessionChanged(const AccountId& account_id) override;
  91. // Updates the visibility of the tray in the shelf based on the feature is
  92. // enabled.
  93. void UpdateVisibility();
  94. // Disables the animation and enables it back after a 5s delay. This tray's
  95. // visibility can be updated when the connection is complete. After a session
  96. // has started (login/unlock/user-switch), a duration is added here to delay
  97. // the animation being enabled, since it would take a few seconds to get
  98. // connected.
  99. void TemporarilyDisableAnimation();
  100. // Button click/press handlers for main phone hub icon and secondary
  101. // Eche icon.
  102. void EcheIconActivated(const ui::Event& event);
  103. void PhoneHubIconActivated(const ui::Event& event);
  104. // Icon of the tray. Unowned.
  105. views::ImageButton* icon_;
  106. // Icon for Eche. Unowned.
  107. views::ImageButton* eche_icon_ = nullptr;
  108. // The loading indicator, showing a throbber animation on top of the icon.
  109. EcheIconLoadingIndicatorView* eche_loading_indicator_ = nullptr;
  110. // This callback is called when the Eche icon is activated.
  111. base::RepeatingCallback<bool(const ui::Event&)> eche_icon_callback_ =
  112. base::BindRepeating([](const ui::Event&) { return true; });
  113. // Controls the main content view displayed in the bubble based on the current
  114. // PhoneHub state.
  115. std::unique_ptr<PhoneHubUiController> ui_controller_;
  116. // The bubble that appears after clicking the tray button.
  117. std::unique_ptr<TrayBubbleWrapper> bubble_;
  118. // The header status view on top of the bubble.
  119. views::View* phone_status_view_ = nullptr;
  120. // The main content view of the bubble, which changes depending on the state.
  121. // Unowned.
  122. PhoneHubContentView* content_view_ = nullptr;
  123. base::ScopedObservation<PhoneHubUiController, PhoneHubUiController::Observer>
  124. observed_phone_hub_ui_controller_{this};
  125. base::ScopedObservation<SessionControllerImpl, SessionObserver>
  126. observed_session_{this};
  127. base::WeakPtrFactory<PhoneHubTray> weak_factory_{this};
  128. };
  129. } // namespace ash
  130. #endif // ASH_SYSTEM_PHONEHUB_PHONE_HUB_TRAY_H_