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

Side by Side Diff: chrome/browser/ui/views/tabs/tab.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
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.h ('k') | chrome/browser/ui/views/tabs/tab_drag_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/views/tabs/tab.h" 5 #include "chrome/browser/ui/views/tabs/tab.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/defaults.h" 12 #include "chrome/browser/defaults.h"
13 #include "chrome/browser/themes/theme_properties.h" 13 #include "chrome/browser/themes/theme_properties.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 15 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
16 #include "chrome/browser/ui/tabs/tab_resources.h" 16 #include "chrome/browser/ui/tabs/tab_resources.h"
17 #include "chrome/browser/ui/view_ids.h" 17 #include "chrome/browser/ui/view_ids.h"
18 #include "chrome/browser/ui/views/tabs/tab_controller.h" 18 #include "chrome/browser/ui/views/tabs/tab_controller.h"
19 #include "chrome/browser/ui/views/theme_image_mapper.h" 19 #include "chrome/browser/ui/views/theme_image_mapper.h"
20 #include "chrome/browser/ui/views/touch_uma/touch_uma.h" 20 #include "chrome/browser/ui/views/touch_uma/touch_uma.h"
21 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
22 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
23 #include "grit/theme_resources.h" 23 #include "grit/theme_resources.h"
24 #include "grit/ui_resources.h" 24 #include "grit/ui_resources.h"
25 #include "third_party/skia/include/effects/SkGradientShader.h" 25 #include "third_party/skia/include/effects/SkGradientShader.h"
26 #include "ui/base/accessibility/accessible_view_state.h" 26 #include "ui/base/accessibility/accessible_view_state.h"
27 #include "ui/base/animation/animation_container.h"
28 #include "ui/base/animation/multi_animation.h"
29 #include "ui/base/animation/slide_animation.h"
30 #include "ui/base/animation/throb_animation.h"
31 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/base/layout.h" 28 #include "ui/base/layout.h"
33 #include "ui/base/models/list_selection_model.h" 29 #include "ui/base/models/list_selection_model.h"
34 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
35 #include "ui/base/theme_provider.h" 31 #include "ui/base/theme_provider.h"
32 #include "ui/gfx/animation/animation_container.h"
33 #include "ui/gfx/animation/multi_animation.h"
34 #include "ui/gfx/animation/slide_animation.h"
35 #include "ui/gfx/animation/throb_animation.h"
36 #include "ui/gfx/canvas.h" 36 #include "ui/gfx/canvas.h"
37 #include "ui/gfx/color_analysis.h" 37 #include "ui/gfx/color_analysis.h"
38 #include "ui/gfx/favicon_size.h" 38 #include "ui/gfx/favicon_size.h"
39 #include "ui/gfx/font.h" 39 #include "ui/gfx/font.h"
40 #include "ui/gfx/image/image_skia_operations.h" 40 #include "ui/gfx/image/image_skia_operations.h"
41 #include "ui/gfx/path.h" 41 #include "ui/gfx/path.h"
42 #include "ui/gfx/text_elider.h" 42 #include "ui/gfx/text_elider.h"
43 #include "ui/views/controls/button/image_button.h" 43 #include "ui/views/controls/button/image_button.h"
44 #include "ui/views/widget/tooltip_manager.h" 44 #include "ui/views/widget/tooltip_manager.h"
45 #include "ui/views/widget/widget.h" 45 #include "ui/views/widget/widget.h"
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 return chrome::GetHostDesktopTypeForNativeView( 307 return chrome::GetHostDesktopTypeForNativeView(
308 widget ? widget->GetNativeView() : NULL); 308 widget ? widget->GetNativeView() : NULL);
309 } 309 }
310 310
311 } // namespace 311 } // namespace
312 312
313 //////////////////////////////////////////////////////////////////////////////// 313 ////////////////////////////////////////////////////////////////////////////////
314 // FaviconCrashAnimation 314 // FaviconCrashAnimation
315 // 315 //
316 // A custom animation subclass to manage the favicon crash animation. 316 // A custom animation subclass to manage the favicon crash animation.
317 class Tab::FaviconCrashAnimation : public ui::LinearAnimation, 317 class Tab::FaviconCrashAnimation : public gfx::LinearAnimation,
318 public ui::AnimationDelegate { 318 public gfx::AnimationDelegate {
319 public: 319 public:
320 explicit FaviconCrashAnimation(Tab* target) 320 explicit FaviconCrashAnimation(Tab* target)
321 : ui::LinearAnimation(1000, 25, this), 321 : gfx::LinearAnimation(1000, 25, this),
322 target_(target) { 322 target_(target) {
323 } 323 }
324 virtual ~FaviconCrashAnimation() {} 324 virtual ~FaviconCrashAnimation() {}
325 325
326 // ui::Animation overrides: 326 // gfx::Animation overrides:
327 virtual void AnimateToState(double state) OVERRIDE { 327 virtual void AnimateToState(double state) OVERRIDE {
328 const double kHidingOffset = 27; 328 const double kHidingOffset = 27;
329 329
330 if (state < .5) { 330 if (state < .5) {
331 target_->SetFaviconHidingOffset( 331 target_->SetFaviconHidingOffset(
332 static_cast<int>(floor(kHidingOffset * 2.0 * state))); 332 static_cast<int>(floor(kHidingOffset * 2.0 * state)));
333 } else { 333 } else {
334 target_->DisplayCrashedFavicon(); 334 target_->DisplayCrashedFavicon();
335 target_->SetFaviconHidingOffset( 335 target_->SetFaviconHidingOffset(
336 static_cast<int>( 336 static_cast<int>(
337 floor(kHidingOffset - ((state - .5) * 2.0 * kHidingOffset)))); 337 floor(kHidingOffset - ((state - .5) * 2.0 * kHidingOffset))));
338 } 338 }
339 } 339 }
340 340
341 // ui::AnimationDelegate overrides: 341 // gfx::AnimationDelegate overrides:
342 virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE { 342 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE {
343 target_->SetFaviconHidingOffset(0); 343 target_->SetFaviconHidingOffset(0);
344 } 344 }
345 345
346 private: 346 private:
347 Tab* target_; 347 Tab* target_;
348 348
349 DISALLOW_COPY_AND_ASSIGN(FaviconCrashAnimation); 349 DISALLOW_COPY_AND_ASSIGN(FaviconCrashAnimation);
350 }; 350 };
351 351
352 //////////////////////////////////////////////////////////////////////////////// 352 ////////////////////////////////////////////////////////////////////////////////
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 AddChildView(close_button_); 492 AddChildView(close_button_);
493 493
494 set_context_menu_controller(this); 494 set_context_menu_controller(this);
495 495
496 tab_audio_indicator_.reset(new TabAudioIndicator(this)); 496 tab_audio_indicator_.reset(new TabAudioIndicator(this));
497 } 497 }
498 498
499 Tab::~Tab() { 499 Tab::~Tab() {
500 } 500 }
501 501
502 void Tab::set_animation_container(ui::AnimationContainer* container) { 502 void Tab::set_animation_container(gfx::AnimationContainer* container) {
503 animation_container_ = container; 503 animation_container_ = container;
504 hover_controller_.SetAnimationContainer(container); 504 hover_controller_.SetAnimationContainer(container);
505 tab_audio_indicator_->SetAnimationContainer(container); 505 tab_audio_indicator_->SetAnimationContainer(container);
506 } 506 }
507 507
508 bool Tab::IsActive() const { 508 bool Tab::IsActive() const {
509 return controller() ? controller()->IsActiveTab(this) : true; 509 return controller() ? controller()->IsActiveTab(this) : true;
510 } 510 }
511 511
512 bool Tab::IsSelected() const { 512 bool Tab::IsSelected() const {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 // need to advance the animation frame. 571 // need to advance the animation frame.
572 return; 572 return;
573 } 573 }
574 574
575 TabRendererData::NetworkState old_state = data_.network_state; 575 TabRendererData::NetworkState old_state = data_.network_state;
576 data_.network_state = state; 576 data_.network_state = state;
577 AdvanceLoadingAnimation(old_state, state); 577 AdvanceLoadingAnimation(old_state, state);
578 } 578 }
579 579
580 void Tab::StartPulse() { 580 void Tab::StartPulse() {
581 ui::ThrobAnimation* animation = new ui::ThrobAnimation(this); 581 gfx::ThrobAnimation* animation = new gfx::ThrobAnimation(this);
582 animation->SetSlideDuration(kPulseDurationMs); 582 animation->SetSlideDuration(kPulseDurationMs);
583 if (animation_container_.get()) 583 if (animation_container_.get())
584 animation->SetContainer(animation_container_.get()); 584 animation->SetContainer(animation_container_.get());
585 animation->StartThrobbing(std::numeric_limits<int>::max()); 585 animation->StartThrobbing(std::numeric_limits<int>::max());
586 tab_animation_.reset(animation); 586 tab_animation_.reset(animation);
587 } 587 }
588 588
589 void Tab::StopPulse() { 589 void Tab::StopPulse() {
590 if (!tab_animation_.get()) 590 if (!tab_animation_.get())
591 return; 591 return;
592 tab_animation_->Stop(); 592 tab_animation_->Stop();
593 tab_animation_.reset(NULL); 593 tab_animation_.reset(NULL);
594 } 594 }
595 595
596 void Tab::StartMiniTabTitleAnimation() { 596 void Tab::StartMiniTabTitleAnimation() {
597 // We can only do this animation if the tab is mini because we will 597 // We can only do this animation if the tab is mini because we will
598 // upcast tab_animation back to MultiAnimation when we draw. 598 // upcast tab_animation back to MultiAnimation when we draw.
599 if (!data().mini) 599 if (!data().mini)
600 return; 600 return;
601 if (!tab_animation_.get()) { 601 if (!tab_animation_.get()) {
602 ui::MultiAnimation::Parts parts; 602 gfx::MultiAnimation::Parts parts;
603 parts.push_back( 603 parts.push_back(
604 ui::MultiAnimation::Part(kMiniTitleChangeAnimationDuration1MS, 604 gfx::MultiAnimation::Part(kMiniTitleChangeAnimationDuration1MS,
605 ui::Tween::EASE_OUT)); 605 gfx::Tween::EASE_OUT));
606 parts.push_back( 606 parts.push_back(
607 ui::MultiAnimation::Part(kMiniTitleChangeAnimationDuration2MS, 607 gfx::MultiAnimation::Part(kMiniTitleChangeAnimationDuration2MS,
608 ui::Tween::ZERO)); 608 gfx::Tween::ZERO));
609 parts.push_back( 609 parts.push_back(
610 ui::MultiAnimation::Part(kMiniTitleChangeAnimationDuration3MS, 610 gfx::MultiAnimation::Part(kMiniTitleChangeAnimationDuration3MS,
611 ui::Tween::EASE_IN)); 611 gfx::Tween::EASE_IN));
612 parts[0].start_time_ms = kMiniTitleChangeAnimationStart1MS; 612 parts[0].start_time_ms = kMiniTitleChangeAnimationStart1MS;
613 parts[0].end_time_ms = kMiniTitleChangeAnimationEnd1MS; 613 parts[0].end_time_ms = kMiniTitleChangeAnimationEnd1MS;
614 parts[2].start_time_ms = kMiniTitleChangeAnimationStart3MS; 614 parts[2].start_time_ms = kMiniTitleChangeAnimationStart3MS;
615 parts[2].end_time_ms = kMiniTitleChangeAnimationEnd3MS; 615 parts[2].end_time_ms = kMiniTitleChangeAnimationEnd3MS;
616 base::TimeDelta timeout = 616 base::TimeDelta timeout =
617 base::TimeDelta::FromMilliseconds(kMiniTitleChangeAnimationIntervalMS); 617 base::TimeDelta::FromMilliseconds(kMiniTitleChangeAnimationIntervalMS);
618 ui::MultiAnimation* animation = new ui::MultiAnimation(parts, timeout); 618 gfx::MultiAnimation* animation = new gfx::MultiAnimation(parts, timeout);
619 if (animation_container_.get()) 619 if (animation_container_.get())
620 animation->SetContainer(animation_container_.get()); 620 animation->SetContainer(animation_container_.get());
621 animation->set_delegate(this); 621 animation->set_delegate(this);
622 tab_animation_.reset(animation); 622 tab_animation_.reset(animation);
623 } 623 }
624 tab_animation_->Start(); 624 tab_animation_->Start();
625 } 625 }
626 626
627 void Tab::StopMiniTabTitleAnimation() { 627 void Tab::StopMiniTabTitleAnimation() {
628 if (!tab_animation_.get()) 628 if (!tab_animation_.get())
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 void Tab::ScheduleAudioIndicatorPaint() { 684 void Tab::ScheduleAudioIndicatorPaint() {
685 // No need to schedule a paint if another animation is active. The other 685 // No need to schedule a paint if another animation is active. The other
686 // animation will do its own scheduling. 686 // animation will do its own scheduling.
687 if (!icon_animation_) 687 if (!icon_animation_)
688 ScheduleIconPaint(); 688 ScheduleIconPaint();
689 } 689 }
690 690
691 //////////////////////////////////////////////////////////////////////////////// 691 ////////////////////////////////////////////////////////////////////////////////
692 // Tab, AnimationDelegate overrides: 692 // Tab, AnimationDelegate overrides:
693 693
694 void Tab::AnimationProgressed(const ui::Animation* animation) { 694 void Tab::AnimationProgressed(const gfx::Animation* animation) {
695 // Ignore if the pulse animation is being performed on active tab because 695 // Ignore if the pulse animation is being performed on active tab because
696 // it repaints the same image. See |Tab::PaintTabBackground()|. 696 // it repaints the same image. See |Tab::PaintTabBackground()|.
697 if (animation == tab_animation_.get() && IsActive()) 697 if (animation == tab_animation_.get() && IsActive())
698 return; 698 return;
699 SchedulePaint(); 699 SchedulePaint();
700 } 700 }
701 701
702 void Tab::AnimationCanceled(const ui::Animation* animation) { 702 void Tab::AnimationCanceled(const gfx::Animation* animation) {
703 SchedulePaint(); 703 SchedulePaint();
704 } 704 }
705 705
706 void Tab::AnimationEnded(const ui::Animation* animation) { 706 void Tab::AnimationEnded(const gfx::Animation* animation) {
707 SchedulePaint(); 707 SchedulePaint();
708 } 708 }
709 709
710 //////////////////////////////////////////////////////////////////////////////// 710 ////////////////////////////////////////////////////////////////////////////////
711 // Tab, views::ButtonListener overrides: 711 // Tab, views::ButtonListener overrides:
712 712
713 void Tab::ButtonPressed(views::Button* sender, const ui::Event& event) { 713 void Tab::ButtonPressed(views::Button* sender, const ui::Event& event) {
714 const CloseTabSource source = 714 const CloseTabSource source =
715 (event.type() == ui::ET_MOUSE_RELEASED && 715 (event.type() == ui::ET_MOUSE_RELEASED &&
716 (event.flags() & ui::EF_FROM_TOUCH) == 0) ? CLOSE_TAB_FROM_MOUSE : 716 (event.flags() & ui::EF_FROM_TOUCH) == 0) ? CLOSE_TAB_FROM_MOUSE :
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 } 1163 }
1164 } 1164 }
1165 1165
1166 void Tab::PaintTabBackground(gfx::Canvas* canvas) { 1166 void Tab::PaintTabBackground(gfx::Canvas* canvas) {
1167 if (IsActive()) { 1167 if (IsActive()) {
1168 PaintActiveTabBackground(canvas); 1168 PaintActiveTabBackground(canvas);
1169 } else { 1169 } else {
1170 if (tab_animation_.get() && 1170 if (tab_animation_.get() &&
1171 tab_animation_->is_animating() && 1171 tab_animation_->is_animating() &&
1172 data().mini) { 1172 data().mini) {
1173 ui::MultiAnimation* animation = 1173 gfx::MultiAnimation* animation =
1174 static_cast<ui::MultiAnimation*>(tab_animation_.get()); 1174 static_cast<gfx::MultiAnimation*>(tab_animation_.get());
1175 PaintInactiveTabBackgroundWithTitleChange(canvas, animation); 1175 PaintInactiveTabBackgroundWithTitleChange(canvas, animation);
1176 } else { 1176 } else {
1177 PaintInactiveTabBackground(canvas); 1177 PaintInactiveTabBackground(canvas);
1178 } 1178 }
1179 1179
1180 double throb_value = GetThrobValue(); 1180 double throb_value = GetThrobValue();
1181 if (throb_value > 0) { 1181 if (throb_value > 0) {
1182 canvas->SaveLayerAlpha(static_cast<int>(throb_value * 0xff), 1182 canvas->SaveLayerAlpha(static_cast<int>(throb_value * 0xff),
1183 GetLocalBounds()); 1183 GetLocalBounds());
1184 PaintActiveTabBackground(canvas); 1184 PaintActiveTabBackground(canvas);
1185 canvas->Restore(); 1185 canvas->Restore();
1186 } 1186 }
1187 } 1187 }
1188 } 1188 }
1189 1189
1190 void Tab::PaintInactiveTabBackgroundWithTitleChange( 1190 void Tab::PaintInactiveTabBackgroundWithTitleChange(
1191 gfx::Canvas* canvas, 1191 gfx::Canvas* canvas,
1192 ui::MultiAnimation* animation) { 1192 gfx::MultiAnimation* animation) {
1193 // Render the inactive tab background. We'll use this for clipping. 1193 // Render the inactive tab background. We'll use this for clipping.
1194 gfx::Canvas background_canvas(size(), canvas->scale_factor(), false); 1194 gfx::Canvas background_canvas(size(), canvas->scale_factor(), false);
1195 PaintInactiveTabBackground(&background_canvas); 1195 PaintInactiveTabBackground(&background_canvas);
1196 1196
1197 gfx::ImageSkia background_image(background_canvas.ExtractImageRep()); 1197 gfx::ImageSkia background_image(background_canvas.ExtractImageRep());
1198 1198
1199 // Draw a radial gradient to hover_canvas. 1199 // Draw a radial gradient to hover_canvas.
1200 gfx::Canvas hover_canvas(size(), canvas->scale_factor(), false); 1200 gfx::Canvas hover_canvas(size(), canvas->scale_factor(), false);
1201 int radius = kMiniTitleChangeGradientRadius; 1201 int radius = kMiniTitleChangeGradientRadius;
1202 int x0 = width() + radius - kMiniTitleChangeInitialXOffset; 1202 int x0 = width() + radius - kMiniTitleChangeInitialXOffset;
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 icon_animation_->Stop(); 1710 icon_animation_->Stop();
1711 icon_animation_.reset(); 1711 icon_animation_.reset();
1712 } 1712 }
1713 1713
1714 void Tab::StartCrashAnimation() { 1714 void Tab::StartCrashAnimation() {
1715 icon_animation_.reset(new FaviconCrashAnimation(this)); 1715 icon_animation_.reset(new FaviconCrashAnimation(this));
1716 icon_animation_->Start(); 1716 icon_animation_->Start();
1717 } 1717 }
1718 1718
1719 void Tab::StartRecordingAnimation() { 1719 void Tab::StartRecordingAnimation() {
1720 ui::ThrobAnimation* animation = new ui::ThrobAnimation(this); 1720 gfx::ThrobAnimation* animation = new gfx::ThrobAnimation(this);
1721 animation->SetTweenType(ui::Tween::EASE_IN_OUT); 1721 animation->SetTweenType(gfx::Tween::EASE_IN_OUT);
1722 animation->SetThrobDuration(kRecordingDurationMs); 1722 animation->SetThrobDuration(kRecordingDurationMs);
1723 animation->StartThrobbing(-1); 1723 animation->StartThrobbing(-1);
1724 icon_animation_.reset(animation); 1724 icon_animation_.reset(animation);
1725 } 1725 }
1726 1726
1727 bool Tab::IsPerformingCrashAnimation() const { 1727 bool Tab::IsPerformingCrashAnimation() const {
1728 return icon_animation_.get() && data_.IsCrashed(); 1728 return icon_animation_.get() && data_.IsCrashed();
1729 } 1729 }
1730 1730
1731 void Tab::ScheduleIconPaint() { 1731 void Tab::ScheduleIconPaint() {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 const gfx::ImageSkia& image) { 1834 const gfx::ImageSkia& image) {
1835 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); 1835 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE);
1836 ImageCacheEntry entry; 1836 ImageCacheEntry entry;
1837 entry.resource_id = resource_id; 1837 entry.resource_id = resource_id;
1838 entry.scale_factor = scale_factor; 1838 entry.scale_factor = scale_factor;
1839 entry.image = image; 1839 entry.image = image;
1840 image_cache_->push_front(entry); 1840 image_cache_->push_front(entry);
1841 if (image_cache_->size() > kMaxImageCacheSize) 1841 if (image_cache_->size() > kMaxImageCacheSize)
1842 image_cache_->pop_back(); 1842 image_cache_->pop_back();
1843 } 1843 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.h ('k') | chrome/browser/ui/views/tabs/tab_drag_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698