continue_section_view.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_CONTINUE_SECTION_VIEW_H_
  5. #define ASH_APP_LIST_VIEWS_CONTINUE_SECTION_VIEW_H_
  6. #include "ash/app_list/app_list_model_provider.h"
  7. #include "ash/app_list/views/continue_task_container_view.h"
  8. #include "ash/ash_export.h"
  9. #include "ash/public/cpp/app_list/app_list_controller_observer.h"
  10. #include "base/timer/timer.h"
  11. #include "ui/views/focus/focus_manager.h"
  12. #include "ui/views/view.h"
  13. namespace views {
  14. class Label;
  15. } // namespace views
  16. namespace ash {
  17. class AppListNudgeController;
  18. class AppListViewDelegate;
  19. class AppListToastView;
  20. class ContinueTaskContainerView;
  21. class ContinueTaskView;
  22. // The "Continue" section of the bubble launcher. This view wraps around
  23. // suggestions with tasks to continue.
  24. class ASH_EXPORT ContinueSectionView : public views::View,
  25. public views::FocusChangeListener,
  26. public AppListModelProvider::Observer,
  27. public AppListControllerObserver {
  28. public:
  29. METADATA_HEADER(ContinueSectionView);
  30. ContinueSectionView(AppListViewDelegate* view_delegate,
  31. int columns,
  32. bool tablet_mode);
  33. ContinueSectionView(const ContinueSectionView&) = delete;
  34. ContinueSectionView& operator=(const ContinueSectionView&) = delete;
  35. ~ContinueSectionView() override;
  36. // Returns true if the continue section removal metrics should be logged.
  37. static bool EnableContinueSectionFileRemovalMetrics();
  38. // Reset for the continue section file removal metric logging enabling.
  39. static void ResetContinueSectionFileRemovalMetricEnabledForTest();
  40. // Called when the `suggestion_container_` finishes updating the tasks.
  41. void OnSearchResultContainerResultsChanged();
  42. // Schedule an update to the `suggestion_container_` tasks.
  43. void UpdateSuggestionTasks();
  44. size_t GetTasksSuggestionsCount() const;
  45. void DisableFocusForShowingActiveFolder(bool disabled);
  46. ContinueTaskView* GetTaskViewAtForTesting(size_t index) const;
  47. // Whether the privacy notice should be shown to the user.
  48. bool ShouldShowPrivacyNotice() const;
  49. // Whether the continue files should be shown to the user.
  50. bool ShouldShowFilesSection() const;
  51. // Stops the running `privacy_notice_shown_timer_` if the privacy notice is
  52. // shown in background.
  53. void SetShownInBackground(bool shown_in_background);
  54. void SetNudgeController(AppListNudgeController* nudge_controller);
  55. // Refresh the continue section element's visibility such as the privacy
  56. // notice, the continue label and the continue section itself.
  57. void UpdateElementsVisibility();
  58. ContinueTaskContainerView* suggestions_container() {
  59. return suggestions_container_;
  60. }
  61. // views::View:
  62. void AddedToWidget() override;
  63. void OnThemeChanged() override;
  64. void RemovedFromWidget() override;
  65. // views::FocusChangeListener:
  66. void OnWillChangeFocus(views::View* focused_before,
  67. views::View* focused_now) override {}
  68. void OnDidChangeFocus(views::View* focused_before,
  69. views::View* focused_now) override;
  70. // AppListModelProvider::Observer:
  71. void OnActiveAppListModelsChanged(AppListModel* model,
  72. SearchModel* search_model) override;
  73. // AppListControllerObserver:
  74. void OnAppListVisibilityChanged(bool shown, int64_t display_id) override;
  75. AppListNudgeController* nudge_controller_for_test() const {
  76. return nudge_controller_;
  77. }
  78. // Fire `privacy_notice_shown_timer_` for testing purposes.
  79. bool FirePrivacyNoticeShownTimerForTest();
  80. AppListToastView* GetPrivacyNoticeForTest() const { return privacy_toast_; }
  81. private:
  82. // Whether there are a sufficient number of files to display the
  83. // section.
  84. bool HasMinimumFilesToShow() const;
  85. // Displays a toast with a privacy notice for the user in place of the
  86. // continue section. The user can accept the notice to display the continue
  87. // section in the launcher.
  88. void MaybeCreatePrivacyNotice();
  89. // Removes the privacy notice from the view.
  90. void RemovePrivacyNotice();
  91. // Invoked when the privacy notice has been shown for enough time.
  92. void OnPrivacyNoticeShowTimerDone();
  93. // Invoked when the privacy notice has been acknowledged.
  94. void OnPrivacyToastAcknowledged();
  95. // Starts the animation to dismiss the privacy notice toast.
  96. void AnimateDismissToast(base::RepeatingClosure callback);
  97. // Starts the animation to show the continue section in the app list bubble.
  98. void AnimateShowContinueSection();
  99. // Starts the animation for sliding other launcher content by
  100. // `vertical_offset`.
  101. void AnimateSlideLauncherContent(int vertical_offset);
  102. // Starts the animation to dismiss the privacy notice toast only. This is used
  103. // when the privacy notice does not have enough items after an update.
  104. void MaybeAnimateOutPrivacyNotice();
  105. AppListViewDelegate* const view_delegate_;
  106. bool tablet_mode_ = false;
  107. // Timer for marking the privacy notice as shown.
  108. base::OneShotTimer privacy_notice_shown_timer_;
  109. // Not owned.
  110. AppListNudgeController* nudge_controller_ = nullptr;
  111. views::Label* continue_label_ = nullptr;
  112. AppListToastView* privacy_toast_ = nullptr;
  113. ContinueTaskContainerView* suggestions_container_ = nullptr;
  114. base::WeakPtrFactory<ContinueSectionView> weak_ptr_factory_{this};
  115. };
  116. } // namespace ash
  117. #endif // ASH_APP_LIST_VIEWS_CONTINUE_SECTION_VIEW_H_