File: glic_window_animator.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (96 lines) | stat: -rw-r--r-- 3,821 bytes parent folder | download | duplicates (3)
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
88
89
90
91
92
93
94
95
96
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_GLIC_WIDGET_GLIC_WINDOW_ANIMATOR_H_
#define CHROME_BROWSER_GLIC_WIDGET_GLIC_WINDOW_ANIMATOR_H_

#include "base/callback_list.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/ui/views/tabs/glic_button.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/linear_animation.h"

namespace glic {

class GlicWindowController;
class GlicWindowResizeAnimation;

// This class will handle the open and close animations for the glic widget
// including referring to GlicWindowResizeAnimation for
// resizing-related animations.
class GlicWindowAnimator : public gfx::AnimationDelegate {
 public:
  explicit GlicWindowAnimator(GlicWindowController* window_controller);
  GlicWindowAnimator(const GlicWindowAnimator&) = delete;
  GlicWindowAnimator& operator=(const GlicWindowAnimator&) = delete;
  ~GlicWindowAnimator() override;

  // Animate the window size, maintaining the position of the top right corner.
  // If there is already a running bounds change animation, update that
  // animation's target size.
  void AnimateSize(const gfx::Size& target_size,
                   base::TimeDelta duration,
                   base::OnceClosure callback);

  // Animate the window's top left position maintaining size. If there is
  // already a running bounds change animation, update that animation's target
  // origin.
  void AnimatePosition(const gfx::Point& target_position,
                       base::TimeDelta duration,
                       base::OnceClosure callback);

  // Called when the programmatic resize has finished. Public for use by
  // GlicWindowResizeAnimation.
  void ResizeFinished();

  // Gets the bounds for the widget's resize animation. If there is an animation
  // already ongoing, use the target bounds for that animation. Otherwise, use
  // the widget's current bounds.
  gfx::Rect GetCurrentTargetBounds();

  // Reset the saved target size.
  void ResetLastTargetSize();

  // If there's a saved target size, start the resize animation for it.
  void MaybeAnimateToTargetSize();

  bool IsAnimating() const;

 private:
  // Sets target bounds for the widget (must exist) and creates a
  // GlicWindowResizeAnimation instance to begin a new animation. If a bounds
  // animation is already running, end it and start a new one. Duration is set
  // to 0 if negative.
  void AnimateBounds(const gfx::Rect& target_bounds,
                     base::TimeDelta duration,
                     base::OnceClosure callback);

  // Sets target opacity for the widget (must exist) and creates a
  // GlicWindowOpacityAnimation instance to begin a new opacity animation.
  void AnimateWindowOpacity(float start_opacity,
                            float target_opacity,
                            base::TimeDelta duration);

  // Sets target opacity for the GlicView's web view and creates a
  // GlicViewOpacityAnimation instance to begin a new animation.
  void AnimateViewOpacity(float start_opacity,
                          float target_opacity,
                          base::TimeDelta duration);

  // GlicWindowController owns GlicWindowAnimator and will outlive it
  const raw_ptr<GlicWindowController> window_controller_;
  std::unique_ptr<GlicWindowResizeAnimation> window_resize_animation_;

  // Last requested target size. Will be (0, 0) if there hasn't been a resize
  // request or glic has already been resized to the target size.
  gfx::Size last_target_size_;

  base::WeakPtrFactory<GlicWindowAnimator> weak_ptr_factory_{this};
};

}  // namespace glic

#endif  // CHROME_BROWSER_GLIC_WIDGET_GLIC_WINDOW_ANIMATOR_H_