File: layer_animation_verifier.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (76 lines) | stat: -rw-r--r-- 2,671 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
// Copyright 2021 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_TEST_LAYER_ANIMATION_VERIFIER_H_
#define ASH_TEST_LAYER_ANIMATION_VERIFIER_H_

#include <optional>

#include "base/memory/raw_ptr.h"
#include "ui/compositor/compositor_observer.h"
#include "ui/gfx/geometry/rect.h"

namespace ui {
class Layer;
}

namespace views {
class View;
}

namespace ash {

// The helper class to verify a layer animation on the following things:
// (1) The observed view should not go back and forth during the animation.
// (2) TODO(crbug.com/40181947): The animation should progress to the end
// rather than get interrupted.
// (3) TODO(https://crbug.com/1209001): The observed view should move smoothly
// during the animation. In other words, the view should not move in a janky
// manner (such as jumping).
class LayerAnimationVerifier : public ui::CompositorObserver {
 public:
  // `layer_with_animation` and `observed_view` should share the compositor.
  // Otherwise it is unmeaningful to watch `observed_view` during animation.
  LayerAnimationVerifier(ui::Layer* layer_with_animation,
                         views::View* observed_view);
  LayerAnimationVerifier(const LayerAnimationVerifier&) = delete;
  LayerAnimationVerifier& operator=(const LayerAnimationVerifier&) = delete;
  ~LayerAnimationVerifier() override;

  // ui::CompositorObserver:
  void OnCompositingDidCommit(ui::Compositor* compositor) override;

 private:
  // Indicates move direction during animation.
  enum class MoveDirection { kForward, kBackward };

  // Compares `current_screen_bounds` with the most recent screen bounds.
  void CompareWithLastBoundsRect(const gfx::Rect& current_screen_bounds);

  // Calculates the move direction.
  MoveDirection CalculateMoveDirection(int current_data, int last_data) const;

  // Returns the compositor of `layer_with_animation`.
  ui::Compositor* GetCompositor();

  // Indicates the layer on which an animation is going to apply.
  const raw_ptr<ui::Layer> layer_with_animation_;

  // Indicates the view that is observed during the layer animation.
  const raw_ptr<const views::View> observed_view_;

  // The screen bounds of `observed_view_` in the most recent compositor commit.
  std::optional<gfx::Rect> last_screen_bounds_;

  // `observed_view_`'s move direction on x-axis and y-axis respectively.
  std::optional<MoveDirection> x_direction_;
  std::optional<MoveDirection> y_direction_;

  // Indicates the number of comparisons during animation.
  int comparison_count_ = 0;
};

}  // namespace ash

#endif  // ASH_TEST_LAYER_ANIMATION_VERIFIER_H_