OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 #ifndef ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_ | |
6 #define ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "ash/ash_export.h" | |
11 #include "ash/common/shelf/shelf_types.h" | |
12 #include "ash/common/shelf/wm_shelf_observer.h" | |
13 #include "ash/common/wm/background_animator.h" | |
14 #include "base/macros.h" | |
15 #include "base/observer_list.h" | |
16 | |
17 namespace ash { | |
18 | |
19 namespace test { | |
20 class ShelfBackgroundAnimatorTestApi; | |
21 } // namespace test | |
22 | |
23 class ShelfBackgroundAnimatorObserver; | |
24 | |
25 // Central controller for the Shelf and Dock opacity animations. | |
26 // | |
27 // The ShelfBackgroundAnimator is capable of observing a WmShelf instance but it | |
28 // needs to be explicitly added as an observer. | |
29 // | |
30 // The Shelf uses 3 surfaces for the animations: | |
31 // | |
32 // Non-Material Design: | |
33 // 1. Shelf button backgrounds | |
34 // 2. Opaque overlay for the SHELF_BACKGROUND_MAXIMIZED state. | |
35 // 3. Shelf and Dock assets for the SHELF_BACKGROUND_OVERLAP state. | |
36 // Material Design: | |
37 // 1. Shelf button backgrounds | |
38 // 2. Opaque overlay for the SHELF_BACKGROUND_OVERLAP and | |
39 // SHELF_BACKGROUND_MAXIMIZED states. | |
40 class ASH_EXPORT ShelfBackgroundAnimator : public WmShelfObserver, | |
41 public BackgroundAnimatorDelegate { | |
42 public: | |
43 explicit ShelfBackgroundAnimator(ShelfBackgroundType background_type); | |
44 ~ShelfBackgroundAnimator() override; | |
45 | |
46 ShelfBackgroundType target_background_type() const { | |
47 return target_background_type_; | |
48 } | |
49 | |
50 // |observer| will be notified of the current values when being added. | |
51 void AddObserver(ShelfBackgroundAnimatorObserver* observer); | |
52 void RemoveObserver(ShelfBackgroundAnimatorObserver* observer); | |
53 | |
54 // Conditionally animates the background to the specified |background_type| | |
55 // and notifies observers of the new background parameters (e.g. alpha). | |
56 // If |change_type| is BACKGROUND_CHANGE_IMMEDIATE then the | |
57 // observers will only receive one notification with the final background | |
58 // state, otherwise the observers will be notified multiple times in order to | |
59 // animate the changes to the backgrounds. | |
60 // | |
61 // NOTE: If a second request to paint the same |background_type| using the | |
62 // BACKGROUND_CHANGE_ANIMATE change type is received it will be ignored and | |
63 // observers will NOT be notified. | |
64 void PaintBackground(ShelfBackgroundType background_type, | |
65 BackgroundAnimatorChangeType change_type); | |
66 | |
67 protected: | |
68 // WmShelfObserver: | |
69 void OnBackgroundChanged(ShelfBackgroundType background_type, | |
70 BackgroundAnimatorChangeType change_type) override; | |
71 | |
72 // BackgroundAnimatorDelegate: | |
73 void UpdateBackground(BackgroundAnimator* animator, int alpha) override; | |
74 void BackgroundAnimationEnded(BackgroundAnimator* animator) override; | |
75 | |
76 private: | |
77 friend class test::ShelfBackgroundAnimatorTestApi; | |
78 | |
79 // Helper function used by PaintBackground() to animate the background. | |
80 void AnimateBackground(ShelfBackgroundType background_type, | |
81 BackgroundAnimatorChangeType change_type); | |
82 | |
83 // Creates new BackgroundAnimators configured with the correct durations and | |
84 // initial/target alpha values. If any BackgroundAnimators are currently | |
85 // animating they will be stopped. | |
86 void CreateAnimators(ShelfBackgroundType background_type, | |
87 BackgroundAnimatorChangeType change_type); | |
88 | |
89 // Stops all existing animators owned by this. | |
90 void StopAnimators(); | |
91 | |
92 // Called when an alpha value changes and observers need to be notified. | |
93 void OnAlphaChanged(BackgroundAnimator* animator, int alpha); | |
94 | |
95 // The background type that this is animating towards or has reached. | |
96 ShelfBackgroundType target_background_type_ = SHELF_BACKGROUND_DEFAULT; | |
97 | |
98 // The last background type this is animating away from. | |
99 ShelfBackgroundType previous_background_type_ = SHELF_BACKGROUND_MAXIMIZED; | |
100 | |
101 // TODO(bruthig): Replace all BackgroundAnimators with a single | |
James Cook
2016/07/27 00:30:38
super-nit: Put the TODO under the other comment, h
bruthig
2016/07/27 17:05:44
Done.
| |
102 // gfx::SlideAnimation. | |
103 // Animates the solid color background of the Shelf. | |
104 std::unique_ptr<BackgroundAnimator> opaque_background_animator_; | |
105 | |
106 // TODO(bruthig): Remove when non-md is no longer needed (crbug.com/614453). | |
107 // Animates the asset/image based background of the Shelf. | |
108 std::unique_ptr<BackgroundAnimator> asset_background_animator_; | |
109 | |
110 // Animates the backgrounds of Shelf child Views. | |
111 std::unique_ptr<BackgroundAnimator> item_background_animator_; | |
112 | |
113 base::ObserverList<ShelfBackgroundAnimatorObserver> observers_; | |
114 | |
115 // True if the existing BackgroundAnimators can be re-used to animate to the | |
116 // |previous_background_type_|. This allows for pre-empted animations to take | |
117 // the same amount of time to reverse to the |previous_background_type_|. | |
118 bool can_reuse_animators_ = false; | |
119 | |
120 // Tracks how many animators complete successfully since the last | |
James Cook
2016/07/27 00:30:38
nit: complete -> completed?
bruthig
2016/07/27 17:05:44
Done.
| |
121 // CreateAnimators() call. Used to properly set |can_reuse_animators_|. | |
122 int successful_animator_count_ = 0; | |
123 | |
124 DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimator); | |
125 }; | |
126 | |
127 } // namespace ash | |
128 | |
129 #endif // ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_ | |
OLD | NEW |