File: home_to_overview_nudge_controller.h

package info (click to toggle)
chromium 120.0.6099.224-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,112,112 kB
  • sloc: cpp: 32,907,025; ansic: 8,148,123; javascript: 3,679,536; python: 2,031,248; asm: 959,718; java: 804,675; xml: 617,256; sh: 111,417; objc: 100,835; perl: 88,443; cs: 53,032; makefile: 29,579; fortran: 24,137; php: 21,162; tcl: 21,147; sql: 20,809; ruby: 17,735; pascal: 12,864; yacc: 8,045; lisp: 3,388; lex: 1,323; ada: 727; awk: 329; jsp: 267; csh: 117; exp: 43; sed: 37
file content (87 lines) | stat: -rw-r--r-- 3,123 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SHELF_HOME_TO_OVERVIEW_NUDGE_CONTROLLER_H_
#define ASH_SHELF_HOME_TO_OVERVIEW_NUDGE_CONTROLLER_H_

#include "ash/ash_export.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_multi_source_observation.h"
#include "base/timer/timer.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"

namespace ash {

class ContextualNudge;
class HotseatWidget;

class ASH_EXPORT HomeToOverviewNudgeController : views::WidgetObserver {
 public:
  // Indicates the reason the nudge is being hidden. Used to determine the exact
  // transition to use when hiding the nudge.
  enum class HideTransition { kShelfStateChange, kUserTap, kNudgeTimeout };

  explicit HomeToOverviewNudgeController(HotseatWidget* hotseat_widget);
  HomeToOverviewNudgeController(const HomeToOverviewNudgeController& other) =
      delete;
  ~HomeToOverviewNudgeController() override;

  HomeToOverviewNudgeController& operator=(
      const HomeToOverviewNudgeController& other) = delete;

  // Sets whether the home to overview nudge can be shown for the current shelf
  // state. If nudge is allowed, controller may show the nudge (if required). If
  // the nudge is not allowed, the nudge will be hidden if currently shown.
  void SetNudgeAllowedForCurrentShelf(bool allowed);

  // views::WidgetObserver:
  void OnWidgetDestroying(views::Widget* widget) override;
  void OnWidgetBoundsChanged(views::Widget* widget,
                             const gfx::Rect& new_bounds) override;

  ContextualNudge* nudge_for_testing() { return nudge_; }

  bool HasShowTimerForTesting() const;
  void FireShowTimerForTesting();

  bool HasHideTimerForTesting() const;
  void FireHideTimerForTesting();

 private:
  // Creates and shows the nudge bubble, schedules showing animation for the
  // nudge and hotseat widgets, and schedules nudge hide timer as needed.
  void ShowNudge();

  // Sets up hotseat and nudge wdget animation for hiding the nudge, and closes
  // the nudge widget when the animation finishes.
  void HideNudge(HideTransition transition);

  // Updates the nudge anchor bounds for the current hotseat and shelf bounds.
  void UpdateNudgeAnchorBounds();

  // Passed to |nudge_| as its tap gesture handler.
  void HandleNudgeTap();

  bool nudge_allowed_for_shelf_state_ = false;

  const raw_ptr<HotseatWidget, DanglingUntriaged | ExperimentalAsh>
      hotseat_widget_;
  raw_ptr<ContextualNudge, ExperimentalAsh> nudge_ = nullptr;

  base::OneShotTimer nudge_show_timer_;
  base::OneShotTimer nudge_hide_timer_;

  // Observes hotseat widget to detect the hotseat bounds changes, and the
  // nudge widget to detect that the widget is being destroyed.
  base::ScopedMultiSourceObservation<views::Widget, views::WidgetObserver>
      widget_observations_{this};

  base::WeakPtrFactory<HomeToOverviewNudgeController> weak_factory_{this};
};

}  // namespace ash

#endif  // ASH_SHELF_HOME_TO_OVERVIEW_NUDGE_CONTROLLER_H_