feature_pods_container_view.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_FEATURE_PODS_CONTAINER_VIEW_H_
  5. #define ASH_SYSTEM_UNIFIED_FEATURE_PODS_CONTAINER_VIEW_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/pagination/pagination_model_observer.h"
  8. #include "ui/views/view.h"
  9. #include "ui/views/view_model.h"
  10. namespace ash {
  11. class FeaturePodButton;
  12. class PaginationModel;
  13. class UnifiedSystemTrayController;
  14. // Container of feature pods buttons in the middle of UnifiedSystemTrayView.
  15. // The container has number of buttons placed in 3x3 plane at regular distances.
  16. // FeaturePodButtons implements these individual buttons.
  17. // The container also implements collapsed state where the top 5 buttons are
  18. // horizontally placed and others are hidden.
  19. class ASH_EXPORT FeaturePodsContainerView : public views::View,
  20. public PaginationModelObserver {
  21. public:
  22. FeaturePodsContainerView(UnifiedSystemTrayController* controller,
  23. bool initially_expanded);
  24. FeaturePodsContainerView(const FeaturePodsContainerView&) = delete;
  25. FeaturePodsContainerView& operator=(const FeaturePodsContainerView&) = delete;
  26. ~FeaturePodsContainerView() override;
  27. // Add a FeaturePodButton as a child view and if it's visible add it to the
  28. // view structure and update the pagination model.
  29. void AddFeaturePodButton(FeaturePodButton* button);
  30. // Change the expanded state. 0.0 if collapsed, and 1.0 if expanded.
  31. // Otherwise, it shows intermediate state. If collapsed, all the buttons are
  32. // horizontally placed.
  33. void SetExpandedAmount(double expanded_amount);
  34. // Set the number of rows of feature pods based on the max height the
  35. // container can have.
  36. void SetMaxHeight(int max_height);
  37. // Get height of the view when |expanded_amount| is set to 1.0.
  38. int GetExpandedHeight() const;
  39. // Get the height of the view when |expanded_amount| is set to 0.0.
  40. int GetCollapsedHeight() const;
  41. // Returns the number of children that prefer to be visible.
  42. int GetVisibleCount() const;
  43. // Make sure button is visible by switching page if needed.
  44. void EnsurePageWithButton(views::View* button);
  45. // views::View:
  46. gfx::Size CalculatePreferredSize() const override;
  47. void ChildVisibilityChanged(View* child) override;
  48. void ViewHierarchyChanged(
  49. const views::ViewHierarchyChangedDetails& details) override;
  50. void Layout() override;
  51. void OnGestureEvent(ui::GestureEvent* event) override;
  52. void OnScrollEvent(ui::ScrollEvent* event) override;
  53. bool OnMouseWheel(const ui::MouseWheelEvent& event) override;
  54. const char* GetClassName() const override;
  55. int row_count() const { return feature_pod_rows_; }
  56. private:
  57. friend class FeaturePodsContainerViewTest;
  58. // Calculate the current position of the button from |visible_index| and
  59. // |expanded_amount_|.
  60. gfx::Point GetButtonPosition(int visible_index) const;
  61. void UpdateChildVisibility();
  62. // Update |collapsed_state_padding_|.
  63. void UpdateCollapsedSidePadding();
  64. // Calculates the ideal bounds for all feature pods.
  65. void CalculateIdealBoundsForFeaturePods();
  66. // Calculate the number of feature pod rows based on available height.
  67. int CalculateRowsFromHeight(int height);
  68. // Calculates the offset for |page_of_view| based on current page and
  69. // transition target page.
  70. const gfx::Vector2d CalculateTransitionOffset(int page_of_view) const;
  71. // Returns true if button at provided index is visible.
  72. bool IsButtonVisible(FeaturePodButton* button, int index);
  73. // Returns the number of tiles per page.
  74. int GetTilesPerPage() const;
  75. // Updates page splits for feature pod buttons.
  76. void UpdateTotalPages();
  77. // PaginationModelObserver:
  78. void TransitionChanged() override;
  79. UnifiedSystemTrayController* const controller_;
  80. // Owned by UnifiedSystemTrayModel.
  81. PaginationModel* const pagination_model_;
  82. // The last |expanded_amount| passed to SetExpandedAmount().
  83. double expanded_amount_;
  84. // Number of rows of feature pods to display. Updated based on the available
  85. // max height for FeaturePodsContainer.
  86. int feature_pod_rows_ = 0;
  87. // Horizontal side padding in dip for collapsed state.
  88. int collapsed_side_padding_ = 0;
  89. // Used for preventing reentrancy issue in ChildVisibilityChanged. Should be
  90. // always false if FeaturePodsContainerView is not in the call stack.
  91. bool changing_visibility_ = false;
  92. // A view model that contains all visible feature pod buttons.
  93. // Used to calculate required number of pages.
  94. views::ViewModelT<FeaturePodButton> visible_buttons_;
  95. };
  96. } // namespace ash
  97. #endif // ASH_SYSTEM_UNIFIED_FEATURE_PODS_CONTAINER_VIEW_H_