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