| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 #ifndef UI_VIEWS_ANIMATION_SQUARE_INK_DROP_ANIMATION_H_ | |
| 6 #define UI_VIEWS_ANIMATION_SQUARE_INK_DROP_ANIMATION_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/time/time.h" | |
| 13 #include "third_party/skia/include/core/SkColor.h" | |
| 14 #include "ui/compositor/layer.h" | |
| 15 #include "ui/compositor/layer_animator.h" | |
| 16 #include "ui/gfx/animation/tween.h" | |
| 17 #include "ui/gfx/geometry/point.h" | |
| 18 #include "ui/gfx/geometry/size.h" | |
| 19 #include "ui/gfx/transform.h" | |
| 20 #include "ui/views/animation/ink_drop_animation.h" | |
| 21 #include "ui/views/animation/ink_drop_state.h" | |
| 22 #include "ui/views/views_export.h" | |
| 23 | |
| 24 namespace ui { | |
| 25 class Layer; | |
| 26 } // namespace ui | |
| 27 | |
| 28 namespace views { | |
| 29 class CircleLayerDelegate; | |
| 30 class RectangleLayerDelegate; | |
| 31 | |
| 32 namespace test { | |
| 33 class SquareInkDropAnimationTestApi; | |
| 34 } // namespace test | |
| 35 | |
| 36 // An ink drop animation that smoothly animates between a circle and a rounded | |
| 37 // rectangle of different sizes for each of the different InkDropStates. The | |
| 38 // final frame for each InkDropState will be bounded by either a |large_size_| | |
| 39 // rectangle or a |small_size_| rectangle. | |
| 40 // | |
| 41 // The valid InkDropState transitions are defined below: | |
| 42 // | |
| 43 // {All InkDropStates} => HIDDEN | |
| 44 // HIDDEN => ACTION_PENDING | |
| 45 // HIDDEN, ACTION_PENDING => ACTION_TRIGGERED | |
| 46 // ACTION_PENDING => ALTERNATE_ACTION_PENDING | |
| 47 // ALTERNATE_ACTION_PENDING => ALTERNATE_ACTION_TRIGGERED | |
| 48 // {All InkDropStates} => ACTIVATED | |
| 49 // {All InkDropStates} => DEACTIVATED | |
| 50 // | |
| 51 class VIEWS_EXPORT SquareInkDropAnimation : public InkDropAnimation { | |
| 52 public: | |
| 53 SquareInkDropAnimation(const gfx::Size& large_size, | |
| 54 int large_corner_radius, | |
| 55 const gfx::Size& small_size, | |
| 56 int small_corner_radius, | |
| 57 const gfx::Point& center_point, | |
| 58 SkColor color); | |
| 59 ~SquareInkDropAnimation() override; | |
| 60 | |
| 61 // InkDropAnimation: | |
| 62 void SnapToActivated() override; | |
| 63 ui::Layer* GetRootLayer() override; | |
| 64 bool IsVisible() const override; | |
| 65 | |
| 66 private: | |
| 67 friend class test::SquareInkDropAnimationTestApi; | |
| 68 | |
| 69 // Enumeration of the different shapes that compose the ink drop. | |
| 70 enum PaintedShape { | |
| 71 TOP_LEFT_CIRCLE = 0, | |
| 72 TOP_RIGHT_CIRCLE, | |
| 73 BOTTOM_RIGHT_CIRCLE, | |
| 74 BOTTOM_LEFT_CIRCLE, | |
| 75 HORIZONTAL_RECT, | |
| 76 VERTICAL_RECT, | |
| 77 // The total number of shapes, not an actual shape. | |
| 78 PAINTED_SHAPE_COUNT | |
| 79 }; | |
| 80 | |
| 81 // Returns a human readable string for the |painted_shape| value. | |
| 82 static std::string ToLayerName(PaintedShape painted_shape); | |
| 83 | |
| 84 // Type that contains a gfx::Tansform for each of the layers required by the | |
| 85 // ink drop. | |
| 86 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; | |
| 87 | |
| 88 float GetCurrentOpacity() const; | |
| 89 | |
| 90 // InkDropAnimation: | |
| 91 void AnimateStateChange(InkDropState old_ink_drop_state, | |
| 92 InkDropState new_ink_drop_state, | |
| 93 ui::LayerAnimationObserver* observer) override; | |
| 94 void SetStateToHidden() override; | |
| 95 void AbortAllAnimations() override; | |
| 96 | |
| 97 // Animates all of the painted shape layers to the specified |transforms|. The | |
| 98 // animation will be configured with the given |duration|, |tween|, and | |
| 99 // |preemption_strategy| values. The |observer| will be added to all | |
| 100 // LayerAnimationSequences if not null. | |
| 101 void AnimateToTransforms( | |
| 102 const InkDropTransforms transforms, | |
| 103 base::TimeDelta duration, | |
| 104 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | |
| 105 gfx::Tween::Type tween, | |
| 106 ui::LayerAnimationObserver* observer); | |
| 107 | |
| 108 // Sets the |transforms| on all of the shape layers. Note that this does not | |
| 109 // perform any animation. | |
| 110 void SetTransforms(const InkDropTransforms transforms); | |
| 111 | |
| 112 // Sets the opacity of the ink drop. Note that this does not perform any | |
| 113 // animation. | |
| 114 void SetOpacity(float opacity); | |
| 115 | |
| 116 // Animates all of the painted shape layers to the specified |opacity|. The | |
| 117 // animation will be configured with the given |duration|, |tween|, and | |
| 118 // |preemption_strategy| values. The |observer| will be added to all | |
| 119 // LayerAnimationSequences if not null. | |
| 120 void AnimateToOpacity( | |
| 121 float opacity, | |
| 122 base::TimeDelta duration, | |
| 123 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | |
| 124 gfx::Tween::Type tween, | |
| 125 ui::LayerAnimationObserver* observer); | |
| 126 | |
| 127 // Updates all of the Transforms in |transforms_out| for a circle of the given | |
| 128 // |size|. | |
| 129 void CalculateCircleTransforms(const gfx::Size& size, | |
| 130 InkDropTransforms* transforms_out) const; | |
| 131 | |
| 132 // Updates all of the Transforms in |transforms_out| for a rounded rectangle | |
| 133 // of the given |size| and |corner_radius|. | |
| 134 void CalculateRectTransforms(const gfx::Size& size, | |
| 135 float corner_radius, | |
| 136 InkDropTransforms* transforms_out) const; | |
| 137 | |
| 138 // Updates all of the Transforms in |transforms_out| to the current Transforms | |
| 139 // of the painted shape Layers. | |
| 140 void GetCurrentTransforms(InkDropTransforms* transforms_out) const; | |
| 141 | |
| 142 // Updates all of the Transforms in |transforms_out| with the target | |
| 143 // Transforms for the ACTIVATED animation. | |
| 144 void GetActivatedTargetTransforms(InkDropTransforms* transforms_out) const; | |
| 145 | |
| 146 // Adds and configures a new |painted_shape| layer to |painted_layers_|. | |
| 147 void AddPaintLayer(PaintedShape painted_shape); | |
| 148 | |
| 149 // Maximum size that an ink drop will be drawn to for any InkDropState whose | |
| 150 // final frame should be large. | |
| 151 gfx::Size large_size_; | |
| 152 | |
| 153 // Corner radius used to draw the rounded rectangles corner for any | |
| 154 // InkDropState whose final frame should be large. | |
| 155 int large_corner_radius_; | |
| 156 | |
| 157 // Maximum size that an ink drop will be drawn to for any InkDropState whose | |
| 158 // final frame should be small. | |
| 159 gfx::Size small_size_; | |
| 160 | |
| 161 // Corner radius used to draw the rounded rectangles corner for any | |
| 162 // InkDropState whose final frame should be small. | |
| 163 int small_corner_radius_; | |
| 164 | |
| 165 // ui::LayerDelegate to paint circles for all the circle layers. | |
| 166 std::unique_ptr<CircleLayerDelegate> circle_layer_delegate_; | |
| 167 | |
| 168 // ui::LayerDelegate to paint rectangles for all the rectangle layers. | |
| 169 std::unique_ptr<RectangleLayerDelegate> rect_layer_delegate_; | |
| 170 | |
| 171 // The root layer that parents the animating layers. The root layer is used to | |
| 172 // manipulate opacity and location, and its children are used to manipulate | |
| 173 // the different painted shapes that compose the ink drop. | |
| 174 ui::Layer root_layer_; | |
| 175 | |
| 176 // ui::Layers for all of the painted shape layers that compose the ink drop. | |
| 177 std::unique_ptr<ui::Layer> painted_layers_[PAINTED_SHAPE_COUNT]; | |
| 178 | |
| 179 DISALLOW_COPY_AND_ASSIGN(SquareInkDropAnimation); | |
| 180 }; | |
| 181 | |
| 182 } // namespace views | |
| 183 | |
| 184 #endif // UI_VIEWS_ANIMATION_SQUARE_INK_DROP_ANIMATION_H_ | |
| OLD | NEW |