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

Unified Diff: chrome/browser/ui/tabs/tab_audio_indicator.cc

Issue 23513039: Replace animated tab audio indicator with static tab audio indicator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments from sky@. Also, rebased. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/tabs/tab_audio_indicator.cc
diff --git a/chrome/browser/ui/tabs/tab_audio_indicator.cc b/chrome/browser/ui/tabs/tab_audio_indicator.cc
deleted file mode 100644
index a1336408c9eac9bf9d324dfc3258c7caf0e1af0b..0000000000000000000000000000000000000000
--- a/chrome/browser/ui/tabs/tab_audio_indicator.cc
+++ /dev/null
@@ -1,165 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/tabs/tab_audio_indicator.h"
-
-#include "grit/theme_resources.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/animation/animation_container.h"
-#include "ui/gfx/animation/linear_animation.h"
-#include "ui/gfx/canvas.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/skia_util.h"
-
-namespace {
-
-// The number of columns to draw for the equalizer graphic.
-const size_t kEqualizerColumnCount = 3;
-
-// The equalizer cycles between these frames. An equalizer frame is 2 columns
-// where each column ranges from 0 to 4.
-const size_t kEqualizerFrames[][kEqualizerColumnCount] = {
- { 1, 1, 1 },
- { 1, 2, 2 },
- { 2, 2, 3 },
- { 3, 3, 2 },
- { 3, 2, 1 },
- { 2, 1, 2 },
- { 1, 2, 3 },
- { 2, 1, 2 },
- { 3, 2, 1 },
- { 3, 2, 1 },
- { 2, 3, 2 },
- { 1, 2, 3 },
- { 2, 1, 2 },
-};
-
-// The space between equalizer levels.
-const int kEqualizerColumnPadding = 1;
-
-// The duration of each equalizer frame.
-const size_t kAnimationCycleDurationMs = 250;
-
-// The duration of the "ending" animation once audio stops playing.
-const size_t kAnimationEndingDurationMs = 1000;
-
-// Target frames per second. In reality fewer frames are drawn because the
-// equalizer levels change slowly.
-const int kFPS = 15;
-
-} // namespace
-
-TabAudioIndicator::TabAudioIndicator(Delegate* delegate)
- : delegate_(delegate),
- frame_index_(0),
- state_(STATE_NOT_ANIMATING) {
-}
-
-TabAudioIndicator::~TabAudioIndicator() {
-}
-
-void TabAudioIndicator::SetAnimationContainer(
- gfx::AnimationContainer* animation_container) {
- animation_container_ = animation_container;
-}
-
-void TabAudioIndicator::SetIsPlayingAudio(bool is_playing_audio) {
- if (is_playing_audio && state_ != STATE_ANIMATING) {
- state_ = STATE_ANIMATING;
- animation_.reset(
- new gfx::LinearAnimation(kAnimationCycleDurationMs, kFPS, this));
- animation_->SetContainer(animation_container_.get());
- animation_->Start();
- } else if (!is_playing_audio && state_ == STATE_ANIMATING) {
- state_ = STATE_ANIMATION_ENDING;
- animation_.reset(
- new gfx::LinearAnimation(kAnimationEndingDurationMs, kFPS, this));
- animation_->SetContainer(animation_container_.get());
- animation_->Start();
- }
-}
-
-bool TabAudioIndicator::IsAnimating() {
- return state_ != STATE_NOT_ANIMATING;
-}
-
-void TabAudioIndicator::Paint(gfx::Canvas* canvas, const gfx::Rect& rect) {
- canvas->Save();
- canvas->ClipRect(rect);
-
- // Draw 3 equalizer columns. |IDR_AUDIO_EQUALIZER_COLUMN| is a column of the
- // equalizer with 4 levels. The current level is between 0 and 4 so the
- // image is shifted down and then drawn.
- if (state_ != STATE_NOT_ANIMATING) {
- ui::ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- gfx::ImageSkia* image(rb.GetImageSkiaNamed(IDR_AUDIO_EQUALIZER_COLUMN));
- int x = rect.right();
- std::vector<int> levels = GetCurrentEqualizerLevels();
- for (int i = levels.size() - 1; i >= 0; --i) {
- x -= image->width();
- if (levels[i] == 0)
- continue;
-
- // Shift the image down by the level.
- int y = rect.bottom() - levels[i] * 2;
- canvas->DrawImageInt(*image, x, y);
-
- // Clip the equalizer column so the favicon doesn't obscure it.
- gfx::Rect equalizer_rect(x, y, image->width(), image->height());
- canvas->sk_canvas()->clipRect(
- gfx::RectToSkRect(equalizer_rect), SkRegion::kDifference_Op);
-
- // Padding is baked into both sides of the icons so overlap the images.
- x += kEqualizerColumnPadding;
- }
-
- // Cache the levels that were just drawn. This is used to prevent
- // unnecessary drawing when animation progress doesn't result in equalizer
- // levels changing.
- last_displayed_equalizer_levels_ = levels;
- }
-
- if (!favicon_.isNull()) {
- int dst_x = rect.x() - (favicon_.width() - rect.width()) / 2;
- int dst_y = rect.y() - (favicon_.height()- rect.height()) / 2;
- canvas->DrawImageInt(favicon_, dst_x, dst_y);
- }
-
- canvas->Restore();
-}
-
-void TabAudioIndicator::AnimationProgressed(const gfx::Animation* animation) {
- std::vector<int> levels = GetCurrentEqualizerLevels();
- if (last_displayed_equalizer_levels_ != levels)
- delegate_->ScheduleAudioIndicatorPaint();
-}
-
-void TabAudioIndicator::AnimationEnded(const gfx::Animation* animation) {
- if (state_ == STATE_ANIMATING) {
- // The current equalizer frame animation has finished. Start animating the
- // next frame.
- frame_index_ = (frame_index_ + 1) % arraysize(kEqualizerFrames);
- animation_->Start();
- } else if (state_ == STATE_ANIMATION_ENDING) {
- // The "ending" animation has stopped. Update the tab state so that the UI
- // can update the tab icon.
- state_ = STATE_NOT_ANIMATING;
- delegate_->ScheduleAudioIndicatorPaint();
- }
-}
-
-std::vector<int> TabAudioIndicator::GetCurrentEqualizerLevels() const {
- int next_frame_index = (frame_index_ + 1) % arraysize(kEqualizerFrames);
- std::vector<int> levels;
- // For all 2 columsn of the equalizer, tween between the current equalizer
- // level and the target equalizer level.
- for (size_t i = 0; i < kEqualizerColumnCount; ++i) {
- int start = kEqualizerFrames[frame_index_][i];
- int end = state_ == STATE_ANIMATION_ENDING
- ? 0
- : kEqualizerFrames[next_frame_index][i];
- levels.push_back(animation_->CurrentValueBetween(start, end));
- }
- return levels;
-}
« 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