Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / gtk / slide_animator_gtk.h
bloba73a6a049a7f4681d076acdcf799e59c958b7229
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.
4 //
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.
8 //
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_
17 #include <gtk/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"
24 namespace gfx {
25 class SlideAnimation;
28 class SlideAnimatorGtk : public gfx::AnimationDelegate {
29 public:
30 class Delegate {
31 public:
32 // Called when a call to Close() finishes animating.
33 virtual void Closed() = 0;
35 protected:
36 virtual ~Delegate() {}
39 enum Direction {
40 DOWN,
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,
52 Direction direction,
53 int duration,
54 bool linear,
55 bool control_child_size,
56 Delegate* delegate);
58 virtual ~SlideAnimatorGtk();
60 GtkWidget* widget() { return widget_.get(); }
62 // Slide open.
63 void Open();
65 // Immediately show the widget.
66 void OpenWithoutAnimation();
68 // Slide shut.
69 void Close();
71 // End the current animation.
72 void End();
74 // Immediately hide the widget.
75 void CloseWithoutAnimation();
77 // Returns whether the widget is visible.
78 bool IsShowing();
80 // Returns whether the widget is currently showing the close animation.
81 bool IsClosing();
83 // Returns whether the widget is currently showing the open or close
84 // animation.
85 bool IsAnimating();
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);
94 private:
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
105 // |widget_|.
106 GtkWidget* child_;
108 // The direction of the slide.
109 Direction direction_;
111 // The object to inform about certain events. It may be NULL.
112 Delegate* delegate_;
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_