Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: ash/common/shelf/shelf_background_animator.h

Issue 2053113002: Replaced BackgroundAnimator with ShelfBackgroundAnimator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made the ShelfView add/remove itself as an observer from the ShelfBackgroundAnimator. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 class WmShelf;
25
26 // Central controller for the Shelf and Dock opacity animations.
27 //
28 // The ShelfBackgroundAnimator is capable of observing a WmShelf instance for
29 // background type changes or clients can call PaintBackground() directly.
30 //
31 // The Shelf uses 3 surfaces for the animations:
32 //
33 // Non-Material Design:
34 // 1. Shelf button backgrounds
35 // 2. Opaque overlay for the SHELF_BACKGROUND_MAXIMIZED state.
36 // 3. Shelf and Dock assets for the SHELF_BACKGROUND_OVERLAP state.
37 // Material Design:
38 // 1. Shelf button backgrounds
39 // 2. Opaque overlay for the SHELF_BACKGROUND_OVERLAP and
40 // SHELF_BACKGROUND_MAXIMIZED states.
41 class ASH_EXPORT ShelfBackgroundAnimator : public WmShelfObserver,
42 public BackgroundAnimatorDelegate {
43 public:
44 // Initializes this with the given |background_type|. This will observe the
45 // |wm_shelf| for background type changes if |wm_shelf| is not null.
46 ShelfBackgroundAnimator(ShelfBackgroundType background_type,
47 WmShelf* wm_shelf);
48 ~ShelfBackgroundAnimator() override;
49
50 ShelfBackgroundType target_background_type() const {
51 return target_background_type_;
52 }
53
54 // |observer| will be notified of the current values when being added.
55 void AddObserver(ShelfBackgroundAnimatorObserver* observer);
56 void RemoveObserver(ShelfBackgroundAnimatorObserver* observer);
57
58 // Conditionally animates the background to the specified |background_type|
59 // and notifies observers of the new background parameters (e.g. alpha).
60 // If |change_type| is BACKGROUND_CHANGE_IMMEDIATE then the
61 // observers will only receive one notification with the final background
62 // state, otherwise the observers will be notified multiple times in order to
63 // animate the changes to the backgrounds.
64 //
65 // NOTE: If a second request to paint the same |background_type| using the
66 // BACKGROUND_CHANGE_ANIMATE change type is received it will be ignored and
67 // observers will NOT be notified.
68 void PaintBackground(ShelfBackgroundType background_type,
69 BackgroundAnimatorChangeType change_type);
70
71 protected:
72 // WmShelfObserver:
73 void OnBackgroundTypeChanged(
74 ShelfBackgroundType background_type,
75 BackgroundAnimatorChangeType change_type) override;
76
77 // BackgroundAnimatorDelegate:
78 void UpdateBackground(BackgroundAnimator* animator, int alpha) override;
79 void BackgroundAnimationEnded(BackgroundAnimator* animator) override;
80
81 private:
82 friend class test::ShelfBackgroundAnimatorTestApi;
83
84 // Helper function used by PaintBackground() to animate the background.
85 void AnimateBackground(ShelfBackgroundType background_type,
86 BackgroundAnimatorChangeType change_type);
87
88 // Creates new BackgroundAnimators configured with the correct durations and
89 // initial/target alpha values. If any BackgroundAnimators are currently
90 // animating they will be stopped.
91 void CreateAnimators(ShelfBackgroundType background_type,
92 BackgroundAnimatorChangeType change_type);
93
94 // Stops all existing animators owned by this.
95 void StopAnimators();
96
97 // Called when an alpha value changes and observers need to be notified.
98 void OnAlphaChanged(BackgroundAnimator* animator, int alpha);
99
100 // The background type that this is animating towards or has reached.
101 ShelfBackgroundType target_background_type_ = SHELF_BACKGROUND_DEFAULT;
102
103 // The last background type this is animating away from.
104 ShelfBackgroundType previous_background_type_ = SHELF_BACKGROUND_MAXIMIZED;
105
106 // Animates the solid color background of the Shelf.
107 // TODO(bruthig): Replace all BackgroundAnimators with a single
108 // gfx::SlideAnimation.
109 std::unique_ptr<BackgroundAnimator> opaque_background_animator_;
110
111 // Animates the asset/image based background of the Shelf.
112 // TODO(bruthig): Remove when non-md is no longer needed (crbug.com/614453).
113 std::unique_ptr<BackgroundAnimator> asset_background_animator_;
114
115 // Animates the backgrounds of Shelf child Views.
116 std::unique_ptr<BackgroundAnimator> item_background_animator_;
117
118 base::ObserverList<ShelfBackgroundAnimatorObserver> observers_;
119
120 // True if the existing BackgroundAnimators can be re-used to animate to the
121 // |previous_background_type_|. This allows for pre-empted animations to take
122 // the same amount of time to reverse to the |previous_background_type_|.
123 bool can_reuse_animators_ = false;
124
125 // Tracks how many animators completed successfully since the last
126 // CreateAnimators() call. Used to properly set |can_reuse_animators_|.
127 int successful_animator_count_ = 0;
128
129 // The shelf to observe for changes to the shelf background type, can be null.
130 WmShelf* wm_shelf_;
131
132 DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimator);
133 };
134
135 } // namespace ash
136
137 #endif // ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698