Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: chrome/browser/ui/tabs/tab_audio_indicator.cc

Issue 23531053: ui/base/animation -> ui/gfx/animation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge 2 trunk Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/ui/tabs/tab_audio_indicator.h" 5 #include "chrome/browser/ui/tabs/tab_audio_indicator.h"
6 6
7 #include "grit/theme_resources.h" 7 #include "grit/theme_resources.h"
8 #include "ui/base/animation/animation_container.h"
9 #include "ui/base/animation/linear_animation.h"
10 #include "ui/base/resource/resource_bundle.h" 8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/animation/animation_container.h"
10 #include "ui/gfx/animation/linear_animation.h"
11 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
13 #include "ui/gfx/skia_util.h" 13 #include "ui/gfx/skia_util.h"
14 14
15 namespace { 15 namespace {
16 16
17 // The number of columns to draw for the equalizer graphic. 17 // The number of columns to draw for the equalizer graphic.
18 const size_t kEqualizerColumnCount = 3; 18 const size_t kEqualizerColumnCount = 3;
19 19
20 // The equalizer cycles between these frames. An equalizer frame is 2 columns 20 // The equalizer cycles between these frames. An equalizer frame is 2 columns
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 TabAudioIndicator::TabAudioIndicator(Delegate* delegate) 53 TabAudioIndicator::TabAudioIndicator(Delegate* delegate)
54 : delegate_(delegate), 54 : delegate_(delegate),
55 frame_index_(0), 55 frame_index_(0),
56 state_(STATE_NOT_ANIMATING) { 56 state_(STATE_NOT_ANIMATING) {
57 } 57 }
58 58
59 TabAudioIndicator::~TabAudioIndicator() { 59 TabAudioIndicator::~TabAudioIndicator() {
60 } 60 }
61 61
62 void TabAudioIndicator::SetAnimationContainer( 62 void TabAudioIndicator::SetAnimationContainer(
63 ui::AnimationContainer* animation_container) { 63 gfx::AnimationContainer* animation_container) {
64 animation_container_ = animation_container; 64 animation_container_ = animation_container;
65 } 65 }
66 66
67 void TabAudioIndicator::SetIsPlayingAudio(bool is_playing_audio) { 67 void TabAudioIndicator::SetIsPlayingAudio(bool is_playing_audio) {
68 if (is_playing_audio && state_ != STATE_ANIMATING) { 68 if (is_playing_audio && state_ != STATE_ANIMATING) {
69 state_ = STATE_ANIMATING; 69 state_ = STATE_ANIMATING;
70 animation_.reset( 70 animation_.reset(
71 new ui::LinearAnimation(kAnimationCycleDurationMs, kFPS, this)); 71 new gfx::LinearAnimation(kAnimationCycleDurationMs, kFPS, this));
72 animation_->SetContainer(animation_container_.get()); 72 animation_->SetContainer(animation_container_.get());
73 animation_->Start(); 73 animation_->Start();
74 } else if (!is_playing_audio && state_ == STATE_ANIMATING) { 74 } else if (!is_playing_audio && state_ == STATE_ANIMATING) {
75 state_ = STATE_ANIMATION_ENDING; 75 state_ = STATE_ANIMATION_ENDING;
76 animation_.reset( 76 animation_.reset(
77 new ui::LinearAnimation(kAnimationEndingDurationMs, kFPS, this)); 77 new gfx::LinearAnimation(kAnimationEndingDurationMs, kFPS, this));
78 animation_->SetContainer(animation_container_.get()); 78 animation_->SetContainer(animation_container_.get());
79 animation_->Start(); 79 animation_->Start();
80 } 80 }
81 } 81 }
82 82
83 bool TabAudioIndicator::IsAnimating() { 83 bool TabAudioIndicator::IsAnimating() {
84 return state_ != STATE_NOT_ANIMATING; 84 return state_ != STATE_NOT_ANIMATING;
85 } 85 }
86 86
87 void TabAudioIndicator::Paint(gfx::Canvas* canvas, const gfx::Rect& rect) { 87 void TabAudioIndicator::Paint(gfx::Canvas* canvas, const gfx::Rect& rect) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 if (!favicon_.isNull()) { 123 if (!favicon_.isNull()) {
124 int dst_x = rect.x() - (favicon_.width() - rect.width()) / 2; 124 int dst_x = rect.x() - (favicon_.width() - rect.width()) / 2;
125 int dst_y = rect.y() - (favicon_.height()- rect.height()) / 2; 125 int dst_y = rect.y() - (favicon_.height()- rect.height()) / 2;
126 canvas->DrawImageInt(favicon_, dst_x, dst_y); 126 canvas->DrawImageInt(favicon_, dst_x, dst_y);
127 } 127 }
128 128
129 canvas->Restore(); 129 canvas->Restore();
130 } 130 }
131 131
132 void TabAudioIndicator::AnimationProgressed(const ui::Animation* animation) { 132 void TabAudioIndicator::AnimationProgressed(const gfx::Animation* animation) {
133 std::vector<int> levels = GetCurrentEqualizerLevels(); 133 std::vector<int> levels = GetCurrentEqualizerLevels();
134 if (last_displayed_equalizer_levels_ != levels) 134 if (last_displayed_equalizer_levels_ != levels)
135 delegate_->ScheduleAudioIndicatorPaint(); 135 delegate_->ScheduleAudioIndicatorPaint();
136 } 136 }
137 137
138 void TabAudioIndicator::AnimationEnded(const ui::Animation* animation) { 138 void TabAudioIndicator::AnimationEnded(const gfx::Animation* animation) {
139 if (state_ == STATE_ANIMATING) { 139 if (state_ == STATE_ANIMATING) {
140 // The current equalizer frame animation has finished. Start animating the 140 // The current equalizer frame animation has finished. Start animating the
141 // next frame. 141 // next frame.
142 frame_index_ = (frame_index_ + 1) % arraysize(kEqualizerFrames); 142 frame_index_ = (frame_index_ + 1) % arraysize(kEqualizerFrames);
143 animation_->Start(); 143 animation_->Start();
144 } else if (state_ == STATE_ANIMATION_ENDING) { 144 } else if (state_ == STATE_ANIMATION_ENDING) {
145 // The "ending" animation has stopped. Update the tab state so that the UI 145 // The "ending" animation has stopped. Update the tab state so that the UI
146 // can update the tab icon. 146 // can update the tab icon.
147 state_ = STATE_NOT_ANIMATING; 147 state_ = STATE_NOT_ANIMATING;
148 delegate_->ScheduleAudioIndicatorPaint(); 148 delegate_->ScheduleAudioIndicatorPaint();
149 } 149 }
150 } 150 }
151 151
152 std::vector<int> TabAudioIndicator::GetCurrentEqualizerLevels() const { 152 std::vector<int> TabAudioIndicator::GetCurrentEqualizerLevels() const {
153 int next_frame_index = (frame_index_ + 1) % arraysize(kEqualizerFrames); 153 int next_frame_index = (frame_index_ + 1) % arraysize(kEqualizerFrames);
154 std::vector<int> levels; 154 std::vector<int> levels;
155 // For all 2 columsn of the equalizer, tween between the current equalizer 155 // For all 2 columsn of the equalizer, tween between the current equalizer
156 // level and the target equalizer level. 156 // level and the target equalizer level.
157 for (size_t i = 0; i < kEqualizerColumnCount; ++i) { 157 for (size_t i = 0; i < kEqualizerColumnCount; ++i) {
158 int start = kEqualizerFrames[frame_index_][i]; 158 int start = kEqualizerFrames[frame_index_][i];
159 int end = state_ == STATE_ANIMATION_ENDING 159 int end = state_ == STATE_ANIMATION_ENDING
160 ? 0 160 ? 0
161 : kEqualizerFrames[next_frame_index][i]; 161 : kEqualizerFrames[next_frame_index][i];
162 levels.push_back(animation_->CurrentValueBetween(start, end)); 162 levels.push_back(animation_->CurrentValueBetween(start, end));
163 } 163 }
164 return levels; 164 return levels;
165 } 165 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/tabs/tab_audio_indicator.h ('k') | chrome/browser/ui/tabs/tab_audio_indicator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698