| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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" | 7 #include "app/animation.h" |
| 8 #include "app/slide_animation.h" | 8 #include "app/slide_animation.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| 11 #include "chrome/browser/gtk/gtk_expanded_container.h" | |
| 12 | |
| 13 namespace { | 11 namespace { |
| 14 | 12 |
| 15 void OnChildSizeRequest(GtkWidget* expanded, | 13 void OnFixedSizeAllocate(GtkWidget* fixed, |
| 16 GtkWidget* child, | 14 GtkAllocation* allocation, |
| 17 GtkRequisition* requisition, | 15 GtkWidget* child) { |
| 18 gpointer control_child_size) { | 16 // The size of the GtkFixed has changed. We want |child_| to match widths, |
| 19 // If |control_child_size| is true, then we want |child_| to match the width | 17 // but the height should not change. |
| 20 // of the |widget_|, but the height of |child_| should not change. | 18 gtk_widget_set_size_request(child, allocation->width, -1); |
| 21 if (!GPOINTER_TO_INT(control_child_size)) { | |
| 22 requisition->width = -1; | |
| 23 } | |
| 24 requisition->height = -1; | |
| 25 } | 19 } |
| 26 | 20 |
| 27 } // namespace | 21 } // namespace |
| 28 | 22 |
| 29 SlideAnimatorGtk::SlideAnimatorGtk(GtkWidget* child, | 23 SlideAnimatorGtk::SlideAnimatorGtk(GtkWidget* child, |
| 30 Direction direction, | 24 Direction direction, |
| 31 int duration, | 25 int duration, |
| 32 bool linear, | 26 bool linear, |
| 33 bool control_child_size, | 27 bool control_child_size, |
| 34 Delegate* delegate) | 28 Delegate* delegate) |
| 35 : child_(child), | 29 : child_(child), |
| 36 direction_(direction), | 30 direction_(direction), |
| 37 delegate_(delegate) { | 31 delegate_(delegate) { |
| 38 widget_.Own(gtk_expanded_container_new()); | 32 widget_.Own(gtk_fixed_new()); |
| 39 gtk_container_add(GTK_CONTAINER(widget_.get()), child); | 33 gtk_fixed_put(GTK_FIXED(widget_.get()), child, 0, 0); |
| 40 gtk_widget_set_size_request(widget_.get(), -1, 0); | 34 gtk_widget_set_size_request(widget_.get(), -1, 0); |
| 41 | 35 if (control_child_size) { |
| 42 // If the child requests it, we will manually set the size request for | 36 // If the child requests it, we will manually set the size request for |
| 43 // |child_| every time the |widget_| changes sizes. This is mainly useful | 37 // |child_| every time the GtkFixed changes sizes. This is mainly useful |
| 44 // for bars, where we want the child to expand to fill all available space. | 38 // for bars, where we want the child to expand to fill all available space. |
| 45 g_signal_connect(widget_.get(), "child-size-request", | 39 g_signal_connect(widget_.get(), "size-allocate", |
| 46 G_CALLBACK(OnChildSizeRequest), | 40 G_CALLBACK(OnFixedSizeAllocate), child_); |
| 47 GINT_TO_POINTER(control_child_size)); | 41 } |
| 48 | 42 |
| 49 // We connect to this signal to set an initial position for our child widget. | 43 // We connect to this signal to set an initial position for our child widget. |
| 50 // The reason we connect to this signal rather than setting the initial | 44 // The reason we connect to this signal rather than setting the initial |
| 51 // position here is that the widget is currently unallocated and may not | 45 // position here is that the widget is currently unallocated and may not |
| 52 // even have a size request. | 46 // even have a size request. |
| 53 g_signal_connect(child, "size-allocate", | 47 g_signal_connect(child, "size-allocate", |
| 54 G_CALLBACK(OnChildSizeAllocate), this); | 48 G_CALLBACK(OnChildSizeAllocate), this); |
| 55 | 49 |
| 56 child_needs_move_ = (direction == DOWN); | 50 child_needs_move_ = (direction == DOWN); |
| 57 | 51 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 return animation_->IsAnimating(); | 99 return animation_->IsAnimating(); |
| 106 } | 100 } |
| 107 | 101 |
| 108 void SlideAnimatorGtk::AnimationProgressed(const Animation* animation) { | 102 void SlideAnimatorGtk::AnimationProgressed(const Animation* animation) { |
| 109 GtkRequisition req; | 103 GtkRequisition req; |
| 110 gtk_widget_size_request(child_, &req); | 104 gtk_widget_size_request(child_, &req); |
| 111 | 105 |
| 112 int showing_height = static_cast<int>(req.height * | 106 int showing_height = static_cast<int>(req.height * |
| 113 animation_->GetCurrentValue()); | 107 animation_->GetCurrentValue()); |
| 114 if (direction_ == DOWN) { | 108 if (direction_ == DOWN) { |
| 115 gtk_expanded_container_move(GTK_EXPANDED_CONTAINER(widget_.get()), | 109 gtk_fixed_move(GTK_FIXED(widget_.get()), child_, 0, |
| 116 child_, 0, showing_height - req.height); | 110 showing_height - req.height); |
| 117 child_needs_move_ = false; | 111 child_needs_move_ = false; |
| 118 } | 112 } |
| 119 gtk_widget_set_size_request(widget_.get(), -1, showing_height); | 113 gtk_widget_set_size_request(widget_.get(), -1, showing_height); |
| 120 } | 114 } |
| 121 | 115 |
| 122 void SlideAnimatorGtk::AnimationEnded(const Animation* animation) { | 116 void SlideAnimatorGtk::AnimationEnded(const Animation* animation) { |
| 123 if (!animation_->IsShowing()) { | 117 if (!animation_->IsShowing()) { |
| 124 gtk_widget_hide(widget_.get()); | 118 gtk_widget_hide(widget_.get()); |
| 125 if (delegate_) | 119 if (delegate_) |
| 126 delegate_->Closed(); | 120 delegate_->Closed(); |
| 127 } | 121 } |
| 128 } | 122 } |
| 129 | 123 |
| 130 // static | 124 // static |
| 131 void SlideAnimatorGtk::OnChildSizeAllocate(GtkWidget* child, | 125 void SlideAnimatorGtk::OnChildSizeAllocate(GtkWidget* child, |
| 132 GtkAllocation* allocation, | 126 GtkAllocation* allocation, |
| 133 SlideAnimatorGtk* slider) { | 127 SlideAnimatorGtk* slider) { |
| 134 if (slider->child_needs_move_) { | 128 if (slider->child_needs_move_) { |
| 135 gtk_expanded_container_move(GTK_EXPANDED_CONTAINER(slider->widget()), | 129 gtk_fixed_move(GTK_FIXED(slider->widget()), child, 0, -allocation->height); |
| 136 child, 0, -allocation->height); | |
| 137 slider->child_needs_move_ = false; | 130 slider->child_needs_move_ = false; |
| 138 } | 131 } |
| 139 } | 132 } |
| OLD | NEW |