| 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 // An ink drop animation that animates between the different InkDropStates. |
| 28 // TODO(bruthig): Document me better. |
| 24 class VIEWS_EXPORT InkDropAnimation { | 29 class VIEWS_EXPORT InkDropAnimation { |
| 25 public: | 30 public: |
| 26 InkDropAnimation(); | 31 InkDropAnimation(const gfx::Size& large_size, |
| 32 int large_corner_radius, |
| 33 const gfx::Size& small_size, |
| 34 int small_corner_radius); |
| 27 ~InkDropAnimation(); | 35 ~InkDropAnimation(); |
| 28 | 36 |
| 29 // The root that can be added in to a Layer tree. | 37 // The root that can be added in to a Layer tree. |
| 30 ui::Layer* root_layer() { return root_layer_.get(); } | 38 ui::Layer* root_layer() { return root_layer_.get(); } |
| 31 | 39 |
| 32 // Animates from the current |state_| to |state|. | 40 InkDropState ink_drop_state() const { return ink_drop_state_; } |
| 41 |
| 42 // Animates from the current |ink_drop_state_| to |state|. |
| 33 void AnimateToState(InkDropState state); | 43 void AnimateToState(InkDropState state); |
| 34 | 44 |
| 35 // Sets the size of the ink drop. | 45 // Sets the origin of the ink drop Layer relative to it's parent Layer. |
| 36 void SetInkDropSize(const gfx::Size& size); | 46 void SetOrigin(const gfx::Point& origin); |
| 37 | |
| 38 // Returns the ink drop bounds. | |
| 39 gfx::Rect GetInkDropBounds() const; | |
| 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 | 47 |
| 45 private: | 48 private: |
| 46 // Starts the animation of a touch event. | 49 // Enumeration of the different shapes that compose the ink drop. |
| 47 void AnimateTapDown(); | 50 enum PaintedShape { |
| 51 TOP_LEFT_CIRCLE, |
| 52 TOP_RIGHT_CIRCLE, |
| 53 BOTTOM_RIGHT_CIRCLE, |
| 54 BOTTOM_LEFT_CIRCLE, |
| 55 HORIZONTAL_RECT, |
| 56 VERTICAL_RECT, |
| 57 // The total number of shapes, not an actual shape. |
| 58 PAINTED_SHAPE_COUNT |
| 59 }; |
| 48 | 60 |
| 49 // Schedules the hide animation of |ink_drop_layer_| for once its current | 61 // Type that contains a gfx::Tansform for each of the layers required by the |
| 50 // animation has completed. If |ink_drop_layer_| is not animating, the hide | 62 // ink drop. |
| 51 // animation begins immediately. | 63 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; |
| 52 void AnimateHide(); | |
| 53 | 64 |
| 54 // Starts the animation of a long press, and cancels hiding |ink_drop_layer_| | 65 // TODO(bruthig): Document me. |
| 55 // until the long press has completed. | 66 void AnimateToTransforms( |
| 56 void AnimateLongPress(); | 67 InkDropTransforms transforms, |
| 68 float opacity, |
| 69 base::TimeDelta duration, |
| 70 ui::LayerAnimator::PreemptionStrategy preemption_strategy); |
| 57 | 71 |
| 58 // Starts the showing animation on |layer|, with a |duration| in milliseconds. | 72 // TODO(bruthig): Document me. |
| 59 void AnimateShow(ui::Layer* layer, | 73 void AnimateToTransform( |
| 60 AppearAnimationObserver* observer, | 74 ui::Layer* layer, |
| 61 base::TimeDelta duration); | 75 const gfx::Transform& target_transform, |
| 76 base::TimeDelta duration, |
| 77 ui::LayerAnimator::PreemptionStrategy preemption_strategy); |
| 62 | 78 |
| 63 // Sets the bounds for |layer|. | 79 // TODO(bruthig): Document me. |
| 64 void SetLayerBounds(ui::Layer* layer); | 80 void ResetTransformsToMinSize(); |
| 65 | 81 |
| 66 // Initializes |layer|'s properties. | 82 // TODO(bruthig): Document me. |
| 67 void SetupAnimationLayer(ui::Layer* layer, InkDropDelegate* delegate); | 83 void SetTransforms(InkDropTransforms transforms); |
| 68 | 84 |
| 69 // The root layer that parents the animating layers. | 85 // TODO(bruthig): Document me. |
| 86 void SetOpacity(float opacity); |
| 87 |
| 88 // TODO(bruthig): Document me. |
| 89 void CalculateCircleTransforms(const gfx::SizeF size, |
| 90 InkDropTransforms transforms) const; |
| 91 |
| 92 // TODO(bruthig): Document me. |
| 93 void CalculateRectTransforms(const gfx::SizeF size, |
| 94 float corner_radius, |
| 95 InkDropTransforms transforms) const; |
| 96 |
| 97 // TODO(bruthig): Document me. |
| 98 void GetCurrentTansforms(InkDropTransforms transforms) const; |
| 99 |
| 100 // TODO(bruthig): Document me. |
| 101 void AddPaintLayer(PaintedShape painted_shape); |
| 102 |
| 103 // Size used for large size animations. |
| 104 gfx::Size large_size_; |
| 105 |
| 106 // Corner radius used for large size animations. |
| 107 int large_corner_radius_; |
| 108 |
| 109 // Size used for small size animations. |
| 110 gfx::Size small_size_; |
| 111 |
| 112 // Corner radius used for small size animations. |
| 113 int small_corner_radius_; |
| 114 |
| 115 // ui::LayerDelegate to paint circles for all the circle layers. |
| 116 scoped_ptr<CircleLayerDelegate> circle_layer_delegate_; |
| 117 |
| 118 // ui::LayerDelegate to paint rectangles for all the rectangle layers. |
| 119 scoped_ptr<RectangleLayerDelegate> rect_layer_delegate_; |
| 120 |
| 121 // The root layer that parents the animating layers. The root layer is used to |
| 122 // manipulate opacity and origin, and its children are used to manipulate the |
| 123 // different painted shapes that compose the ink drop. |
| 70 scoped_ptr<ui::Layer> root_layer_; | 124 scoped_ptr<ui::Layer> root_layer_; |
| 71 | 125 |
| 72 // The layer used for animating a user touch. | 126 // The gfx::Transform to apply to the |root_layer_|. This is used to place the |
| 73 scoped_ptr<ui::Layer> ink_drop_layer_; | 127 // ink drop to the specified origin. |
| 128 gfx::Transform root_layer_transform_; |
| 74 | 129 |
| 75 // ui::LayerDelegate responsible for painting to |ink_drop_layer_|. | 130 // ui::Layers for all of the painted shape layers that compose the ink drop. |
| 76 scoped_ptr<InkDropDelegate> ink_drop_delegate_; | 131 scoped_ptr<ui::Layer> painted_layers_[PAINTED_SHAPE_COUNT]; |
| 77 | 132 |
| 78 // ui::ImplicitAnimationObserver which observes |ink_drop_layer_| and can be | 133 // The current ink drop state. |
| 79 // used to automatically trigger a hide animation upon completion. | 134 InkDropState ink_drop_state_; |
| 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 | 135 |
| 96 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); | 136 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); |
| 97 }; | 137 }; |
| 98 | 138 |
| 99 } // namespace views | 139 } // namespace views |
| 100 | 140 |
| 101 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ | 141 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ |
| OLD | NEW |