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

Side by Side Diff: chrome/browser/gtk/tabs/tab_strip_gtk.cc

Issue 6154001: Move animation code to new ui/base/animation directory.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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) 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/gtk/tabs/tab_strip_gtk.h" 5 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/animation_delegate.h"
10 #include "app/gtk_dnd_util.h" 9 #include "app/gtk_dnd_util.h"
11 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
12 #include "app/slide_animation.h"
13 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
14 #include "base/string_util.h" 12 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/autocomplete/autocomplete.h" 14 #include "chrome/browser/autocomplete/autocomplete.h"
17 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
18 #include "chrome/browser/autocomplete/autocomplete_match.h" 16 #include "chrome/browser/autocomplete/autocomplete_match.h"
19 #include "chrome/browser/gtk/browser_window_gtk.h" 17 #include "chrome/browser/gtk/browser_window_gtk.h"
20 #include "chrome/browser/gtk/custom_button.h" 18 #include "chrome/browser/gtk/custom_button.h"
21 #include "chrome/browser/gtk/gtk_theme_provider.h" 19 #include "chrome/browser/gtk/gtk_theme_provider.h"
22 #include "chrome/browser/gtk/gtk_util.h" 20 #include "chrome/browser/gtk/gtk_util.h"
23 #include "chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h" 21 #include "chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h"
24 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/tab_contents/tab_contents.h" 23 #include "chrome/browser/tab_contents/tab_contents.h"
26 #include "chrome/browser/tabs/tab_strip_model_delegate.h" 24 #include "chrome/browser/tabs/tab_strip_model_delegate.h"
27 #include "chrome/browser/themes/browser_theme_provider.h" 25 #include "chrome/browser/themes/browser_theme_provider.h"
28 #include "chrome/browser/ui/browser.h" 26 #include "chrome/browser/ui/browser.h"
29 #include "chrome/browser/ui/browser_navigator.h" 27 #include "chrome/browser/ui/browser_navigator.h"
30 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
31 #include "chrome/common/notification_service.h" 29 #include "chrome/common/notification_service.h"
32 #include "chrome/common/notification_type.h" 30 #include "chrome/common/notification_type.h"
33 #include "gfx/gtk_util.h" 31 #include "gfx/gtk_util.h"
34 #include "gfx/point.h" 32 #include "gfx/point.h"
35 #include "grit/app_resources.h" 33 #include "grit/app_resources.h"
36 #include "grit/theme_resources.h" 34 #include "grit/theme_resources.h"
35 #include "ui/base/animation/animation_delegate.h"
36 #include "ui/base/animation/slide_animation.h"
37 37
38 namespace { 38 namespace {
39 39
40 const int kDefaultAnimationDurationMs = 100; 40 const int kDefaultAnimationDurationMs = 100;
41 const int kResizeLayoutAnimationDurationMs = 166; 41 const int kResizeLayoutAnimationDurationMs = 166;
42 const int kReorderAnimationDurationMs = 166; 42 const int kReorderAnimationDurationMs = 166;
43 const int kAnimateToBoundsDurationMs = 150; 43 const int kAnimateToBoundsDurationMs = 150;
44 const int kMiniTabAnimationDurationMs = 150; 44 const int kMiniTabAnimationDurationMs = 150;
45 45
46 const int kNewTabButtonHOffset = -5; 46 const int kNewTabButtonHOffset = -5;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 101
102 } // namespace 102 } // namespace
103 103
104 //////////////////////////////////////////////////////////////////////////////// 104 ////////////////////////////////////////////////////////////////////////////////
105 // 105 //
106 // TabAnimation 106 // TabAnimation
107 // 107 //
108 // A base class for all TabStrip animations. 108 // A base class for all TabStrip animations.
109 // 109 //
110 class TabStripGtk::TabAnimation : public AnimationDelegate { 110 class TabStripGtk::TabAnimation : public ui::AnimationDelegate {
111 public: 111 public:
112 friend class TabStripGtk; 112 friend class TabStripGtk;
113 113
114 // Possible types of animation. 114 // Possible types of animation.
115 enum Type { 115 enum Type {
116 INSERT, 116 INSERT,
117 REMOVE, 117 REMOVE,
118 MOVE, 118 MOVE,
119 RESIZE, 119 RESIZE,
120 MINI, 120 MINI,
121 MINI_MOVE 121 MINI_MOVE
122 }; 122 };
123 123
124 TabAnimation(TabStripGtk* tabstrip, Type type) 124 TabAnimation(TabStripGtk* tabstrip, Type type)
125 : tabstrip_(tabstrip), 125 : tabstrip_(tabstrip),
126 animation_(this), 126 animation_(this),
127 start_selected_width_(0), 127 start_selected_width_(0),
128 start_unselected_width_(0), 128 start_unselected_width_(0),
129 end_selected_width_(0), 129 end_selected_width_(0),
130 end_unselected_width_(0), 130 end_unselected_width_(0),
131 layout_on_completion_(false), 131 layout_on_completion_(false),
132 type_(type) { 132 type_(type) {
133 } 133 }
134 virtual ~TabAnimation() {} 134 virtual ~TabAnimation() {}
135 135
136 Type type() const { return type_; } 136 Type type() const { return type_; }
137 137
138 void Start() { 138 void Start() {
139 animation_.SetSlideDuration(GetDuration()); 139 animation_.SetSlideDuration(GetDuration());
140 animation_.SetTweenType(Tween::EASE_OUT); 140 animation_.SetTweenType(ui::Tween::EASE_OUT);
141 if (!animation_.IsShowing()) { 141 if (!animation_.IsShowing()) {
142 animation_.Reset(); 142 animation_.Reset();
143 animation_.Show(); 143 animation_.Show();
144 } 144 }
145 } 145 }
146 146
147 void Stop() { 147 void Stop() {
148 animation_.Stop(); 148 animation_.Stop();
149 } 149 }
150 150
(...skipping 18 matching lines...) Expand all
169 169
170 if (animation) { 170 if (animation) {
171 double specified_tab_width = animation->GetWidthForTab(index); 171 double specified_tab_width = animation->GetWidthForTab(index);
172 if (specified_tab_width != -1) 172 if (specified_tab_width != -1)
173 tab_width = specified_tab_width; 173 tab_width = specified_tab_width;
174 } 174 }
175 175
176 return tab_width; 176 return tab_width;
177 } 177 }
178 178
179 // Overridden from AnimationDelegate: 179 // Overridden from ui::AnimationDelegate:
180 virtual void AnimationProgressed(const Animation* animation) { 180 virtual void AnimationProgressed(const ui::Animation* animation) {
181 tabstrip_->AnimationLayout(end_unselected_width_); 181 tabstrip_->AnimationLayout(end_unselected_width_);
182 } 182 }
183 183
184 virtual void AnimationEnded(const Animation* animation) { 184 virtual void AnimationEnded(const ui::Animation* animation) {
185 tabstrip_->FinishAnimation(this, layout_on_completion_); 185 tabstrip_->FinishAnimation(this, layout_on_completion_);
186 // This object is destroyed now, so we can't do anything else after this. 186 // This object is destroyed now, so we can't do anything else after this.
187 } 187 }
188 188
189 virtual void AnimationCanceled(const Animation* animation) { 189 virtual void AnimationCanceled(const ui::Animation* animation) {
190 AnimationEnded(animation); 190 AnimationEnded(animation);
191 } 191 }
192 192
193 // Returns the gap before the tab at the specified index. Subclass if during 193 // Returns the gap before the tab at the specified index. Subclass if during
194 // an animation you need to insert a gap before a tab. 194 // an animation you need to insert a gap before a tab.
195 virtual double GetGapWidth(int index) { 195 virtual double GetGapWidth(int index) {
196 return 0; 196 return 0;
197 } 197 }
198 198
199 protected: 199 protected:
(...skipping 27 matching lines...) Expand all
227 start_unselected_width_ -= minimum_tab_width / start_tab_count; 227 start_unselected_width_ -= minimum_tab_width / start_tab_count;
228 } 228 }
229 229
230 tabstrip_->GenerateIdealBounds(); 230 tabstrip_->GenerateIdealBounds();
231 tabstrip_->GetDesiredTabWidths(end_tab_count, end_mini_count, 231 tabstrip_->GetDesiredTabWidths(end_tab_count, end_mini_count,
232 &end_unselected_width_, 232 &end_unselected_width_,
233 &end_selected_width_); 233 &end_selected_width_);
234 } 234 }
235 235
236 TabStripGtk* tabstrip_; 236 TabStripGtk* tabstrip_;
237 SlideAnimation animation_; 237 ui::SlideAnimation animation_;
238 238
239 double start_selected_width_; 239 double start_selected_width_;
240 double start_unselected_width_; 240 double start_unselected_width_;
241 double end_selected_width_; 241 double end_selected_width_;
242 double end_unselected_width_; 242 double end_unselected_width_;
243 243
244 private: 244 private:
245 // True if a complete re-layout is required upon completion of the animation. 245 // True if a complete re-layout is required upon completion of the animation.
246 // Subclasses set this if they don't perform a complete layout 246 // Subclasses set this if they don't perform a complete layout
247 // themselves and canceling the animation may leave the strip in an 247 // themselves and canceling the animation may leave the strip in an
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // the start of the animation. 381 // the start of the animation.
382 if (tab->IsSelected()) { 382 if (tab->IsSelected()) {
383 double delta = end_selected_width_ - start_selected_width_; 383 double delta = end_selected_width_ - start_selected_width_;
384 return start_selected_width_ + (delta * animation_.GetCurrentValue()); 384 return start_selected_width_ + (delta * animation_.GetCurrentValue());
385 } 385 }
386 386
387 double delta = end_unselected_width_ - start_unselected_width_; 387 double delta = end_unselected_width_ - start_unselected_width_;
388 return start_unselected_width_ + (delta * animation_.GetCurrentValue()); 388 return start_unselected_width_ + (delta * animation_.GetCurrentValue());
389 } 389 }
390 390
391 virtual void AnimationEnded(const Animation* animation) { 391 virtual void AnimationEnded(const ui::Animation* animation) {
392 tabstrip_->RemoveTabAt(index_); 392 tabstrip_->RemoveTabAt(index_);
393 TabStripGtk::TabAnimation::AnimationEnded(animation); 393 TabStripGtk::TabAnimation::AnimationEnded(animation);
394 } 394 }
395 395
396 private: 396 private:
397 int index_; 397 int index_;
398 398
399 DISALLOW_COPY_AND_ASSIGN(RemoveTabAnimation); 399 DISALLOW_COPY_AND_ASSIGN(RemoveTabAnimation);
400 }; 400 };
401 401
402 //////////////////////////////////////////////////////////////////////////////// 402 ////////////////////////////////////////////////////////////////////////////////
403 403
404 // Handles the movement of a Tab from one position to another. 404 // Handles the movement of a Tab from one position to another.
405 class MoveTabAnimation : public TabStripGtk::TabAnimation { 405 class MoveTabAnimation : public TabStripGtk::TabAnimation {
406 public: 406 public:
407 MoveTabAnimation(TabStripGtk* tabstrip, int tab_a_index, int tab_b_index) 407 MoveTabAnimation(TabStripGtk* tabstrip, int tab_a_index, int tab_b_index)
408 : TabAnimation(tabstrip, MOVE), 408 : TabAnimation(tabstrip, MOVE),
409 start_tab_a_bounds_(tabstrip_->GetIdealBounds(tab_b_index)), 409 start_tab_a_bounds_(tabstrip_->GetIdealBounds(tab_b_index)),
410 start_tab_b_bounds_(tabstrip_->GetIdealBounds(tab_a_index)) { 410 start_tab_b_bounds_(tabstrip_->GetIdealBounds(tab_a_index)) {
411 tab_a_ = tabstrip_->GetTabAt(tab_a_index); 411 tab_a_ = tabstrip_->GetTabAt(tab_a_index);
412 tab_b_ = tabstrip_->GetTabAt(tab_b_index); 412 tab_b_ = tabstrip_->GetTabAt(tab_b_index);
413 413
414 // Since we don't do a full TabStrip re-layout, we need to force a full 414 // Since we don't do a full TabStrip re-layout, we need to force a full
415 // layout upon completion since we're not guaranteed to be in a good state 415 // layout upon completion since we're not guaranteed to be in a good state
416 // if for example the animation is canceled. 416 // if for example the animation is canceled.
417 set_layout_on_completion(true); 417 set_layout_on_completion(true);
418 } 418 }
419 virtual ~MoveTabAnimation() {} 419 virtual ~MoveTabAnimation() {}
420 420
421 // Overridden from AnimationDelegate: 421 // Overridden from ui::AnimationDelegate:
422 virtual void AnimationProgressed(const Animation* animation) { 422 virtual void AnimationProgressed(const ui::Animation* animation) {
423 // Position Tab A 423 // Position Tab A
424 double distance = start_tab_b_bounds_.x() - start_tab_a_bounds_.x(); 424 double distance = start_tab_b_bounds_.x() - start_tab_a_bounds_.x();
425 double delta = distance * animation_.GetCurrentValue(); 425 double delta = distance * animation_.GetCurrentValue();
426 double new_x = start_tab_a_bounds_.x() + delta; 426 double new_x = start_tab_a_bounds_.x() + delta;
427 gfx::Rect bounds(Round(new_x), start_tab_a_bounds_.y(), tab_a_->width(), 427 gfx::Rect bounds(Round(new_x), start_tab_a_bounds_.y(), tab_a_->width(),
428 tab_a_->height()); 428 tab_a_->height());
429 tabstrip_->SetTabBounds(tab_a_, bounds); 429 tabstrip_->SetTabBounds(tab_a_, bounds);
430 430
431 // Position Tab B 431 // Position Tab B
432 distance = start_tab_a_bounds_.x() - start_tab_b_bounds_.x(); 432 distance = start_tab_a_bounds_.x() - start_tab_b_bounds_.x();
(...skipping 29 matching lines...) Expand all
462 explicit ResizeLayoutAnimation(TabStripGtk* tabstrip) 462 explicit ResizeLayoutAnimation(TabStripGtk* tabstrip)
463 : TabAnimation(tabstrip, RESIZE) { 463 : TabAnimation(tabstrip, RESIZE) {
464 int tab_count = tabstrip->GetTabCount(); 464 int tab_count = tabstrip->GetTabCount();
465 int mini_tab_count = tabstrip->GetMiniTabCount(); 465 int mini_tab_count = tabstrip->GetMiniTabCount();
466 GenerateStartAndEndWidths(tab_count, tab_count, mini_tab_count, 466 GenerateStartAndEndWidths(tab_count, tab_count, mini_tab_count,
467 mini_tab_count); 467 mini_tab_count);
468 InitStartState(); 468 InitStartState();
469 } 469 }
470 virtual ~ResizeLayoutAnimation() {} 470 virtual ~ResizeLayoutAnimation() {}
471 471
472 // Overridden from AnimationDelegate: 472 // Overridden from ui::AnimationDelegate:
473 virtual void AnimationEnded(const Animation* animation) { 473 virtual void AnimationEnded(const ui::Animation* animation) {
474 tabstrip_->needs_resize_layout_ = false; 474 tabstrip_->needs_resize_layout_ = false;
475 TabStripGtk::TabAnimation::AnimationEnded(animation); 475 TabStripGtk::TabAnimation::AnimationEnded(animation);
476 } 476 }
477 477
478 protected: 478 protected:
479 // Overridden from TabStripGtk::TabAnimation: 479 // Overridden from TabStripGtk::TabAnimation:
480 virtual int GetDuration() const { 480 virtual int GetDuration() const {
481 return kResizeLayoutAnimationDurationMs; 481 return kResizeLayoutAnimationDurationMs;
482 } 482 }
483 483
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 if (tabstrip->GetTabAt(to_index)->mini()) 596 if (tabstrip->GetTabAt(to_index)->mini())
597 start_mini_count--; 597 start_mini_count--;
598 else 598 else
599 start_mini_count++; 599 start_mini_count++;
600 GenerateStartAndEndWidths(tab_count, tab_count, start_mini_count, 600 GenerateStartAndEndWidths(tab_count, tab_count, start_mini_count,
601 end_mini_count); 601 end_mini_count);
602 target_bounds_ = tabstrip->GetIdealBounds(to_index); 602 target_bounds_ = tabstrip->GetIdealBounds(to_index);
603 tab_->set_animating_mini_change(true); 603 tab_->set_animating_mini_change(true);
604 } 604 }
605 605
606 // Overridden from AnimationDelegate: 606 // Overridden from ui::AnimationDelegate:
607 virtual void AnimationProgressed(const Animation* animation) { 607 virtual void AnimationProgressed(const ui::Animation* animation) {
608 // Do the normal layout. 608 // Do the normal layout.
609 TabAnimation::AnimationProgressed(animation); 609 TabAnimation::AnimationProgressed(animation);
610 610
611 // Then special case the position of the tab being moved. 611 // Then special case the position of the tab being moved.
612 int x = animation_.CurrentValueBetween(start_bounds_.x(), 612 int x = animation_.CurrentValueBetween(start_bounds_.x(),
613 target_bounds_.x()); 613 target_bounds_.x());
614 int width = animation_.CurrentValueBetween(start_bounds_.width(), 614 int width = animation_.CurrentValueBetween(start_bounds_.width(),
615 target_bounds_.width()); 615 target_bounds_.width());
616 gfx::Rect tab_bounds(x, start_bounds_.y(), width, 616 gfx::Rect tab_bounds(x, start_bounds_.y(), width,
617 start_bounds_.height()); 617 start_bounds_.height());
618 tabstrip_->SetTabBounds(tab_, tab_bounds); 618 tabstrip_->SetTabBounds(tab_, tab_bounds);
619 } 619 }
620 620
621 virtual void AnimationEnded(const Animation* animation) { 621 virtual void AnimationEnded(const ui::Animation* animation) {
622 tabstrip_->needs_resize_layout_ = false; 622 tabstrip_->needs_resize_layout_ = false;
623 TabStripGtk::TabAnimation::AnimationEnded(animation); 623 TabStripGtk::TabAnimation::AnimationEnded(animation);
624 } 624 }
625 625
626 virtual double GetGapWidth(int index) { 626 virtual double GetGapWidth(int index) {
627 if (to_index_ < from_index_) { 627 if (to_index_ < from_index_) {
628 // The tab was made mini. 628 // The tab was made mini.
629 if (index == to_index_) { 629 if (index == to_index_) {
630 double current_size = 630 double current_size =
631 animation_.CurrentValueBetween(0, target_bounds_.width()); 631 animation_.CurrentValueBetween(0, target_bounds_.width());
(...skipping 1421 matching lines...) Expand 10 before | Expand all | Expand 10 after
2053 2053
2054 // Let the middle mouse button initiate clicks as well. 2054 // Let the middle mouse button initiate clicks as well.
2055 gtk_util::SetButtonTriggersNavigation(button->widget()); 2055 gtk_util::SetButtonTriggersNavigation(button->widget());
2056 g_signal_connect(button->widget(), "clicked", 2056 g_signal_connect(button->widget(), "clicked",
2057 G_CALLBACK(OnNewTabClickedThunk), this); 2057 G_CALLBACK(OnNewTabClickedThunk), this);
2058 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); 2058 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS);
2059 gtk_fixed_put(GTK_FIXED(tabstrip_.get()), button->widget(), 0, 0); 2059 gtk_fixed_put(GTK_FIXED(tabstrip_.get()), button->widget(), 0, 0);
2060 2060
2061 return button; 2061 return button;
2062 } 2062 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/tabs/tab_renderer_gtk.cc ('k') | chrome/browser/gtk/translate/translate_infobar_base_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698