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_ANIMATION_H_ | 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ |
| 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ | 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_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 "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "ui/gfx/geometry/rect.h" | 11 #include "ui/compositor/layer_animator.h" |
| 12 #include "ui/gfx/geometry/size.h" | |
| 13 #include "ui/gfx/geometry/size_f.h" | |
| 14 #include "ui/gfx/transform.h" | |
| 12 #include "ui/views/animation/ink_drop_state.h" | 15 #include "ui/views/animation/ink_drop_state.h" |
| 13 #include "ui/views/views_export.h" | 16 #include "ui/views/views_export.h" |
| 14 | 17 |
| 15 namespace ui { | 18 namespace ui { |
| 16 class Layer; | 19 class Layer; |
| 20 class LayerDelegate; | |
| 17 } // namespace ui | 21 } // namespace ui |
| 18 | 22 |
| 19 namespace views { | 23 namespace views { |
| 20 class AppearAnimationObserver; | 24 class CircleLayerDelegate; |
| 21 class InkDropDelegate; | 25 class RectangleLayerDelegate; |
| 22 | 26 |
| 23 // An ink drop animation that animates between the different InkDropStates. | 27 namespace test { |
| 28 class InkDropAnimationTestApi; | |
| 29 } // namespace test | |
| 30 | |
| 31 // An ink drop animation that smoothly animates between a circle and a rounded | |
| 32 // rectangle of different sizes for each of the different InkDropStates. The | |
| 33 // final frame for each InkDropState will be bounded by either a |large_size_| | |
| 34 // rectangle or a |small_size_| rectangle. | |
| 24 class VIEWS_EXPORT InkDropAnimation { | 35 class VIEWS_EXPORT InkDropAnimation { |
| 25 public: | 36 public: |
| 26 InkDropAnimation(); | 37 InkDropAnimation(const gfx::Size& large_size, |
| 38 int large_corner_radius, | |
| 39 const gfx::Size& small_size, | |
| 40 int small_corner_radius); | |
| 27 ~InkDropAnimation(); | 41 ~InkDropAnimation(); |
| 28 | 42 |
| 29 // The root that can be added in to a Layer tree. | 43 // The root Layer that can be added in to a Layer tree. |
| 30 ui::Layer* root_layer() { return root_layer_.get(); } | 44 ui::Layer* root_layer() { return root_layer_.get(); } |
| 31 | 45 |
| 32 // Animates from the current |state_| to |state|. | 46 InkDropState ink_drop_state() const { return ink_drop_state_; } |
| 33 void AnimateToState(InkDropState state); | |
| 34 | 47 |
| 35 // Sets the size of the ink drop. | 48 // Animates from the current |ink_drop_state_| to a new |ink_drop_state|. It |
| 36 void SetInkDropSize(const gfx::Size& size); | 49 // is possible to animate from any |ink_drop_state_| to any new |
| 50 // |ink_drop_state|. Note that some state transitions will also perform an | |
| 51 // implicit transition to the another state. e.g. AnimateToState(QUICK_ACTION) | |
| 52 // will implicitly transition to the HIDDEN state. | |
| 53 void AnimateToState(InkDropState ink_drop_state); | |
| 37 | 54 |
| 38 // Returns the ink drop bounds. | 55 // Sets the |center_point| of the ink drop layer relative to its parent Layer. |
| 39 gfx::Rect GetInkDropBounds() const; | 56 void SetCenterPoint(const gfx::Point& center_point); |
| 40 | |
| 41 // Sets the bounds for the ink drop. |bounds| are in the coordinate space of | |
| 42 // the parent ui::Layer that the ink drop layer is added to. | |
| 43 void SetInkDropBounds(const gfx::Rect& bounds); | |
| 44 | 57 |
| 45 private: | 58 private: |
| 46 // Starts the animation of a touch event. | 59 friend class test::InkDropAnimationTestApi; |
| 47 void AnimateTapDown(); | |
| 48 | 60 |
| 49 // Schedules the hide animation of |ink_drop_layer_| for once its current | 61 // Enumeration of the different shapes that compose the ink drop. |
| 50 // animation has completed. If |ink_drop_layer_| is not animating, the hide | 62 enum PaintedShape { |
| 51 // animation begins immediately. | 63 TOP_LEFT_CIRCLE, |
|
sadrul
2015/09/14 20:05:40
= 0
bruthig
2015/09/15 19:47:09
Done.
| |
| 52 void AnimateHide(); | 64 TOP_RIGHT_CIRCLE, |
| 65 BOTTOM_RIGHT_CIRCLE, | |
| 66 BOTTOM_LEFT_CIRCLE, | |
| 67 HORIZONTAL_RECT, | |
| 68 VERTICAL_RECT, | |
| 69 // The total number of shapes, not an actual shape. | |
| 70 PAINTED_SHAPE_COUNT | |
| 71 }; | |
| 53 | 72 |
| 54 // Starts the animation of a long press, and cancels hiding |ink_drop_layer_| | 73 // Type that contains a gfx::Tansform for each of the layers required by the |
| 55 // until the long press has completed. | 74 // ink drop. |
| 56 void AnimateLongPress(); | 75 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; |
| 57 | 76 |
| 58 // Starts the showing animation on |layer|, with a |duration| in milliseconds. | 77 // Animates all of the painted shape layers to the specified |transforms| and |
| 59 void AnimateShow(ui::Layer* layer, | 78 // |opacity|. |
| 60 AppearAnimationObserver* observer, | 79 void AnimateToTransforms( |
| 61 base::TimeDelta duration); | 80 InkDropTransforms transforms, |
|
sadrul
2015/09/14 20:05:40
const
bruthig
2015/09/15 19:47:09
Done.
| |
| 81 float opacity, | |
| 82 base::TimeDelta duration, | |
| 83 ui::LayerAnimator::PreemptionStrategy preemption_strategy); | |
| 62 | 84 |
| 63 // Sets the bounds for |layer|. | 85 // Resets the Transforms on all the owned Layers to a minium size. |
|
tdanderson
2015/09/10 15:37:51
nit: minium -> minimum
bruthig
2015/09/15 19:47:09
Done.
| |
| 64 void SetLayerBounds(ui::Layer* layer); | 86 void ResetTransformsToMinSize(); |
| 65 | 87 |
| 66 // Initializes |layer|'s properties. | 88 // Sets the |transforms| on all of the shape layers. Note that this does not |
| 67 void SetupAnimationLayer(ui::Layer* layer, InkDropDelegate* delegate); | 89 // perform any animation. |
| 90 void SetTransforms(InkDropTransforms transforms); | |
|
sadrul
2015/09/14 20:05:40
const
bruthig
2015/09/15 19:47:09
Done.
| |
| 68 | 91 |
| 69 // The root layer that parents the animating layers. | 92 // Sets the opacity of the ink drop. |
| 93 void SetOpacity(float opacity); | |
| 94 | |
| 95 // Updates all of the Transforms in |transforms| for a circle of the given | |
| 96 // |size|. | |
| 97 void CalculateCircleTransforms(const gfx::SizeF size, | |
|
sadrul
2015/09/14 20:05:40
const &
bruthig
2015/09/15 19:47:09
Done.
| |
| 98 InkDropTransforms transforms) const; | |
|
sadrul
2015/09/14 20:05:40
const
bruthig
2015/09/15 19:47:09
|transforms| is an output parameter.
| |
| 99 | |
| 100 // Updates all of the Transforms in |transforms| for a rounded rectangle of | |
| 101 // the given |size| and |corner_radius|. | |
| 102 void CalculateRectTransforms(const gfx::SizeF size, | |
|
sadrul
2015/09/14 20:05:40
const &
bruthig
2015/09/15 19:47:09
Done.
| |
| 103 float corner_radius, | |
| 104 InkDropTransforms transforms) const; | |
|
sadrul
2015/09/14 20:05:41
const
bruthig
2015/09/15 19:47:09
|transforms| is an output parameter.
| |
| 105 | |
| 106 // Updates all of the Transforms in |transforms| to the current target | |
| 107 // Transforms of the Layers. | |
| 108 void GetCurrentTansforms(InkDropTransforms transforms) const; | |
|
sadrul
2015/09/14 20:05:40
*Transforms
InkDropTransforms* since out-param.
bruthig
2015/09/15 19:47:09
Done.
| |
| 109 | |
| 110 // Adds and configures a new |painted_shape| layer to |painted_layers_|. | |
| 111 void AddPaintLayer(PaintedShape painted_shape); | |
| 112 | |
| 113 // Maximum size that an ink drop will be drawn to for any InkDropState whose | |
| 114 // final frame should be large. | |
| 115 gfx::Size large_size_; | |
| 116 | |
| 117 // Corner radius used to draw the rounded rectangles corner for any | |
| 118 // InkDropState whose final frame should be large. | |
| 119 int large_corner_radius_; | |
| 120 | |
| 121 // Maximum size that an ink drop will be drawn to for any InkDropState whose | |
| 122 // final frame should be small. | |
| 123 gfx::Size small_size_; | |
| 124 | |
| 125 // Corner radius used to draw the rounded rectangles corner for any | |
| 126 // InkDropState whose final frame should be small. | |
| 127 int small_corner_radius_; | |
| 128 | |
| 129 // ui::LayerDelegate to paint circles for all the circle layers. | |
| 130 scoped_ptr<CircleLayerDelegate> circle_layer_delegate_; | |
| 131 | |
| 132 // ui::LayerDelegate to paint rectangles for all the rectangle layers. | |
| 133 scoped_ptr<RectangleLayerDelegate> rect_layer_delegate_; | |
| 134 | |
| 135 // The root layer that parents the animating layers. The root layer is used to | |
| 136 // manipulate opacity and location, and its children are used to manipulate | |
| 137 // the different painted shapes that compose the ink drop. | |
| 70 scoped_ptr<ui::Layer> root_layer_; | 138 scoped_ptr<ui::Layer> root_layer_; |
| 71 | 139 |
| 72 // The layer used for animating a user touch. | 140 // ui::Layers for all of the painted shape layers that compose the ink drop. |
| 73 scoped_ptr<ui::Layer> ink_drop_layer_; | 141 scoped_ptr<ui::Layer> painted_layers_[PAINTED_SHAPE_COUNT]; |
| 74 | 142 |
| 75 // ui::LayerDelegate responsible for painting to |ink_drop_layer_|. | 143 // The current ink drop state. |
| 76 scoped_ptr<InkDropDelegate> ink_drop_delegate_; | 144 InkDropState ink_drop_state_; |
| 77 | |
| 78 // ui::ImplicitAnimationObserver which observes |ink_drop_layer_| and can be | |
| 79 // used to automatically trigger a hide animation upon completion. | |
| 80 scoped_ptr<AppearAnimationObserver> appear_animation_observer_; | |
| 81 | |
| 82 // The layer used for animating a long press. | |
| 83 scoped_ptr<ui::Layer> long_press_layer_; | |
| 84 | |
| 85 // ui::LayerDelegate responsible for painting to |long_press_layer_|. | |
| 86 scoped_ptr<InkDropDelegate> long_press_delegate_; | |
| 87 | |
| 88 // ui::ImplicitAnimationObserver which observers |long_press_layer_| and can | |
| 89 // be used to automatically trigger a hide animation upon completion. | |
| 90 scoped_ptr<AppearAnimationObserver> long_press_animation_observer_; | |
| 91 | |
| 92 // The bounds of the ink drop layers. Defined in the coordinate space of the | |
| 93 // parent ui::Layer that the ink drop layers were added to. | |
| 94 gfx::Rect ink_drop_bounds_; | |
| 95 | 145 |
| 96 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); | 146 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); |
| 97 }; | 147 }; |
| 98 | 148 |
| 99 } // namespace views | 149 } // namespace views |
| 100 | 150 |
| 101 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ | 151 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ |
| OLD | NEW |