Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: chrome/browser/ui/toolbar/app_menu_animation.h

Issue 2858313002: Refactored AppMenuAnimation (Closed)
Patch Set: Add comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Delegate class for AppMenuAnimation. The delegate is expected to
20 // draw the dots and handle animation events.
21 class AppMenuAnimationDelegate {
msw 2017/05/05 18:47:38 It'd be nice if we could use Skia on Cocoa too and
spqchan 2017/05/05 21:20:53 Thanks for pointing that out! I had no idea that w
22 public:
23 // Paints a dot according to the given parameters. |canvas| is null
msw 2017/05/05 18:47:38 nit: specify the coordinates for |point|? (screen
spqchan 2017/05/05 21:20:53 The function is gone
24 // on the Mac platform.
25 virtual void PaintDot(const gfx::PointF point,
msw 2017/05/05 18:47:38 nit: pass a rect instead of a point and a size?
spqchan 2017/05/05 21:20:53 gone
26 SkColor color,
27 gfx::SizeF size,
msw 2017/05/05 18:47:38 nit: pass a const ref here (and for the point, or
spqchan 2017/05/05 21:20:53 gone
28 gfx::Canvas* canvas) = 0;
29
30 // Called when the animation has started/ended.
31 virtual void AppMenuAnimationStarted() = 0;
32 virtual void AppMenuAnimationEnded() = 0;
33
34 // Schedules a redraw of the icon.
35 virtual void InvalidateIcon() = 0;
36 };
19 37
20 // This class is used for animating and drawing the app menu icon. 38 // This class is used for animating and drawing the app menu icon.
21 class AppMenuAnimation : public gfx::AnimationDelegate { 39 class AppMenuAnimation : public gfx::AnimationDelegate {
22 public: 40 public:
23 AppMenuAnimation(AppMenuButton* owner, SkColor initial_color); 41 AppMenuAnimation(AppMenuAnimationDelegate* owner, SkColor initial_color);
24 42
25 ~AppMenuAnimation() override; 43 ~AppMenuAnimation() override;
26 44
27 // Paints the app menu icon. 45 // Paints the app menu icon.
28 void PaintAppMenu(gfx::Canvas* canvas, const gfx::Rect& bounds); 46 void PaintAppMenu(gfx::Canvas* canvas, const gfx::Rect& bounds);
29 47
30 void set_target_color(SkColor target_color) { target_color_ = target_color; }
31
32 // Starts the animation if it's not already running. 48 // Starts the animation if it's not already running.
33 void StartAnimation(); 49 void StartAnimation();
34 50
35 // gfx::AnimationDelegate: 51 // gfx::AnimationDelegate:
36 void AnimationEnded(const gfx::Animation* animation) override; 52 void AnimationEnded(const gfx::Animation* animation) override;
37 void AnimationProgressed(const gfx::Animation* animation) override; 53 void AnimationProgressed(const gfx::Animation* animation) override;
38 54
55 void set_target_color(SkColor target_color) { target_color_ = target_color; }
56
39 private: 57 private:
40 // This class is used to represent and paint a dot on the app menu. 58 // This class is used to represent and paint a dot on the app menu.
41 class AppMenuDot { 59 class AppMenuDot {
42 public: 60 public:
43 AppMenuDot(base::TimeDelta delay, 61 AppMenuDot(base::TimeDelta delay,
44 float width_open_interval, 62 float width_open_interval,
45 float stroke_open_interval); 63 float stroke_open_interval);
46 64
47 // Paints the dot on the given |canvas| according to the progress of 65 // 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|. 66 // |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 67 // |center_point| is the dot's position on the canvas. The dot's color is
50 // a transition from |start_color| to |final_color|. 68 // a transition from |start_color| to |final_color|.
51 void Paint(const gfx::PointF& center_point, 69 void Paint(const gfx::PointF& center_point,
52 SkColor start_color, 70 SkColor start_color,
53 SkColor final_color, 71 SkColor final_color,
54 gfx::Canvas* canvas, 72 gfx::Canvas* canvas,
55 const gfx::Rect& bounds, 73 const gfx::Rect& bounds,
56 const gfx::SlideAnimation* animation); 74 const gfx::SlideAnimation* animation,
75 AppMenuAnimationDelegate* delegate);
57 76
58 private: 77 private:
59 // The delay before the dot starts animating in ms. 78 // The delay before the dot starts animating in ms.
60 const base::TimeDelta delay_; 79 const base::TimeDelta delay_;
61 80
62 // The percentage of the overall animation duration it takes to animate the 81 // The percentage of the overall animation duration it takes to animate the
63 // width and stroke to their open state. 82 // width and stroke to their open state.
64 const float width_open_interval_; 83 const float width_open_interval_;
65 const float stroke_open_interval_; 84 const float stroke_open_interval_;
66 85
67 DISALLOW_COPY_AND_ASSIGN(AppMenuDot); 86 DISALLOW_COPY_AND_ASSIGN(AppMenuDot);
68 }; 87 };
69 88
70 AppMenuButton* const owner_; 89 AppMenuAnimationDelegate* const delegate_;
71 90
72 std::unique_ptr<gfx::SlideAnimation> animation_; 91 std::unique_ptr<gfx::SlideAnimation> animation_;
73 92
74 AppMenuDot bottom_dot_; 93 AppMenuDot bottom_dot_;
75 AppMenuDot middle_dot_; 94 AppMenuDot middle_dot_;
76 AppMenuDot top_dot_; 95 AppMenuDot top_dot_;
77 96
78 // The starting color of the dots. The animation is expected to transition 97 // The starting color of the dots. The animation is expected to transition
79 // from this color to |target_color_|. 98 // from this color to |target_color_|.
80 SkColor start_color_; 99 SkColor start_color_;
81 100
82 // The severity color of the dots. This is final color at the end of the 101 // The severity color of the dots. This is final color at the end of the
83 // animation. 102 // animation.
84 SkColor target_color_; 103 SkColor target_color_;
85 104
86 DISALLOW_COPY_AND_ASSIGN(AppMenuAnimation); 105 DISALLOW_COPY_AND_ASSIGN(AppMenuAnimation);
87 }; 106 };
88 107
89 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_ANIMATION_H_ 108 #endif // CHROME_BROWSER_UI_TOOLBAR_APP_MENU_ANIMATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698