app_list_page.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // Copyright 2015 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_PAGE_H_
  5. #define ASH_APP_LIST_VIEWS_APP_LIST_PAGE_H_
  6. #include "ash/app_list/model/app_list_model.h"
  7. #include "ash/ash_export.h"
  8. #include "ui/views/view.h"
  9. namespace ash {
  10. class ContentsView;
  11. class ASH_EXPORT AppListPage : public views::View {
  12. public:
  13. AppListPage();
  14. AppListPage(const AppListPage&) = delete;
  15. AppListPage& operator=(const AppListPage&) = delete;
  16. ~AppListPage() override;
  17. // Triggered when the page is about to be shown.
  18. virtual void OnWillBeShown();
  19. // Triggered after the page has been shown.
  20. virtual void OnShown();
  21. // Triggered when the page is about to be hidden.
  22. virtual void OnWillBeHidden();
  23. // Triggered after the page has been hidden.
  24. virtual void OnHidden();
  25. // Triggered when the page transition animation started.
  26. virtual void OnAnimationStarted(AppListState from_state,
  27. AppListState to_state) = 0;
  28. // Triggered after the page transition animation has updated.
  29. virtual void OnAnimationUpdated(double progress,
  30. AppListState from_state,
  31. AppListState to_state);
  32. // Returns the search box size that is preferred by the page. Used by
  33. // ContentsView to calculate the search box widget bounds that
  34. // should be used on this page.
  35. //
  36. // If this method returns an empty size, the ContentsView will use
  37. // the default search box size.
  38. // Default implementation returns an empty size.
  39. virtual gfx::Size GetPreferredSearchBoxSize() const;
  40. // Should update the app list page opacity for the current state. Called when
  41. // the selected page changes without animation - if the page implements this,
  42. // it should make sure the page transition animation updates the opacity as
  43. // well.
  44. // |state| - The current app list state.
  45. // |search_box_opacity| - The current search box opacity.
  46. // |restore_opacity| - Whether the page opacity should be restored, e.g. when
  47. // the app list drag ends. Note that |search_box_opacity| will be 1.0f if
  48. // |restore_opacity| is true.
  49. virtual void UpdatePageOpacityForState(AppListState state,
  50. float search_box_opacity,
  51. bool restore_opacity) = 0;
  52. // Updates the page bounds to match the provided app list state.
  53. // The default implementation sets the bounds returned by
  54. // GetPageBoundsForState().
  55. // The arguments match the GetPageBoundsForState() arguments.
  56. virtual void UpdatePageBoundsForState(AppListState state,
  57. const gfx::Rect& contents_bounds,
  58. const gfx::Rect& search_box_bounds);
  59. // Returns the bounds the app list page should have for the app list state.
  60. // |state| - The current app list state.
  61. // |contents_bounds| - The current app list contents bounds.
  62. // |search_box_bounds| - The current search box bounds.
  63. virtual gfx::Rect GetPageBoundsForState(
  64. AppListState state,
  65. const gfx::Rect& contents_bounds,
  66. const gfx::Rect& search_box_bounds) const = 0;
  67. const ContentsView* contents_view() const { return contents_view_; }
  68. ContentsView* contents_view() { return contents_view_; }
  69. void set_contents_view(ContentsView* contents_view) {
  70. contents_view_ = contents_view;
  71. }
  72. // Returns the first focusable view in this page.
  73. views::View* GetFirstFocusableView();
  74. // Returns the last focusable view in this page.
  75. views::View* GetLastFocusableView();
  76. // Called when the app list view state changes to |target_view_state| to
  77. // animate the app list page opacity.
  78. // |current_progress| - the current app list transition progress.
  79. // |animator| - callback that when run starts the opacity animation.
  80. using OpacityAnimator =
  81. base::RepeatingCallback<void(views::View* view, bool target_visibility)>;
  82. virtual void AnimateOpacity(float current_progress,
  83. AppListViewState target_view_state,
  84. const OpacityAnimator& animator);
  85. // Called when the app list view state changes to |target_view_state| to
  86. // animate the app list page vertical offset from the app list view top.
  87. // |animator| - The callback that runs the transform animation to update the
  88. // page's vertical position.
  89. // |default_offset| - the default transform offset that can be passed to
  90. // |animator| to follow the search box position animation.
  91. using TransformAnimator =
  92. base::RepeatingCallback<void(float offset, ui::Layer* layer)>;
  93. virtual void AnimateYPosition(AppListViewState target_view_state,
  94. const TransformAnimator& animator,
  95. float default_offset);
  96. // Returns the area above the contents view, given the desired size of this
  97. // page, in the contents view's coordinate space.
  98. gfx::Rect GetAboveContentsOffscreenBounds(const gfx::Size& size) const;
  99. // Returns the area below the contents view, given the desired size of this
  100. // page, in the contents view's coordinate space.
  101. gfx::Rect GetBelowContentsOffscreenBounds(const gfx::Size& size) const;
  102. // Returns the entire bounds of the contents view, in the contents view's
  103. // coordinate space.
  104. gfx::Rect GetFullContentsBounds() const;
  105. // Returns the default bounds of pages inside the contents view, in the
  106. // contents view's coordinate space. This is the area of the contents view
  107. // below the search box.
  108. gfx::Rect GetDefaultContentsBounds() const;
  109. // views::View:
  110. const char* GetClassName() const override;
  111. private:
  112. ContentsView* contents_view_;
  113. };
  114. } // namespace ash
  115. #endif // ASH_APP_LIST_VIEWS_APP_LIST_PAGE_H_