scrollable_apps_grid_view.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_SCROLLABLE_APPS_GRID_VIEW_H_
  5. #define ASH_APP_LIST_VIEWS_SCROLLABLE_APPS_GRID_VIEW_H_
  6. #include "ash/app_list/app_list_metrics.h"
  7. #include "ash/app_list/views/apps_grid_view.h"
  8. #include "ash/ash_export.h"
  9. #include "base/time/time.h"
  10. #include "base/timer/timer.h"
  11. #include "ui/base/metadata/metadata_header_macros.h"
  12. namespace views {
  13. class ScrollView;
  14. }
  15. namespace ash {
  16. class AppListKeyboardController;
  17. class AppListViewDelegate;
  18. // An apps grid that shows all the apps in a long scrolling list. Used for
  19. // the clamshell mode bubble launcher. Implemented as a single "page" of apps.
  20. // GridIndex in this class always has a page of 0. Supports "auto-scroll", a
  21. // feature where the user can drag an app icon to the top or bottom of the
  22. // containing ScrollView and the view will be scrolled automatically.
  23. class ASH_EXPORT ScrollableAppsGridView : public AppsGridView {
  24. public:
  25. METADATA_HEADER(ScrollableAppsGridView);
  26. ScrollableAppsGridView(AppListA11yAnnouncer* a11y_announcer,
  27. AppListViewDelegate* view_delegate,
  28. AppsGridViewFolderDelegate* folder_delegate,
  29. views::ScrollView* scroll_view,
  30. AppListFolderController* folder_controller,
  31. AppListKeyboardController* keyboard_controller);
  32. ScrollableAppsGridView(const ScrollableAppsGridView&) = delete;
  33. ScrollableAppsGridView& operator=(const ScrollableAppsGridView&) = delete;
  34. ~ScrollableAppsGridView() override;
  35. // Sets the max number of columns the grid can have.
  36. // See `AppsGridView::SetMaxColumnsInternal()` for details.
  37. void SetMaxColumns(int max_cols);
  38. // views::View:
  39. void Layout() override;
  40. // AppsGridView:
  41. gfx::Size GetTileViewSize() const override;
  42. gfx::Insets GetTilePadding(int page) const override;
  43. gfx::Size GetTileGridSize() const override;
  44. int GetTotalPages() const override;
  45. int GetSelectedPage() const override;
  46. bool IsScrollAxisVertical() const override;
  47. bool MaybeAutoScroll() override;
  48. void StopAutoScroll() override;
  49. void HandleScrollFromParentView(const gfx::Vector2d& offset,
  50. ui::EventType type) override;
  51. void SetFocusAfterEndDrag(AppListItem* drag_item) override;
  52. void RecordAppMovingTypeMetrics(AppListAppMovingType type) override;
  53. int GetMaxRowsInPage(int page) const override;
  54. gfx::Vector2d GetGridCenteringOffset(int page) const override;
  55. const gfx::Vector2d CalculateTransitionOffset(
  56. int page_of_view) const override;
  57. void EnsureViewVisible(const GridIndex& index) override;
  58. absl::optional<VisibleItemIndexRange> GetVisibleItemIndexRange()
  59. const override;
  60. base::ScopedClosureRunner LockAppsGridOpacity() override;
  61. views::ScrollView* scroll_view_for_test() { return scroll_view_; }
  62. base::OneShotTimer* auto_scroll_timer_for_test() {
  63. return &auto_scroll_timer_;
  64. }
  65. private:
  66. enum class ScrollDirection { kUp, kDown };
  67. // Returns true if a drag to `point_in_grid_view` should trigger auto-scroll.
  68. // If so, sets `scroll_direction`.
  69. bool IsPointInAutoScrollMargin(const gfx::Point& point_in_grid_view,
  70. ScrollDirection* direction) const;
  71. // Returns true if `scroll_view_` can be scrolled (i.e. it is not already at
  72. // the top or the bottom).
  73. bool CanAutoScrollView(ScrollDirection direction) const;
  74. // Returns the number of DIPs to auto-scroll.
  75. int GetAutoScrollOffset() const;
  76. // The scroll view that contains this view (and other views).
  77. views::ScrollView* const scroll_view_;
  78. // Timer to scroll the `scroll_view_`.
  79. base::OneShotTimer auto_scroll_timer_;
  80. // When the last auto-scroll happened.
  81. base::TimeTicks last_auto_scroll_time_;
  82. };
  83. } // namespace ash
  84. #endif // ASH_APP_LIST_VIEWS_SCROLLABLE_APPS_GRID_VIEW_H_