| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef UI_VIEWS_ANIMATION_BOUNDS_ANIMATOR_H_ | 5 #ifndef UI_VIEWS_ANIMATION_BOUNDS_ANIMATOR_H_ |
| 6 #define UI_VIEWS_ANIMATION_BOUNDS_ANIMATOR_H_ | 6 #define UI_VIEWS_ANIMATION_BOUNDS_ANIMATOR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/observer_list.h" |
| 13 #include "ui/base/animation/animation_container_observer.h" | 14 #include "ui/base/animation/animation_container_observer.h" |
| 14 #include "ui/base/animation/animation_delegate.h" | 15 #include "ui/base/animation/animation_delegate.h" |
| 15 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 16 #include "ui/views/views_export.h" | 17 #include "ui/views/views_export.h" |
| 17 | 18 |
| 18 namespace ui { | 19 namespace ui { |
| 19 class SlideAnimation; | 20 class SlideAnimation; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace views { | 23 namespace views { |
| 23 | 24 |
| 24 class BoundsAnimator; | 25 class BoundsAnimator; |
| 25 class View; | 26 class View; |
| 26 | 27 |
| 27 class BoundsAnimatorObserver { | 28 class VIEWS_EXPORT BoundsAnimatorObserver { |
| 28 public: | 29 public: |
| 29 // Invoked when all animations are complete. | 30 // Invoked when all animations are complete. |
| 30 virtual void OnBoundsAnimatorDone(BoundsAnimator* animator) = 0; | 31 virtual void OnBoundsAnimatorDone(BoundsAnimator* animator) = 0; |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 // Bounds animator is responsible for animating the bounds of a view from the | 34 // Bounds animator is responsible for animating the bounds of a view from the |
| 34 // the views current location and size to a target position and size. To use | 35 // the views current location and size to a target position and size. To use |
| 35 // BoundsAnimator invoke AnimateViewTo for the set of views you want to | 36 // BoundsAnimator invoke AnimateViewTo for the set of views you want to |
| 36 // animate. | 37 // animate. |
| 37 // | 38 // |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Returns true if BoundsAnimator is animating the bounds of |view|. | 86 // Returns true if BoundsAnimator is animating the bounds of |view|. |
| 86 bool IsAnimating(View* view) const; | 87 bool IsAnimating(View* view) const; |
| 87 | 88 |
| 88 // Returns true if BoundsAnimator is animating any view. | 89 // Returns true if BoundsAnimator is animating any view. |
| 89 bool IsAnimating() const; | 90 bool IsAnimating() const; |
| 90 | 91 |
| 91 // Cancels all animations, leaving the views at their current location and | 92 // Cancels all animations, leaving the views at their current location and |
| 92 // size. Any views marked for deletion are deleted. | 93 // size. Any views marked for deletion are deleted. |
| 93 void Cancel(); | 94 void Cancel(); |
| 94 | 95 |
| 95 void set_observer(BoundsAnimatorObserver* observer) { | 96 // Overrides default animation duration. |duration_ms| is the new duration in |
| 96 observer_ = observer; | 97 // milliseconds. |
| 97 } | 98 void SetAnimationDuration(int duration_ms); |
| 99 |
| 100 void AddObserver(BoundsAnimatorObserver* observer); |
| 101 void RemoveObserver(BoundsAnimatorObserver* observer); |
| 98 | 102 |
| 99 protected: | 103 protected: |
| 100 // Creates the animation to use for animating views. | 104 // Creates the animation to use for animating views. |
| 101 virtual ui::SlideAnimation* CreateAnimation(); | 105 virtual ui::SlideAnimation* CreateAnimation(); |
| 102 | 106 |
| 103 private: | 107 private: |
| 104 // Tracks data about the view being animated. | 108 // Tracks data about the view being animated. |
| 105 struct Data { | 109 struct Data { |
| 106 Data() | 110 Data() |
| 107 : delete_delegate_when_done(false), | 111 : delete_delegate_when_done(false), |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 162 |
| 159 // ui::AnimationContainerObserver overrides. | 163 // ui::AnimationContainerObserver overrides. |
| 160 virtual void AnimationContainerProgressed( | 164 virtual void AnimationContainerProgressed( |
| 161 ui::AnimationContainer* container) OVERRIDE; | 165 ui::AnimationContainer* container) OVERRIDE; |
| 162 virtual void AnimationContainerEmpty( | 166 virtual void AnimationContainerEmpty( |
| 163 ui::AnimationContainer* container) OVERRIDE; | 167 ui::AnimationContainer* container) OVERRIDE; |
| 164 | 168 |
| 165 // Parent of all views being animated. | 169 // Parent of all views being animated. |
| 166 View* parent_; | 170 View* parent_; |
| 167 | 171 |
| 168 BoundsAnimatorObserver* observer_; | 172 ObserverList<BoundsAnimatorObserver> observers_; |
| 169 | 173 |
| 170 // All animations we create up with the same container. | 174 // All animations we create up with the same container. |
| 171 scoped_refptr<ui::AnimationContainer> container_; | 175 scoped_refptr<ui::AnimationContainer> container_; |
| 172 | 176 |
| 173 // Maps from view being animated to info about the view. | 177 // Maps from view being animated to info about the view. |
| 174 ViewToDataMap data_; | 178 ViewToDataMap data_; |
| 175 | 179 |
| 176 // Maps from animation to view. | 180 // Maps from animation to view. |
| 177 AnimationToViewMap animation_to_view_; | 181 AnimationToViewMap animation_to_view_; |
| 178 | 182 |
| 179 // As the animations we create update (AnimationProgressed is invoked) this | 183 // As the animations we create update (AnimationProgressed is invoked) this |
| 180 // is updated. When all the animations have completed for a given tick of | 184 // is updated. When all the animations have completed for a given tick of |
| 181 // the timer (AnimationContainerProgressed is invoked) the parent_ is asked | 185 // the timer (AnimationContainerProgressed is invoked) the parent_ is asked |
| 182 // to repaint these bounds. | 186 // to repaint these bounds. |
| 183 gfx::Rect repaint_bounds_; | 187 gfx::Rect repaint_bounds_; |
| 184 | 188 |
| 189 int animation_duration_ms_; |
| 190 |
| 185 DISALLOW_COPY_AND_ASSIGN(BoundsAnimator); | 191 DISALLOW_COPY_AND_ASSIGN(BoundsAnimator); |
| 186 }; | 192 }; |
| 187 | 193 |
| 188 } // namespace views | 194 } // namespace views |
| 189 | 195 |
| 190 #endif // UI_VIEWS_ANIMATION_BOUNDS_ANIMATOR_H_ | 196 #endif // UI_VIEWS_ANIMATION_BOUNDS_ANIMATOR_H_ |
| OLD | NEW |