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

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

Issue 2679133003: [ash-md] Wired in the Shelf color to be derived from the Wallpaper. (Closed)
Patch Set: Addressed nits. Created 3 years, 10 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
« no previous file with comments | « ash/common/shelf/overflow_button.cc ('k') | ash/common/shelf/shelf_background_animator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_ 5 #ifndef ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_
6 #define ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_ 6 #define ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/ash_export.h" 11 #include "ash/ash_export.h"
12 #include "ash/common/shelf/wm_shelf_observer.h" 12 #include "ash/common/shelf/wm_shelf_observer.h"
13 #include "ash/common/wallpaper/wallpaper_controller_observer.h"
13 #include "ash/public/cpp/shelf_types.h" 14 #include "ash/public/cpp/shelf_types.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "third_party/skia/include/core/SkColor.h"
16 #include "ui/gfx/animation/animation_delegate.h" 18 #include "ui/gfx/animation/animation_delegate.h"
17 19
18 namespace gfx { 20 namespace gfx {
19 class SlideAnimation; 21 class SlideAnimation;
20 } // namespace gfx 22 } // namespace gfx
21 23
22 namespace ash { 24 namespace ash {
23 25
24 enum class AnimationChangeType; 26 enum class AnimationChangeType;
25 class ShelfBackgroundAnimatorObserver; 27 class ShelfBackgroundAnimatorObserver;
26 class ShelfBackgroundAnimatorTestApi; 28 class ShelfBackgroundAnimatorTestApi;
29 class WallpaperController;
27 class WmShelf; 30 class WmShelf;
28 31
29 // Central controller for the Shelf and Dock opacity animations. 32 // Central controller for the Shelf and Dock opacity animations.
30 // 33 //
31 // The ShelfBackgroundAnimator is capable of observing a WmShelf instance for 34 // The ShelfBackgroundAnimator is capable of observing a WmShelf instance for
32 // background type changes or clients can call PaintBackground() directly. 35 // background type changes or clients can call PaintBackground() directly.
33 // 36 //
34 // The Shelf uses 2 surfaces for the animations: 37 // The Shelf uses 2 surfaces for the animations:
35 // 38 //
36 // Material Design: 39 // Material Design:
37 // 1. Shelf button backgrounds 40 // 1. Shelf button backgrounds
38 // 2. Overlay for the SHELF_BACKGROUND_OVERLAP and SHELF_BACKGROUND_MAXIMIZED 41 // 2. Overlay for the SHELF_BACKGROUND_OVERLAP and SHELF_BACKGROUND_MAXIMIZED
39 // states. 42 // states.
40 class ASH_EXPORT ShelfBackgroundAnimator : public WmShelfObserver, 43 class ASH_EXPORT ShelfBackgroundAnimator : public WmShelfObserver,
41 public gfx::AnimationDelegate { 44 public gfx::AnimationDelegate,
45 public WallpaperControllerObserver {
42 public: 46 public:
47 // The maximum alpha value that can be used.
48 static const int kMaxAlpha = SK_AlphaOPAQUE;
49
43 // Initializes this with the given |background_type|. This will observe the 50 // Initializes this with the given |background_type|. This will observe the
44 // |wm_shelf| for background type changes if |wm_shelf| is not null. 51 // |wm_shelf| for background type changes and the |wallpaper_controller| for
52 // wallpaper changes if not null.
45 ShelfBackgroundAnimator(ShelfBackgroundType background_type, 53 ShelfBackgroundAnimator(ShelfBackgroundType background_type,
46 WmShelf* wm_shelf); 54 WmShelf* wm_shelf,
55 WallpaperController* wallpaper_controller);
47 ~ShelfBackgroundAnimator() override; 56 ~ShelfBackgroundAnimator() override;
48 57
49 ShelfBackgroundType target_background_type() const { 58 ShelfBackgroundType target_background_type() const {
50 return target_background_type_; 59 return target_background_type_;
51 } 60 }
52 61
53 // Initializes |observer| with current values using the Initialize() function. 62 // Initializes |observer| with current values using the Initialize() function.
54 void AddObserver(ShelfBackgroundAnimatorObserver* observer); 63 void AddObserver(ShelfBackgroundAnimatorObserver* observer);
55 void RemoveObserver(ShelfBackgroundAnimatorObserver* observer); 64 void RemoveObserver(ShelfBackgroundAnimatorObserver* observer);
56 65
57 // Updates |observer| with current values. 66 // Updates |observer| with current values.
58 void NotifyObserver(ShelfBackgroundAnimatorObserver* observer); 67 void NotifyObserver(ShelfBackgroundAnimatorObserver* observer);
59 68
60 // Conditionally animates the background to the specified |background_type| 69 // Conditionally animates the background to the specified |background_type|
61 // and notifies observers of the new background parameters (e.g. alpha). 70 // and notifies observers of the new background parameters (e.g. color).
62 // If |change_type| is BACKGROUND_CHANGE_IMMEDIATE then the 71 // If |change_type| is BACKGROUND_CHANGE_IMMEDIATE then the
63 // observers will only receive one notification with the final background 72 // observers will only receive one notification with the final background
64 // state, otherwise the observers will be notified multiple times in order to 73 // state, otherwise the observers will be notified multiple times in order to
65 // animate the changes to the backgrounds. 74 // animate the changes to the backgrounds.
66 // 75 //
67 // NOTE: If a second request to paint the same |background_type| using the 76 // NOTE: If a second request to paint the same |background_type| using the
68 // BACKGROUND_CHANGE_ANIMATE change type is received it will be ignored and 77 // BACKGROUND_CHANGE_ANIMATE change type is received it will be ignored and
69 // observers will NOT be notified. 78 // observers will NOT be notified.
70 void PaintBackground(ShelfBackgroundType background_type, 79 void PaintBackground(ShelfBackgroundType background_type,
71 AnimationChangeType change_type); 80 AnimationChangeType change_type);
72 81
73 // gfx::AnimationDelegate: 82 // gfx::AnimationDelegate:
74 void AnimationProgressed(const gfx::Animation* animation) override; 83 void AnimationProgressed(const gfx::Animation* animation) override;
75 void AnimationEnded(const gfx::Animation* animation) override; 84 void AnimationEnded(const gfx::Animation* animation) override;
76 void AnimationCanceled(const gfx::Animation* animation) override; 85 void AnimationCanceled(const gfx::Animation* animation) override;
77 86
78 protected: 87 protected:
79 // WmShelfObserver: 88 // WmShelfObserver:
80 void OnBackgroundTypeChanged(ShelfBackgroundType background_type, 89 void OnBackgroundTypeChanged(ShelfBackgroundType background_type,
81 AnimationChangeType change_type) override; 90 AnimationChangeType change_type) override;
82 91
92 // WallpaperControllerObserver:
93 void OnWallpaperDataChanged() override;
94 void OnWallpaperColorsChanged() override;
95
83 private: 96 private:
84 friend class ShelfBackgroundAnimatorTestApi; 97 friend class ShelfBackgroundAnimatorTestApi;
85 98
86 // Track the values related to a single animation (e.g. Shelf background, 99 // Track the values related to a single animation (e.g. Shelf background,
87 // shelf item background) 100 // shelf item background)
88 class AnimationValues { 101 class AnimationValues {
89 public: 102 public:
90 AnimationValues(); 103 AnimationValues();
91 ~AnimationValues(); 104 ~AnimationValues();
92 105
93 int current_alpha() const { return current_alpha_; } 106 SkColor current_color() const { return current_color_; }
107 SkColor target_color() const { return target_color_; }
94 108
95 // Updates the current values based on |t| value between 0 and 1. 109 // Updates the |current_color_| based on |t| value between 0 and 1.
96 void UpdateCurrentValues(double t); 110 void UpdateCurrentValues(double t);
97 111
98 // Set the target values and assign the current values to the initial 112 // Set the target color and assign the current color to the initial color.
99 // values. 113 void SetTargetValues(SkColor target_color);
100 void SetTargetValues(int target_alpha);
101 114
102 // Returns true if the initial values of |this| equal the target values of 115 // Returns true if the initial values of |this| equal the target values of
103 // |other|. 116 // |other|.
104 bool InitialValuesEqualTargetValuesOf(const AnimationValues& other) const; 117 bool InitialValuesEqualTargetValuesOf(const AnimationValues& other) const;
105 118
106 private: 119 private:
107 int initial_alpha_ = 0; 120 SkColor initial_color_ = SK_ColorTRANSPARENT;
108 int current_alpha_ = 0; 121 SkColor current_color_ = SK_ColorTRANSPARENT;
109 int target_alpha_ = 0; 122 SkColor target_color_ = SK_ColorTRANSPARENT;
110 123
111 DISALLOW_COPY_AND_ASSIGN(AnimationValues); 124 DISALLOW_COPY_AND_ASSIGN(AnimationValues);
112 }; 125 };
113 126
114 // The maximum alpha value that can be used.
115 static const int kMaxAlpha = 255;
116
117 // Helper function used by PaintBackground() to animate the background. 127 // Helper function used by PaintBackground() to animate the background.
118 void AnimateBackground(ShelfBackgroundType background_type, 128 void AnimateBackground(ShelfBackgroundType background_type,
119 AnimationChangeType change_type); 129 AnimationChangeType change_type);
120 130
121 // Returns true if the current |animator_| should be re-used to animate to the 131 // Returns true if the current |animator_| should be re-used to animate to the
122 // given |background_type|. This allows for pre-empted animations to take the 132 // given |background_type|. This allows for pre-empted animations to take the
123 // same amount of time to reverse to the |previous_background_type_|. 133 // same amount of time to reverse to the |previous_background_type_|.
124 bool CanReuseAnimator(ShelfBackgroundType background_type) const; 134 bool CanReuseAnimator(ShelfBackgroundType background_type) const;
125 135
126 // Creates a new |animator_| configured with the correct duration. If the 136 // Creates a new |animator_| configured with the correct duration. If the
(...skipping 15 matching lines...) Expand all
142 // Updates the animation values corresponding to the |t| value between 0 and 152 // Updates the animation values corresponding to the |t| value between 0 and
143 // 1. 153 // 1.
144 void SetAnimationValues(double t); 154 void SetAnimationValues(double t);
145 155
146 // Called when observers need to be notified. 156 // Called when observers need to be notified.
147 void NotifyObservers(); 157 void NotifyObservers();
148 158
149 // The shelf to observe for changes to the shelf background type, can be null. 159 // The shelf to observe for changes to the shelf background type, can be null.
150 WmShelf* wm_shelf_; 160 WmShelf* wm_shelf_;
151 161
162 // The wallpaper controller to observe for changes and to extract colors from.
163 WallpaperController* wallpaper_controller_;
164
152 // The background type that this is animating towards or has reached. 165 // The background type that this is animating towards or has reached.
153 ShelfBackgroundType target_background_type_ = SHELF_BACKGROUND_DEFAULT; 166 ShelfBackgroundType target_background_type_ = SHELF_BACKGROUND_DEFAULT;
154 167
155 // The last background type this is animating away from. 168 // The last background type this is animating away from.
156 ShelfBackgroundType previous_background_type_ = SHELF_BACKGROUND_MAXIMIZED; 169 ShelfBackgroundType previous_background_type_ = SHELF_BACKGROUND_MAXIMIZED;
157 170
158 // Drives the animtion. 171 // Drives the animtion.
159 std::unique_ptr<gfx::SlideAnimation> animator_; 172 std::unique_ptr<gfx::SlideAnimation> animator_;
160 173
161 // Tracks the shelf background animation values. 174 // Tracks the shelf background animation values.
162 AnimationValues shelf_background_values_; 175 AnimationValues shelf_background_values_;
163 176
164 // Tracks the item background animation values. 177 // Tracks the item background animation values.
165 AnimationValues item_background_values_; 178 AnimationValues item_background_values_;
166 179
167 base::ObserverList<ShelfBackgroundAnimatorObserver> observers_; 180 base::ObserverList<ShelfBackgroundAnimatorObserver> observers_;
168 181
169 DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimator); 182 DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimator);
170 }; 183 };
171 184
172 } // namespace ash 185 } // namespace ash
173 186
174 #endif // ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_ 187 #endif // ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_
OLDNEW
« no previous file with comments | « ash/common/shelf/overflow_button.cc ('k') | ash/common/shelf/shelf_background_animator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698