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

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

Issue 2858313002: Refactored AppMenuAnimation (Closed)
Patch Set: Fix for msw 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 #include "chrome/browser/ui/views/toolbar/app_menu_animation.h" 5 #include "chrome/browser/ui/toolbar/app_menu_animation.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "cc/paint/paint_flags.h" 8 #include "cc/paint/paint_flags.h"
9 #include "chrome/browser/ui/views/toolbar/app_menu_button.h"
10 #include "ui/gfx/animation/tween.h" 9 #include "ui/gfx/animation/tween.h"
11 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/color_palette.h" 11 #include "ui/gfx/color_palette.h"
13 #include "ui/gfx/color_utils.h" 12 #include "ui/gfx/color_utils.h"
14 #include "ui/gfx/skia_util.h" 13 #include "ui/gfx/skia_util.h"
15 14
16 namespace { 15 namespace {
17 16
18 // Duration of the open and close animations in ms. 17 // Duration of the open and close animations in ms.
19 constexpr float kOpenDurationMs = 733.0f; 18 constexpr float kOpenDurationMs = 733.0f;
20 constexpr float kCloseDurationMs = 283.0f; 19 constexpr float kCloseDurationMs = 283.0f;
21 20
22 // Duration of the color animation in ms. 21 // Duration of the color animation in ms.
23 constexpr float kColorDurationMs = 100.0f; 22 constexpr float kColorDurationMs = 100.0f;
24 23
24 // The radius of each dot in the icon.
25 constexpr float kDotRadius = 2.0f;
26
25 // The % the top and bottom dots need to be offset from the middle. 27 // The % the top and bottom dots need to be offset from the middle.
26 constexpr float kDotYOffset = 0.32f; 28 constexpr float kDotYOffset = 0.32f;
27 29
28 // Value of the stroke when the icon is opened or closed. 30 // Value of the stroke when the icon is opened or closed.
29 constexpr float kCloseStroke = 0.204f; 31 constexpr float kCloseStroke = 0.204f;
30 constexpr float kOpenStroke = 0.136f; 32 constexpr float kOpenStroke = 0.136f;
31 33
32 // Value of the width when the animation is fully opened. 34 // Value of the width when the animation is fully opened.
33 constexpr float kOpenWidth = 0.52f; 35 constexpr float kOpenWidth = 0.52f;
34 36
(...skipping 21 matching lines...) Expand all
56 float stroke_open_interval) 58 float stroke_open_interval)
57 : delay_(delay), 59 : delay_(delay),
58 width_open_interval_(width_open_interval), 60 width_open_interval_(width_open_interval),
59 stroke_open_interval_(stroke_open_interval) {} 61 stroke_open_interval_(stroke_open_interval) {}
60 62
61 void AppMenuAnimation::AppMenuDot::Paint(const gfx::PointF& center_point, 63 void AppMenuAnimation::AppMenuDot::Paint(const gfx::PointF& center_point,
62 SkColor start_color, 64 SkColor start_color,
63 SkColor target_color, 65 SkColor target_color,
64 gfx::Canvas* canvas, 66 gfx::Canvas* canvas,
65 const gfx::Rect& bounds, 67 const gfx::Rect& bounds,
66 const gfx::SlideAnimation* animation) { 68 const gfx::SlideAnimation* animation,
69 AppMenuAnimationDelegate* delegate) {
67 bool is_opening = animation->IsShowing(); 70 bool is_opening = animation->IsShowing();
68 float total_duration = is_opening ? kOpenDurationMs : kCloseDurationMs; 71 float total_duration = is_opening ? kOpenDurationMs : kCloseDurationMs;
69 float width_duration = 72 float width_duration =
70 is_opening ? width_open_interval_ : kWidthStrokeCloseInterval; 73 is_opening ? width_open_interval_ : kWidthStrokeCloseInterval;
71 float stroke_duration = 74 float stroke_duration =
72 is_opening ? stroke_open_interval_ : kWidthStrokeCloseInterval; 75 is_opening ? stroke_open_interval_ : kWidthStrokeCloseInterval;
73 76
74 // When the animation is closing, each dot uses the remainder of the full 77 // When the animation is closing, each dot uses the remainder of the full
75 // delay period (2 * kDotDelayMs). The results should be (0->2x, 1x->1x, 78 // delay period (2 * kDotDelayMs). The results should be (0->2x, 1x->1x,
76 // 2x->0). 79 // 2x->0).
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 111
109 gfx::PointF point = center_point; 112 gfx::PointF point = center_point;
110 point.Offset(-dot_width / 2, -dot_height / 2); 113 point.Offset(-dot_width / 2, -dot_height / 2);
111 114
112 SkColor color = is_opening ? gfx::Tween::ColorValueBetween( 115 SkColor color = is_opening ? gfx::Tween::ColorValueBetween(
113 color_progress, start_color, target_color) 116 color_progress, start_color, target_color)
114 : target_color; 117 : target_color;
115 118
116 cc::PaintFlags flags; 119 cc::PaintFlags flags;
117 flags.setColor(color); 120 flags.setColor(color);
118 flags.setStrokeWidth(bounds.height() * kCloseStroke); 121 flags.setStrokeWidth(dot_height);
119 flags.setStrokeCap(cc::PaintFlags::kRound_Cap); 122 flags.setStrokeCap(cc::PaintFlags::kRound_Cap);
120 flags.setStyle(cc::PaintFlags::kFill_Style); 123 flags.setStyle(cc::PaintFlags::kFill_Style);
121 flags.setAntiAlias(true); 124 flags.setAntiAlias(true);
122 125 canvas->DrawRoundRect(gfx::RectF(point, gfx::SizeF(dot_width, dot_height)),
123 gfx::SizeF dot_size = gfx::SizeF(dot_width, dot_height); 126 kDotRadius, flags);
124 canvas->DrawRoundRect(gfx::RectF(point, dot_size), 2.0, flags);
125 } 127 }
126 128
127 AppMenuAnimation::AppMenuAnimation(AppMenuButton* owner, SkColor initial_color) 129 AppMenuAnimation::AppMenuAnimation(AppMenuAnimationDelegate* delegate,
128 : owner_(owner), 130 SkColor initial_color)
131 : delegate_(delegate),
129 animation_(base::MakeUnique<gfx::SlideAnimation>(this)), 132 animation_(base::MakeUnique<gfx::SlideAnimation>(this)),
130 bottom_dot_(base::TimeDelta(), 133 bottom_dot_(base::TimeDelta(),
131 kBottomWidthOpenInterval, 134 kBottomWidthOpenInterval,
132 kBottomStrokeOpenInterval), 135 kBottomStrokeOpenInterval),
133 middle_dot_(base::TimeDelta::FromMilliseconds(kDotDelayMs), 136 middle_dot_(base::TimeDelta::FromMilliseconds(kDotDelayMs),
134 kMiddleWidthOpenInterval, 137 kMiddleWidthOpenInterval,
135 kMiddleStrokeOpenInterval), 138 kMiddleStrokeOpenInterval),
136 top_dot_(base::TimeDelta::FromMilliseconds(kDotDelayMs * 2), 139 top_dot_(base::TimeDelta::FromMilliseconds(kDotDelayMs * 2),
137 kTopWidthOpenInterval, 140 kTopWidthOpenInterval,
138 kTopStrokeOpenInterval), 141 kTopStrokeOpenInterval),
139 start_color_(initial_color), 142 start_color_(initial_color),
140 target_color_(initial_color) { 143 target_color_(initial_color) {
141 animation_->SetSlideDuration(kOpenDurationMs); 144 animation_->SetSlideDuration(kOpenDurationMs);
142 animation_->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN); 145 animation_->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN);
143 } 146 }
144 147
145 AppMenuAnimation::~AppMenuAnimation() {} 148 AppMenuAnimation::~AppMenuAnimation() {}
146 149
147 void AppMenuAnimation::PaintAppMenu(gfx::Canvas* canvas, 150 void AppMenuAnimation::PaintAppMenu(gfx::Canvas* canvas,
148 const gfx::Rect& bounds) { 151 const gfx::Rect& bounds) {
149 gfx::PointF middle_point = gfx::PointF(bounds.CenterPoint()); 152 gfx::PointF middle_point = gfx::PointF(bounds.CenterPoint());
150 float y_offset = kDotYOffset * bounds.height(); 153 float y_offset = kDotYOffset * bounds.height();
151 gfx::PointF top_point = middle_point; 154 gfx::PointF top_point = middle_point;
152 top_point.Offset(0, -y_offset); 155 top_point.Offset(0, -y_offset);
153 156
154 gfx::PointF bottom_point = middle_point; 157 gfx::PointF bottom_point = middle_point;
155 bottom_point.Offset(0, y_offset); 158 bottom_point.Offset(0, y_offset);
156 159
157 middle_dot_.Paint(middle_point, start_color_, target_color_, canvas, bounds, 160 middle_dot_.Paint(middle_point, start_color_, target_color_, canvas, bounds,
158 animation_.get()); 161 animation_.get(), delegate_);
159 top_dot_.Paint(top_point, start_color_, target_color_, canvas, bounds, 162 top_dot_.Paint(top_point, start_color_, target_color_, canvas, bounds,
160 animation_.get()); 163 animation_.get(), delegate_);
161 bottom_dot_.Paint(bottom_point, start_color_, target_color_, canvas, bounds, 164 bottom_dot_.Paint(bottom_point, start_color_, target_color_, canvas, bounds,
162 animation_.get()); 165 animation_.get(), delegate_);
163 } 166 }
164 167
165 void AppMenuAnimation::StartAnimation() { 168 void AppMenuAnimation::StartAnimation() {
166 if (!animation_->is_animating()) { 169 if (!animation_->is_animating()) {
167 animation_->SetSlideDuration(kOpenDurationMs); 170 animation_->SetSlideDuration(kOpenDurationMs);
168 animation_->Show(); 171 animation_->Show();
169 owner_->AppMenuAnimationStarted(); 172 delegate_->AppMenuAnimationStarted();
170 } 173 }
171 } 174 }
172 175
173 void AppMenuAnimation::AnimationEnded(const gfx::Animation* animation) { 176 void AppMenuAnimation::AnimationEnded(const gfx::Animation* animation) {
174 if (animation_->IsShowing()) { 177 if (animation_->IsShowing()) {
175 animation_->SetSlideDuration(kCloseDurationMs); 178 animation_->SetSlideDuration(kCloseDurationMs);
176 animation_->Hide(); 179 animation_->Hide();
177 } else { 180 } else {
178 start_color_ = target_color_; 181 start_color_ = target_color_;
179 } 182 }
180 183
181 owner_->AppMenuAnimationEnded(); 184 delegate_->AppMenuAnimationEnded();
182 } 185 }
183 186
184 void AppMenuAnimation::AnimationProgressed(const gfx::Animation* animation) { 187 void AppMenuAnimation::AnimationProgressed(const gfx::Animation* animation) {
185 owner_->SchedulePaint(); 188 delegate_->InvalidateIcon();
186 } 189 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/app_menu_animation.h ('k') | chrome/browser/ui/views/toolbar/app_menu_animation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698