multitask_menu_nudge_controller.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2022 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_WM_MULTITASK_MENU_NUDGE_CONTROLLER_H_
  5. #define ASH_WM_MULTITASK_MENU_NUDGE_CONTROLLER_H_
  6. #include "ash/ash_export.h"
  7. #include "base/scoped_observation.h"
  8. #include "base/time/clock.h"
  9. #include "base/timer/timer.h"
  10. #include "ui/aura/window.h"
  11. #include "ui/aura/window_observer.h"
  12. #include "ui/views/view.h"
  13. #include "ui/views/widget/unique_widget_ptr.h"
  14. class PrefRegistrySimple;
  15. namespace ui {
  16. class Layer;
  17. }
  18. namespace ash {
  19. // Controller for showing the user education nudge for the multitask menu.
  20. // TODO(sammiequon|shidi): This will be extended for the multitask menu in
  21. // tablet mode too once that is implemented.
  22. class MultitaskMenuNudgeController : public aura::WindowObserver {
  23. public:
  24. MultitaskMenuNudgeController();
  25. MultitaskMenuNudgeController(const MultitaskMenuNudgeController&) = delete;
  26. MultitaskMenuNudgeController& operator=(const MultitaskMenuNudgeController&) =
  27. delete;
  28. ~MultitaskMenuNudgeController() override;
  29. static void RegisterProfilePrefs(PrefRegistrySimple* registry);
  30. // Shows the nudge if it can be shown. The nudge can be shown if it hasn't
  31. // been shown 3 times already, or shown in the last 24 hours.
  32. void MaybeShowNudge(aura::Window* window);
  33. // aura::WindowObserver:
  34. void OnWindowParentChanged(aura::Window* window,
  35. aura::Window* parent) override;
  36. void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
  37. void OnWindowBoundsChanged(aura::Window* window,
  38. const gfx::Rect& old_bounds,
  39. const gfx::Rect& new_bounds,
  40. ui::PropertyChangeReason reason) override;
  41. void OnWindowTargetTransformChanging(
  42. aura::Window* window,
  43. const gfx::Transform& new_transform) override;
  44. void OnWindowStackingChanged(aura::Window* window) override;
  45. void OnWindowDestroying(aura::Window* window) override;
  46. private:
  47. friend class MultitaskMenuNudgeControllerTest;
  48. // Used to control the clock in a test setting.
  49. ASH_EXPORT static void SetOverrideClockForTesting(base::Clock* test_clock);
  50. // Runs when the nudge dismiss timer expires. Dismisses the nudge if it is
  51. // being shown.
  52. void OnDismissTimerEnded();
  53. // Closes the widget and cleans up all pointers and observers in this class.
  54. void DismissNudgeInternal();
  55. // Dismisses the widget and pulse if `anchor_view` is not drawn, or `window`
  56. // is not visible. Otherwise updates the bounds and reparents the two if
  57. // necessary.
  58. void UpdateWidgetAndPulse();
  59. // The animation associated with `pulse_layer_`. Runs until `pulse_layer_` is
  60. // destroyed or `pulse_count` reaches 3.
  61. void PerformPulseAnimation(int pulse_count);
  62. base::OneShotTimer nudge_dismiss_timer_;
  63. views::UniqueWidgetPtr nudge_widget_;
  64. std::unique_ptr<ui::Layer> pulse_layer_;
  65. // The app window that the nudge is associated with. It is expected to have a
  66. // header with a maximize/restore button.
  67. aura::Window* window_ = nullptr;
  68. // The view that the nudge will be anchored to. It is the maximize or resize
  69. // button on `window_`'s frame.
  70. views::View* anchor_view_ = nullptr;
  71. base::ScopedObservation<aura::Window, aura::WindowObserver>
  72. window_observation_{this};
  73. };
  74. } // namespace ash
  75. #endif // ASH_WM_MULTITASK_MENU_NUDGE_CONTROLLER_H_