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

Side by Side Diff: chrome/browser/ui/gtk/tabs/tab_strip_gtk.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/gtk/tabs/tab_renderer_gtk.cc ('k') | chrome/browser/ui/gtk/throbber_gtk.h » ('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/gtk/tabs/tab_strip_gtk.h" 5 #include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 21 matching lines...) Expand all
32 #include "chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h" 32 #include "chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h"
33 #include "chrome/browser/ui/gtk/tabs/tab_strip_menu_controller.h" 33 #include "chrome/browser/ui/gtk/tabs/tab_strip_menu_controller.h"
34 #include "chrome/browser/ui/tabs/tab_strip_model.h" 34 #include "chrome/browser/ui/tabs/tab_strip_model.h"
35 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" 35 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
36 #include "content/public/browser/notification_source.h" 36 #include "content/public/browser/notification_source.h"
37 #include "content/public/browser/user_metrics.h" 37 #include "content/public/browser/user_metrics.h"
38 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
39 #include "grit/generated_resources.h" 39 #include "grit/generated_resources.h"
40 #include "grit/theme_resources.h" 40 #include "grit/theme_resources.h"
41 #include "grit/ui_resources.h" 41 #include "grit/ui_resources.h"
42 #include "ui/base/animation/animation_delegate.h"
43 #include "ui/base/animation/slide_animation.h"
44 #include "ui/base/dragdrop/gtk_dnd_util.h" 42 #include "ui/base/dragdrop/gtk_dnd_util.h"
45 #include "ui/base/gtk/gtk_screen_util.h" 43 #include "ui/base/gtk/gtk_screen_util.h"
46 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
47 #include "ui/base/resource/resource_bundle.h" 45 #include "ui/base/resource/resource_bundle.h"
46 #include "ui/gfx/animation/animation_delegate.h"
47 #include "ui/gfx/animation/slide_animation.h"
48 #include "ui/gfx/gtk_compat.h" 48 #include "ui/gfx/gtk_compat.h"
49 #include "ui/gfx/gtk_util.h" 49 #include "ui/gfx/gtk_util.h"
50 #include "ui/gfx/image/image.h" 50 #include "ui/gfx/image/image.h"
51 #include "ui/gfx/point.h" 51 #include "ui/gfx/point.h"
52 52
53 using content::UserMetricsAction; 53 using content::UserMetricsAction;
54 using content::WebContents; 54 using content::WebContents;
55 55
56 namespace { 56 namespace {
57 57
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 124 }
125 125
126 } // namespace 126 } // namespace
127 127
128 //////////////////////////////////////////////////////////////////////////////// 128 ////////////////////////////////////////////////////////////////////////////////
129 // 129 //
130 // TabAnimation 130 // TabAnimation
131 // 131 //
132 // A base class for all TabStrip animations. 132 // A base class for all TabStrip animations.
133 // 133 //
134 class TabStripGtk::TabAnimation : public ui::AnimationDelegate { 134 class TabStripGtk::TabAnimation : public gfx::AnimationDelegate {
135 public: 135 public:
136 friend class TabStripGtk; 136 friend class TabStripGtk;
137 137
138 // Possible types of animation. 138 // Possible types of animation.
139 enum Type { 139 enum Type {
140 INSERT, 140 INSERT,
141 REMOVE, 141 REMOVE,
142 MOVE, 142 MOVE,
143 RESIZE, 143 RESIZE,
144 MINI, 144 MINI,
145 MINI_MOVE 145 MINI_MOVE
146 }; 146 };
147 147
148 TabAnimation(TabStripGtk* tabstrip, Type type) 148 TabAnimation(TabStripGtk* tabstrip, Type type)
149 : tabstrip_(tabstrip), 149 : tabstrip_(tabstrip),
150 animation_(this), 150 animation_(this),
151 start_selected_width_(0), 151 start_selected_width_(0),
152 start_unselected_width_(0), 152 start_unselected_width_(0),
153 end_selected_width_(0), 153 end_selected_width_(0),
154 end_unselected_width_(0), 154 end_unselected_width_(0),
155 layout_on_completion_(false), 155 layout_on_completion_(false),
156 type_(type) { 156 type_(type) {
157 } 157 }
158 virtual ~TabAnimation() {} 158 virtual ~TabAnimation() {}
159 159
160 Type type() const { return type_; } 160 Type type() const { return type_; }
161 161
162 void Start() { 162 void Start() {
163 animation_.SetSlideDuration(GetDuration()); 163 animation_.SetSlideDuration(GetDuration());
164 animation_.SetTweenType(ui::Tween::EASE_OUT); 164 animation_.SetTweenType(gfx::Tween::EASE_OUT);
165 if (!animation_.IsShowing()) { 165 if (!animation_.IsShowing()) {
166 animation_.Reset(); 166 animation_.Reset();
167 animation_.Show(); 167 animation_.Show();
168 } 168 }
169 } 169 }
170 170
171 void Stop() { 171 void Stop() {
172 animation_.Stop(); 172 animation_.Stop();
173 } 173 }
174 174
(...skipping 18 matching lines...) Expand all
193 193
194 if (animation) { 194 if (animation) {
195 double specified_tab_width = animation->GetWidthForTab(index); 195 double specified_tab_width = animation->GetWidthForTab(index);
196 if (specified_tab_width != -1) 196 if (specified_tab_width != -1)
197 tab_width = specified_tab_width; 197 tab_width = specified_tab_width;
198 } 198 }
199 199
200 return tab_width; 200 return tab_width;
201 } 201 }
202 202
203 // Overridden from ui::AnimationDelegate: 203 // Overridden from gfx::AnimationDelegate:
204 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE { 204 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE {
205 tabstrip_->AnimationLayout(end_unselected_width_); 205 tabstrip_->AnimationLayout(end_unselected_width_);
206 } 206 }
207 207
208 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE { 208 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE {
209 tabstrip_->FinishAnimation(this, layout_on_completion_); 209 tabstrip_->FinishAnimation(this, layout_on_completion_);
210 // This object is destroyed now, so we can't do anything else after this. 210 // This object is destroyed now, so we can't do anything else after this.
211 } 211 }
212 212
213 virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE { 213 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE {
214 AnimationEnded(animation); 214 AnimationEnded(animation);
215 } 215 }
216 216
217 // Returns the gap before the tab at the specified index. Subclass if during 217 // Returns the gap before the tab at the specified index. Subclass if during
218 // an animation you need to insert a gap before a tab. 218 // an animation you need to insert a gap before a tab.
219 virtual double GetGapWidth(int index) { 219 virtual double GetGapWidth(int index) {
220 return 0; 220 return 0;
221 } 221 }
222 222
223 protected: 223 protected:
(...skipping 27 matching lines...) Expand all
251 start_unselected_width_ -= minimum_tab_width / start_tab_count; 251 start_unselected_width_ -= minimum_tab_width / start_tab_count;
252 } 252 }
253 253
254 tabstrip_->GenerateIdealBounds(); 254 tabstrip_->GenerateIdealBounds();
255 tabstrip_->GetDesiredTabWidths(end_tab_count, end_mini_count, 255 tabstrip_->GetDesiredTabWidths(end_tab_count, end_mini_count,
256 &end_unselected_width_, 256 &end_unselected_width_,
257 &end_selected_width_); 257 &end_selected_width_);
258 } 258 }
259 259
260 TabStripGtk* tabstrip_; 260 TabStripGtk* tabstrip_;
261 ui::SlideAnimation animation_; 261 gfx::SlideAnimation animation_;
262 262
263 double start_selected_width_; 263 double start_selected_width_;
264 double start_unselected_width_; 264 double start_unselected_width_;
265 double end_selected_width_; 265 double end_selected_width_;
266 double end_unselected_width_; 266 double end_unselected_width_;
267 267
268 private: 268 private:
269 // True if a complete re-layout is required upon completion of the animation. 269 // True if a complete re-layout is required upon completion of the animation.
270 // Subclasses set this if they don't perform a complete layout 270 // Subclasses set this if they don't perform a complete layout
271 // themselves and canceling the animation may leave the strip in an 271 // themselves and canceling the animation may leave the strip in an
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 // the start of the animation. 405 // the start of the animation.
406 if (tab->IsActive()) { 406 if (tab->IsActive()) {
407 double delta = end_selected_width_ - start_selected_width_; 407 double delta = end_selected_width_ - start_selected_width_;
408 return start_selected_width_ + (delta * animation_.GetCurrentValue()); 408 return start_selected_width_ + (delta * animation_.GetCurrentValue());
409 } 409 }
410 410
411 double delta = end_unselected_width_ - start_unselected_width_; 411 double delta = end_unselected_width_ - start_unselected_width_;
412 return start_unselected_width_ + (delta * animation_.GetCurrentValue()); 412 return start_unselected_width_ + (delta * animation_.GetCurrentValue());
413 } 413 }
414 414
415 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE { 415 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE {
416 tabstrip_->RemoveTabAt(index_); 416 tabstrip_->RemoveTabAt(index_);
417 TabStripGtk::TabAnimation::AnimationEnded(animation); 417 TabStripGtk::TabAnimation::AnimationEnded(animation);
418 } 418 }
419 419
420 private: 420 private:
421 int index_; 421 int index_;
422 422
423 DISALLOW_COPY_AND_ASSIGN(RemoveTabAnimation); 423 DISALLOW_COPY_AND_ASSIGN(RemoveTabAnimation);
424 }; 424 };
425 425
426 //////////////////////////////////////////////////////////////////////////////// 426 ////////////////////////////////////////////////////////////////////////////////
427 427
428 // Handles the movement of a Tab from one position to another. 428 // Handles the movement of a Tab from one position to another.
429 class MoveTabAnimation : public TabStripGtk::TabAnimation { 429 class MoveTabAnimation : public TabStripGtk::TabAnimation {
430 public: 430 public:
431 MoveTabAnimation(TabStripGtk* tabstrip, int tab_a_index, int tab_b_index) 431 MoveTabAnimation(TabStripGtk* tabstrip, int tab_a_index, int tab_b_index)
432 : TabAnimation(tabstrip, MOVE), 432 : TabAnimation(tabstrip, MOVE),
433 start_tab_a_bounds_(tabstrip_->GetIdealBounds(tab_b_index)), 433 start_tab_a_bounds_(tabstrip_->GetIdealBounds(tab_b_index)),
434 start_tab_b_bounds_(tabstrip_->GetIdealBounds(tab_a_index)) { 434 start_tab_b_bounds_(tabstrip_->GetIdealBounds(tab_a_index)) {
435 tab_a_ = tabstrip_->GetTabAt(tab_a_index); 435 tab_a_ = tabstrip_->GetTabAt(tab_a_index);
436 tab_b_ = tabstrip_->GetTabAt(tab_b_index); 436 tab_b_ = tabstrip_->GetTabAt(tab_b_index);
437 437
438 // Since we don't do a full TabStrip re-layout, we need to force a full 438 // Since we don't do a full TabStrip re-layout, we need to force a full
439 // layout upon completion since we're not guaranteed to be in a good state 439 // layout upon completion since we're not guaranteed to be in a good state
440 // if for example the animation is canceled. 440 // if for example the animation is canceled.
441 set_layout_on_completion(true); 441 set_layout_on_completion(true);
442 } 442 }
443 virtual ~MoveTabAnimation() {} 443 virtual ~MoveTabAnimation() {}
444 444
445 // Overridden from ui::AnimationDelegate: 445 // Overridden from gfx::AnimationDelegate:
446 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE { 446 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE {
447 // Position Tab A 447 // Position Tab A
448 double distance = start_tab_b_bounds_.x() - start_tab_a_bounds_.x(); 448 double distance = start_tab_b_bounds_.x() - start_tab_a_bounds_.x();
449 double delta = distance * animation_.GetCurrentValue(); 449 double delta = distance * animation_.GetCurrentValue();
450 double new_x = start_tab_a_bounds_.x() + delta; 450 double new_x = start_tab_a_bounds_.x() + delta;
451 gfx::Rect bounds(Round(new_x), start_tab_a_bounds_.y(), tab_a_->width(), 451 gfx::Rect bounds(Round(new_x), start_tab_a_bounds_.y(), tab_a_->width(),
452 tab_a_->height()); 452 tab_a_->height());
453 tabstrip_->SetTabBounds(tab_a_, bounds); 453 tabstrip_->SetTabBounds(tab_a_, bounds);
454 454
455 // Position Tab B 455 // Position Tab B
456 distance = start_tab_a_bounds_.x() - start_tab_b_bounds_.x(); 456 distance = start_tab_a_bounds_.x() - start_tab_b_bounds_.x();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 explicit ResizeLayoutAnimation(TabStripGtk* tabstrip) 488 explicit ResizeLayoutAnimation(TabStripGtk* tabstrip)
489 : TabAnimation(tabstrip, RESIZE) { 489 : TabAnimation(tabstrip, RESIZE) {
490 int tab_count = tabstrip->GetTabCount(); 490 int tab_count = tabstrip->GetTabCount();
491 int mini_tab_count = tabstrip->GetMiniTabCount(); 491 int mini_tab_count = tabstrip->GetMiniTabCount();
492 GenerateStartAndEndWidths(tab_count, tab_count, mini_tab_count, 492 GenerateStartAndEndWidths(tab_count, tab_count, mini_tab_count,
493 mini_tab_count); 493 mini_tab_count);
494 InitStartState(); 494 InitStartState();
495 } 495 }
496 virtual ~ResizeLayoutAnimation() {} 496 virtual ~ResizeLayoutAnimation() {}
497 497
498 // Overridden from ui::AnimationDelegate: 498 // Overridden from gfx::AnimationDelegate:
499 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE { 499 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE {
500 tabstrip_->needs_resize_layout_ = false; 500 tabstrip_->needs_resize_layout_ = false;
501 TabStripGtk::TabAnimation::AnimationEnded(animation); 501 TabStripGtk::TabAnimation::AnimationEnded(animation);
502 } 502 }
503 503
504 protected: 504 protected:
505 // Overridden from TabStripGtk::TabAnimation: 505 // Overridden from TabStripGtk::TabAnimation:
506 virtual int GetDuration() const OVERRIDE { 506 virtual int GetDuration() const OVERRIDE {
507 return kResizeLayoutAnimationDurationMs; 507 return kResizeLayoutAnimationDurationMs;
508 } 508 }
509 509
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 if (tabstrip->GetTabAt(to_index)->mini()) 622 if (tabstrip->GetTabAt(to_index)->mini())
623 start_mini_count--; 623 start_mini_count--;
624 else 624 else
625 start_mini_count++; 625 start_mini_count++;
626 GenerateStartAndEndWidths(tab_count, tab_count, start_mini_count, 626 GenerateStartAndEndWidths(tab_count, tab_count, start_mini_count,
627 end_mini_count); 627 end_mini_count);
628 target_bounds_ = tabstrip->GetIdealBounds(to_index); 628 target_bounds_ = tabstrip->GetIdealBounds(to_index);
629 tab_->set_animating_mini_change(true); 629 tab_->set_animating_mini_change(true);
630 } 630 }
631 631
632 // Overridden from ui::AnimationDelegate: 632 // Overridden from gfx::AnimationDelegate:
633 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE { 633 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE {
634 // Do the normal layout. 634 // Do the normal layout.
635 TabAnimation::AnimationProgressed(animation); 635 TabAnimation::AnimationProgressed(animation);
636 636
637 // Then special case the position of the tab being moved. 637 // Then special case the position of the tab being moved.
638 int x = animation_.CurrentValueBetween(start_bounds_.x(), 638 int x = animation_.CurrentValueBetween(start_bounds_.x(),
639 target_bounds_.x()); 639 target_bounds_.x());
640 int width = animation_.CurrentValueBetween(start_bounds_.width(), 640 int width = animation_.CurrentValueBetween(start_bounds_.width(),
641 target_bounds_.width()); 641 target_bounds_.width());
642 gfx::Rect tab_bounds(x, start_bounds_.y(), width, 642 gfx::Rect tab_bounds(x, start_bounds_.y(), width,
643 start_bounds_.height()); 643 start_bounds_.height());
644 tabstrip_->SetTabBounds(tab_, tab_bounds); 644 tabstrip_->SetTabBounds(tab_, tab_bounds);
645 } 645 }
646 646
647 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE { 647 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE {
648 tabstrip_->needs_resize_layout_ = false; 648 tabstrip_->needs_resize_layout_ = false;
649 TabStripGtk::TabAnimation::AnimationEnded(animation); 649 TabStripGtk::TabAnimation::AnimationEnded(animation);
650 } 650 }
651 651
652 virtual double GetGapWidth(int index) OVERRIDE { 652 virtual double GetGapWidth(int index) OVERRIDE {
653 if (to_index_ < from_index_) { 653 if (to_index_ < from_index_) {
654 // The tab was made mini. 654 // The tab was made mini.
655 if (index == to_index_) { 655 if (index == to_index_) {
656 double current_size = 656 double current_size =
657 animation_.CurrentValueBetween(0, target_bounds_.width()); 657 animation_.CurrentValueBetween(0, target_bounds_.width());
(...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after
2268 2268
2269 void TabStripGtk::SetNewTabButtonBackground() { 2269 void TabStripGtk::SetNewTabButtonBackground() {
2270 SkColor color = theme_service_->GetColor( 2270 SkColor color = theme_service_->GetColor(
2271 ThemeProperties::COLOR_BUTTON_BACKGROUND); 2271 ThemeProperties::COLOR_BUTTON_BACKGROUND);
2272 SkBitmap background = theme_service_->GetImageNamed( 2272 SkBitmap background = theme_service_->GetImageNamed(
2273 IDR_THEME_WINDOW_CONTROL_BACKGROUND).AsBitmap(); 2273 IDR_THEME_WINDOW_CONTROL_BACKGROUND).AsBitmap();
2274 SkBitmap mask = theme_service_->GetImageNamed( 2274 SkBitmap mask = theme_service_->GetImageNamed(
2275 IDR_NEWTAB_BUTTON_MASK).AsBitmap(); 2275 IDR_NEWTAB_BUTTON_MASK).AsBitmap();
2276 newtab_button_->SetBackground(color, background, mask); 2276 newtab_button_->SetBackground(color, background, mask);
2277 } 2277 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc ('k') | chrome/browser/ui/gtk/throbber_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698