| 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 #ifndef UI_VIEWS_CONTROLS_ANIMATED_ICON_VIEW_H_ |
| 6 #define UI_VIEWS_CONTROLS_ANIMATED_ICON_VIEW_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/time/time.h" |
| 10 #include "ui/compositor/compositor_animation_observer.h" |
| 11 #include "ui/gfx/vector_icon_types.h" |
| 12 #include "ui/views/controls/image_view.h" |
| 13 |
| 14 namespace views { |
| 15 |
| 16 // This class hosts a vector icon that defines transitions. It can be in the |
| 17 // start steady state, the end steady state, or transitioning in between. |
| 18 class VIEWS_EXPORT AnimatedIconView : public views::ImageView, |
| 19 public ui::CompositorAnimationObserver { |
| 20 public: |
| 21 enum State { |
| 22 START, |
| 23 END, |
| 24 }; |
| 25 |
| 26 explicit AnimatedIconView(const gfx::VectorIcon& icon); |
| 27 ~AnimatedIconView() override; |
| 28 |
| 29 void set_color(SkColor color) { color_ = color; } |
| 30 |
| 31 // Animates to the end or start state. |
| 32 void Animate(State target); |
| 33 |
| 34 // Jumps to the end or start state. |
| 35 void SetState(State state); |
| 36 |
| 37 // views::ImageView |
| 38 void OnPaint(gfx::Canvas* canvas) override; |
| 39 |
| 40 // ui::CompositorAnimationObserver |
| 41 void OnAnimationStep(base::TimeTicks timestamp) override; |
| 42 void OnCompositingShuttingDown(ui::Compositor* compositor) override; |
| 43 |
| 44 private: |
| 45 bool IsAnimating() const; |
| 46 |
| 47 void UpdateStaticImage(); |
| 48 |
| 49 const gfx::VectorIcon& icon_; |
| 50 SkColor color_; |
| 51 |
| 52 // Tracks the last time Animate() was called. |
| 53 base::TimeTicks start_time_; |
| 54 |
| 55 // The amount of time that must elapse until all transitions are done, i.e. |
| 56 // the length of the animation. |
| 57 const base::TimeDelta duration_; |
| 58 |
| 59 // The current state, or when transitioning the goal state. |
| 60 State state_ = START; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(AnimatedIconView); |
| 63 }; |
| 64 |
| 65 } // namespace views |
| 66 |
| 67 #endif // UI_VIEWS_CONTROLS_ANIMATED_ICON_VIEW_H_ |
| OLD | NEW |