flood_fill_ink_drop_ripple.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #ifndef UI_VIEWS_ANIMATION_FLOOD_FILL_INK_DROP_RIPPLE_H_
  5. #define UI_VIEWS_ANIMATION_FLOOD_FILL_INK_DROP_RIPPLE_H_
  6. #include "base/callback_list.h"
  7. #include "base/time/time.h"
  8. #include "third_party/skia/include/core/SkColor.h"
  9. #include "ui/compositor/layer.h"
  10. #include "ui/compositor/layer_animator.h"
  11. #include "ui/gfx/animation/tween.h"
  12. #include "ui/gfx/geometry/insets.h"
  13. #include "ui/gfx/geometry/point.h"
  14. #include "ui/gfx/geometry/size.h"
  15. #include "ui/gfx/geometry/transform.h"
  16. #include "ui/views/animation/ink_drop_painted_layer_delegates.h"
  17. #include "ui/views/animation/ink_drop_ripple.h"
  18. #include "ui/views/animation/ink_drop_state.h"
  19. #include "ui/views/views_export.h"
  20. namespace ui {
  21. class Layer;
  22. } // namespace ui
  23. namespace views {
  24. class CircleLayerDelegate;
  25. namespace test {
  26. class FloodFillInkDropRippleTestApi;
  27. } // namespace test
  28. // An ink drop ripple that starts as a small circle and flood fills a rectangle
  29. // of the size determined by |host_size| and |clip_insets| (if provided). The
  30. // circle is clipped to this rectangle's bounds.
  31. // Constructors take |host_size| and |clip_insets| and calculate the effective
  32. // bounds of the flood fill based on them. This way, the ripple's bounds are
  33. // defined relative to the host size and can be recalculated whenever the host
  34. // size is changed.
  35. //
  36. // The valid InkDropState transitions are defined below:
  37. //
  38. // {All InkDropStates} => HIDDEN
  39. // HIDDEN => ACTION_PENDING
  40. // HIDDEN, ACTION_PENDING => ACTION_TRIGGERED
  41. // ACTION_PENDING => ALTERNATE_ACTION_PENDING
  42. // ALTERNATE_ACTION_PENDING => ALTERNATE_ACTION_TRIGGERED
  43. // {All InkDropStates} => ACTIVATED
  44. // {All InkDropStates} => DEACTIVATED
  45. //
  46. class VIEWS_EXPORT FloodFillInkDropRipple : public InkDropRipple {
  47. public:
  48. FloodFillInkDropRipple(const gfx::Size& host_size,
  49. const gfx::Insets& clip_insets,
  50. const gfx::Point& center_point,
  51. SkColor color,
  52. float visible_opacity);
  53. FloodFillInkDropRipple(const gfx::Size& host_size,
  54. const gfx::Point& center_point,
  55. SkColor color,
  56. float visible_opacity);
  57. FloodFillInkDropRipple(const FloodFillInkDropRipple&) = delete;
  58. FloodFillInkDropRipple& operator=(const FloodFillInkDropRipple&) = delete;
  59. ~FloodFillInkDropRipple() override;
  60. // InkDropRipple:
  61. void SnapToActivated() override;
  62. ui::Layer* GetRootLayer() override;
  63. void set_use_hide_transform_duration_for_hide_fade_out(bool value) {
  64. use_hide_transform_duration_for_hide_fade_out_ = value;
  65. }
  66. void set_duration_factor(float duration_factor) {
  67. duration_factor_ = duration_factor;
  68. }
  69. private:
  70. friend class test::FloodFillInkDropRippleTestApi;
  71. // InkDropRipple:
  72. void AnimateStateChange(InkDropState old_ink_drop_state,
  73. InkDropState new_ink_drop_state) override;
  74. void SetStateToHidden() override;
  75. void AbortAllAnimations() override;
  76. // Sets the opacity of the ink drop. Note that this does not perform any
  77. // animation.
  78. void SetOpacity(float opacity);
  79. // Returns the Transform to be applied to the |painted_layer_| for the given
  80. // |target_radius|.
  81. gfx::Transform CalculateTransform(float target_radius) const;
  82. // Returns the target Transform for when the ink drop is fully shown.
  83. gfx::Transform GetMaxSizeTargetTransform() const;
  84. // Returns the largest distance from |point| to the corners of the
  85. // |root_layer_| bounds.
  86. float MaxDistanceToCorners(const gfx::Point& point) const;
  87. // Returns the InkDropState sub animation duration for the given |state|.
  88. base::TimeDelta GetAnimationDuration(int state);
  89. // Called from LayerAnimator when a new LayerAnimationSequence is scheduled
  90. // which allows for assigning the observer to the sequence.
  91. void OnLayerAnimationSequenceScheduled(ui::LayerAnimationSequence* sequence);
  92. // Insets of the clip area relative to the host bounds.
  93. gfx::Insets clip_insets_;
  94. // The point where the Center of the ink drop's circle should be drawn.
  95. gfx::Point center_point_;
  96. // Ink drop opacity when it is visible.
  97. float visible_opacity_;
  98. // Whether the fade out animation to hidden state should have the same
  99. // duration as the associated scale transform animation.
  100. bool use_hide_transform_duration_for_hide_fade_out_;
  101. // The factor used to scale down/up animation duration.
  102. float duration_factor_;
  103. // The root layer that parents the animating layer. The root layer is used to
  104. // manipulate opacity and clipping bounds, and it child is used to manipulate
  105. // the different shape of the ink drop.
  106. ui::Layer root_layer_;
  107. // Sequence scheduled callback subscription for the root layer.
  108. base::CallbackListSubscription root_callback_subscription_;
  109. // ui::LayerDelegate to paint the |painted_layer_|.
  110. CircleLayerDelegate circle_layer_delegate_;
  111. // Child ui::Layer of |root_layer_|. Used to manipulate the different size
  112. // and shape of the ink drop.
  113. ui::Layer painted_layer_;
  114. // Sequence scheduled callback subscriptions for the painted layer.
  115. base::CallbackListSubscription painted_layer_callback_subscription_;
  116. // The current ink drop state.
  117. InkDropState ink_drop_state_ = InkDropState::HIDDEN;
  118. };
  119. } // namespace views
  120. #endif // UI_VIEWS_ANIMATION_FLOOD_FILL_INK_DROP_RIPPLE_H_