| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/animation/test/test_ink_drop_host.h" | 5 #include "ui/views/animation/test/test_ink_drop_host.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "ui/gfx/geometry/size.h" | 8 #include "ui/gfx/geometry/size.h" |
| 9 #include "ui/views/animation/ink_drop_hover.h" | 9 #include "ui/views/animation/ink_drop_hover.h" |
| 10 #include "ui/views/animation/square_ink_drop_animation.h" | 10 #include "ui/views/animation/square_ink_drop_animation.h" |
| 11 #include "ui/views/animation/test/ink_drop_hover_test_api.h" |
| 12 #include "ui/views/animation/test/square_ink_drop_animation_test_api.h" |
| 11 | 13 |
| 12 namespace views { | 14 namespace views { |
| 13 | 15 |
| 16 namespace { |
| 17 |
| 18 // Test specific subclass of InkDropAnimation that returns a test api from |
| 19 // GetTestApi(). |
| 20 class TestInkDropAnimation : public SquareInkDropAnimation { |
| 21 public: |
| 22 TestInkDropAnimation(const gfx::Size& large_size, |
| 23 int large_corner_radius, |
| 24 const gfx::Size& small_size, |
| 25 int small_corner_radius, |
| 26 const gfx::Point& center_point, |
| 27 SkColor color) |
| 28 : SquareInkDropAnimation(large_size, |
| 29 large_corner_radius, |
| 30 small_size, |
| 31 small_corner_radius, |
| 32 center_point, |
| 33 color) {} |
| 34 |
| 35 ~TestInkDropAnimation() override {} |
| 36 |
| 37 test::InkDropAnimationTestApi* GetTestApi() override { |
| 38 if (!test_api_) |
| 39 test_api_.reset(new test::SquareInkDropAnimationTestApi(this)); |
| 40 return test_api_.get(); |
| 41 } |
| 42 |
| 43 private: |
| 44 std::unique_ptr<test::InkDropAnimationTestApi> test_api_; |
| 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(TestInkDropAnimation); |
| 47 }; |
| 48 |
| 49 // Test specific subclass of InkDropHover that returns a test api from |
| 50 // GetTestApi(). |
| 51 class TestInkDropHover : public InkDropHover { |
| 52 public: |
| 53 TestInkDropHover(const gfx::Size& size, |
| 54 int corner_radius, |
| 55 const gfx::Point& center_point, |
| 56 SkColor color) |
| 57 : InkDropHover(size, corner_radius, center_point, color) {} |
| 58 |
| 59 ~TestInkDropHover() override {} |
| 60 |
| 61 test::InkDropHoverTestApi* GetTestApi() override { |
| 62 if (!test_api_) |
| 63 test_api_.reset(new test::InkDropHoverTestApi(this)); |
| 64 return test_api_.get(); |
| 65 } |
| 66 |
| 67 private: |
| 68 std::unique_ptr<test::InkDropHoverTestApi> test_api_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(TestInkDropHover); |
| 71 }; |
| 72 |
| 73 } // namespace |
| 74 |
| 14 TestInkDropHost::TestInkDropHost() | 75 TestInkDropHost::TestInkDropHost() |
| 15 : num_ink_drop_layers_(0), should_show_hover_(false) {} | 76 : num_ink_drop_layers_(0), |
| 77 should_show_hover_(false), |
| 78 disable_timers_for_test_(false) {} |
| 16 | 79 |
| 17 TestInkDropHost::~TestInkDropHost() {} | 80 TestInkDropHost::~TestInkDropHost() {} |
| 18 | 81 |
| 19 void TestInkDropHost::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 82 void TestInkDropHost::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 20 ++num_ink_drop_layers_; | 83 ++num_ink_drop_layers_; |
| 21 } | 84 } |
| 22 | 85 |
| 23 void TestInkDropHost::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 86 void TestInkDropHost::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 24 --num_ink_drop_layers_; | 87 --num_ink_drop_layers_; |
| 25 } | 88 } |
| 26 | 89 |
| 27 std::unique_ptr<InkDropAnimation> TestInkDropHost::CreateInkDropAnimation() | 90 std::unique_ptr<InkDropAnimation> TestInkDropHost::CreateInkDropAnimation() |
| 28 const { | 91 const { |
| 29 gfx::Size size(10, 10); | 92 gfx::Size size(10, 10); |
| 30 return base::WrapUnique(new SquareInkDropAnimation( | 93 std::unique_ptr<InkDropAnimation> animation( |
| 31 size, 5, size, 5, gfx::Point(), SK_ColorBLACK)); | 94 new TestInkDropAnimation(size, 5, size, 5, gfx::Point(), SK_ColorBLACK)); |
| 95 if (disable_timers_for_test_) |
| 96 animation->GetTestApi()->SetDisableAnimationTimers(true); |
| 97 return animation; |
| 32 } | 98 } |
| 33 | 99 |
| 34 std::unique_ptr<InkDropHover> TestInkDropHost::CreateInkDropHover() const { | 100 std::unique_ptr<InkDropHover> TestInkDropHost::CreateInkDropHover() const { |
| 35 return should_show_hover_ | 101 std::unique_ptr<InkDropHover> hover; |
| 36 ? base::WrapUnique(new InkDropHover(gfx::Size(10, 10), 4, | 102 if (should_show_hover_) { |
| 37 gfx::Point(), SK_ColorBLACK)) | 103 hover.reset(new TestInkDropHover(gfx::Size(10, 10), 4, gfx::Point(), |
| 38 : nullptr; | 104 SK_ColorBLACK)); |
| 105 if (disable_timers_for_test_) |
| 106 hover->GetTestApi()->SetDisableAnimationTimers(true); |
| 107 } |
| 108 return hover; |
| 39 } | 109 } |
| 40 | 110 |
| 41 } // namespace views | 111 } // namespace views |
| OLD | NEW |