search_result_page_view.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. // Copyright 2014 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_SEARCH_RESULT_PAGE_VIEW_H_
  5. #define ASH_APP_LIST_VIEWS_SEARCH_RESULT_PAGE_VIEW_H_
  6. #include <memory>
  7. #include <utility>
  8. #include <vector>
  9. #include "ash/app_list/app_list_model_provider.h"
  10. #include "ash/app_list/model/app_list_model.h"
  11. #include "ash/app_list/views/app_list_page.h"
  12. #include "ash/app_list/views/result_selection_controller.h"
  13. #include "ash/app_list/views/search_result_container_view.h"
  14. #include "ash/app_list/views/search_result_page_dialog_controller.h"
  15. #include "ash/ash_export.h"
  16. #include "base/memory/weak_ptr.h"
  17. #include "base/timer/timer.h"
  18. namespace ash {
  19. class AppListMainView;
  20. class ProductivityLauncherSearchView;
  21. class PrivacyContainerView;
  22. class SearchBoxView;
  23. class SearchResultBaseView;
  24. class SearchResultListView;
  25. class SearchResultTileItemListView;
  26. class SearchResultPageAnchoredDialog;
  27. class SystemShadow;
  28. // The search results page for the app list.
  29. class ASH_EXPORT SearchResultPageView
  30. : public AppListPage,
  31. public AppListModelProvider::Observer,
  32. public SearchResultContainerView::Delegate {
  33. public:
  34. SearchResultPageView();
  35. SearchResultPageView(const SearchResultPageView&) = delete;
  36. SearchResultPageView& operator=(const SearchResultPageView&) = delete;
  37. ~SearchResultPageView() override;
  38. void InitializeContainers(AppListViewDelegate* view_delegate,
  39. AppListMainView* app_list_main_view,
  40. SearchBoxView* search_box_view);
  41. const std::vector<SearchResultContainerView*>& result_container_views() {
  42. return result_container_views_;
  43. }
  44. bool IsFirstResultTile() const;
  45. bool IsFirstResultHighlighted() const;
  46. // Overridden from views::View:
  47. const char* GetClassName() const override;
  48. gfx::Size CalculatePreferredSize() const override;
  49. void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
  50. void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
  51. void OnThemeChanged() override;
  52. // AppListPage overrides:
  53. void OnHidden() override;
  54. void OnShown() override;
  55. void AnimateYPosition(AppListViewState target_view_state,
  56. const TransformAnimator& animator,
  57. float default_offset) override;
  58. void UpdatePageOpacityForState(AppListState state,
  59. float search_box_opacity,
  60. bool restore_opacity) override;
  61. void UpdatePageBoundsForState(AppListState state,
  62. const gfx::Rect& contents_bounds,
  63. const gfx::Rect& search_box_bounds) override;
  64. gfx::Rect GetPageBoundsForState(
  65. AppListState state,
  66. const gfx::Rect& contents_bounds,
  67. const gfx::Rect& search_box_bounds) const override;
  68. void OnAnimationStarted(AppListState from_state,
  69. AppListState to_state) override;
  70. void OnAnimationUpdated(double progress,
  71. AppListState from_state,
  72. AppListState to_state) override;
  73. gfx::Size GetPreferredSearchBoxSize() const override;
  74. // Overridden from AppListModelProvider::Observer:
  75. void OnActiveAppListModelsChanged(AppListModel* model,
  76. SearchModel* search_model) override;
  77. // Overridden from SearchResultContainerView::Delegate:
  78. void OnSearchResultContainerResultsChanging() override;
  79. void OnSearchResultContainerResultsChanged() override;
  80. // Whether any results are available for selection within the search result
  81. // UI.
  82. bool CanSelectSearchResults() const;
  83. views::View* contents_view() { return contents_view_; }
  84. SearchResultBaseView* first_result_view() const { return first_result_view_; }
  85. ResultSelectionController* result_selection_controller() {
  86. return result_selection_controller_.get();
  87. }
  88. ProductivityLauncherSearchView* productivity_launcher_search_view_for_test() {
  89. return productivity_launcher_search_view_;
  90. }
  91. SearchResultPageAnchoredDialog* dialog_for_test() {
  92. return dialog_controller_->dialog();
  93. }
  94. // Returns background color for the given state.
  95. SkColor GetBackgroundColorForState(AppListState state) const;
  96. // Hide zero state search result view when ProductivityLauncher is enabled.
  97. bool ShouldShowSearchResultView() const;
  98. // Called when the app list search query changes and new search is about to
  99. // start or cleared.
  100. void UpdateForNewSearch();
  101. // Sets visibility of result container and separator views so only containers
  102. // that contain some results are shown.
  103. void UpdateResultContainersVisibility();
  104. PrivacyContainerView* GetPrivacyContainerViewForTest();
  105. SearchResultTileItemListView* GetSearchResultTileItemListViewForTest();
  106. SearchResultListView* GetSearchResultListViewForTest();
  107. private:
  108. // All possible states for the search results page. Used with productivity
  109. // launcher.
  110. enum class SearchResultsState { kClosed, kActive, kExpanded };
  111. // Separator between SearchResultContainerView.
  112. class HorizontalSeparator;
  113. // Passed to |result_selection_controller_| as a callback that gets called
  114. // when the currently selected result changes.
  115. // Ensures that |scroller_| visible rect contains the newly selected result.
  116. void SelectedResultChanged();
  117. // Sets whether changes in search result containers should be hidden from the
  118. // accessibility framework.
  119. // This is set while search results are being updated to reduce noisy updates
  120. // sent to the accessibility framework while the search result containers are
  121. // being rebuilt.
  122. // The |ignore| value is reset in NotifyA11yResultsChanged(), at which time
  123. // accessibility framework is notified that the view value/selected children
  124. // have changed.
  125. void SetIgnoreResultChangesForA11y(bool ignore);
  126. // Schedules a call to |NotifyA11yResultsChanged|. Called from
  127. // OnSearchResultContainerResultsChanged() when all result containers have
  128. // finished changing. The goal of the delay is to reduce the noise if the set
  129. // of results for a query has not stabilized, or while the user is still
  130. // changing the query.
  131. void ScheduleResultsChangedA11yNotification();
  132. // Notifies the accessibility framework that the set of search results has
  133. // changed.
  134. // Note: This ensures that results changes are not being hidden from a11y
  135. // framework.
  136. void NotifyA11yResultsChanged();
  137. // If required, sends a kSelection a11y notification for the currently
  138. // selected search result view.
  139. void NotifySelectedResultChanged();
  140. // Animates from the current search results state to the `target_state`. Used
  141. // with productivity launcher.
  142. void AnimateToSearchResultsState(SearchResultsState target_state);
  143. // Transitions between `from_rect` and `to_rect` by animating the clip rect.
  144. void AnimateBetweenBounds(const gfx::Rect& from_rect,
  145. const gfx::Rect& to_rect);
  146. // Called when the clip rect animation between bounds has ended.
  147. void OnAnimationBetweenBoundsEnded();
  148. // Get the page bounds according to the input SearchResultsState.
  149. gfx::Rect GetPageBoundsForResultState(SearchResultsState state) const;
  150. // Get the corner radius associated with the SearchResultsState.
  151. int GetCornerRadiusForSearchResultsState(SearchResultsState state);
  152. template <typename T>
  153. T* AddSearchResultContainerView(std::unique_ptr<T> result_container) {
  154. auto* result = result_container.get();
  155. AddSearchResultContainerViewInternal(std::move(result_container));
  156. return result;
  157. }
  158. void AddSearchResultContainerViewInternal(
  159. std::unique_ptr<SearchResultContainerView> result_container);
  160. AppListViewDelegate* view_delegate_ = nullptr;
  161. // The SearchResultContainerViews that compose the search page. All owned by
  162. // the views hierarchy.
  163. std::vector<SearchResultContainerView*> result_container_views_;
  164. // |ResultSelectionController| handles selection within the
  165. // |result_container_views_|
  166. std::unique_ptr<ResultSelectionController> result_selection_controller_;
  167. // Search result containers shown within search results page (and added to
  168. // `result_container_views_`).
  169. PrivacyContainerView* privacy_container_view_ = nullptr;
  170. SearchResultTileItemListView* search_result_tile_item_list_view_ = nullptr;
  171. SearchResultListView* search_result_list_view_ = nullptr;
  172. // Search result container used for productivity launcher.
  173. ProductivityLauncherSearchView* productivity_launcher_search_view_ = nullptr;
  174. // Separator view shown between search result tile item list and search
  175. // results list.
  176. HorizontalSeparator* result_lists_separator_ = nullptr;
  177. // View containing SearchCardView instances. Owned by view hierarchy.
  178. views::View* const contents_view_;
  179. // The first search result's view or nullptr if there's no search result.
  180. SearchResultBaseView* first_result_view_ = nullptr;
  181. // Timer used to delay calls to NotifyA11yResultsChanged().
  182. base::OneShotTimer notify_a11y_results_changed_timer_;
  183. // Whether the changes in search result containers are being hidden from the
  184. // accessibility framework.
  185. bool ignore_result_changes_for_a11y_ = false;
  186. // The last reported number of search results shown within search result
  187. // containers.
  188. int last_search_result_count_ = 0;
  189. // The currently shown search results state. Used with productivity launcher.
  190. SearchResultsState current_search_results_state_ =
  191. SearchResultsState::kClosed;
  192. std::unique_ptr<SystemShadow> shadow_;
  193. // The controller that manages dialogs modal to the search results page.
  194. std::unique_ptr<SearchResultPageDialogController> dialog_controller_;
  195. };
  196. } // namespace ash
  197. #endif // ASH_APP_LIST_VIEWS_SEARCH_RESULT_PAGE_VIEW_H_