File: fullscreen_control_popup.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 (86 lines) | stat: -rw-r--r-- 3,043 bytes parent folder | download | duplicates (6)
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
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_FULLSCREEN_CONTROL_FULLSCREEN_CONTROL_POPUP_H_
#define COMPONENTS_FULLSCREEN_CONTROL_FULLSCREEN_CONTROL_POPUP_H_

#include <memory>

#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/animation/animation_delegate_views.h"

namespace views {
class Widget;
}  // namespace views

class FullscreenControlView;

// FullscreenControlPopup is a helper class that holds a FullscreenControlView
// and allows showing and hiding the view with a drop down animation.
class FullscreenControlPopup : public views::AnimationDelegateViews {
 public:
  FullscreenControlPopup(gfx::NativeView parent_view,
                         const base::RepeatingClosure& on_button_pressed,
                         const base::RepeatingClosure& on_visibility_changed);

  FullscreenControlPopup(const FullscreenControlPopup&) = delete;
  FullscreenControlPopup& operator=(const FullscreenControlPopup&) = delete;

  ~FullscreenControlPopup() override;

  // Returns the final bottom of the button as a y offset to its parent view.
  static int GetButtonBottomOffset();

  // Shows the indicator with an animation that drops it off the top of
  // |parent_view|.
  // |parent_bounds_in_screen| holds the bounds of |parent_view| in the screen
  // coordinate system.
  void Show(const gfx::Rect& parent_bounds_in_screen);

  // Hides the indicator. If |animated| is true, the indicator will be hidden by
  // the reversed animation of Show(), i.e. the indicator flies to the top of
  // |parent_widget|.
  void Hide(bool animated);

  views::Widget* GetPopupWidget();
  gfx::SlideAnimation* GetAnimationForTesting();

  bool IsAnimating() const;

  // Returns true if the popup is visible on the screen, i.e. Show() has been
  // called and Hide() has never been called since then.
  bool IsVisible() const;

  FullscreenControlView* control_view() { return control_view_; }

 private:
  FullscreenControlPopup(std::unique_ptr<views::Widget> popup,
                         const base::RepeatingClosure& on_visibility_changed);

  // views::AnimationDelegateViews:
  void AnimationProgressed(const gfx::Animation* animation) override;
  void AnimationEnded(const gfx::Animation* animation) override;

  gfx::Rect CalculateBounds(int y_offset) const;

  void OnVisibilityChanged();

  // Must outlive `control_view_`.
  const std::unique_ptr<views::Widget> popup_;
  const raw_ptr<FullscreenControlView> control_view_;

  const std::unique_ptr<gfx::SlideAnimation> animation_;

  // The bounds is empty when the popup is not showing.
  gfx::Rect parent_bounds_in_screen_;

  const base::RepeatingClosure on_visibility_changed_;
};

#endif  // COMPONENTS_FULLSCREEN_CONTROL_FULLSCREEN_CONTROL_POPUP_H_