app_list_bubble_view.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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_VIEW_H_
  5. #define ASH_APP_LIST_VIEWS_APP_LIST_BUBBLE_VIEW_H_
  6. #include <memory>
  7. #include "ash/app_list/app_list_view_provider.h"
  8. #include "ash/app_list/views/app_list_folder_controller.h"
  9. #include "ash/app_list/views/search_box_view_delegate.h"
  10. #include "ash/ash_export.h"
  11. #include "ash/public/cpp/app_list/app_list_types.h"
  12. #include "base/callback_forward.h"
  13. #include "base/memory/weak_ptr.h"
  14. #include "ui/views/view.h"
  15. namespace ash {
  16. class ApplicationDragAndDropHost;
  17. class AppListA11yAnnouncer;
  18. class AppListBubbleAppsPage;
  19. class AppListBubbleAssistantPage;
  20. class AppListBubbleSearchPage;
  21. class AppListFolderItem;
  22. class AppListFolderView;
  23. class AppListViewDelegate;
  24. class ButtonFocusSkipper;
  25. class FolderBackgroundView;
  26. class SearchBoxView;
  27. class SearchResultPageDialogController;
  28. class ViewShadow;
  29. // Contains the views for the bubble version of the launcher. It looks like a
  30. // system tray bubble. It does not derive from TrayBubbleView because it takes
  31. // focus by default, uses a different EventHandler for closing, and isn't tied
  32. // to the system tray area.
  33. class ASH_EXPORT AppListBubbleView : public views::View,
  34. public SearchBoxViewDelegate,
  35. public AppListFolderController {
  36. public:
  37. AppListBubbleView(AppListViewDelegate* view_delegate,
  38. ApplicationDragAndDropHost* drag_and_drop_host);
  39. AppListBubbleView(const AppListBubbleView&) = delete;
  40. AppListBubbleView& operator=(const AppListBubbleView&) = delete;
  41. ~AppListBubbleView() override;
  42. // If |drag_and_drop_host| is not nullptr it will be called upon drag and drop
  43. // operations outside the app list (e.g. to the shelf).
  44. void SetDragAndDropHostOfCurrentAppList(
  45. ApplicationDragAndDropHost* drag_and_drop_host);
  46. // Updates continue tasks and recent apps.
  47. void UpdateSuggestions();
  48. // Starts the bubble show animation. Pass `is_side_shelf` true for left or
  49. // right aligned shelf.
  50. void StartShowAnimation(bool is_side_shelf);
  51. // Starts the bubble hide animation. Pass `is_side_shelf` true for left or
  52. // right aligned shelf. `on_hide_animation_ended` is called on end or abort.
  53. void StartHideAnimation(bool is_side_shelf,
  54. base::OnceClosure on_hide_animation_ended);
  55. // Aborts all layer animations started by StartShowAnimation() or
  56. // StartHideAnimation(). This invokes their cleanup callbacks.
  57. void AbortAllAnimations();
  58. // Handles back action if it we have a use for it besides dismissing.
  59. bool Back();
  60. // Shows a sub-page.
  61. void ShowPage(AppListBubblePage page);
  62. // Returns true if the assistant page is showing.
  63. bool IsShowingEmbeddedAssistantUI() const;
  64. // Shows the assistant page.
  65. void ShowEmbeddedAssistantUI();
  66. // Returns the required height for this view in DIPs to show all apps in the
  67. // apps grid. Used for computing the bubble height on large screens.
  68. int GetHeightToFitAllApps() const;
  69. // Updates the continue section visibility based on user preference.
  70. void UpdateContinueSectionVisibility();
  71. // Handles `AppListController::UpdateAppListWithNewSortingOrder()` for the
  72. // app list bubble view.
  73. void UpdateForNewSortingOrder(
  74. const absl::optional<AppListSortOrder>& new_order,
  75. bool animate,
  76. base::OnceClosure update_position_closure);
  77. // views::View:
  78. const char* GetClassName() const override;
  79. bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
  80. void OnThemeChanged() override;
  81. void Layout() override;
  82. // SearchBoxViewDelegate:
  83. void QueryChanged(const std::u16string& trimmed_query,
  84. bool initiated_by_user) override;
  85. void AssistantButtonPressed() override;
  86. void CloseButtonPressed() override;
  87. void ActiveChanged(SearchBoxViewBase* sender) override {}
  88. void OnSearchBoxKeyEvent(ui::KeyEvent* event) override;
  89. bool CanSelectSearchResults() override;
  90. // AppListFolderController:
  91. void ShowFolderForItemView(AppListItemView* folder_item_view,
  92. bool focus_name_input,
  93. base::OnceClosure hide_callback) override;
  94. void ShowApps(AppListItemView* folder_item_view, bool select_folder) override;
  95. void ReparentFolderItemTransit(AppListFolderItem* folder_item) override;
  96. void ReparentDragEnded() override;
  97. // Initialize Assistant UIs for bubble view. Assistant UIs
  98. // (AppListAssistantMainStage, SuggestionContainerView) expect that their
  99. // OnUiVisibilityChanged methods get called via value update in
  100. // AssistantUiModel.
  101. //
  102. // But it does not happen for bubble view as AppListBubblePresenter have an
  103. // async call for OnZeroStateSearchDone. AppListBubbleView is instantiated
  104. // after the async call and those UIs will miss the event.
  105. //
  106. // This is a helper method to manually trigger the UI initialization.
  107. //
  108. // This method is designed to be explicitly called from AppListBubblePresenter
  109. // (i.e. instead of doing this in the constructor of AppListBubbleView) to
  110. // make the intention clear.
  111. //
  112. // TODO(b/239754561): Clean up: refactor Assistant UI initialization
  113. void InitializeUIForBubbleView();
  114. AppListBubblePage current_page_for_test() { return current_page_; }
  115. ViewShadow* view_shadow_for_test() { return view_shadow_.get(); }
  116. SearchBoxView* search_box_view_for_test() { return search_box_view_; }
  117. views::View* separator_for_test() { return separator_; }
  118. bool showing_folder_for_test() { return showing_folder_; }
  119. AppListBubbleAppsPage* apps_page_for_test() { return apps_page_; }
  120. AppListFolderView* folder_view_for_test() { return folder_view_; }
  121. private:
  122. friend class AppListTestHelper;
  123. friend class AssistantTestApiImpl;
  124. // Initializes the main contents (search box, apps page, and search page).
  125. void InitContentsView(ApplicationDragAndDropHost* drag_and_drop_host);
  126. // Initializes the folder view, which appears on top of all other views.
  127. void InitFolderView(ApplicationDragAndDropHost* drag_and_drop_host);
  128. // Makes the root apps grid view and other top-level views unfocusable if
  129. // `disabled` is true, such that focus is contained in the folder view.
  130. void DisableFocusForShowingActiveFolder(bool disabled);
  131. // Called when the show animation ends or aborts.
  132. void OnShowAnimationEnded(const gfx::Rect& layer_bounds);
  133. // Called when the hide animation ends or aborts.
  134. void OnHideAnimationEnded(const gfx::Rect& layer_bounds);
  135. // Hides the folder view if it's currently shown. It can be called if the
  136. // folder is not currently shown.
  137. // `animate` - Whether the folder view should be hidden using an animation.
  138. // `hide_for_reparent` - Whether the folder view is being hidden to initiate
  139. // item reparent user action (e.g. when dragging folder item out of the folder
  140. // view bounds).
  141. void HideFolderView(bool animate, bool hide_for_reparent);
  142. // Called when the reorder animation completes.
  143. void OnAppListReorderAnimationDone();
  144. // Focuses the search box if the view is not hiding.
  145. void MaybeFocusAndActivateSearchBox();
  146. AppListViewDelegate* const view_delegate_;
  147. std::unique_ptr<AppListA11yAnnouncer> a11y_announcer_;
  148. // Controller for showing a modal dialog in search results page.
  149. std::unique_ptr<SearchResultPageDialogController>
  150. search_page_dialog_controller_;
  151. // Explicitly store the current page because multiple pages can be visible
  152. // during animations.
  153. AppListBubblePage current_page_ = AppListBubblePage::kNone;
  154. std::unique_ptr<ViewShadow> view_shadow_;
  155. // The individual views are implementation details and are intentionally not
  156. // exposed via getters (except for tests).
  157. SearchBoxView* search_box_view_ = nullptr;
  158. views::View* separator_ = nullptr;
  159. AppListBubbleAppsPage* apps_page_ = nullptr;
  160. AppListBubbleSearchPage* search_page_ = nullptr;
  161. AppListBubbleAssistantPage* assistant_page_ = nullptr;
  162. // Lives in this class because it can overlap the search box.
  163. AppListFolderView* folder_view_ = nullptr;
  164. // Used to close an open folder view.
  165. FolderBackgroundView* folder_background_view_ = nullptr;
  166. // Whether we're showing the folder view. This is different from
  167. // folder_view_->GetVisible() because the view is "visible" but hidden when
  168. // dragging an item out of a folder.
  169. bool showing_folder_ = false;
  170. // Whether the view is animating hidden.
  171. bool is_hiding_ = false;
  172. // Called after the hide animation ends or aborts.
  173. base::OnceClosure on_hide_animation_ended_;
  174. // See class comment in .cc file.
  175. std::unique_ptr<ButtonFocusSkipper> button_focus_skipper_;
  176. base::WeakPtrFactory<AppListBubbleView> weak_factory_{this};
  177. };
  178. } // namespace ash
  179. #endif // ASH_APP_LIST_VIEWS_APP_LIST_BUBBLE_VIEW_H_