Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/views/controls/animated_icon_view.h" | |
| 6 | |
| 7 #include "ui/compositor/compositor.h" | |
| 8 #include "ui/gfx/canvas.h" | |
| 9 #include "ui/gfx/color_palette.h" | |
| 10 #include "ui/gfx/paint_vector_icon.h" | |
| 11 #include "ui/views/widget/widget.h" | |
| 12 | |
| 13 namespace views { | |
| 14 | |
| 15 AnimatedIconView::AnimatedIconView(const gfx::VectorIcon& icon) | |
| 16 : icon_(icon), | |
| 17 color_(gfx::kPlaceholderColor), | |
| 18 duration_(gfx::GetDurationOfAnimation(icon)) { | |
| 19 set_can_process_events_within_subtree(false); | |
|
sadrul
2017/05/23 18:01:14
Why? Shouldn't this be something the creator of An
Evan Stade
2017/05/23 23:38:42
I don't think there will be any instances of this
sadrul
2017/05/24 17:35:14
When you create a View, the default expectation sh
Evan Stade
2017/05/24 17:47:53
ok, I will move this to AppMenuButton.
| |
| 20 UpdateStaticImage(); | |
| 21 } | |
| 22 | |
| 23 AnimatedIconView::~AnimatedIconView() {} | |
| 24 | |
| 25 void AnimatedIconView::Animate(State target) { | |
| 26 SetState(target); | |
| 27 start_time_ = base::TimeTicks::Now(); | |
| 28 if (!IsAnimating()) | |
| 29 GetWidget()->GetCompositor()->AddAnimationObserver(this); | |
| 30 } | |
| 31 | |
| 32 void AnimatedIconView::SetState(State state) { | |
| 33 state_ = state; | |
| 34 UpdateStaticImage(); | |
| 35 } | |
| 36 | |
| 37 void AnimatedIconView::OnPaint(gfx::Canvas* canvas) { | |
| 38 if (!IsAnimating()) { | |
| 39 views::ImageView::OnPaint(canvas); | |
|
sadrul
2017/05/23 18:01:14
How does this work when the animation ends? (i.e.
Evan Stade
2017/05/23 23:38:42
Animate() calls SetState() calls UpdateStaticImage
sadrul
2017/05/24 17:35:14
Who is calling Animate(END)? Shouldn't that happen
Evan Stade
2017/05/24 17:47:53
The client is calling it. In this case, AppMenuBut
sadrul
2017/05/26 19:44:47
The client having to track when the animation ends
Evan Stade
2017/05/26 20:48:52
The client doesn't have to do anything when the an
sadrul
2017/05/30 17:06:51
I see. So I guess I don't quite understand how OnP
Evan Stade
2017/05/30 18:53:45
You would have called Animate(END), not Animate(ST
sadrul
2017/05/30 19:48:33
Aah, yes. That makes sense now. Thanks for explain
| |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 auto timestamp = base::TimeTicks::Now(); | |
| 44 base::TimeDelta elapsed = timestamp - start_time_; | |
| 45 if (state_ == END) | |
| 46 elapsed = start_time_ + duration_ - timestamp; | |
| 47 | |
| 48 gfx::Rect target_bounds = GetContentsBounds(); | |
| 49 target_bounds.ClampToCenteredSize(GetImage().size()); | |
|
sadrul
2017/05/23 18:01:14
Can this use GetImageBounds()?
Evan Stade
2017/05/23 23:38:42
seems so, thanks!
| |
| 50 canvas->Translate(gfx::Vector2d(target_bounds.OffsetFromOrigin())); | |
|
sadrul
2017/05/23 18:01:14
OffsetFromOrigin() already returns a Vector2d, rig
Evan Stade
2017/05/23 23:38:42
Done.
| |
| 51 gfx::PaintVectorIcon(canvas, icon_, color_, elapsed); | |
| 52 } | |
| 53 | |
| 54 void AnimatedIconView::OnAnimationStep(base::TimeTicks timestamp) { | |
| 55 base::TimeDelta elapsed = timestamp - start_time_; | |
| 56 if (elapsed > duration_) | |
| 57 GetWidget()->GetCompositor()->RemoveAnimationObserver(this); | |
| 58 | |
| 59 SchedulePaint(); | |
| 60 } | |
| 61 | |
| 62 void AnimatedIconView::OnCompositingShuttingDown(ui::Compositor* compositor) {} | |
| 63 | |
| 64 bool AnimatedIconView::IsAnimating() { | |
| 65 return GetWidget()->GetCompositor()->HasAnimationObserver(this); | |
|
sadrul
2017/05/23 18:01:14
Can we maintain a flag instead?
Evan Stade
2017/05/23 23:38:42
how's this?
| |
| 66 } | |
| 67 | |
| 68 void AnimatedIconView::UpdateStaticImage() { | |
| 69 gfx::IconDescription description( | |
| 70 icon_, 0, color_, state_ == START ? base::TimeDelta() : duration_, | |
| 71 gfx::kNoneIcon); | |
| 72 SetImage(gfx::CreateVectorIcon(description)); | |
| 73 } | |
| 74 | |
| 75 } // namespace views | |
| OLD | NEW |