Commit bf3253e0 authored by sky@chromium.org's avatar sky@chromium.org

It was possible to think we had set tab_animation_ to a MultiAnimation

when we hadn't. To avoid errors like this I'm splitting tab_animation_
into two distinct fields. Less possibility of error this way.

BUG=387371
TEST=none

Review URL: https://codereview.chromium.org/382693002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282455 0039d316-1c4b-4281-b951-d872f2087c98
parent 12b8a94e
...@@ -186,6 +186,13 @@ chrome::HostDesktopType GetHostDesktopType(views::View* view) { ...@@ -186,6 +186,13 @@ chrome::HostDesktopType GetHostDesktopType(views::View* view) {
widget ? widget->GetNativeView() : NULL); widget ? widget->GetNativeView() : NULL);
} }
// Stop()s |animation| and then deletes it. We do this rather than just deleting
// so that the delegate is notified before the destruction.
void StopAndDeleteAnimation(scoped_ptr<gfx::Animation> animation) {
if (animation)
animation->Stop();
}
} // namespace } // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -518,10 +525,8 @@ void Tab::SetData(const TabRendererData& data) { ...@@ -518,10 +525,8 @@ void Tab::SetData(const TabRendererData& data) {
} }
if (old.mini != data_.mini) { if (old.mini != data_.mini) {
if (tab_animation_.get() && tab_animation_->is_animating()) { StopAndDeleteAnimation(
tab_animation_->Stop(); mini_title_change_animation_.PassAs<gfx::Animation>());
tab_animation_.reset(NULL);
}
} }
DataChanged(old); DataChanged(old);
...@@ -544,27 +549,21 @@ void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) { ...@@ -544,27 +549,21 @@ void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) {
} }
void Tab::StartPulse() { void Tab::StartPulse() {
gfx::ThrobAnimation* animation = new gfx::ThrobAnimation(this); pulse_animation_.reset(new gfx::ThrobAnimation(this));
animation->SetSlideDuration(kPulseDurationMs); pulse_animation_->SetSlideDuration(kPulseDurationMs);
if (animation_container_.get()) if (animation_container_)
animation->SetContainer(animation_container_.get()); pulse_animation_->SetContainer(animation_container_.get());
animation->StartThrobbing(std::numeric_limits<int>::max()); pulse_animation_->StartThrobbing(std::numeric_limits<int>::max());
tab_animation_.reset(animation);
} }
void Tab::StopPulse() { void Tab::StopPulse() {
if (!tab_animation_.get()) StopAndDeleteAnimation(pulse_animation_.PassAs<gfx::Animation>());
return;
tab_animation_->Stop();
tab_animation_.reset(NULL);
} }
void Tab::StartMiniTabTitleAnimation() { void Tab::StartMiniTabTitleAnimation() {
// We can only do this animation if the tab is mini because we will
// upcast tab_animation back to MultiAnimation when we draw.
if (!data().mini) if (!data().mini)
return; return;
if (!tab_animation_.get()) { if (!mini_title_change_animation_) {
gfx::MultiAnimation::Parts parts; gfx::MultiAnimation::Parts parts;
parts.push_back( parts.push_back(
gfx::MultiAnimation::Part(kMiniTitleChangeAnimationDuration1MS, gfx::MultiAnimation::Part(kMiniTitleChangeAnimationDuration1MS,
...@@ -581,20 +580,16 @@ void Tab::StartMiniTabTitleAnimation() { ...@@ -581,20 +580,16 @@ void Tab::StartMiniTabTitleAnimation() {
parts[2].end_time_ms = kMiniTitleChangeAnimationEnd3MS; parts[2].end_time_ms = kMiniTitleChangeAnimationEnd3MS;
base::TimeDelta timeout = base::TimeDelta timeout =
base::TimeDelta::FromMilliseconds(kMiniTitleChangeAnimationIntervalMS); base::TimeDelta::FromMilliseconds(kMiniTitleChangeAnimationIntervalMS);
gfx::MultiAnimation* animation = new gfx::MultiAnimation(parts, timeout); mini_title_change_animation_.reset(new gfx::MultiAnimation(parts, timeout));
if (animation_container_.get()) if (animation_container_)
animation->SetContainer(animation_container_.get()); mini_title_change_animation_->SetContainer(animation_container_.get());
animation->set_delegate(this); mini_title_change_animation_->set_delegate(this);
tab_animation_.reset(animation);
} }
tab_animation_->Start(); mini_title_change_animation_->Start();
} }
void Tab::StopMiniTabTitleAnimation() { void Tab::StopMiniTabTitleAnimation() {
if (!tab_animation_.get()) StopAndDeleteAnimation(mini_title_change_animation_.PassAs<gfx::Animation>());
return;
tab_animation_->Stop();
tab_animation_.reset(NULL);
} }
// static // static
...@@ -650,7 +645,7 @@ int Tab::GetImmersiveHeight() { ...@@ -650,7 +645,7 @@ int Tab::GetImmersiveHeight() {
void Tab::AnimationProgressed(const gfx::Animation* animation) { void Tab::AnimationProgressed(const gfx::Animation* animation) {
// Ignore if the pulse animation is being performed on active tab because // Ignore if the pulse animation is being performed on active tab because
// it repaints the same image. See |Tab::PaintTabBackground()|. // it repaints the same image. See |Tab::PaintTabBackground()|.
if (animation == tab_animation_.get() && IsActive()) if (animation == pulse_animation_.get() && IsActive())
return; return;
SchedulePaint(); SchedulePaint();
} }
...@@ -1087,10 +1082,8 @@ void Tab::PaintTab(gfx::Canvas* canvas) { ...@@ -1087,10 +1082,8 @@ void Tab::PaintTab(gfx::Canvas* canvas) {
void Tab::PaintImmersiveTab(gfx::Canvas* canvas) { void Tab::PaintImmersiveTab(gfx::Canvas* canvas) {
// Use transparency for the draw-attention animation. // Use transparency for the draw-attention animation.
int alpha = 255; int alpha = 255;
if (tab_animation_ && if (pulse_animation_ && pulse_animation_->is_animating() && !data().mini) {
tab_animation_->is_animating() && alpha = pulse_animation_->CurrentValueBetween(
!data().mini) {
alpha = tab_animation_->CurrentValueBetween(
255, static_cast<int>(255 * kImmersiveTabMinThrobOpacity)); 255, static_cast<int>(255 * kImmersiveTabMinThrobOpacity));
} }
...@@ -1134,12 +1127,9 @@ void Tab::PaintTabBackground(gfx::Canvas* canvas) { ...@@ -1134,12 +1127,9 @@ void Tab::PaintTabBackground(gfx::Canvas* canvas) {
if (IsActive()) { if (IsActive()) {
PaintActiveTabBackground(canvas); PaintActiveTabBackground(canvas);
} else { } else {
if (tab_animation_.get() && if (mini_title_change_animation_ &&
tab_animation_->is_animating() && mini_title_change_animation_->is_animating()) {
data().mini) { PaintInactiveTabBackgroundWithTitleChange(canvas);
gfx::MultiAnimation* animation =
static_cast<gfx::MultiAnimation*>(tab_animation_.get());
PaintInactiveTabBackgroundWithTitleChange(canvas, animation);
} else { } else {
PaintInactiveTabBackground(canvas); PaintInactiveTabBackground(canvas);
} }
...@@ -1154,9 +1144,7 @@ void Tab::PaintTabBackground(gfx::Canvas* canvas) { ...@@ -1154,9 +1144,7 @@ void Tab::PaintTabBackground(gfx::Canvas* canvas) {
} }
} }
void Tab::PaintInactiveTabBackgroundWithTitleChange( void Tab::PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas) {
gfx::Canvas* canvas,
gfx::MultiAnimation* animation) {
// Render the inactive tab background. We'll use this for clipping. // Render the inactive tab background. We'll use this for clipping.
gfx::Canvas background_canvas(size(), canvas->image_scale(), false); gfx::Canvas background_canvas(size(), canvas->image_scale(), false);
PaintInactiveTabBackground(&background_canvas); PaintInactiveTabBackground(&background_canvas);
...@@ -1170,12 +1158,12 @@ void Tab::PaintInactiveTabBackgroundWithTitleChange( ...@@ -1170,12 +1158,12 @@ void Tab::PaintInactiveTabBackgroundWithTitleChange(
int x1 = radius; int x1 = radius;
int x2 = -radius; int x2 = -radius;
int x; int x;
if (animation->current_part_index() == 0) { if (mini_title_change_animation_->current_part_index() == 0) {
x = animation->CurrentValueBetween(x0, x1); x = mini_title_change_animation_->CurrentValueBetween(x0, x1);
} else if (animation->current_part_index() == 1) { } else if (mini_title_change_animation_->current_part_index() == 1) {
x = x1; x = x1;
} else { } else {
x = animation->CurrentValueBetween(x1, x2); x = mini_title_change_animation_->CurrentValueBetween(x1, x2);
} }
SkPoint center_point; SkPoint center_point;
center_point.iset(x, 0); center_point.iset(x, 0);
...@@ -1198,8 +1186,8 @@ void Tab::PaintInactiveTabBackgroundWithTitleChange( ...@@ -1198,8 +1186,8 @@ void Tab::PaintInactiveTabBackgroundWithTitleChange(
canvas->DrawImageInt(background_image, 0, 0); canvas->DrawImageInt(background_image, 0, 0);
// And then the gradient on top of that. // And then the gradient on top of that.
if (animation->current_part_index() == 2) { if (mini_title_change_animation_->current_part_index() == 2) {
uint8 alpha = animation->CurrentValueBetween(255, 0); uint8 alpha = mini_title_change_animation_->CurrentValueBetween(255, 0);
canvas->DrawImageInt(hover_image, 0, 0, alpha); canvas->DrawImageInt(hover_image, 0, 0, alpha);
} else { } else {
canvas->DrawImageInt(hover_image, 0, 0); canvas->DrawImageInt(hover_image, 0, 0);
...@@ -1512,13 +1500,16 @@ bool Tab::ShouldShowCloseBox() const { ...@@ -1512,13 +1500,16 @@ bool Tab::ShouldShowCloseBox() const {
} }
double Tab::GetThrobValue() { double Tab::GetThrobValue() {
bool is_selected = IsSelected(); const bool is_selected = IsSelected();
double min = is_selected ? kSelectedTabOpacity : 0; const double min = is_selected ? kSelectedTabOpacity : 0;
double scale = is_selected ? kSelectedTabThrobScale : 1; const double scale = is_selected ? kSelectedTabThrobScale : 1;
if (!data().mini) { // Showing both the pulse and title change animation at the same time is too
if (tab_animation_.get() && tab_animation_->is_animating()) // much.
return tab_animation_->GetCurrentValue() * kHoverOpacity * scale + min; if (pulse_animation_ && pulse_animation_->is_animating() &&
(!mini_title_change_animation_ ||
!mini_title_change_animation_->is_animating())) {
return pulse_animation_->GetCurrentValue() * kHoverOpacity * scale + min;
} }
if (hover_controller_.ShouldDraw()) { if (hover_controller_.ShouldDraw()) {
......
...@@ -27,6 +27,7 @@ class Animation; ...@@ -27,6 +27,7 @@ class Animation;
class AnimationContainer; class AnimationContainer;
class LinearAnimation; class LinearAnimation;
class MultiAnimation; class MultiAnimation;
class ThrobAnimation;
} }
namespace views { namespace views {
class ImageButton; class ImageButton;
...@@ -218,9 +219,7 @@ class Tab : public gfx::AnimationDelegate, ...@@ -218,9 +219,7 @@ class Tab : public gfx::AnimationDelegate,
// Paint various portions of the Tab // Paint various portions of the Tab
void PaintTabBackground(gfx::Canvas* canvas); void PaintTabBackground(gfx::Canvas* canvas);
void PaintInactiveTabBackgroundWithTitleChange( void PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas);
gfx::Canvas* canvas,
gfx::MultiAnimation* animation);
void PaintInactiveTabBackground(gfx::Canvas* canvas); void PaintInactiveTabBackground(gfx::Canvas* canvas);
void PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, void PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas,
int tab_id); int tab_id);
...@@ -329,7 +328,9 @@ class Tab : public gfx::AnimationDelegate, ...@@ -329,7 +328,9 @@ class Tab : public gfx::AnimationDelegate,
bool should_display_crashed_favicon_; bool should_display_crashed_favicon_;
// Whole-tab throbbing "pulse" animation. // Whole-tab throbbing "pulse" animation.
scoped_ptr<gfx::Animation> tab_animation_; scoped_ptr<gfx::ThrobAnimation> pulse_animation_;
scoped_ptr<gfx::MultiAnimation> mini_title_change_animation_;
// Crash icon animation (in place of favicon). // Crash icon animation (in place of favicon).
scoped_ptr<gfx::LinearAnimation> crash_icon_animation_; scoped_ptr<gfx::LinearAnimation> crash_icon_animation_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment