File: ink_drop_impl_test_api.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 (119 lines) | stat: -rw-r--r-- 4,218 bytes parent folder | download | duplicates (7)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_VIEWS_ANIMATION_TEST_INK_DROP_IMPL_TEST_API_H_
#define UI_VIEWS_ANIMATION_TEST_INK_DROP_IMPL_TEST_API_H_

#include <memory>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "ui/compositor/test/multi_layer_animator_test_controller.h"
#include "ui/compositor/test/multi_layer_animator_test_controller_delegate.h"
#include "ui/views/animation/ink_drop_impl.h"

namespace ui {
class LayerAnimator;
}  // namespace ui

namespace views {
class InkDropHighlight;

namespace test {

// Test API to provide internal access to an InkDropImpl instance. This can also
// be used to control the InkDropRipple and InkDropHighlight animations via the
// ui::test::MultiLayerAnimatorTestController API.
class InkDropImplTestApi
    : public ui::test::MultiLayerAnimatorTestController,
      public ui::test::MultiLayerAnimatorTestControllerDelegate {
 public:
  // Highlight state that access the HighlightStateFactory during the Exit()
  // method.
  class AccessFactoryOnExitHighlightState : public InkDropImpl::HighlightState {
   public:
    // Installs an instance of |this| to the ink drop that owns |state_factory|.
    static void Install(InkDropImpl::HighlightStateFactory* state_factory);

    explicit AccessFactoryOnExitHighlightState(
        InkDropImpl::HighlightStateFactory* state_factory);

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

    // HighlightState:
    void Exit() override;
    void ShowOnHoverChanged() override;
    void OnHoverChanged() override;
    void ShowOnFocusChanged() override;
    void OnFocusChanged() override;
    void AnimationStarted(InkDropState ink_drop_state) override;
    void AnimationEnded(InkDropState ink_drop_state,
                        InkDropAnimationEndedReason reason) override;
  };

  // Highlight state that attempts to set a new highlight state during Exit().
  class SetStateOnExitHighlightState : public InkDropImpl::HighlightState {
   public:
    // Installs an instance of |this| to the ink drop that owns |state_factory|.
    static void Install(InkDropImpl::HighlightStateFactory* state_factory);

    explicit SetStateOnExitHighlightState(
        InkDropImpl::HighlightStateFactory* state_factory);

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

    // HighlightState:
    void Exit() override;
    void ShowOnHoverChanged() override;
    void OnHoverChanged() override;
    void ShowOnFocusChanged() override;
    void OnFocusChanged() override;
    void AnimationStarted(InkDropState ink_drop_state) override;
    void AnimationEnded(InkDropState ink_drop_state,
                        InkDropAnimationEndedReason reason) override;
  };

  explicit InkDropImplTestApi(InkDropImpl* ink_drop);

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

  ~InkDropImplTestApi() override;

  // Ensures that |ink_drop_|->ShouldHighlight() returns the same value as
  // |should_highlight| by updating the hover/focus status of |ink_drop_|.
  void SetShouldHighlight(bool should_highlight);

  // Wrappers to InkDropImpl internals:
  InkDropImpl::HighlightStateFactory* state_factory() {
    return &ink_drop_->highlight_state_factory_;
  }

  void SetHighlightState(
      std::unique_ptr<InkDropImpl::HighlightState> highlight_state);

  const InkDropHighlight* highlight() const;
  bool IsHighlightFadingInOrVisible() const;
  bool ShouldHighlight() const;

  ui::Layer* GetRootLayer() const;

 protected:
  // MultiLayerAnimatorTestControllerDelegate:
  std::vector<ui::LayerAnimator*> GetLayerAnimators() override;

 private:
  // The InkDrop to provide internal access to.
  raw_ptr<InkDropImpl> ink_drop_;
};

}  // namespace test
}  // namespace views

#endif  // UI_VIEWS_ANIMATION_TEST_INK_DROP_IMPL_TEST_API_H_