File: test_ink_drop_host.cc

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 (141 lines) | stat: -rw-r--r-- 4,956 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/views/animation/test/test_ink_drop_host.h"

#include <memory>

#include "base/functional/bind.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/square_ink_drop_ripple.h"
#include "ui/views/animation/test/ink_drop_highlight_test_api.h"
#include "ui/views/animation/test/square_ink_drop_ripple_test_api.h"

namespace views {
class InkDropHost;

namespace {

// Test specific subclass of InkDropRipple that returns a test api from
// GetTestApi().
class TestInkDropRipple : public SquareInkDropRipple {
 public:
  TestInkDropRipple(InkDropHost* ink_drop_host,
                    const gfx::Size& large_size,
                    int large_corner_radius,
                    const gfx::Size& small_size,
                    int small_corner_radius,
                    const gfx::Point& center_point,
                    SkColor color,
                    float visible_opacity)
      : SquareInkDropRipple(ink_drop_host,
                            large_size,
                            large_corner_radius,
                            small_size,
                            small_corner_radius,
                            center_point,
                            color,
                            visible_opacity) {}

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

  ~TestInkDropRipple() override = default;

  test::InkDropRippleTestApi* GetTestApi() override {
    if (!test_api_) {
      test_api_ = std::make_unique<test::SquareInkDropRippleTestApi>(this);
    }
    return test_api_.get();
  }

 private:
  std::unique_ptr<test::InkDropRippleTestApi> test_api_;
};

// Test specific subclass of InkDropHighlight that returns a test api from
// GetTestApi().
class TestInkDropHighlight : public InkDropHighlight {
 public:
  TestInkDropHighlight(const gfx::Size& size,
                       int corner_radius,
                       const gfx::PointF& center_point,
                       SkColor color)
      : InkDropHighlight(size, corner_radius, center_point, color) {}

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

  ~TestInkDropHighlight() override = default;

  test::InkDropHighlightTestApi* GetTestApi() override {
    if (!test_api_) {
      test_api_ = std::make_unique<test::InkDropHighlightTestApi>(this);
    }
    return test_api_.get();
  }

 private:
  std::unique_ptr<test::InkDropHighlightTestApi> test_api_;
};

}  // namespace

TestInkDropHost::TestInkDropHost(
    InkDropImpl::AutoHighlightMode auto_highlight_mode) {
  InkDrop::Install(this, std::make_unique<InkDropHost>(this));
  InkDrop::Get(this)->SetCreateInkDropCallback(base::BindRepeating(
      [](TestInkDropHost* host,
         InkDropImpl::AutoHighlightMode auto_highlight_mode)
          -> std::unique_ptr<views::InkDrop> {
        return std::make_unique<views::InkDropImpl>(
            InkDrop::Get(host), host->size(), auto_highlight_mode);
      },
      this, auto_highlight_mode));

  InkDrop::Get(this)->SetCreateHighlightCallback(base::BindRepeating(
      [](TestInkDropHost* host) -> std::unique_ptr<views::InkDropHighlight> {
        auto highlight = std::make_unique<TestInkDropHighlight>(
            host->size(), 0, gfx::PointF(), SK_ColorBLACK);
        if (host->disable_timers_for_test_) {
          highlight->GetTestApi()->SetDisableAnimationTimers(true);
        }
        host->num_ink_drop_highlights_created_++;
        return highlight;
      },
      this));
  InkDrop::Get(this)->SetCreateRippleCallback(base::BindRepeating(
      [](TestInkDropHost* host) -> std::unique_ptr<views::InkDropRipple> {
        auto ripple = std::make_unique<TestInkDropRipple>(
            InkDrop::Get(host), host->size(), 0, host->size(), 0, gfx::Point(),
            SK_ColorBLACK, 0.175f);
        if (host->disable_timers_for_test_) {
          ripple->GetTestApi()->SetDisableAnimationTimers(true);
        }
        host->num_ink_drop_ripples_created_++;
        return ripple;
      },
      this));
}

void TestInkDropHost::AddLayerToRegion(ui::Layer* layer,
                                       views::LayerRegion region) {
  ++num_ink_drop_layers_added_;
}

void TestInkDropHost::RemoveLayerFromRegions(ui::Layer* layer) {
  ++num_ink_drop_layers_removed_;
}

TestInkDropHost::~TestInkDropHost() {
  // TODO(pbos): Revisit explicit removal of InkDrop for classes that override
  // Add/RemoveLayerFromRegions(). This is done so that the InkDrop doesn't
  // access the non-override versions in ~View.
  views::InkDrop::Remove(this);
}

}  // namespace views