holding_space_tray_child_bubble.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_HOLDING_SPACE_HOLDING_SPACE_TRAY_CHILD_BUBBLE_H_
  5. #define ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_TRAY_CHILD_BUBBLE_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "ash/public/cpp/holding_space/holding_space_controller.h"
  9. #include "ash/public/cpp/holding_space/holding_space_controller_observer.h"
  10. #include "ash/public/cpp/holding_space/holding_space_model.h"
  11. #include "ash/public/cpp/holding_space/holding_space_model_observer.h"
  12. #include "base/scoped_observation.h"
  13. #include "ui/views/view.h"
  14. namespace ui {
  15. class LayerAnimationObserver;
  16. } // namespace ui
  17. namespace ash {
  18. class HoldingSpaceItemView;
  19. class HoldingSpaceItemViewsSection;
  20. class HoldingSpaceViewDelegate;
  21. // Child bubble of the `HoldingSpaceTrayBubble`.
  22. class HoldingSpaceTrayChildBubble : public views::View,
  23. public HoldingSpaceControllerObserver,
  24. public HoldingSpaceModelObserver {
  25. public:
  26. explicit HoldingSpaceTrayChildBubble(HoldingSpaceViewDelegate* delegate);
  27. HoldingSpaceTrayChildBubble(const HoldingSpaceTrayChildBubble& other) =
  28. delete;
  29. HoldingSpaceTrayChildBubble& operator=(
  30. const HoldingSpaceTrayChildBubble& other) = delete;
  31. ~HoldingSpaceTrayChildBubble() override;
  32. // Initializes the child bubble.
  33. void Init();
  34. // Resets the child bubble. Called when the tray bubble starts closing to stop
  35. // observing the holding space controller/model to ensure that no new items
  36. // are created while the bubble widget is begin asynchronously closed.
  37. void Reset();
  38. // Returns all holding space item views in the child bubble. Views are
  39. // returned in top-to-bottom, left-to-right order (or mirrored for RTL).
  40. std::vector<HoldingSpaceItemView*> GetHoldingSpaceItemViews();
  41. // HoldingSpaceControllerObserver:
  42. void OnHoldingSpaceModelAttached(HoldingSpaceModel* model) override;
  43. void OnHoldingSpaceModelDetached(HoldingSpaceModel* model) override;
  44. // HoldingSpaceModelObserver:
  45. void OnHoldingSpaceItemsAdded(
  46. const std::vector<const HoldingSpaceItem*>& items) override;
  47. void OnHoldingSpaceItemsRemoved(
  48. const std::vector<const HoldingSpaceItem*>& items) override;
  49. void OnHoldingSpaceItemInitialized(const HoldingSpaceItem* item) override;
  50. protected:
  51. // Invoked to create the `sections_` for this child bubble.
  52. virtual std::vector<std::unique_ptr<HoldingSpaceItemViewsSection>>
  53. CreateSections() = 0;
  54. HoldingSpaceViewDelegate* delegate() { return delegate_; }
  55. private:
  56. // views::View:
  57. const char* GetClassName() const override;
  58. void ChildPreferredSizeChanged(views::View* child) override;
  59. void ChildVisibilityChanged(views::View* child) override;
  60. void OnGestureEvent(ui::GestureEvent* event) override;
  61. bool OnMousePressed(const ui::MouseEvent& event) override;
  62. void OnThemeChanged() override;
  63. // Invoked to animate in/out this view if necessary.
  64. void MaybeAnimateIn();
  65. void MaybeAnimateOut();
  66. // Invoked to animate in/out this view. These methods should only be called
  67. // from `MaybeAnimateIn()`/`MaybeAnimateOut()` respectively as those methods
  68. // contain gating criteria for when these methods may be invoked.
  69. void AnimateIn(ui::LayerAnimationObserver* observer);
  70. void AnimateOut(ui::LayerAnimationObserver* observer);
  71. // Invoked when an in/out animation has completed. If `aborted` is true,
  72. // the animation was cancelled and did not animation to target end values.
  73. void OnAnimateInCompleted(bool aborted);
  74. void OnAnimateOutCompleted(bool aborted);
  75. HoldingSpaceViewDelegate* const delegate_;
  76. // Views owned by view hierarchy.
  77. std::vector<HoldingSpaceItemViewsSection*> sections_;
  78. // Whether or not to ignore `ChildVisibilityChanged()` events. This is used
  79. // when removing all holding space item views from `sections_` to prevent this
  80. // view from inadvertently regaining visibility.
  81. bool ignore_child_visibility_changed_ = false;
  82. // Whether or not this view is currently being animated out.
  83. bool is_animating_out_ = false;
  84. base::ScopedObservation<HoldingSpaceController,
  85. HoldingSpaceControllerObserver>
  86. controller_observer_{this};
  87. base::ScopedObservation<HoldingSpaceModel, HoldingSpaceModelObserver>
  88. model_observer_{this};
  89. base::WeakPtrFactory<HoldingSpaceTrayChildBubble> weak_factory_{this};
  90. };
  91. } // namespace ash
  92. #endif // ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_TRAY_CHILD_BUBBLE_H_