recent_apps_view.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_RECENT_APPS_VIEW_H_
  5. #define ASH_APP_LIST_VIEWS_RECENT_APPS_VIEW_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "ash/app_list/model/app_list_model_observer.h"
  10. #include "ash/ash_export.h"
  11. #include "ui/base/metadata/metadata_header_macros.h"
  12. #include "ui/views/view.h"
  13. namespace views {
  14. class BoxLayout;
  15. }
  16. namespace ash {
  17. class AppListKeyboardController;
  18. class AppListModel;
  19. class AppListConfig;
  20. class AppListItemView;
  21. class AppListViewDelegate;
  22. class SearchModel;
  23. // The recent apps row in the "Continue" section of the bubble launcher. Shows
  24. // a list of app icons.
  25. class ASH_EXPORT RecentAppsView : public AppListModelObserver,
  26. public views::View {
  27. public:
  28. METADATA_HEADER(RecentAppsView);
  29. RecentAppsView(AppListKeyboardController* keyboard_controller,
  30. AppListViewDelegate* view_delegate);
  31. RecentAppsView(const RecentAppsView&) = delete;
  32. RecentAppsView& operator=(const RecentAppsView&) = delete;
  33. ~RecentAppsView() override;
  34. // AppListModelObserver:
  35. void OnAppListItemWillBeDeleted(AppListItem* item) override;
  36. // Sets the `AppListConfig` that should be used to configure layout of
  37. // `AppListItemViews` shown within this view.
  38. void UpdateAppListConfig(const AppListConfig* app_list_config);
  39. // Sets the search model and app list model used to obtain the list of the
  40. // most recent apps. Should be called at least once, otherwise the recent apps
  41. // view will not display any results.
  42. void SetModels(SearchModel* search_model, AppListModel* model);
  43. // Updates the visibility of this view. The view may be hidden if there are
  44. // not enough suggestions or if the user has chosen to hide it.
  45. void UpdateVisibility();
  46. // Returns the number of AppListItemView children.
  47. int GetItemViewCount() const;
  48. // Returns an AppListItemView child. `index` must be valid.
  49. AppListItemView* GetItemViewAt(int index) const;
  50. // See AppsGridView::DisableFocusForShowingActiveFolder().
  51. void DisableFocusForShowingActiveFolder(bool disabled);
  52. // views::View:
  53. bool OnKeyPressed(const ui::KeyEvent& event) override;
  54. void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
  55. private:
  56. // Updates the recent apps view contents to show results provided by the
  57. // search model. Should be called at least once, otherwise the recent apps
  58. // view will not display any results.
  59. void UpdateResults(const std::vector<std::string>& ids_to_ignore);
  60. // Requests that focus move up and out (usually to the continue tasks).
  61. void MoveFocusUp();
  62. // Requests that focus move down and out (usually to the apps grid).
  63. void MoveFocusDown();
  64. // Returns the visual column of the child with focus, or -1 if there is none.
  65. int GetColumnOfFocusedChild() const;
  66. // Calculates how much padding is assigned to the AppListItemView.
  67. int CalculateTilePadding() const;
  68. AppListKeyboardController* const keyboard_controller_;
  69. AppListViewDelegate* const view_delegate_;
  70. const AppListConfig* app_list_config_ = nullptr;
  71. views::BoxLayout* layout_ = nullptr;
  72. AppListModel* model_ = nullptr;
  73. SearchModel* search_model_ = nullptr;
  74. // The grid delegate for each AppListItemView.
  75. class GridDelegateImpl;
  76. std::unique_ptr<GridDelegateImpl> grid_delegate_;
  77. // The recent app items. Stored here because this view has child views for
  78. // spacing that are not AppListItemViews.
  79. std::vector<AppListItemView*> item_views_;
  80. };
  81. } // namespace ash
  82. #endif // ASH_APP_LIST_VIEWS_RECENT_APPS_VIEW_H_