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