1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // A helper class for animating the display of native widget content.
6 // Currently only handle vertical sliding, but could be extended to handle
7 // horizontal slides or other types of animations.
9 // NOTE: This does not handle clipping. If you are not careful, you will
10 // wind up with visibly overlapping widgets. If you need clipping, you can
11 // extend the constructor to take an option to give |fixed| its own GdkWindow
12 // (via gtk_fixed_set_has_window).
14 #ifndef CHROME_BROWSER_UI_GTK_SLIDE_ANIMATOR_GTK_H_
15 #define CHROME_BROWSER_UI_GTK_SLIDE_ANIMATOR_GTK_H_
19 #include "base/compiler_specific.h"
20 #include "base/memory/scoped_ptr.h"
21 #include "ui/base/gtk/owned_widget_gtk.h"
22 #include "ui/gfx/animation/animation_delegate.h"
28 class SlideAnimatorGtk
: public gfx::AnimationDelegate
{
32 // Called when a call to Close() finishes animating.
33 virtual void Closed() = 0;
36 virtual ~Delegate() {}
44 // |child| is the widget we pack into |widget_|.
45 // |direction| indicates which side the contents will appear to come from.
46 // |duration| is the duration of the slide in milliseconds, or 0 for default.
47 // |linear| controls how the animation progresses. If true, the
48 // velocity of the slide is constant over time, otherwise it goes a bit faster
49 // at the beginning and slows to a halt.
50 // |delegate| may be NULL.
51 SlideAnimatorGtk(GtkWidget
* child
,
55 bool control_child_size
,
58 virtual ~SlideAnimatorGtk();
60 GtkWidget
* widget() { return widget_
.get(); }
65 // Immediately show the widget.
66 void OpenWithoutAnimation();
71 // End the current animation.
74 // Immediately hide the widget.
75 void CloseWithoutAnimation();
77 // Returns whether the widget is visible.
80 // Returns whether the widget is currently showing the close animation.
83 // Returns whether the widget is currently showing the open or close
87 // gfx::AnimationDelegate implementation.
88 virtual void AnimationProgressed(const gfx::Animation
* animation
) OVERRIDE
;
89 virtual void AnimationEnded(const gfx::Animation
* animation
) OVERRIDE
;
91 // Used during testing; disable or enable animations (default is enabled).
92 static void SetAnimationsForTesting(bool enable
);
95 static void OnChildSizeAllocate(GtkWidget
* child
,
96 GtkAllocation
* allocation
,
97 SlideAnimatorGtk
* slider
);
99 scoped_ptr
<gfx::SlideAnimation
> animation_
;
101 // The top level widget of the SlideAnimatorGtk. It is a GtkFixed.
102 ui::OwnedWidgetGtk widget_
;
104 // The widget passed to us at construction time, and the only direct child of
108 // The direction of the slide.
109 Direction direction_
;
111 // The object to inform about certain events. It may be NULL.
114 // We need to move the child widget to (0, -height), but we don't know its
115 // height until it has been allocated. This variable will be true until the
116 // child widget has been allocated, at which point we will move it, and then
117 // set this variable to false to indicate it should not be moved again.
118 bool child_needs_move_
;
120 static bool animations_enabled_
;
123 #endif // CHROME_BROWSER_UI_GTK_SLIDE_ANIMATOR_GTK_H_