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