| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 // | |
| 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). | |
| 13 | 4 |
| 14 #ifndef CHROME_BROWSER_GTK_SLIDE_ANIMATOR_GTK_H_ | 5 #ifndef CHROME_BROWSER_GTK_SLIDE_ANIMATOR_GTK_H_ |
| 15 #define CHROME_BROWSER_GTK_SLIDE_ANIMATOR_GTK_H_ | 6 #define CHROME_BROWSER_GTK_SLIDE_ANIMATOR_GTK_H_ |
| 16 #pragma once | 7 #pragma once |
| 17 | 8 |
| 18 #include <gtk/gtk.h> | 9 #include "chrome/browser/ui/gtk/slide_animator_gtk.h" |
| 19 | 10 // TODO(msw): remove this file once all includes have been updated. |
| 20 #include "base/scoped_ptr.h" | |
| 21 #include "chrome/browser/gtk/owned_widget_gtk.h" | |
| 22 #include "ui/base/animation/animation_delegate.h" | |
| 23 | |
| 24 namespace ui { | |
| 25 class SlideAnimation; | |
| 26 } | |
| 27 | |
| 28 class SlideAnimatorGtk : public ui::AnimationDelegate { | |
| 29 public: | |
| 30 class Delegate { | |
| 31 public: | |
| 32 // Called when a call to Close() finishes animating. | |
| 33 virtual void Closed() = 0; | |
| 34 | |
| 35 protected: | |
| 36 virtual ~Delegate() {} | |
| 37 }; | |
| 38 | |
| 39 enum Direction { | |
| 40 DOWN, | |
| 41 UP | |
| 42 }; | |
| 43 | |
| 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); | |
| 57 | |
| 58 virtual ~SlideAnimatorGtk(); | |
| 59 | |
| 60 GtkWidget* widget() { return widget_.get(); } | |
| 61 | |
| 62 // Slide open. | |
| 63 void Open(); | |
| 64 | |
| 65 // Immediately show the widget. | |
| 66 void OpenWithoutAnimation(); | |
| 67 | |
| 68 // Slide shut. | |
| 69 void Close(); | |
| 70 | |
| 71 // End the current animation. | |
| 72 void End(); | |
| 73 | |
| 74 // Immediately hide the widget. | |
| 75 void CloseWithoutAnimation(); | |
| 76 | |
| 77 // Returns whether the widget is visible. | |
| 78 bool IsShowing(); | |
| 79 | |
| 80 // Returns whether the widget is currently showing the close animation. | |
| 81 bool IsClosing(); | |
| 82 | |
| 83 // Returns whether the widget is currently showing the open or close | |
| 84 // animation. | |
| 85 bool IsAnimating(); | |
| 86 | |
| 87 // ui::AnimationDelegate implementation. | |
| 88 virtual void AnimationProgressed(const ui::Animation* animation); | |
| 89 virtual void AnimationEnded(const ui::Animation* animation); | |
| 90 | |
| 91 // Used during testing; disable or enable animations (default is enabled). | |
| 92 static void SetAnimationsForTesting(bool enable); | |
| 93 | |
| 94 private: | |
| 95 static void OnChildSizeAllocate(GtkWidget* child, | |
| 96 GtkAllocation* allocation, | |
| 97 SlideAnimatorGtk* slider); | |
| 98 | |
| 99 scoped_ptr<ui::SlideAnimation> animation_; | |
| 100 | |
| 101 // The top level widget of the SlideAnimatorGtk. It is a GtkFixed. | |
| 102 OwnedWidgetGtk widget_; | |
| 103 | |
| 104 // The widget passed to us at construction time, and the only direct child of | |
| 105 // |widget_|. | |
| 106 GtkWidget* child_; | |
| 107 | |
| 108 // The direction of the slide. | |
| 109 Direction direction_; | |
| 110 | |
| 111 // The object to inform about certain events. It may be NULL. | |
| 112 Delegate* delegate_; | |
| 113 | |
| 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_; | |
| 119 | |
| 120 static bool animations_enabled_; | |
| 121 }; | |
| 122 | 11 |
| 123 #endif // CHROME_BROWSER_GTK_SLIDE_ANIMATOR_GTK_H_ | 12 #endif // CHROME_BROWSER_GTK_SLIDE_ANIMATOR_GTK_H_ |
| OLD | NEW |