unified_system_tray_view.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. #ifndef ASH_SYSTEM_UNIFIED_UNIFIED_SYSTEM_TRAY_VIEW_H_
  5. #define ASH_SYSTEM_UNIFIED_UNIFIED_SYSTEM_TRAY_VIEW_H_
  6. #include "ash/ash_export.h"
  7. #include "ui/views/focus/focus_manager.h"
  8. #include "ui/views/view.h"
  9. namespace ash {
  10. class FeaturePodButton;
  11. class FeaturePodsContainerView;
  12. class TopShortcutsView;
  13. class UnifiedMediaControlsContainer;
  14. class NotificationHiddenView;
  15. class PageIndicatorView;
  16. class UnifiedSystemInfoView;
  17. class UnifiedSystemTrayController;
  18. // Container view of slider views. If SetExpandedAmount() is called with 1.0,
  19. // the behavior is same as vertiacal BoxLayout, but otherwise it shows
  20. // intermediate state during animation.
  21. class UnifiedSlidersContainerView : public views::View {
  22. public:
  23. explicit UnifiedSlidersContainerView(bool initially_expanded);
  24. UnifiedSlidersContainerView(const UnifiedSlidersContainerView&) = delete;
  25. UnifiedSlidersContainerView& operator=(const UnifiedSlidersContainerView&) =
  26. delete;
  27. ~UnifiedSlidersContainerView() override;
  28. // Change the expanded state. 0.0 if collapsed, and 1.0 if expanded.
  29. // Otherwise, it shows intermediate state.
  30. void SetExpandedAmount(double expanded_amount);
  31. // Get height of the view when |expanded_amount| is set to 1.0.
  32. int GetExpandedHeight() const;
  33. // Update opacity of each child slider views based on |expanded_amount_|.
  34. void UpdateOpacity();
  35. // views::View:
  36. void Layout() override;
  37. gfx::Size CalculatePreferredSize() const override;
  38. const char* GetClassName() const override;
  39. private:
  40. double expanded_amount_;
  41. };
  42. // View class of the main bubble in UnifiedSystemTray.
  43. //
  44. // The UnifiedSystemTray contains two sub components:
  45. // 1. MessageCenter: contains the list of notifications
  46. // 2. SystemTray: contains quick settings controls
  47. // Note that the term "UnifiedSystemTray" refers to entire bubble containing
  48. // both (1) and (2).
  49. class ASH_EXPORT UnifiedSystemTrayView : public views::View,
  50. public views::FocusTraversable,
  51. public views::FocusChangeListener {
  52. public:
  53. UnifiedSystemTrayView(UnifiedSystemTrayController* controller,
  54. bool initially_expanded);
  55. UnifiedSystemTrayView(const UnifiedSystemTrayView&) = delete;
  56. UnifiedSystemTrayView& operator=(const UnifiedSystemTrayView&) = delete;
  57. ~UnifiedSystemTrayView() override;
  58. // Set the maximum height that the view can take.
  59. void SetMaxHeight(int max_height);
  60. // Add feature pod button to |feature_pods_|.
  61. void AddFeaturePodButton(FeaturePodButton* button);
  62. // Add slider view.
  63. void AddSliderView(views::View* slider_view);
  64. // Add media controls view to |media_controls_container_|;
  65. void AddMediaControlsView(views::View* media_controls);
  66. // Hide the main view and show the given |detailed_view|.
  67. void SetDetailedView(views::View* detailed_view);
  68. // Remove the detailed view set by SetDetailedView, and show the main view.
  69. // It deletes |detailed_view| and children.
  70. void ResetDetailedView();
  71. // Save and restore keyboard focus of the currently focused element. Called
  72. // before transitioning into a detailed view.
  73. void SaveFocus();
  74. void RestoreFocus();
  75. // Set the first child view to be focused when focus is acquired.
  76. // This is the first visible child unless reverse is true, in which case
  77. // it is the last visible child.
  78. void FocusEntered(bool reverse);
  79. // Change the expanded state. 0.0 if collapsed, and 1.0 if expanded.
  80. // Otherwise, it shows intermediate state. This is triggered during the
  81. // progress of expand/collapse animation, updating the children accordingly.
  82. void SetExpandedAmount(double expanded_amount);
  83. // Get height of the system tray (excluding the message center) when
  84. // |expanded_amount| is set to 1.0.
  85. //
  86. // Note that this function is used to calculate the transform-based
  87. // collapse/expand animation, which is currently only enabled when there are
  88. // no notifications.
  89. int GetExpandedSystemTrayHeight() const;
  90. // Get height of the system menu (excluding the message center) when
  91. // |expanded_amount| is set to 0.0.
  92. int GetCollapsedSystemTrayHeight() const;
  93. // Get current height of the view (including the message center).
  94. int GetCurrentHeight() const;
  95. // Returns the number of visible feature pods.
  96. int GetVisibleFeaturePodCount() const;
  97. // Get the accessible name for the currently shown detailed view.
  98. std::u16string GetDetailedViewAccessibleName() const;
  99. // Returns true if a detailed view is being shown in the tray. (e.g Bluetooth
  100. // Settings).
  101. bool IsDetailedViewShown() const;
  102. // Show media controls view.
  103. void ShowMediaControls();
  104. // views::View:
  105. gfx::Size CalculatePreferredSize() const override;
  106. void OnGestureEvent(ui::GestureEvent* event) override;
  107. void Layout() override;
  108. void ChildPreferredSizeChanged(views::View* child) override;
  109. const char* GetClassName() const override;
  110. views::FocusTraversable* GetFocusTraversable() override;
  111. void AddedToWidget() override;
  112. void RemovedFromWidget() override;
  113. // views::FocusTraversable:
  114. views::FocusSearch* GetFocusSearch() override;
  115. views::FocusTraversable* GetFocusTraversableParent() override;
  116. views::View* GetFocusTraversableParentView() override;
  117. // views::FocusChangeListener:
  118. void OnWillChangeFocus(views::View* before, views::View* now) override;
  119. void OnDidChangeFocus(views::View* before, views::View* now) override;
  120. FeaturePodsContainerView* feature_pods_container() {
  121. return feature_pods_container_;
  122. }
  123. NotificationHiddenView* notification_hidden_view_for_testing() {
  124. return notification_hidden_view_;
  125. }
  126. View* detailed_view() { return detailed_view_container_; }
  127. View* detailed_view_for_testing() { return detailed_view_container_; }
  128. PageIndicatorView* page_indicator_view_for_test() {
  129. return page_indicator_view_;
  130. }
  131. UnifiedMediaControlsContainer* media_controls_container_for_testing() {
  132. return media_controls_container_;
  133. }
  134. private:
  135. class SystemTrayContainer;
  136. friend class UnifiedMessageCenterBubbleTest;
  137. // Get first and last focusable child views. These functions are used to
  138. // figure out if we need to focus out or to set the correct focused view
  139. // when focus is acquired from another widget.
  140. View* GetFirstFocusableChild();
  141. View* GetLastFocusableChild();
  142. double expanded_amount_;
  143. // Unowned.
  144. UnifiedSystemTrayController* const controller_;
  145. // Owned by views hierarchy.
  146. NotificationHiddenView* const notification_hidden_view_;
  147. TopShortcutsView* const top_shortcuts_view_;
  148. FeaturePodsContainerView* const feature_pods_container_;
  149. PageIndicatorView* const page_indicator_view_;
  150. UnifiedSlidersContainerView* const sliders_container_;
  151. UnifiedSystemInfoView* const system_info_view_;
  152. SystemTrayContainer* const system_tray_container_;
  153. views::View* const detailed_view_container_;
  154. // Null if media::kGlobalMediaControlsForChromeOS is disabled.
  155. UnifiedMediaControlsContainer* media_controls_container_ = nullptr;
  156. // The maximum height available to the view.
  157. int max_height_ = 0;
  158. // The view that is saved by calling SaveFocus().
  159. views::View* saved_focused_view_ = nullptr;
  160. const std::unique_ptr<views::FocusSearch> focus_search_;
  161. views::FocusManager* focus_manager_ = nullptr;
  162. const std::unique_ptr<ui::EventHandler> interacted_by_tap_recorder_;
  163. };
  164. } // namespace ash
  165. #endif // ASH_SYSTEM_UNIFIED_UNIFIED_SYSTEM_TRAY_VIEW_H_