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
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_
6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.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"
15 #include "ui/views/animation/ink_drop_state.h"
16 #include "ui/views/views_export.h"
24 class CircleLayerDelegate
;
25 class RectangleLayerDelegate
;
28 class InkDropAnimationTestApi
;
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.
36 // TODO(bruthig): Document the ink drop ripple on chromium.org and add a link to
38 class VIEWS_EXPORT InkDropAnimation
{
40 InkDropAnimation(const gfx::Size
& large_size
,
41 int large_corner_radius
,
42 const gfx::Size
& small_size
,
43 int small_corner_radius
);
46 // The root Layer that can be added in to a Layer tree.
47 ui::Layer
* root_layer() { return root_layer_
.get(); }
49 InkDropState
ink_drop_state() const { return ink_drop_state_
; }
51 // Animates from the current |ink_drop_state_| to a new |ink_drop_state|. It
52 // is possible to animate from any |ink_drop_state_| to any new
53 // |ink_drop_state|. Note that some state transitions will also perform an
54 // implicit transition to the another state. e.g. AnimateToState(QUICK_ACTION)
55 // will implicitly transition to the HIDDEN state.
56 void AnimateToState(InkDropState ink_drop_state
);
58 // Sets the |center_point| of the ink drop layer relative to its parent Layer.
59 void SetCenterPoint(const gfx::Point
& center_point
);
62 friend class test::InkDropAnimationTestApi
;
64 // Enumeration of the different shapes that compose the ink drop.
72 // The total number of shapes, not an actual shape.
76 // Type that contains a gfx::Tansform for each of the layers required by the
78 typedef gfx::Transform InkDropTransforms
[PAINTED_SHAPE_COUNT
];
80 // Animates all of the painted shape layers to the specified |transforms| and
82 void AnimateToTransforms(
83 const InkDropTransforms transforms
,
85 base::TimeDelta duration
,
86 ui::LayerAnimator::PreemptionStrategy preemption_strategy
);
88 // Resets the Transforms on all the owned Layers to a minimum size.
89 void ResetTransformsToMinSize();
91 // Sets the |transforms| on all of the shape layers. Note that this does not
92 // perform any animation.
93 void SetTransforms(const InkDropTransforms transforms
);
95 // Sets the opacity of the ink drop.
96 void SetOpacity(float opacity
);
98 // Updates all of the Transforms in |transforms_out| for a circle of the given
100 void CalculateCircleTransforms(const gfx::SizeF
& size
,
101 InkDropTransforms
* transforms_out
) const;
103 // Updates all of the Transforms in |transforms_out| for a rounded rectangle
104 // of the given |size| and |corner_radius|.
105 void CalculateRectTransforms(const gfx::SizeF
& size
,
107 InkDropTransforms
* transforms_out
) const;
109 // Updates all of the Transforms in |transforms_out| to the current target
110 // Transforms of the Layers.
111 void GetCurrentTansforms(InkDropTransforms
* transforms_out
) const;
113 // Adds and configures a new |painted_shape| layer to |painted_layers_|.
114 void AddPaintLayer(PaintedShape painted_shape
);
116 // Maximum size that an ink drop will be drawn to for any InkDropState whose
117 // final frame should be large.
118 gfx::Size large_size_
;
120 // Corner radius used to draw the rounded rectangles corner for any
121 // InkDropState whose final frame should be large.
122 int large_corner_radius_
;
124 // Maximum size that an ink drop will be drawn to for any InkDropState whose
125 // final frame should be small.
126 gfx::Size small_size_
;
128 // Corner radius used to draw the rounded rectangles corner for any
129 // InkDropState whose final frame should be small.
130 int small_corner_radius_
;
132 // ui::LayerDelegate to paint circles for all the circle layers.
133 scoped_ptr
<CircleLayerDelegate
> circle_layer_delegate_
;
135 // ui::LayerDelegate to paint rectangles for all the rectangle layers.
136 scoped_ptr
<RectangleLayerDelegate
> rect_layer_delegate_
;
138 // The root layer that parents the animating layers. The root layer is used to
139 // manipulate opacity and location, and its children are used to manipulate
140 // the different painted shapes that compose the ink drop.
141 scoped_ptr
<ui::Layer
> root_layer_
;
143 // ui::Layers for all of the painted shape layers that compose the ink drop.
144 scoped_ptr
<ui::Layer
> painted_layers_
[PAINTED_SHAPE_COUNT
];
146 // The current ink drop state.
147 InkDropState ink_drop_state_
;
149 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation
);
154 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_