app_list_bubble_apps_page.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // Copyright 2021 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_APP_LIST_VIEWS_APP_LIST_BUBBLE_APPS_PAGE_H_
  5. #define ASH_APP_LIST_VIEWS_APP_LIST_BUBBLE_APPS_PAGE_H_
  6. #include <memory>
  7. #include "ash/app_list/app_list_model_provider.h"
  8. #include "ash/app_list/app_list_view_provider.h"
  9. #include "ash/app_list/views/app_list_nudge_controller.h"
  10. #include "ash/app_list/views/app_list_toast_container_view.h"
  11. #include "ash/ash_export.h"
  12. #include "base/callback_forward.h"
  13. #include "base/memory/weak_ptr.h"
  14. #include "ui/base/metadata/metadata_header_macros.h"
  15. #include "ui/gfx/animation/tween.h"
  16. #include "ui/views/view.h"
  17. #include "ui/views/view_observer.h"
  18. namespace base {
  19. class TimeDelta;
  20. } // namespace base
  21. namespace ui {
  22. class Layer;
  23. } // namespace ui
  24. namespace views {
  25. class Label;
  26. class Separator;
  27. } // namespace views
  28. namespace ash {
  29. class ApplicationDragAndDropHost;
  30. class AppListA11yAnnouncer;
  31. class AppListConfig;
  32. class AppListFolderController;
  33. class AppListKeyboardController;
  34. class AppListNudgeController;
  35. class AppListViewDelegate;
  36. class ContinueSectionView;
  37. class IconButton;
  38. class RecentAppsView;
  39. class RoundedScrollBar;
  40. class ScrollableAppsGridView;
  41. class ScrollViewGradientHelper;
  42. class SearchBoxView;
  43. // The default page for the app list bubble / clamshell launcher. Contains a
  44. // scroll view with:
  45. // - Continue section with recent tasks and recent apps
  46. // - Grid of all apps
  47. // Does not include the search box, which is owned by a parent view.
  48. class ASH_EXPORT AppListBubbleAppsPage
  49. : public views::View,
  50. public views::ViewObserver,
  51. public AppListModelProvider::Observer,
  52. public AppListToastContainerView::Delegate,
  53. public AppListViewProvider {
  54. public:
  55. METADATA_HEADER(AppListBubbleAppsPage);
  56. AppListBubbleAppsPage(AppListViewDelegate* view_delegate,
  57. ApplicationDragAndDropHost* drag_and_drop_host,
  58. AppListConfig* app_list_config,
  59. AppListA11yAnnouncer* a11y_announcer,
  60. AppListFolderController* folder_controller,
  61. SearchBoxView* search_box);
  62. AppListBubbleAppsPage(const AppListBubbleAppsPage&) = delete;
  63. AppListBubbleAppsPage& operator=(const AppListBubbleAppsPage&) = delete;
  64. ~AppListBubbleAppsPage() override;
  65. // Updates the continue section and recent apps.
  66. void UpdateSuggestions();
  67. // Starts the launcher show animation.
  68. void AnimateShowLauncher(bool is_side_shelf);
  69. // Prepares for launcher hide animation. None of the child views animate, but
  70. // this disables the scroll view gradient mask to improve performance.
  71. void PrepareForHideLauncher();
  72. // Starts the animation for showing the apps page, coming from another page.
  73. void AnimateShowPage();
  74. // Starts the animation for hiding the apps page, going to another page.
  75. void AnimateHidePage();
  76. // Resets the scroll position to the top.
  77. void ResetScrollPosition();
  78. // Aborts all layer animations, which invokes their cleanup callbacks.
  79. void AbortAllAnimations();
  80. // Disables all children so they cannot be focused, allowing the open folder
  81. // view to handle focus.
  82. void DisableFocusForShowingActiveFolder(bool disabled);
  83. // Handles `AppListController::UpdateAppListWithNewSortingOrder()` for the
  84. // bubble launcher apps page.
  85. void UpdateForNewSortingOrder(
  86. const absl::optional<AppListSortOrder>& new_order,
  87. bool animate,
  88. base::OnceClosure update_position_closure,
  89. base::OnceClosure animation_done_closure);
  90. // Scrolls to fully show the toast if the toast is partially shown or hidden
  91. // from the scroll view's perspective. Returns true if scrolling is performed.
  92. bool MaybeScrollToShowToast();
  93. // views::View:
  94. void Layout() override;
  95. void VisibilityChanged(views::View* starting_from, bool is_visible) override;
  96. void OnThemeChanged() override;
  97. // view::ViewObserver:
  98. void OnViewVisibilityChanged(views::View* observed_view,
  99. views::View* starting_view) override;
  100. // AppListModelProvider::Observer:
  101. void OnActiveAppListModelsChanged(AppListModel* model,
  102. SearchModel* search_model) override;
  103. // AppListToastContainerView::Delegate:
  104. void OnNudgeRemoved() override;
  105. // AppListViewProvider:
  106. ContinueSectionView* GetContinueSectionView() override;
  107. RecentAppsView* GetRecentAppsView() override;
  108. AppsGridView* GetAppsGridView() override;
  109. AppListToastContainerView* GetToastContainerView() override;
  110. // Updates the visibility of the continue section based on user preference.
  111. void UpdateContinueSectionVisibility();
  112. views::ScrollView* scroll_view() { return scroll_view_; }
  113. IconButton* toggle_continue_section_button() {
  114. return toggle_continue_section_button_;
  115. }
  116. ScrollableAppsGridView* scrollable_apps_grid_view() {
  117. return scrollable_apps_grid_view_;
  118. }
  119. // Which layer animates is an implementation detail.
  120. ui::Layer* GetPageAnimationLayerForTest();
  121. views::View* continue_label_container_for_test() {
  122. return continue_label_container_;
  123. }
  124. RecentAppsView* recent_apps_for_test() { return recent_apps_; }
  125. views::Separator* separator_for_test() { return separator_; }
  126. AppListToastContainerView* toast_container_for_test() {
  127. return toast_container_;
  128. }
  129. AppListNudgeController* app_list_nudge_controller() {
  130. return app_list_nudge_controller_.get();
  131. }
  132. ScrollViewGradientHelper* gradient_helper_for_test() {
  133. return gradient_helper_.get();
  134. }
  135. private:
  136. friend class AppListTestHelper;
  137. // Creates the `continue_label_container_` view and its contents, the
  138. // continue label and the toggle continue section button.
  139. void InitContinueLabelContainer(views::View* scroll_contents);
  140. // Updates the continue label container and its child views, including the
  141. // container visibility and the toggle button state.
  142. void UpdateContinueLabelContainer();
  143. void UpdateSeparatorVisibility();
  144. // Destroys the layer for `view`. Not static so it can be used with weak
  145. // pointers.
  146. void DestroyLayerForView(views::View* view);
  147. // Callback for when the apps grid view animation ends.
  148. void OnAppsGridViewAnimationEnded();
  149. // Called after sort to handle focus.
  150. void HandleFocusAfterSort();
  151. // Called when the animation to fade out app list items is completed.
  152. // `aborted` indicates whether the fade out animation is aborted.
  153. void OnAppsGridViewFadeOutAnimationEnded(
  154. const absl::optional<AppListSortOrder>& new_order,
  155. bool aborted);
  156. // Called when the animation to fade in app list items is completed.
  157. // `aborted` indicates whether the fade in animation is aborted.
  158. void OnAppsGridViewFadeInAnimationEnded(bool aborted);
  159. // Called at the end of the reorder animation. In detail, it is executed in
  160. // the following scenarios:
  161. // (1) At the end of the fade out animation when the fade out is aborted, or
  162. // (2) At the end of the fade in animation.
  163. void OnReorderAnimationEnded();
  164. // Animates `view` using a layer animation. Creates the layer if needed. The
  165. // layer is pushed down by `vertical_offset` at the start of the animation and
  166. // animates back to its original position with `duration`.
  167. void SlideViewIntoPosition(views::View* view,
  168. int vertical_offset,
  169. base::TimeDelta duration,
  170. gfx::Tween::Type tween_type);
  171. // Animates `view` using a layer fade-in animation as part of the show
  172. // continue section animation. Takes `view` because the same animation is used
  173. // for continue tasks and for recent apps.
  174. void FadeInContinueSectionView(views::View* view);
  175. // Pressed callback for `toggle_continue_section_button_`.
  176. void OnToggleContinueSection();
  177. AppListViewDelegate* view_delegate_ = nullptr;
  178. views::ScrollView* scroll_view_ = nullptr;
  179. RoundedScrollBar* scroll_bar_ = nullptr;
  180. // Wraps both the continue label and the toggle continue section button.
  181. // Only exists when feature LauncherHideContinueSection is enabled.
  182. views::View* continue_label_container_ = nullptr;
  183. views::Label* continue_label_ = nullptr;
  184. IconButton* toggle_continue_section_button_ = nullptr;
  185. ContinueSectionView* continue_section_ = nullptr;
  186. RecentAppsView* recent_apps_ = nullptr;
  187. views::Separator* separator_ = nullptr;
  188. AppListToastContainerView* toast_container_ = nullptr;
  189. ScrollableAppsGridView* scrollable_apps_grid_view_ = nullptr;
  190. // The search box owned by AppListBubbleView.
  191. SearchBoxView* search_box_ = nullptr;
  192. std::unique_ptr<AppListKeyboardController> app_list_keyboard_controller_;
  193. std::unique_ptr<AppListNudgeController> app_list_nudge_controller_;
  194. // Adds fade in/out gradients to `scroll_view_`.
  195. std::unique_ptr<ScrollViewGradientHelper> gradient_helper_;
  196. // A closure to update item positions. It should run at the end of the fade
  197. // out animation when items are reordered.
  198. base::OnceClosure update_position_closure_;
  199. // A closure that runs at the end of the reorder animation.
  200. base::OnceClosure reorder_animation_done_closure_;
  201. base::WeakPtrFactory<AppListBubbleAppsPage> weak_factory_{this};
  202. };
  203. } // namespace ash
  204. #endif // ASH_APP_LIST_VIEWS_APP_LIST_BUBBLE_APPS_PAGE_H_