Chromium Code Reviews| 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_IMPL_H_ | 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_IMPL_H_ |
| 6 #define UI_VIEWS_ANIMATION_INK_DROP_IMPL_H_ | 6 #define UI_VIEWS_ANIMATION_INK_DROP_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "ui/gfx/geometry/rect.h" | 11 #include "ui/gfx/geometry/rect.h" |
| 12 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
| 13 #include "ui/views/animation/ink_drop.h" | 13 #include "ui/views/animation/ink_drop.h" |
| 14 #include "ui/views/animation/ink_drop_hover_observer.h" | 14 #include "ui/views/animation/ink_drop_highlight_observer.h" |
| 15 #include "ui/views/animation/ink_drop_ripple_observer.h" | 15 #include "ui/views/animation/ink_drop_ripple_observer.h" |
| 16 #include "ui/views/views_export.h" | 16 #include "ui/views/views_export.h" |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class Timer; | 19 class Timer; |
| 20 } // namespace base | 20 } // namespace base |
| 21 | 21 |
| 22 namespace views { | 22 namespace views { |
| 23 namespace test { | 23 namespace test { |
| 24 class InkDropImplTestApi; | 24 class InkDropImplTestApi; |
| 25 } // namespace test | 25 } // namespace test |
| 26 | 26 |
| 27 class InkDropRipple; | 27 class InkDropRipple; |
| 28 class InkDropHost; | 28 class InkDropHost; |
| 29 class InkDropHover; | 29 class InkDropHighlight; |
| 30 class InkDropFactoryTest; | 30 class InkDropFactoryTest; |
| 31 | 31 |
| 32 // A functional implementation of an InkDrop. | 32 // A functional implementation of an InkDrop. |
| 33 class VIEWS_EXPORT InkDropImpl : public InkDrop, | 33 class VIEWS_EXPORT InkDropImpl : public InkDrop, |
| 34 public InkDropRippleObserver, | 34 public InkDropRippleObserver, |
| 35 public InkDropHoverObserver { | 35 public InkDropHighlightObserver { |
| 36 public: | 36 public: |
| 37 // Constructs an ink drop that will attach the ink drop to the given | 37 // Constructs an ink drop that will attach the ink drop to the given |
| 38 // |ink_drop_host|. | 38 // |ink_drop_host|. |
| 39 explicit InkDropImpl(InkDropHost* ink_drop_host); | 39 explicit InkDropImpl(InkDropHost* ink_drop_host); |
| 40 ~InkDropImpl() override; | 40 ~InkDropImpl() override; |
| 41 | 41 |
| 42 // InkDrop: | 42 // InkDrop: |
| 43 InkDropState GetTargetInkDropState() const override; | 43 InkDropState GetTargetInkDropState() const override; |
| 44 bool IsVisible() const override; | 44 bool IsVisible() const override; |
| 45 void AnimateToState(InkDropState ink_drop_state) override; | 45 void AnimateToState(InkDropState ink_drop_state) override; |
| 46 void SnapToActivated() override; | 46 void SnapToActivated() override; |
| 47 void SetHovered(bool is_hovered) override; | 47 void SetHovered(bool is_hovered) override; |
| 48 void SetFocused(bool is_focused) override; | 48 void SetFocused(bool is_focused) override; |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 friend class test::InkDropImplTestApi; | 51 friend class test::InkDropImplTestApi; |
| 52 | 52 |
| 53 // Destroys |ink_drop_ripple_| if it's targeted to the HIDDEN state. | 53 // Destroys |ink_drop_ripple_| if it's targeted to the HIDDEN state. |
| 54 void DestroyHiddenTargetedAnimations(); | 54 void DestroyHiddenTargetedAnimations(); |
| 55 | 55 |
| 56 // Creates a new InkDropRipple and sets it to |ink_drop_ripple_|. If | 56 // Creates a new InkDropRipple and sets it to |ink_drop_ripple_|. If |
| 57 // |ink_drop_ripple_| wasn't null then it will be destroyed using | 57 // |ink_drop_ripple_| wasn't null then it will be destroyed using |
| 58 // DestroyInkDropRipple(). | 58 // DestroyInkDropRipple(). |
| 59 void CreateInkDropRipple(); | 59 void CreateInkDropRipple(); |
| 60 | 60 |
| 61 // Destroys the current |ink_drop_ripple_|. | 61 // Destroys the current |ink_drop_ripple_|. |
| 62 void DestroyInkDropRipple(); | 62 void DestroyInkDropRipple(); |
| 63 | 63 |
| 64 // Creates a new InkDropHover and sets it to |hover_|. If |hover_| wasn't null | 64 // Creates a new InkDropHighlight and assigns it to |highlight_|. If |
| 65 // then it will be destroyed using DestroyInkDropHover(). | 65 // |highlight_| wasn't null then it will be destroyed using |
| 66 void CreateInkDropHover(); | 66 // DestroyInkDropHighlight(). |
| 67 void CreateInkDropHighlight(); | |
| 67 | 68 |
| 68 // Destroys the current |hover_|. | 69 // Destroys the current |highlight_|. |
| 69 void DestroyInkDropHover(); | 70 void DestroyInkDropHighlight(); |
| 70 | 71 |
| 71 // Adds the |root_layer_| to the |ink_drop_host_| if it hasn't already been | 72 // Adds the |root_layer_| to the |ink_drop_host_| if it hasn't already been |
| 72 // added. | 73 // added. |
| 73 void AddRootLayerToHostIfNeeded(); | 74 void AddRootLayerToHostIfNeeded(); |
| 74 | 75 |
| 75 // Removes the |root_layer_| from the |ink_drop_host_| if no ink drop ripple | 76 // Removes the |root_layer_| from the |ink_drop_host_| if no ink drop ripple |
| 76 // or hover is active. | 77 // or highlight is active. |
| 77 void RemoveRootLayerFromHostIfNeeded(); | 78 void RemoveRootLayerFromHostIfNeeded(); |
| 78 | 79 |
| 79 // Returns true if the hover animation is in the process of fading in or | 80 // Returns true if the highlight animation is in the process of fading in or |
| 80 // is visible. | 81 // is visible. |
| 81 bool IsHoverFadingInOrVisible() const; | 82 bool IsHighlightFadingInOrVisible() const; |
| 82 | 83 |
| 83 // views::InkDropRippleObserver: | 84 // views::InkDropRippleObserver: |
| 84 void AnimationStarted(InkDropState ink_drop_state) override; | 85 void AnimationStarted(InkDropState ink_drop_state) override; |
| 85 void AnimationEnded(InkDropState ink_drop_state, | 86 void AnimationEnded(InkDropState ink_drop_state, |
| 86 InkDropAnimationEndedReason reason) override; | 87 InkDropAnimationEndedReason reason) override; |
| 87 | 88 |
| 88 // views::InkDropHoverObserver: | 89 // views::InkDropHighlightObserver: |
| 89 void AnimationStarted(InkDropHover::AnimationType animation_type) override; | 90 void AnimationStarted( |
| 90 void AnimationEnded(InkDropHover::AnimationType animation_type, | 91 InkDropHighlight::AnimationType animation_type) override; |
| 92 void AnimationEnded(InkDropHighlight::AnimationType animation_type, | |
| 91 InkDropAnimationEndedReason reason) override; | 93 InkDropAnimationEndedReason reason) override; |
| 92 | 94 |
| 93 // Enables or disables the hover state based on |should_highlight| and if an | 95 // Enables or disables the highlight state based on |should_highlight| and if |
| 96 // an | |
|
bruthig
2016/06/03 02:50:46
Join lines 96/97.
Evan Stade
2016/06/03 03:01:41
Done.
| |
| 94 // animation is triggered it will be scheduled to have the given | 97 // animation is triggered it will be scheduled to have the given |
| 95 // |animation_duration|. If |explode| is true the hover will expand as it | 98 // |animation_duration|. If |explode| is true the highlight will expand as it |
| 96 // fades out. |explode| is ignored when |should_higlight| is true. | 99 // fades out. |explode| is ignored when |should_higlight| is true. |
| 97 void SetHighlight(bool should_highlight, | 100 void SetHighlight(bool should_highlight, |
| 98 base::TimeDelta animation_duration, | 101 base::TimeDelta animation_duration, |
| 99 bool explode); | 102 bool explode); |
| 100 | 103 |
| 101 // Returns true if this ink drop is hovered or focused. | 104 // Returns true if this ink drop is hovered or focused. |
| 102 bool ShouldHighlight() const; | 105 bool ShouldHighlight() const; |
| 103 | 106 |
| 104 // Starts the |hover_after_ripple_timer_| timer. This will stop the current | 107 // Starts the |highlight_after_ripple_timer_| timer. This will stop the |
| 105 // |hover_after_ripple_timer_| instance if it exists. | 108 // current |
| 106 void StartHoverAfterRippleTimer(); | 109 // |highlight_after_ripple_timer_| instance if it exists. |
| 110 void StartHighlightAfterRippleTimer(); | |
| 107 | 111 |
| 108 // Stops and destroys the current |hover_after_ripple_timer_| instance. | 112 // Stops and destroys the current |highlight_after_ripple_timer_| instance. |
| 109 void StopHoverAfterRippleTimer(); | 113 void StopHighlightAfterRippleTimer(); |
| 110 | 114 |
| 111 // Callback for when the |hover_after_ripple_timer_| fires. | 115 // Callback for when the |highlight_after_ripple_timer_| fires. |
| 112 void HoverAfterRippleTimerFired(); | 116 void HighlightAfterRippleTimerFired(); |
| 113 | 117 |
| 114 // The host of the ink drop. Used to poll for information such as whether the | 118 // The host of the ink drop. Used to poll for information such as whether the |
| 115 // hover should be shown or not. | 119 // highlight should be shown or not. |
| 116 InkDropHost* ink_drop_host_; | 120 InkDropHost* ink_drop_host_; |
| 117 | 121 |
| 118 // The root Layer that parents the InkDropRipple layers and the InkDropHover | 122 // The root Layer that parents the InkDropRipple layers and the |
| 119 // layers. The |root_layer_| is the one that is added and removed from the | 123 // InkDropHighlight layers. The |root_layer_| is the one that is added and |
| 120 // InkDropHost. | 124 // removed from the InkDropHost. |
| 121 std::unique_ptr<ui::Layer> root_layer_; | 125 std::unique_ptr<ui::Layer> root_layer_; |
| 122 | 126 |
| 123 // True when the |root_layer_| has been added to the |ink_drop_host_|. | 127 // True when the |root_layer_| has been added to the |ink_drop_host_|. |
| 124 bool root_layer_added_to_host_; | 128 bool root_layer_added_to_host_; |
| 125 | 129 |
| 126 // The current InkDropHover. Lazily created using CreateInkDropHover(); | 130 // The current InkDropHighlight. Lazily created using |
| 127 std::unique_ptr<InkDropHover> hover_; | 131 // CreateInkDropHighlight(); |
| 132 std::unique_ptr<InkDropHighlight> highlight_; | |
| 128 | 133 |
| 129 // Tracks the logical hovered state of |this| as manipulated by the public | 134 // Tracks the logical hovered state of |this| as manipulated by the public |
| 130 // SetHovered() function. | 135 // SetHovered() function. |
| 131 bool is_hovered_; | 136 bool is_hovered_; |
| 132 | 137 |
| 133 // Tracks the logical focused state of |this| as manipulated by the public | 138 // Tracks the logical focused state of |this| as manipulated by the public |
| 134 // SetFocused() function. | 139 // SetFocused() function. |
| 135 bool is_focused_; | 140 bool is_focused_; |
| 136 | 141 |
| 137 // The current InkDropRipple. Created on demand using CreateInkDropRipple(). | 142 // The current InkDropRipple. Created on demand using CreateInkDropRipple(). |
| 138 std::unique_ptr<InkDropRipple> ink_drop_ripple_; | 143 std::unique_ptr<InkDropRipple> ink_drop_ripple_; |
| 139 | 144 |
| 140 // The timer used to delay the hover fade in after an ink drop ripple | 145 // The timer used to delay the highlight fade in after an ink drop ripple |
| 141 // animation. | 146 // animation. |
| 142 std::unique_ptr<base::Timer> hover_after_ripple_timer_; | 147 std::unique_ptr<base::Timer> highlight_after_ripple_timer_; |
| 143 | 148 |
| 144 DISALLOW_COPY_AND_ASSIGN(InkDropImpl); | 149 DISALLOW_COPY_AND_ASSIGN(InkDropImpl); |
| 145 }; | 150 }; |
| 146 | 151 |
| 147 } // namespace views | 152 } // namespace views |
| 148 | 153 |
| 149 #endif // UI_VIEWS_ANIMATION_INK_DROP_IMPL_H_ | 154 #endif // UI_VIEWS_ANIMATION_INK_DROP_IMPL_H_ |
| OLD | NEW |