| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bounds_animator.h" | 5 #include "ui/views/animation/bounds_animator.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/gfx/animation/slide_animation.h" | 8 #include "ui/gfx/animation/slide_animation.h" |
| 9 #include "ui/gfx/animation/test_animation_delegate.h" | 9 #include "ui/gfx/animation/test_animation_delegate.h" |
| 10 #include "ui/views/view.h" | 10 #include "ui/views/view.h" |
| 11 | 11 |
| 12 using gfx::Animation; | 12 using gfx::Animation; |
| 13 using gfx::SlideAnimation; | 13 using gfx::SlideAnimation; |
| 14 using gfx::TestAnimationDelegate; | 14 using gfx::TestAnimationDelegate; |
| 15 | 15 |
| 16 namespace views { | 16 namespace views { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 class TestBoundsAnimator : public BoundsAnimator { | 19 class TestBoundsAnimator : public BoundsAnimator { |
| 20 public: | 20 public: |
| 21 explicit TestBoundsAnimator(View* view) : BoundsAnimator(view) { | 21 explicit TestBoundsAnimator(View* view) : BoundsAnimator(view) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 protected: | 24 protected: |
| 25 virtual SlideAnimation* CreateAnimation() override { | 25 SlideAnimation* CreateAnimation() override { |
| 26 SlideAnimation* animation = BoundsAnimator::CreateAnimation(); | 26 SlideAnimation* animation = BoundsAnimator::CreateAnimation(); |
| 27 animation->SetSlideDuration(10); | 27 animation->SetSlideDuration(10); |
| 28 return animation; | 28 return animation; |
| 29 } | 29 } |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 DISALLOW_COPY_AND_ASSIGN(TestBoundsAnimator); | 32 DISALLOW_COPY_AND_ASSIGN(TestBoundsAnimator); |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 class OwnedDelegate : public gfx::AnimationDelegate { | 35 class OwnedDelegate : public gfx::AnimationDelegate { |
| 36 public: | 36 public: |
| 37 OwnedDelegate() {} | 37 OwnedDelegate() {} |
| 38 | 38 |
| 39 virtual ~OwnedDelegate() { | 39 ~OwnedDelegate() override { deleted_ = true; } |
| 40 deleted_ = true; | |
| 41 } | |
| 42 | 40 |
| 43 static bool GetAndClearDeleted() { | 41 static bool GetAndClearDeleted() { |
| 44 bool value = deleted_; | 42 bool value = deleted_; |
| 45 deleted_ = false; | 43 deleted_ = false; |
| 46 return value; | 44 return value; |
| 47 } | 45 } |
| 48 | 46 |
| 49 static bool GetAndClearCanceled() { | 47 static bool GetAndClearCanceled() { |
| 50 bool value = canceled_; | 48 bool value = canceled_; |
| 51 canceled_ = false; | 49 canceled_ = false; |
| 52 return value; | 50 return value; |
| 53 } | 51 } |
| 54 | 52 |
| 55 // Overridden from gfx::AnimationDelegate: | 53 // Overridden from gfx::AnimationDelegate: |
| 56 virtual void AnimationCanceled(const Animation* animation) override { | 54 void AnimationCanceled(const Animation* animation) override { |
| 57 canceled_ = true; | 55 canceled_ = true; |
| 58 } | 56 } |
| 59 | 57 |
| 60 private: | 58 private: |
| 61 static bool deleted_; | 59 static bool deleted_; |
| 62 static bool canceled_; | 60 static bool canceled_; |
| 63 | 61 |
| 64 DISALLOW_COPY_AND_ASSIGN(OwnedDelegate); | 62 DISALLOW_COPY_AND_ASSIGN(OwnedDelegate); |
| 65 }; | 63 }; |
| 66 | 64 |
| 67 // static | 65 // static |
| 68 bool OwnedDelegate::deleted_ = false; | 66 bool OwnedDelegate::deleted_ = false; |
| 69 bool OwnedDelegate::canceled_ = false; | 67 bool OwnedDelegate::canceled_ = false; |
| 70 | 68 |
| 71 class TestView : public View { | 69 class TestView : public View { |
| 72 public: | 70 public: |
| 73 TestView() {} | 71 TestView() {} |
| 74 | 72 |
| 75 virtual void SchedulePaintInRect(const gfx::Rect& r) override { | 73 void SchedulePaintInRect(const gfx::Rect& r) override { |
| 76 if (dirty_rect_.IsEmpty()) | 74 if (dirty_rect_.IsEmpty()) |
| 77 dirty_rect_ = r; | 75 dirty_rect_ = r; |
| 78 else | 76 else |
| 79 dirty_rect_.Union(r); | 77 dirty_rect_.Union(r); |
| 80 } | 78 } |
| 81 | 79 |
| 82 const gfx::Rect& dirty_rect() const { return dirty_rect_; } | 80 const gfx::Rect& dirty_rect() const { return dirty_rect_; } |
| 83 | 81 |
| 84 private: | 82 private: |
| 85 gfx::Rect dirty_rect_; | 83 gfx::Rect dirty_rect_; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 173 |
| 176 // Shouldn't be animating now. | 174 // Shouldn't be animating now. |
| 177 EXPECT_FALSE(animator()->IsAnimating()); | 175 EXPECT_FALSE(animator()->IsAnimating()); |
| 178 | 176 |
| 179 // Stopping should both cancel the delegate and delete it. | 177 // Stopping should both cancel the delegate and delete it. |
| 180 EXPECT_TRUE(OwnedDelegate::GetAndClearDeleted()); | 178 EXPECT_TRUE(OwnedDelegate::GetAndClearDeleted()); |
| 181 EXPECT_TRUE(OwnedDelegate::GetAndClearCanceled()); | 179 EXPECT_TRUE(OwnedDelegate::GetAndClearCanceled()); |
| 182 } | 180 } |
| 183 | 181 |
| 184 } // namespace views | 182 } // namespace views |
| OLD | NEW |