| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_SQUARE_INK_DROP_ANIMATION_H_ | 5 #ifndef UI_VIEWS_ANIMATION_SQUARE_INK_DROP_RIPPLE_H_ |
| 6 #define UI_VIEWS_ANIMATION_SQUARE_INK_DROP_ANIMATION_H_ | 6 #define UI_VIEWS_ANIMATION_SQUARE_INK_DROP_RIPPLE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
| 14 #include "ui/compositor/layer.h" | 14 #include "ui/compositor/layer.h" |
| 15 #include "ui/compositor/layer_animator.h" | 15 #include "ui/compositor/layer_animator.h" |
| 16 #include "ui/gfx/animation/tween.h" | 16 #include "ui/gfx/animation/tween.h" |
| 17 #include "ui/gfx/geometry/point.h" | 17 #include "ui/gfx/geometry/point.h" |
| 18 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
| 19 #include "ui/gfx/transform.h" | 19 #include "ui/gfx/transform.h" |
| 20 #include "ui/views/animation/ink_drop_animation.h" | 20 #include "ui/views/animation/ink_drop_ripple.h" |
| 21 #include "ui/views/animation/ink_drop_state.h" | 21 #include "ui/views/animation/ink_drop_state.h" |
| 22 #include "ui/views/views_export.h" | 22 #include "ui/views/views_export.h" |
| 23 | 23 |
| 24 namespace ui { | 24 namespace ui { |
| 25 class Layer; | 25 class Layer; |
| 26 } // namespace ui | 26 } // namespace ui |
| 27 | 27 |
| 28 namespace views { | 28 namespace views { |
| 29 class CircleLayerDelegate; | 29 class CircleLayerDelegate; |
| 30 class RectangleLayerDelegate; | 30 class RectangleLayerDelegate; |
| 31 | 31 |
| 32 namespace test { | 32 namespace test { |
| 33 class SquareInkDropAnimationTestApi; | 33 class SquareInkDropRippleTestApi; |
| 34 } // namespace test | 34 } // namespace test |
| 35 | 35 |
| 36 // An ink drop animation that smoothly animates between a circle and a rounded | 36 // An ink drop ripple that smoothly animates between a circle and a rounded |
| 37 // rectangle of different sizes for each of the different InkDropStates. The | 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_| | 38 // final frame for each InkDropState will be bounded by either a |large_size_| |
| 39 // rectangle or a |small_size_| rectangle. | 39 // rectangle or a |small_size_| rectangle. |
| 40 // | 40 // |
| 41 // The valid InkDropState transitions are defined below: | 41 // The valid InkDropState transitions are defined below: |
| 42 // | 42 // |
| 43 // {All InkDropStates} => HIDDEN | 43 // {All InkDropStates} => HIDDEN |
| 44 // HIDDEN => ACTION_PENDING | 44 // HIDDEN => ACTION_PENDING |
| 45 // HIDDEN, ACTION_PENDING => ACTION_TRIGGERED | 45 // HIDDEN, ACTION_PENDING => ACTION_TRIGGERED |
| 46 // ACTION_PENDING => ALTERNATE_ACTION_PENDING | 46 // ACTION_PENDING => ALTERNATE_ACTION_PENDING |
| 47 // ALTERNATE_ACTION_PENDING => ALTERNATE_ACTION_TRIGGERED | 47 // ALTERNATE_ACTION_PENDING => ALTERNATE_ACTION_TRIGGERED |
| 48 // {All InkDropStates} => ACTIVATED | 48 // {All InkDropStates} => ACTIVATED |
| 49 // {All InkDropStates} => DEACTIVATED | 49 // {All InkDropStates} => DEACTIVATED |
| 50 // | 50 // |
| 51 class VIEWS_EXPORT SquareInkDropAnimation : public InkDropAnimation { | 51 class VIEWS_EXPORT SquareInkDropRipple : public InkDropRipple { |
| 52 public: | 52 public: |
| 53 SquareInkDropAnimation(const gfx::Size& large_size, | 53 SquareInkDropRipple(const gfx::Size& large_size, |
| 54 int large_corner_radius, | 54 int large_corner_radius, |
| 55 const gfx::Size& small_size, | 55 const gfx::Size& small_size, |
| 56 int small_corner_radius, | 56 int small_corner_radius, |
| 57 const gfx::Point& center_point, | 57 const gfx::Point& center_point, |
| 58 SkColor color); | 58 SkColor color); |
| 59 ~SquareInkDropAnimation() override; | 59 ~SquareInkDropRipple() override; |
| 60 | 60 |
| 61 // InkDropAnimation: | 61 // InkDropRipple: |
| 62 void SnapToActivated() override; | 62 void SnapToActivated() override; |
| 63 ui::Layer* GetRootLayer() override; | 63 ui::Layer* GetRootLayer() override; |
| 64 bool IsVisible() const override; | 64 bool IsVisible() const override; |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 friend class test::SquareInkDropAnimationTestApi; | 67 friend class test::SquareInkDropRippleTestApi; |
| 68 | 68 |
| 69 // Enumeration of the different shapes that compose the ink drop. | 69 // Enumeration of the different shapes that compose the ink drop. |
| 70 enum PaintedShape { | 70 enum PaintedShape { |
| 71 TOP_LEFT_CIRCLE = 0, | 71 TOP_LEFT_CIRCLE = 0, |
| 72 TOP_RIGHT_CIRCLE, | 72 TOP_RIGHT_CIRCLE, |
| 73 BOTTOM_RIGHT_CIRCLE, | 73 BOTTOM_RIGHT_CIRCLE, |
| 74 BOTTOM_LEFT_CIRCLE, | 74 BOTTOM_LEFT_CIRCLE, |
| 75 HORIZONTAL_RECT, | 75 HORIZONTAL_RECT, |
| 76 VERTICAL_RECT, | 76 VERTICAL_RECT, |
| 77 // The total number of shapes, not an actual shape. | 77 // The total number of shapes, not an actual shape. |
| 78 PAINTED_SHAPE_COUNT | 78 PAINTED_SHAPE_COUNT |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // Returns a human readable string for the |painted_shape| value. | 81 // Returns a human readable string for the |painted_shape| value. |
| 82 static std::string ToLayerName(PaintedShape painted_shape); | 82 static std::string ToLayerName(PaintedShape painted_shape); |
| 83 | 83 |
| 84 // Type that contains a gfx::Tansform for each of the layers required by the | 84 // Type that contains a gfx::Tansform for each of the layers required by the |
| 85 // ink drop. | 85 // ink drop. |
| 86 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; | 86 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; |
| 87 | 87 |
| 88 float GetCurrentOpacity() const; | 88 float GetCurrentOpacity() const; |
| 89 | 89 |
| 90 // InkDropAnimation: | 90 // InkDropRipple: |
| 91 void AnimateStateChange(InkDropState old_ink_drop_state, | 91 void AnimateStateChange(InkDropState old_ink_drop_state, |
| 92 InkDropState new_ink_drop_state, | 92 InkDropState new_ink_drop_state, |
| 93 ui::LayerAnimationObserver* observer) override; | 93 ui::LayerAnimationObserver* observer) override; |
| 94 void SetStateToHidden() override; | 94 void SetStateToHidden() override; |
| 95 void AbortAllAnimations() override; | 95 void AbortAllAnimations() override; |
| 96 | 96 |
| 97 // Animates all of the painted shape layers to the specified |transforms|. The | 97 // Animates all of the painted shape layers to the specified |transforms|. The |
| 98 // animation will be configured with the given |duration|, |tween|, and | 98 // animation will be configured with the given |duration|, |tween|, and |
| 99 // |preemption_strategy| values. The |observer| will be added to all | 99 // |preemption_strategy| values. The |observer| will be added to all |
| 100 // LayerAnimationSequences if not null. | 100 // LayerAnimationSequences if not null. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 std::unique_ptr<RectangleLayerDelegate> rect_layer_delegate_; | 169 std::unique_ptr<RectangleLayerDelegate> rect_layer_delegate_; |
| 170 | 170 |
| 171 // The root layer that parents the animating layers. The root layer is used to | 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 | 172 // manipulate opacity and location, and its children are used to manipulate |
| 173 // the different painted shapes that compose the ink drop. | 173 // the different painted shapes that compose the ink drop. |
| 174 ui::Layer root_layer_; | 174 ui::Layer root_layer_; |
| 175 | 175 |
| 176 // ui::Layers for all of the painted shape layers that compose the ink drop. | 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]; | 177 std::unique_ptr<ui::Layer> painted_layers_[PAINTED_SHAPE_COUNT]; |
| 178 | 178 |
| 179 DISALLOW_COPY_AND_ASSIGN(SquareInkDropAnimation); | 179 DISALLOW_COPY_AND_ASSIGN(SquareInkDropRipple); |
| 180 }; | 180 }; |
| 181 | 181 |
| 182 } // namespace views | 182 } // namespace views |
| 183 | 183 |
| 184 #endif // UI_VIEWS_ANIMATION_SQUARE_INK_DROP_ANIMATION_H_ | 184 #endif // UI_VIEWS_ANIMATION_SQUARE_INK_DROP_RIPPLE_H_ |
| OLD | NEW |