| 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 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_IMPL_H_ | 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_IMPL_H_ |
| 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_IMPL_H_ | 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "ui/gfx/geometry/rect.h" | 9 #include "ui/gfx/geometry/rect.h" |
| 10 #include "ui/gfx/geometry/size.h" | 10 #include "ui/gfx/geometry/size.h" |
| 11 #include "ui/views/animation/ink_drop_animation_controller.h" | 11 #include "ui/views/animation/ink_drop_animation_controller.h" |
| 12 #include "ui/views/animation/ink_drop_animation_observer.h" | 12 #include "ui/views/animation/ink_drop_animation_observer.h" |
| 13 #include "ui/views/views_export.h" | 13 #include "ui/views/views_export.h" |
| 14 | 14 |
| 15 namespace base { |
| 16 class Timer; |
| 17 } // namespace base |
| 18 |
| 15 namespace views { | 19 namespace views { |
| 16 class InkDropAnimation; | 20 class InkDropAnimation; |
| 21 class InkDropConsumer; |
| 17 class InkDropHost; | 22 class InkDropHost; |
| 23 class InkDropHover; |
| 24 class MDInkDropAnimationControllerFactoryTest; |
| 18 | 25 |
| 19 // A functional implementation of an InkDropAnimationController. | 26 // A functional implementation of an InkDropAnimationController. |
| 20 class VIEWS_EXPORT InkDropAnimationControllerImpl | 27 class VIEWS_EXPORT InkDropAnimationControllerImpl |
| 21 : public InkDropAnimationController, | 28 : public InkDropAnimationController, |
| 22 public InkDropAnimationObserver { | 29 public InkDropAnimationObserver { |
| 23 public: | 30 public: |
| 24 // Constructs an ink drop controller that will attach the ink drop to the | 31 // Constructs an ink drop controller that will attach the ink drop to the |
| 25 // given |ink_drop_host|. | 32 // given |ink_drop_host|. |
| 26 explicit InkDropAnimationControllerImpl(InkDropHost* ink_drop_host); | 33 InkDropAnimationControllerImpl(InkDropHost* ink_drop_host, |
| 34 InkDropConsumer* ink_drop_consumer); |
| 27 ~InkDropAnimationControllerImpl() override; | 35 ~InkDropAnimationControllerImpl() override; |
| 28 | 36 |
| 29 // InkDropAnimationController: | 37 // InkDropAnimationController: |
| 30 InkDropState GetInkDropState() const override; | 38 InkDropState GetInkDropState() const override; |
| 31 void AnimateToState(InkDropState ink_drop_state) override; | 39 void AnimateToState(InkDropState ink_drop_state) override; |
| 40 void SetHovered(bool is_hovered) override; |
| 41 bool IsHovered() const override; |
| 32 gfx::Size GetInkDropLargeSize() const override; | 42 gfx::Size GetInkDropLargeSize() const override; |
| 33 void SetInkDropSize(const gfx::Size& large_size, | 43 void SetInkDropSize(const gfx::Size& large_size, |
| 34 int large_corner_radius, | 44 int large_corner_radius, |
| 35 const gfx::Size& small_size, | 45 const gfx::Size& small_size, |
| 36 int small_corner_radius) override; | 46 int small_corner_radius) override; |
| 37 void SetInkDropCenter(const gfx::Point& center_point) override; | 47 void SetInkDropCenter(const gfx::Point& center_point) override; |
| 38 | 48 |
| 39 private: | 49 private: |
| 50 friend class MDInkDropAnimationControllerFactoryTest; |
| 51 |
| 52 // Replace the |hover_after_animation_timer_| with |timer|. To be used by |
| 53 // tests only. |
| 54 void SetTimerForTest(base::Timer* timer); |
| 55 |
| 40 // Creates a new InkDropAnimation and sets it to |ink_drop_animation_|. If | 56 // Creates a new InkDropAnimation and sets it to |ink_drop_animation_|. If |
| 41 // |ink_drop_animation_| wasn't null then it will be destroyed using | 57 // |ink_drop_animation_| wasn't null then it will be destroyed using |
| 42 // DestroyInkDropAnimation(). | 58 // DestroyInkDropAnimation(). |
| 43 void CreateInkDropAnimation(); | 59 void CreateInkDropAnimation(); |
| 44 | 60 |
| 45 // Destroys the current |ink_drop_animation_|. | 61 // Destroys the current |ink_drop_animation_|. |
| 46 void DestroyInkDropAnimation(); | 62 void DestroyInkDropAnimation(); |
| 47 | 63 |
| 64 // Creates a new InkDropHover and sets it to |hover_|. If |hover_| wasn't null |
| 65 // then it will be destroyed using DestroyInkDropHover(). |
| 66 void CreateInkDropHover(); |
| 67 |
| 68 // Destroys the current |hover_|. |
| 69 void DestroyInkDropHover(); |
| 70 |
| 48 // views::InkDropAnimationObserver: | 71 // views::InkDropAnimationObserver: |
| 49 void InkDropAnimationStarted(InkDropState ink_drop_state) override; | 72 void InkDropAnimationStarted(InkDropState ink_drop_state) override; |
| 50 void InkDropAnimationEnded(InkDropState ink_drop_state, | 73 void InkDropAnimationEnded(InkDropState ink_drop_state, |
| 51 InkDropAnimationEndedReason reason) override; | 74 InkDropAnimationEndedReason reason) override; |
| 52 | 75 |
| 76 // Enables or disables the hover state based on |is_hovered| and if an |
| 77 // animation is triggered it will be scheduled to have the given |
| 78 // |animation_duration|. |
| 79 void SetHoveredInternal(bool is_hovered, base::TimeDelta animation_duration); |
| 80 |
| 81 // Starts the |hover_after_animation_timer_| timer. This will stop the current |
| 82 // |hover_after_animation_timer_| instance if it exists. |
| 83 void StartHoverAfterAnimationTimer(); |
| 84 |
| 85 // Stops and destroys the current |hover_after_animation_timer_| instance. |
| 86 void StopHoverAfterAnimationTimer(); |
| 87 |
| 88 // Callback for when the |hover_after_animation_timer_| fires. |
| 89 void HoverAfterAnimationTimerFired(); |
| 90 |
| 53 // The host of the ink drop. | 91 // The host of the ink drop. |
| 54 InkDropHost* ink_drop_host_; | 92 InkDropHost* ink_drop_host_; |
| 55 | 93 |
| 94 // The consuming surface of the ink drop. Used to poll for information such as |
| 95 // whether the hover should be shown or not. |
| 96 InkDropConsumer* ink_drop_consumer_; |
| 97 |
| 56 // Cached size for the ink drop's large size animations. | 98 // Cached size for the ink drop's large size animations. |
| 57 gfx::Size ink_drop_large_size_; | 99 gfx::Size ink_drop_large_size_; |
| 58 | 100 |
| 59 // Cached corner radius for the ink drop's large size animations. | 101 // Cached corner radius for the ink drop's large size animations. |
| 60 int ink_drop_large_corner_radius_; | 102 int ink_drop_large_corner_radius_; |
| 61 | 103 |
| 62 // Cached size for the ink drop's small size animations. | 104 // Cached size for the ink drop's small size animations. |
| 63 gfx::Size ink_drop_small_size_; | 105 gfx::Size ink_drop_small_size_; |
| 64 | 106 |
| 65 // Cached corner radius for the ink drop's small size animations. | 107 // Cached corner radius for the ink drop's small size animations. |
| 66 int ink_drop_small_corner_radius_; | 108 int ink_drop_small_corner_radius_; |
| 67 | 109 |
| 68 // Cached center point for the ink drop. | 110 // Cached center point for the ink drop. |
| 69 gfx::Point ink_drop_center_; | 111 gfx::Point ink_drop_center_; |
| 70 | 112 |
| 113 // The root Layer that parents the InkDropAnimation layers and the |
| 114 // InkDropHover layers. The |root_layer_| is the one that is added and removed |
| 115 // from the InkDropHost. |
| 116 scoped_ptr<ui::Layer> root_layer_; |
| 117 |
| 118 // The current InkDropHover. Lazily created using CreateInkDropHover(); |
| 119 scoped_ptr<InkDropHover> hover_; |
| 120 |
| 71 // The current InkDropAnimation. Created on demand using | 121 // The current InkDropAnimation. Created on demand using |
| 72 // CreateInkDropAnimation(). | 122 // CreateInkDropAnimation(). |
| 73 scoped_ptr<InkDropAnimation> ink_drop_animation_; | 123 scoped_ptr<InkDropAnimation> ink_drop_animation_; |
| 74 | 124 |
| 125 // The timer used to delay the hover fade in after an ink drop animation. |
| 126 scoped_ptr<base::Timer> hover_after_animation_timer_; |
| 127 |
| 75 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerImpl); | 128 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerImpl); |
| 76 }; | 129 }; |
| 77 | 130 |
| 78 } // namespace views | 131 } // namespace views |
| 79 | 132 |
| 80 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_IMPL_H_ | 133 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_IMPL_H_ |
| OLD | NEW |