OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 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 CHROME_BROWSER_UI_TABS_TAB_AUDIO_INDICATOR_H_ | |
6 #define CHROME_BROWSER_UI_TABS_TAB_AUDIO_INDICATOR_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/compiler_specific.h" | |
11 #include "base/gtest_prod_util.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "ui/gfx/animation/animation_delegate.h" | |
15 #include "ui/gfx/image/image_skia.h" | |
16 | |
17 namespace gfx { | |
18 class Animation; | |
19 class AnimationContainer; | |
20 class Canvas; | |
21 class LinearAnimation; | |
22 class Rect; | |
23 } | |
24 | |
25 // This class is used to draw an animating tab audio indicator. | |
26 class TabAudioIndicator : public gfx::AnimationDelegate { | |
27 public: | |
28 class Delegate { | |
29 public: | |
30 virtual void ScheduleAudioIndicatorPaint() = 0; | |
31 | |
32 protected: | |
33 virtual ~Delegate() {} | |
34 }; | |
35 | |
36 explicit TabAudioIndicator(Delegate* delegate); | |
37 virtual ~TabAudioIndicator(); | |
38 | |
39 void set_favicon(const gfx::ImageSkia& favicon) { favicon_ = favicon; } | |
40 | |
41 void SetAnimationContainer(gfx::AnimationContainer* animation_container); | |
42 void SetIsPlayingAudio(bool is_playing_audio); | |
43 bool IsAnimating(); | |
44 | |
45 void Paint(gfx::Canvas* canvas, const gfx::Rect& rect); | |
46 | |
47 private: | |
48 enum State { | |
49 STATE_NOT_ANIMATING, | |
50 STATE_ANIMATING, | |
51 STATE_ANIMATION_ENDING, | |
52 }; | |
53 | |
54 FRIEND_TEST_ALL_PREFIXES(TabAudioIndicatorTest, AnimationState); | |
55 FRIEND_TEST_ALL_PREFIXES(TabAudioIndicatorTest, SchedulePaint); | |
56 | |
57 // AnimationDelegate: | |
58 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; | |
59 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; | |
60 | |
61 // Gets the equalizer levels for all 3 columns. The values are tweened between | |
62 // the current and target frame. | |
63 std::vector<int> GetCurrentEqualizerLevels() const; | |
64 | |
65 Delegate* delegate_; | |
66 scoped_ptr<gfx::LinearAnimation> animation_; | |
67 scoped_refptr<gfx::AnimationContainer> animation_container_; | |
68 gfx::ImageSkia favicon_; | |
69 | |
70 // The equalizer frame that's currently being displayed. | |
71 size_t frame_index_; | |
72 | |
73 // The equalizer levels that were last displayed. This is used to prevent | |
74 // unnecessary drawing when animation progress doesn't result in equalizer | |
75 // levels changing. | |
76 std::vector<int> last_displayed_equalizer_levels_; | |
77 | |
78 State state_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(TabAudioIndicator); | |
81 }; | |
82 | |
83 #endif // CHROME_BROWSER_UI_TABS_TAB_AUDIO_INDICATOR_H_ | |
OLD | NEW |