Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: ui/views/animation/ink_drop_animation.h

Issue 1298513003: Implemented prototype for new ink drop specs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from patch set 10. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/ui_base_switches.cc ('k') | ui/views/animation/ink_drop_animation.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
35 //
36 // TODO(bruthig): Document the ink drop ripple on chromium.org and add a link to
37 // it.
24 class VIEWS_EXPORT InkDropAnimation { 38 class VIEWS_EXPORT InkDropAnimation {
25 public: 39 public:
26 InkDropAnimation(); 40 InkDropAnimation(const gfx::Size& large_size,
41 int large_corner_radius,
42 const gfx::Size& small_size,
43 int small_corner_radius);
27 ~InkDropAnimation(); 44 ~InkDropAnimation();
28 45
29 // The root that can be added in to a Layer tree. 46 // The root Layer that can be added in to a Layer tree.
30 ui::Layer* root_layer() { return root_layer_.get(); } 47 ui::Layer* root_layer() { return root_layer_.get(); }
31 48
32 // Animates from the current |state_| to |state|. 49 InkDropState ink_drop_state() const { return ink_drop_state_; }
33 void AnimateToState(InkDropState state);
34 50
35 // Sets the size of the ink drop. 51 // Animates from the current |ink_drop_state_| to a new |ink_drop_state|. It
36 void SetInkDropSize(const gfx::Size& size); 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);
37 57
38 // Returns the ink drop bounds. 58 // Sets the |center_point| of the ink drop layer relative to its parent Layer.
39 gfx::Rect GetInkDropBounds() const; 59 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 60
45 private: 61 private:
46 // Starts the animation of a touch event. 62 friend class test::InkDropAnimationTestApi;
47 void AnimateTapDown();
48 63
49 // Schedules the hide animation of |ink_drop_layer_| for once its current 64 // Enumeration of the different shapes that compose the ink drop.
50 // animation has completed. If |ink_drop_layer_| is not animating, the hide 65 enum PaintedShape {
51 // animation begins immediately. 66 TOP_LEFT_CIRCLE = 0,
52 void AnimateHide(); 67 TOP_RIGHT_CIRCLE,
68 BOTTOM_RIGHT_CIRCLE,
69 BOTTOM_LEFT_CIRCLE,
70 HORIZONTAL_RECT,
71 VERTICAL_RECT,
72 // The total number of shapes, not an actual shape.
73 PAINTED_SHAPE_COUNT
74 };
53 75
54 // Starts the animation of a long press, and cancels hiding |ink_drop_layer_| 76 // Type that contains a gfx::Tansform for each of the layers required by the
55 // until the long press has completed. 77 // ink drop.
56 void AnimateLongPress(); 78 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT];
57 79
58 // Starts the showing animation on |layer|, with a |duration| in milliseconds. 80 // Animates all of the painted shape layers to the specified |transforms| and
59 void AnimateShow(ui::Layer* layer, 81 // |opacity|.
60 AppearAnimationObserver* observer, 82 void AnimateToTransforms(
61 base::TimeDelta duration); 83 const InkDropTransforms transforms,
84 float opacity,
85 base::TimeDelta duration,
86 ui::LayerAnimator::PreemptionStrategy preemption_strategy);
62 87
63 // Sets the bounds for |layer|. 88 // Resets the Transforms on all the owned Layers to a minimum size.
64 void SetLayerBounds(ui::Layer* layer); 89 void ResetTransformsToMinSize();
65 90
66 // Initializes |layer|'s properties. 91 // Sets the |transforms| on all of the shape layers. Note that this does not
67 void SetupAnimationLayer(ui::Layer* layer, InkDropDelegate* delegate); 92 // perform any animation.
93 void SetTransforms(const InkDropTransforms transforms);
68 94
69 // The root layer that parents the animating layers. 95 // Sets the opacity of the ink drop.
96 void SetOpacity(float opacity);
97
98 // Updates all of the Transforms in |transforms_out| for a circle of the given
99 // |size|.
100 void CalculateCircleTransforms(const gfx::SizeF& size,
101 InkDropTransforms* transforms_out) const;
102
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,
106 float corner_radius,
107 InkDropTransforms* transforms_out) const;
108
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;
112
113 // Adds and configures a new |painted_shape| layer to |painted_layers_|.
114 void AddPaintLayer(PaintedShape painted_shape);
115
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_;
119
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_;
123
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_;
127
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_;
131
132 // ui::LayerDelegate to paint circles for all the circle layers.
133 scoped_ptr<CircleLayerDelegate> circle_layer_delegate_;
134
135 // ui::LayerDelegate to paint rectangles for all the rectangle layers.
136 scoped_ptr<RectangleLayerDelegate> rect_layer_delegate_;
137
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.
70 scoped_ptr<ui::Layer> root_layer_; 141 scoped_ptr<ui::Layer> root_layer_;
71 142
72 // The layer used for animating a user touch. 143 // ui::Layers for all of the painted shape layers that compose the ink drop.
73 scoped_ptr<ui::Layer> ink_drop_layer_; 144 scoped_ptr<ui::Layer> painted_layers_[PAINTED_SHAPE_COUNT];
74 145
75 // ui::LayerDelegate responsible for painting to |ink_drop_layer_|. 146 // The current ink drop state.
76 scoped_ptr<InkDropDelegate> ink_drop_delegate_; 147 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 148
96 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); 149 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation);
97 }; 150 };
98 151
99 } // namespace views 152 } // namespace views
100 153
101 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ 154 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_
OLDNEW
« no previous file with comments | « ui/base/ui_base_switches.cc ('k') | ui/views/animation/ink_drop_animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698