productivity_launcher_search_view.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_PRODUCTIVITY_LAUNCHER_SEARCH_VIEW_H_
  5. #define ASH_APP_LIST_VIEWS_PRODUCTIVITY_LAUNCHER_SEARCH_VIEW_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "ash/app_list/app_list_model_provider.h"
  10. #include "ash/app_list/views/search_result_container_view.h"
  11. #include "ash/ash_export.h"
  12. #include "base/time/time.h"
  13. #include "base/timer/timer.h"
  14. #include "ui/base/metadata/metadata_header_macros.h"
  15. #include "ui/views/view.h"
  16. namespace ash {
  17. class AppListViewDelegate;
  18. class ResultSelectionController;
  19. class SearchBoxView;
  20. class SearchResultPageDialogController;
  21. // The search results view for productivity launcher. Contains a scrolling list
  22. // of search results. Does not include the search box, which is owned by a
  23. // parent view.
  24. class ASH_EXPORT ProductivityLauncherSearchView
  25. : public views::View,
  26. public SearchResultContainerView::Delegate,
  27. public AppListModelProvider::Observer {
  28. public:
  29. METADATA_HEADER(ProductivityLauncherSearchView);
  30. ProductivityLauncherSearchView(
  31. AppListViewDelegate* view_delegate,
  32. SearchResultPageDialogController* dialog_controller,
  33. SearchBoxView* search_box_view);
  34. ProductivityLauncherSearchView(const ProductivityLauncherSearchView&) =
  35. delete;
  36. ProductivityLauncherSearchView& operator=(
  37. const ProductivityLauncherSearchView&) = delete;
  38. ~ProductivityLauncherSearchView() override;
  39. // SearchResultContainerView::Delegate:
  40. void OnSearchResultContainerResultsChanging() override;
  41. void OnSearchResultContainerResultsChanged() override;
  42. // views::View:
  43. void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
  44. // AppListModelProvider::Observer:
  45. void OnActiveAppListModelsChanged(AppListModel* model,
  46. SearchModel* search_model) override;
  47. // Called when the app list search query changes and new search is about to
  48. // start or cleared.
  49. // `search_active` - whether search update will result in a new search. This
  50. // will be false when the search is about to be cleared using an empty query.
  51. void UpdateForNewSearch(bool search_active);
  52. // Returns true if there are search results that can be keyboard selected.
  53. bool CanSelectSearchResults();
  54. // Sums the heights of all search_result_list_views_ owned by this view.
  55. int TabletModePreferredHeight();
  56. // Returns a layer that can be used for launcher page animations. Which layer
  57. // is an implementation detail.
  58. ui::Layer* GetPageAnimationLayer() const;
  59. std::vector<SearchResultContainerView*> result_container_views_for_test() {
  60. return result_container_views_;
  61. }
  62. ResultSelectionController* result_selection_controller_for_test() {
  63. return result_selection_controller_.get();
  64. }
  65. private:
  66. // Passed to |result_selection_controller_| as a callback that gets called
  67. // when the currently selected result changes.
  68. // Scrolls the list view to the newly selected result.
  69. void OnSelectedResultChanged();
  70. // Sets whether changes in search result containers should be hidden from the
  71. // accessibility framework.
  72. // This is set while search results are being updated to reduce noisy updates
  73. // sent to the accessibility framework while the search result containers are
  74. // being rebuilt.
  75. // The |ignore| value is reset in NotifyA11yResultsChanged(), at which time
  76. // accessibility framework is notified that the view value/selected children
  77. // have changed.
  78. void SetIgnoreResultChangesForA11y(bool ignore);
  79. // Schedules a call to |NotifyA11yResultsChanged|. Called from
  80. // OnSearchResultContainerResultsChanged() when all result containers have
  81. // finished changing. The goal of the delay is to silence bursts of A11Y
  82. // events caused by from rapidly changing user queries and consecutive search
  83. // result updates.
  84. void ScheduleResultsChangedA11yNotification();
  85. // Notifies the accessibility framework that the set of search results has
  86. // changed.
  87. // Note: This ensures that results changes are not being hidden from a11y
  88. // framework.
  89. void NotifyA11yResultsChanged();
  90. // Send a kSelection a11y notification for the currently selected search
  91. // result view unless overridden by |ignore_result_changes_for_a11y_|.
  92. void MaybeNotifySelectedResultChanged();
  93. SearchResultPageDialogController* const dialog_controller_;
  94. SearchBoxView* const search_box_view_;
  95. // The scroll view that contains all the result_container_views_.
  96. views::ScrollView* scroll_view_ = nullptr;
  97. // Whether changes in search result containers are hidden from the
  98. // accessibility framework.
  99. bool ignore_result_changes_for_a11y_ = false;
  100. // Containers for search result views. The contained views are owned by the
  101. // views hierarchy. Used by result_selection_controller_.
  102. std::vector<SearchResultContainerView*> result_container_views_;
  103. // Cache of the last shown search results' animation metadata.
  104. std::vector<SearchResultContainerView::SearchResultAimationMetadata>
  105. last_result_metadata_;
  106. // Handles search result selection.
  107. std::unique_ptr<ResultSelectionController> result_selection_controller_;
  108. // Timer used to delay calls to NotifyA11yResultsChanged().
  109. base::OneShotTimer notify_a11y_results_changed_timer_;
  110. // Stores the last time fast search result update animations were used.
  111. absl::optional<base::TimeTicks> search_result_fast_update_time_;
  112. // The last reported number of search results shown by all containers.
  113. int last_search_result_count_ = 0;
  114. };
  115. } // namespace ash
  116. #endif // ASH_APP_LIST_VIEWS_PRODUCTIVITY_LAUNCHER_SEARCH_VIEW_H_