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/gtk/slide_animator_gtk.h" | 5 #include "chrome/browser/gtk/slide_animator_gtk.h" |
6 | 6 |
7 #include "app/animation.h" | |
8 #include "app/slide_animation.h" | |
9 | |
10 #include "chrome/browser/gtk/gtk_expanded_container.h" | 7 #include "chrome/browser/gtk/gtk_expanded_container.h" |
| 8 #include "ui/base/animation/animation.h" |
| 9 #include "ui/base/animation/slide_animation.h" |
11 | 10 |
12 namespace { | 11 namespace { |
13 | 12 |
14 void OnChildSizeRequest(GtkWidget* expanded, | 13 void OnChildSizeRequest(GtkWidget* expanded, |
15 GtkWidget* child, | 14 GtkWidget* child, |
16 GtkRequisition* requisition, | 15 GtkRequisition* requisition, |
17 gpointer control_child_size) { | 16 gpointer control_child_size) { |
18 // If |control_child_size| is true, then we want |child_| to match the width | 17 // If |control_child_size| is true, then we want |child_| to match the width |
19 // of the |widget_|, but the height of |child_| should not change. | 18 // of the |widget_|, but the height of |child_| should not change. |
20 if (!GPOINTER_TO_INT(control_child_size)) { | 19 if (!GPOINTER_TO_INT(control_child_size)) { |
(...skipping 28 matching lines...) Expand all Loading... |
49 | 48 |
50 // We connect to this signal to set an initial position for our child widget. | 49 // We connect to this signal to set an initial position for our child widget. |
51 // The reason we connect to this signal rather than setting the initial | 50 // The reason we connect to this signal rather than setting the initial |
52 // position here is that the widget is currently unallocated and may not | 51 // position here is that the widget is currently unallocated and may not |
53 // even have a size request. | 52 // even have a size request. |
54 g_signal_connect(child, "size-allocate", | 53 g_signal_connect(child, "size-allocate", |
55 G_CALLBACK(OnChildSizeAllocate), this); | 54 G_CALLBACK(OnChildSizeAllocate), this); |
56 | 55 |
57 child_needs_move_ = (direction == DOWN); | 56 child_needs_move_ = (direction == DOWN); |
58 | 57 |
59 animation_.reset(new SlideAnimation(this)); | 58 animation_.reset(new ui::SlideAnimation(this)); |
60 // Default tween type is EASE_OUT. | 59 // Default tween type is EASE_OUT. |
61 if (linear) | 60 if (linear) |
62 animation_->SetTweenType(Tween::LINEAR); | 61 animation_->SetTweenType(ui::Tween::LINEAR); |
63 if (duration != 0) | 62 if (duration != 0) |
64 animation_->SetSlideDuration(duration); | 63 animation_->SetSlideDuration(duration); |
65 } | 64 } |
66 | 65 |
67 SlideAnimatorGtk::~SlideAnimatorGtk() { | 66 SlideAnimatorGtk::~SlideAnimatorGtk() { |
68 widget_.Destroy(); | 67 widget_.Destroy(); |
69 } | 68 } |
70 | 69 |
71 void SlideAnimatorGtk::Open() { | 70 void SlideAnimatorGtk::Open() { |
72 if (!animations_enabled_) | 71 if (!animations_enabled_) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 105 } |
107 | 106 |
108 bool SlideAnimatorGtk::IsClosing() { | 107 bool SlideAnimatorGtk::IsClosing() { |
109 return animation_->IsClosing(); | 108 return animation_->IsClosing(); |
110 } | 109 } |
111 | 110 |
112 bool SlideAnimatorGtk::IsAnimating() { | 111 bool SlideAnimatorGtk::IsAnimating() { |
113 return animation_->is_animating(); | 112 return animation_->is_animating(); |
114 } | 113 } |
115 | 114 |
116 void SlideAnimatorGtk::AnimationProgressed(const Animation* animation) { | 115 void SlideAnimatorGtk::AnimationProgressed(const ui::Animation* animation) { |
117 GtkRequisition req; | 116 GtkRequisition req; |
118 gtk_widget_size_request(child_, &req); | 117 gtk_widget_size_request(child_, &req); |
119 | 118 |
120 int showing_height = static_cast<int>(req.height * | 119 int showing_height = static_cast<int>(req.height * |
121 animation_->GetCurrentValue()); | 120 animation_->GetCurrentValue()); |
122 if (direction_ == DOWN) { | 121 if (direction_ == DOWN) { |
123 gtk_expanded_container_move(GTK_EXPANDED_CONTAINER(widget_.get()), | 122 gtk_expanded_container_move(GTK_EXPANDED_CONTAINER(widget_.get()), |
124 child_, 0, showing_height - req.height); | 123 child_, 0, showing_height - req.height); |
125 child_needs_move_ = false; | 124 child_needs_move_ = false; |
126 } | 125 } |
127 gtk_widget_set_size_request(widget_.get(), -1, showing_height); | 126 gtk_widget_set_size_request(widget_.get(), -1, showing_height); |
128 } | 127 } |
129 | 128 |
130 void SlideAnimatorGtk::AnimationEnded(const Animation* animation) { | 129 void SlideAnimatorGtk::AnimationEnded(const ui::Animation* animation) { |
131 if (!animation_->IsShowing()) { | 130 if (!animation_->IsShowing()) { |
132 gtk_widget_hide(widget_.get()); | 131 gtk_widget_hide(widget_.get()); |
133 if (delegate_) | 132 if (delegate_) |
134 delegate_->Closed(); | 133 delegate_->Closed(); |
135 } | 134 } |
136 } | 135 } |
137 | 136 |
138 // static | 137 // static |
139 void SlideAnimatorGtk::SetAnimationsForTesting(bool enable) { | 138 void SlideAnimatorGtk::SetAnimationsForTesting(bool enable) { |
140 animations_enabled_ = enable; | 139 animations_enabled_ = enable; |
141 } | 140 } |
142 | 141 |
143 // static | 142 // static |
144 void SlideAnimatorGtk::OnChildSizeAllocate(GtkWidget* child, | 143 void SlideAnimatorGtk::OnChildSizeAllocate(GtkWidget* child, |
145 GtkAllocation* allocation, | 144 GtkAllocation* allocation, |
146 SlideAnimatorGtk* slider) { | 145 SlideAnimatorGtk* slider) { |
147 if (slider->child_needs_move_) { | 146 if (slider->child_needs_move_) { |
148 gtk_expanded_container_move(GTK_EXPANDED_CONTAINER(slider->widget()), | 147 gtk_expanded_container_move(GTK_EXPANDED_CONTAINER(slider->widget()), |
149 child, 0, -allocation->height); | 148 child, 0, -allocation->height); |
150 slider->child_needs_move_ = false; | 149 slider->child_needs_move_ = false; |
151 } | 150 } |
152 } | 151 } |
OLD | NEW |