Chromium Code Reviews| 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 #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; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 float stroke_open_interval) | 55 float stroke_open_interval) |
| 57 : delay_(delay), | 56 : delay_(delay), |
| 58 width_open_interval_(width_open_interval), | 57 width_open_interval_(width_open_interval), |
| 59 stroke_open_interval_(stroke_open_interval) {} | 58 stroke_open_interval_(stroke_open_interval) {} |
| 60 | 59 |
| 61 void AppMenuAnimation::AppMenuDot::Paint(const gfx::PointF& center_point, | 60 void AppMenuAnimation::AppMenuDot::Paint(const gfx::PointF& center_point, |
| 62 SkColor start_color, | 61 SkColor start_color, |
| 63 SkColor target_color, | 62 SkColor target_color, |
| 64 gfx::Canvas* canvas, | 63 gfx::Canvas* canvas, |
| 65 const gfx::Rect& bounds, | 64 const gfx::Rect& bounds, |
| 66 const gfx::SlideAnimation* animation) { | 65 const gfx::SlideAnimation* animation, |
| 66 AppMenuAnimationDelegate* delegate) { | |
| 67 bool is_opening = animation->IsShowing(); | 67 bool is_opening = animation->IsShowing(); |
| 68 float total_duration = is_opening ? kOpenDurationMs : kCloseDurationMs; | 68 float total_duration = is_opening ? kOpenDurationMs : kCloseDurationMs; |
| 69 float width_duration = | 69 float width_duration = |
| 70 is_opening ? width_open_interval_ : kWidthStrokeCloseInterval; | 70 is_opening ? width_open_interval_ : kWidthStrokeCloseInterval; |
| 71 float stroke_duration = | 71 float stroke_duration = |
| 72 is_opening ? stroke_open_interval_ : kWidthStrokeCloseInterval; | 72 is_opening ? stroke_open_interval_ : kWidthStrokeCloseInterval; |
| 73 | 73 |
| 74 // When the animation is closing, each dot uses the remainder of the full | 74 // 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, | 75 // delay period (2 * kDotDelayMs). The results should be (0->2x, 1x->1x, |
| 76 // 2x->0). | 76 // 2x->0). |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 106 gfx::Tween::FloatValueBetween(width_progress, kCloseStroke, kOpenWidth); | 106 gfx::Tween::FloatValueBetween(width_progress, kCloseStroke, kOpenWidth); |
| 107 dot_width *= bounds.width(); | 107 dot_width *= bounds.width(); |
| 108 | 108 |
| 109 gfx::PointF point = center_point; | 109 gfx::PointF point = center_point; |
| 110 point.Offset(-dot_width / 2, -dot_height / 2); | 110 point.Offset(-dot_width / 2, -dot_height / 2); |
| 111 | 111 |
| 112 SkColor color = is_opening ? gfx::Tween::ColorValueBetween( | 112 SkColor color = is_opening ? gfx::Tween::ColorValueBetween( |
| 113 color_progress, start_color, target_color) | 113 color_progress, start_color, target_color) |
| 114 : target_color; | 114 : target_color; |
| 115 | 115 |
| 116 cc::PaintFlags flags; | 116 delegate->PaintDot(point, color, gfx::SizeF(dot_width, dot_height), canvas); |
|
msw
2017/05/05 18:47:38
Would #if defined(OS_MACOSX) && !BUILDFLAG(MAC_VIE
spqchan
2017/05/05 21:20:53
Removed the delegate method
| |
| 117 flags.setColor(color); | |
| 118 flags.setStrokeWidth(bounds.height() * kCloseStroke); | |
| 119 flags.setStrokeCap(cc::PaintFlags::kRound_Cap); | |
| 120 flags.setStyle(cc::PaintFlags::kFill_Style); | |
| 121 flags.setAntiAlias(true); | |
| 122 | |
| 123 gfx::SizeF dot_size = gfx::SizeF(dot_width, dot_height); | |
| 124 canvas->DrawRoundRect(gfx::RectF(point, dot_size), 2.0, flags); | |
| 125 } | 117 } |
| 126 | 118 |
| 127 AppMenuAnimation::AppMenuAnimation(AppMenuButton* owner, SkColor initial_color) | 119 AppMenuAnimation::AppMenuAnimation(AppMenuAnimationDelegate* delegate, |
| 128 : owner_(owner), | 120 SkColor initial_color) |
| 121 : delegate_(delegate), | |
| 129 animation_(base::MakeUnique<gfx::SlideAnimation>(this)), | 122 animation_(base::MakeUnique<gfx::SlideAnimation>(this)), |
| 130 bottom_dot_(base::TimeDelta(), | 123 bottom_dot_(base::TimeDelta(), |
| 131 kBottomWidthOpenInterval, | 124 kBottomWidthOpenInterval, |
| 132 kBottomStrokeOpenInterval), | 125 kBottomStrokeOpenInterval), |
| 133 middle_dot_(base::TimeDelta::FromMilliseconds(kDotDelayMs), | 126 middle_dot_(base::TimeDelta::FromMilliseconds(kDotDelayMs), |
| 134 kMiddleWidthOpenInterval, | 127 kMiddleWidthOpenInterval, |
| 135 kMiddleStrokeOpenInterval), | 128 kMiddleStrokeOpenInterval), |
| 136 top_dot_(base::TimeDelta::FromMilliseconds(kDotDelayMs * 2), | 129 top_dot_(base::TimeDelta::FromMilliseconds(kDotDelayMs * 2), |
| 137 kTopWidthOpenInterval, | 130 kTopWidthOpenInterval, |
| 138 kTopStrokeOpenInterval), | 131 kTopStrokeOpenInterval), |
| 139 start_color_(initial_color), | 132 start_color_(initial_color), |
| 140 target_color_(initial_color) { | 133 target_color_(initial_color) { |
| 141 animation_->SetSlideDuration(kOpenDurationMs); | 134 animation_->SetSlideDuration(kOpenDurationMs); |
| 142 animation_->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN); | 135 animation_->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN); |
| 143 } | 136 } |
| 144 | 137 |
| 145 AppMenuAnimation::~AppMenuAnimation() {} | 138 AppMenuAnimation::~AppMenuAnimation() {} |
| 146 | 139 |
| 147 void AppMenuAnimation::PaintAppMenu(gfx::Canvas* canvas, | 140 void AppMenuAnimation::PaintAppMenu(gfx::Canvas* canvas, |
| 148 const gfx::Rect& bounds) { | 141 const gfx::Rect& bounds) { |
| 149 gfx::PointF middle_point = gfx::PointF(bounds.CenterPoint()); | 142 gfx::PointF middle_point = gfx::PointF(bounds.CenterPoint()); |
| 150 float y_offset = kDotYOffset * bounds.height(); | 143 float y_offset = kDotYOffset * bounds.height(); |
| 151 gfx::PointF top_point = middle_point; | 144 gfx::PointF top_point = middle_point; |
| 152 top_point.Offset(0, -y_offset); | 145 top_point.Offset(0, -y_offset); |
| 153 | 146 |
| 154 gfx::PointF bottom_point = middle_point; | 147 gfx::PointF bottom_point = middle_point; |
| 155 bottom_point.Offset(0, y_offset); | 148 bottom_point.Offset(0, y_offset); |
| 156 | 149 |
| 157 middle_dot_.Paint(middle_point, start_color_, target_color_, canvas, bounds, | 150 middle_dot_.Paint(middle_point, start_color_, target_color_, canvas, bounds, |
| 158 animation_.get()); | 151 animation_.get(), delegate_); |
| 159 top_dot_.Paint(top_point, start_color_, target_color_, canvas, bounds, | 152 top_dot_.Paint(top_point, start_color_, target_color_, canvas, bounds, |
| 160 animation_.get()); | 153 animation_.get(), delegate_); |
| 161 bottom_dot_.Paint(bottom_point, start_color_, target_color_, canvas, bounds, | 154 bottom_dot_.Paint(bottom_point, start_color_, target_color_, canvas, bounds, |
| 162 animation_.get()); | 155 animation_.get(), delegate_); |
| 163 } | 156 } |
| 164 | 157 |
| 165 void AppMenuAnimation::StartAnimation() { | 158 void AppMenuAnimation::StartAnimation() { |
| 166 if (!animation_->is_animating()) { | 159 if (!animation_->is_animating()) { |
| 167 animation_->SetSlideDuration(kOpenDurationMs); | 160 animation_->SetSlideDuration(kOpenDurationMs); |
| 168 animation_->Show(); | 161 animation_->Show(); |
| 169 owner_->AppMenuAnimationStarted(); | 162 delegate_->AppMenuAnimationStarted(); |
| 170 } | 163 } |
| 171 } | 164 } |
| 172 | 165 |
| 173 void AppMenuAnimation::AnimationEnded(const gfx::Animation* animation) { | 166 void AppMenuAnimation::AnimationEnded(const gfx::Animation* animation) { |
| 174 if (animation_->IsShowing()) { | 167 if (animation_->IsShowing()) { |
| 175 animation_->SetSlideDuration(kCloseDurationMs); | 168 animation_->SetSlideDuration(kCloseDurationMs); |
| 176 animation_->Hide(); | 169 animation_->Hide(); |
| 177 } else { | 170 } else { |
| 178 start_color_ = target_color_; | 171 start_color_ = target_color_; |
| 179 } | 172 } |
| 180 | 173 |
| 181 owner_->AppMenuAnimationEnded(); | 174 delegate_->AppMenuAnimationEnded(); |
| 182 } | 175 } |
| 183 | 176 |
| 184 void AppMenuAnimation::AnimationProgressed(const gfx::Animation* animation) { | 177 void AppMenuAnimation::AnimationProgressed(const gfx::Animation* animation) { |
| 185 owner_->SchedulePaint(); | 178 delegate_->InvalidateIcon(); |
| 186 } | 179 } |
| OLD | NEW |