| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/tabs/tab_renderer.h" | 5 #include "chrome/browser/views/tabs/tab_renderer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "app/animation_container.h" | 9 #include "app/animation_container.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 private: | 215 private: |
| 216 DISALLOW_COPY_AND_ASSIGN(TabCloseButton); | 216 DISALLOW_COPY_AND_ASSIGN(TabCloseButton); |
| 217 }; | 217 }; |
| 218 | 218 |
| 219 } // namespace | 219 } // namespace |
| 220 | 220 |
| 221 //////////////////////////////////////////////////////////////////////////////// | 221 //////////////////////////////////////////////////////////////////////////////// |
| 222 // FaviconCrashAnimation | 222 // FaviconCrashAnimation |
| 223 // | 223 // |
| 224 // A custom animation subclass to manage the favicon crash animation. | 224 // A custom animation subclass to manage the favicon crash animation. |
| 225 class TabRenderer::FavIconCrashAnimation : public Animation, | 225 class TabRenderer::FavIconCrashAnimation : public LinearAnimation, |
| 226 public AnimationDelegate { | 226 public AnimationDelegate { |
| 227 public: | 227 public: |
| 228 explicit FavIconCrashAnimation(TabRenderer* target) | 228 explicit FavIconCrashAnimation(TabRenderer* target) |
| 229 : ALLOW_THIS_IN_INITIALIZER_LIST(Animation(1000, 25, this)), | 229 : ALLOW_THIS_IN_INITIALIZER_LIST(LinearAnimation(1000, 25, this)), |
| 230 target_(target) { | 230 target_(target) { |
| 231 } | 231 } |
| 232 virtual ~FavIconCrashAnimation() {} | 232 virtual ~FavIconCrashAnimation() {} |
| 233 | 233 |
| 234 // Animation overrides: | 234 // Animation overrides: |
| 235 virtual void AnimateToState(double state) { | 235 virtual void AnimateToState(double state) { |
| 236 const double kHidingOffset = 27; | 236 const double kHidingOffset = 27; |
| 237 | 237 |
| 238 if (state < .5) { | 238 if (state < .5) { |
| 239 target_->SetFavIconHidingOffset( | 239 target_->SetFavIconHidingOffset( |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 387 |
| 388 SchedulePaint(); | 388 SchedulePaint(); |
| 389 } | 389 } |
| 390 | 390 |
| 391 void TabRenderer::StartPulse() { | 391 void TabRenderer::StartPulse() { |
| 392 pulse_animation_->Reset(); | 392 pulse_animation_->Reset(); |
| 393 pulse_animation_->StartThrobbing(std::numeric_limits<int>::max()); | 393 pulse_animation_->StartThrobbing(std::numeric_limits<int>::max()); |
| 394 } | 394 } |
| 395 | 395 |
| 396 void TabRenderer::StopPulse() { | 396 void TabRenderer::StopPulse() { |
| 397 if (pulse_animation_->IsAnimating()) | 397 pulse_animation_->Stop(); |
| 398 pulse_animation_->Stop(); | |
| 399 } | 398 } |
| 400 | 399 |
| 401 void TabRenderer::StartMiniTabTitleAnimation() { | 400 void TabRenderer::StartMiniTabTitleAnimation() { |
| 402 if (!mini_title_animation_.get()) { | 401 if (!mini_title_animation_.get()) { |
| 403 mini_title_animation_.reset(new ThrobAnimation(this)); | 402 mini_title_animation_.reset(new ThrobAnimation(this)); |
| 404 mini_title_animation_->SetThrobDuration(kMiniTitleChangeThrobDuration); | 403 mini_title_animation_->SetThrobDuration(kMiniTitleChangeThrobDuration); |
| 405 } | 404 } |
| 406 | 405 |
| 407 if (!mini_title_animation_->IsAnimating()) { | 406 if (!mini_title_animation_->is_animating()) { |
| 408 mini_title_animation_->StartThrobbing(2); | 407 mini_title_animation_->StartThrobbing(2); |
| 409 } else if (mini_title_animation_->cycles_remaining() <= 2) { | 408 } else if (mini_title_animation_->cycles_remaining() <= 2) { |
| 410 // The title changed while we're already animating. Add at most one more | 409 // The title changed while we're already animating. Add at most one more |
| 411 // cycle. This is done in an attempt to smooth out pages that continuously | 410 // cycle. This is done in an attempt to smooth out pages that continuously |
| 412 // change the title. | 411 // change the title. |
| 413 mini_title_animation_->set_cycles_remaining( | 412 mini_title_animation_->set_cycles_remaining( |
| 414 mini_title_animation_->cycles_remaining() + 2); | 413 mini_title_animation_->cycles_remaining() + 2); |
| 415 } | 414 } |
| 416 } | 415 } |
| 417 | 416 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 442 } else { | 441 } else { |
| 443 if (!data_.favicon.isNull()) { | 442 if (!data_.favicon.isNull()) { |
| 444 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch | 443 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch |
| 445 // to using that class to render the favicon). | 444 // to using that class to render the favicon). |
| 446 int x = favicon_bounds_.x(); | 445 int x = favicon_bounds_.x(); |
| 447 int y = favicon_bounds_.y() + fav_icon_hiding_offset_; | 446 int y = favicon_bounds_.y() + fav_icon_hiding_offset_; |
| 448 // TODO(sky): this isn't right for app tabs, but we're redoing this | 447 // TODO(sky): this isn't right for app tabs, but we're redoing this |
| 449 // effect separately. | 448 // effect separately. |
| 450 int size = data_.favicon.width(); | 449 int size = data_.favicon.width(); |
| 451 if (mini() && mini_title_animation_.get() && | 450 if (mini() && mini_title_animation_.get() && |
| 452 mini_title_animation_->IsAnimating()) { | 451 mini_title_animation_->is_animating()) { |
| 453 int throb_size = mini_title_animation_->CurrentValueBetween( | 452 int throb_size = mini_title_animation_->CurrentValueBetween( |
| 454 size, kMiniTitleChangeMaxFaviconSize); | 453 size, kMiniTitleChangeMaxFaviconSize); |
| 455 x -= (throb_size - size) / 2; | 454 x -= (throb_size - size) / 2; |
| 456 y -= (throb_size - size) / 2; | 455 y -= (throb_size - size) / 2; |
| 457 size = throb_size; | 456 size = throb_size; |
| 458 } | 457 } |
| 459 canvas->DrawBitmapInt(data_.favicon, 0, 0, | 458 canvas->DrawBitmapInt(data_.favicon, 0, 0, |
| 460 data_.favicon.width(), | 459 data_.favicon.width(), |
| 461 data_.favicon.height(), | 460 data_.favicon.height(), |
| 462 x, y, size, size, | 461 x, y, size, size, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 } | 499 } |
| 501 | 500 |
| 502 //////////////////////////////////////////////////////////////////////////////// | 501 //////////////////////////////////////////////////////////////////////////////// |
| 503 // TabRenderer, protected: | 502 // TabRenderer, protected: |
| 504 | 503 |
| 505 std::wstring TabRenderer::GetTitle() const { | 504 std::wstring TabRenderer::GetTitle() const { |
| 506 return UTF16ToWideHack(data_.title); | 505 return UTF16ToWideHack(data_.title); |
| 507 } | 506 } |
| 508 | 507 |
| 509 void TabRenderer::OnMouseEntered(const views::MouseEvent& e) { | 508 void TabRenderer::OnMouseEntered(const views::MouseEvent& e) { |
| 510 hover_animation_->SetTweenType(SlideAnimation::EASE_OUT); | 509 hover_animation_->SetTweenType(Tween::EASE_OUT); |
| 511 hover_animation_->Show(); | 510 hover_animation_->Show(); |
| 512 } | 511 } |
| 513 | 512 |
| 514 void TabRenderer::OnMouseExited(const views::MouseEvent& e) { | 513 void TabRenderer::OnMouseExited(const views::MouseEvent& e) { |
| 515 hover_animation_->SetTweenType(SlideAnimation::EASE_IN); | 514 hover_animation_->SetTweenType(Tween::EASE_IN); |
| 516 hover_animation_->Hide(); | 515 hover_animation_->Hide(); |
| 517 } | 516 } |
| 518 | 517 |
| 519 //////////////////////////////////////////////////////////////////////////////// | 518 //////////////////////////////////////////////////////////////////////////////// |
| 520 // TabRenderer, views::View overrides: | 519 // TabRenderer, views::View overrides: |
| 521 | 520 |
| 522 void TabRenderer::Paint(gfx::Canvas* canvas) { | 521 void TabRenderer::Paint(gfx::Canvas* canvas) { |
| 523 if (data_.render_as_new_tab) { | 522 if (data_.render_as_new_tab) { |
| 524 if (UILayoutIsRightToLeft()) { | 523 if (UILayoutIsRightToLeft()) { |
| 525 canvas->TranslateInt(width(), 0); | 524 canvas->TranslateInt(width(), 0); |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 | 922 |
| 924 bool TabRenderer::ShouldShowCloseBox() const { | 923 bool TabRenderer::ShouldShowCloseBox() const { |
| 925 // The selected tab never clips close button. | 924 // The selected tab never clips close button. |
| 926 return !mini() && (IsSelected() || IconCapacity() >= 3); | 925 return !mini() && (IsSelected() || IconCapacity() >= 3); |
| 927 } | 926 } |
| 928 | 927 |
| 929 double TabRenderer::GetThrobValue() { | 928 double TabRenderer::GetThrobValue() { |
| 930 if (data_.alpha != 1) | 929 if (data_.alpha != 1) |
| 931 return data_.alpha; | 930 return data_.alpha; |
| 932 | 931 |
| 933 if (pulse_animation_->IsAnimating()) | 932 if (pulse_animation_->is_animating()) |
| 934 return pulse_animation_->GetCurrentValue() * kHoverOpacity; | 933 return pulse_animation_->GetCurrentValue() * kHoverOpacity; |
| 935 | 934 |
| 936 return hover_animation_.get() ? | 935 return hover_animation_.get() ? |
| 937 kHoverOpacity * hover_animation_->GetCurrentValue() : 0; | 936 kHoverOpacity * hover_animation_->GetCurrentValue() : 0; |
| 938 } | 937 } |
| 939 | 938 |
| 940 //////////////////////////////////////////////////////////////////////////////// | 939 //////////////////////////////////////////////////////////////////////////////// |
| 941 // TabRenderer, private: | 940 // TabRenderer, private: |
| 942 | 941 |
| 943 void TabRenderer::StartCrashAnimation() { | 942 void TabRenderer::StartCrashAnimation() { |
| 944 if (!crash_animation_) | 943 if (!crash_animation_) |
| 945 crash_animation_ = new FavIconCrashAnimation(this); | 944 crash_animation_ = new FavIconCrashAnimation(this); |
| 946 crash_animation_->Stop(); | 945 crash_animation_->Stop(); |
| 947 crash_animation_->Start(); | 946 crash_animation_->Start(); |
| 948 } | 947 } |
| 949 | 948 |
| 950 void TabRenderer::StopCrashAnimation() { | 949 void TabRenderer::StopCrashAnimation() { |
| 951 if (!crash_animation_) | 950 if (!crash_animation_) |
| 952 return; | 951 return; |
| 953 crash_animation_->Stop(); | 952 crash_animation_->Stop(); |
| 954 } | 953 } |
| 955 | 954 |
| 956 bool TabRenderer::IsPerformingCrashAnimation() const { | 955 bool TabRenderer::IsPerformingCrashAnimation() const { |
| 957 return crash_animation_ && crash_animation_->IsAnimating(); | 956 return crash_animation_ && crash_animation_->is_animating(); |
| 958 } | 957 } |
| 959 | 958 |
| 960 void TabRenderer::SetFavIconHidingOffset(int offset) { | 959 void TabRenderer::SetFavIconHidingOffset(int offset) { |
| 961 fav_icon_hiding_offset_ = offset; | 960 fav_icon_hiding_offset_ = offset; |
| 962 SchedulePaint(); | 961 SchedulePaint(); |
| 963 } | 962 } |
| 964 | 963 |
| 965 void TabRenderer::DisplayCrashedFavIcon() { | 964 void TabRenderer::DisplayCrashedFavIcon() { |
| 966 should_display_crashed_favicon_ = true; | 965 should_display_crashed_favicon_ = true; |
| 967 } | 966 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 | 1020 |
| 1022 void TabRenderer::SetBlocked(bool blocked) { | 1021 void TabRenderer::SetBlocked(bool blocked) { |
| 1023 if (data_.blocked == blocked) | 1022 if (data_.blocked == blocked) |
| 1024 return; | 1023 return; |
| 1025 data_.blocked = blocked; | 1024 data_.blocked = blocked; |
| 1026 if (blocked) | 1025 if (blocked) |
| 1027 StartPulse(); | 1026 StartPulse(); |
| 1028 else | 1027 else |
| 1029 StopPulse(); | 1028 StopPulse(); |
| 1030 } | 1029 } |
| OLD | NEW |