| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_ANIMATION_H_ | 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_APP_MENU_ANIMATION_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_ANIMATION_H_ | 6 #define CHROME_BROWSER_UI_TOOLBAR_APP_MENU_ANIMATION_H_ |
| 7 | 7 |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
| 10 #include "ui/gfx/animation/animation_delegate.h" | 10 #include "ui/gfx/animation/animation_delegate.h" |
| 11 #include "ui/gfx/animation/slide_animation.h" | 11 #include "ui/gfx/animation/slide_animation.h" |
| 12 | 12 |
| 13 namespace gfx { | 13 namespace gfx { |
| 14 class Canvas; | 14 class Canvas; |
| 15 class PointF; | 15 class PointF; |
| 16 class SizeF; |
| 16 } // namespace gfx | 17 } // namespace gfx |
| 17 | 18 |
| 18 class AppMenuButton; | 19 class AppMenuAnimationDelegate { |
| 20 public: |
| 21 virtual void PaintDot(const gfx::PointF point, |
| 22 SkColor color, |
| 23 gfx::SizeF size, |
| 24 gfx::Canvas* canvas) = 0; |
| 25 |
| 26 virtual void AppMenuAnimationStarted() = 0; |
| 27 virtual void AppMenuAnimationEnded() = 0; |
| 28 virtual void InvalidateIcon() = 0; |
| 29 }; |
| 19 | 30 |
| 20 // This class is used for animating and drawing the app menu icon. | 31 // This class is used for animating and drawing the app menu icon. |
| 21 class AppMenuAnimation : public gfx::AnimationDelegate { | 32 class AppMenuAnimation : public gfx::AnimationDelegate { |
| 22 public: | 33 public: |
| 23 AppMenuAnimation(AppMenuButton* owner, SkColor initial_color); | 34 AppMenuAnimation(AppMenuAnimationDelegate* owner, SkColor initial_color); |
| 24 | 35 |
| 25 ~AppMenuAnimation() override; | 36 ~AppMenuAnimation() override; |
| 26 | 37 |
| 27 // Paints the app menu icon. | 38 // Paints the app menu icon. |
| 28 void PaintAppMenu(gfx::Canvas* canvas, const gfx::Rect& bounds); | 39 void PaintAppMenu(gfx::Canvas* canvas, const gfx::Rect& bounds); |
| 29 | 40 |
| 30 void set_target_color(SkColor target_color) { target_color_ = target_color; } | |
| 31 | |
| 32 // Starts the animation if it's not already running. | 41 // Starts the animation if it's not already running. |
| 33 void StartAnimation(); | 42 void StartAnimation(); |
| 34 | 43 |
| 35 // gfx::AnimationDelegate: | 44 // gfx::AnimationDelegate: |
| 36 void AnimationEnded(const gfx::Animation* animation) override; | 45 void AnimationEnded(const gfx::Animation* animation) override; |
| 37 void AnimationProgressed(const gfx::Animation* animation) override; | 46 void AnimationProgressed(const gfx::Animation* animation) override; |
| 38 | 47 |
| 48 void set_target_color(SkColor target_color) { target_color_ = target_color; } |
| 49 |
| 39 private: | 50 private: |
| 40 // This class is used to represent and paint a dot on the app menu. | 51 // This class is used to represent and paint a dot on the app menu. |
| 41 class AppMenuDot { | 52 class AppMenuDot { |
| 42 public: | 53 public: |
| 43 AppMenuDot(base::TimeDelta delay, | 54 AppMenuDot(base::TimeDelta delay, |
| 44 float width_open_interval, | 55 float width_open_interval, |
| 45 float stroke_open_interval); | 56 float stroke_open_interval); |
| 46 | 57 |
| 47 // Paints the dot on the given |canvas| according to the progress of | 58 // Paints the dot on the given |canvas| according to the progress of |
| 48 // |animation|. The size of the dot is calculated to fit in |bounds|. | 59 // |animation|. The size of the dot is calculated to fit in |bounds|. |
| 49 // |center_point| is the dot's position on the canvas. The dot's color is | 60 // |center_point| is the dot's position on the canvas. The dot's color is |
| 50 // a transition from |start_color| to |final_color|. | 61 // a transition from |start_color| to |final_color|. |
| 51 void Paint(const gfx::PointF& center_point, | 62 void Paint(const gfx::PointF& center_point, |
| 52 SkColor start_color, | 63 SkColor start_color, |
| 53 SkColor final_color, | 64 SkColor final_color, |
| 54 gfx::Canvas* canvas, | 65 gfx::Canvas* canvas, |
| 55 const gfx::Rect& bounds, | 66 const gfx::Rect& bounds, |
| 56 const gfx::SlideAnimation* animation); | 67 const gfx::SlideAnimation* animation, |
| 68 AppMenuAnimationDelegate* delegate); |
| 57 | 69 |
| 58 private: | 70 private: |
| 59 // The delay before the dot starts animating in ms. | 71 // The delay before the dot starts animating in ms. |
| 60 const base::TimeDelta delay_; | 72 const base::TimeDelta delay_; |
| 61 | 73 |
| 62 // The percentage of the overall animation duration it takes to animate the | 74 // The percentage of the overall animation duration it takes to animate the |
| 63 // width and stroke to their open state. | 75 // width and stroke to their open state. |
| 64 const float width_open_interval_; | 76 const float width_open_interval_; |
| 65 const float stroke_open_interval_; | 77 const float stroke_open_interval_; |
| 66 | 78 |
| 67 DISALLOW_COPY_AND_ASSIGN(AppMenuDot); | 79 DISALLOW_COPY_AND_ASSIGN(AppMenuDot); |
| 68 }; | 80 }; |
| 69 | 81 |
| 70 AppMenuButton* const owner_; | 82 AppMenuAnimationDelegate* const delegate_; |
| 71 | 83 |
| 72 std::unique_ptr<gfx::SlideAnimation> animation_; | 84 std::unique_ptr<gfx::SlideAnimation> animation_; |
| 73 | 85 |
| 74 AppMenuDot bottom_dot_; | 86 AppMenuDot bottom_dot_; |
| 75 AppMenuDot middle_dot_; | 87 AppMenuDot middle_dot_; |
| 76 AppMenuDot top_dot_; | 88 AppMenuDot top_dot_; |
| 77 | 89 |
| 78 // The starting color of the dots. The animation is expected to transition | 90 // The starting color of the dots. The animation is expected to transition |
| 79 // from this color to |target_color_|. | 91 // from this color to |target_color_|. |
| 80 SkColor start_color_; | 92 SkColor start_color_; |
| 81 | 93 |
| 82 // The severity color of the dots. This is final color at the end of the | 94 // The severity color of the dots. This is final color at the end of the |
| 83 // animation. | 95 // animation. |
| 84 SkColor target_color_; | 96 SkColor target_color_; |
| 85 | 97 |
| 86 DISALLOW_COPY_AND_ASSIGN(AppMenuAnimation); | 98 DISALLOW_COPY_AND_ASSIGN(AppMenuAnimation); |
| 87 }; | 99 }; |
| 88 | 100 |
| 89 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_ANIMATION_H_ | 101 #endif // CHROME_BROWSER_UI_TOOLBAR_APP_MENU_ANIMATION_H_ |
| OLD | NEW |