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

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

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
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 #include "ash/common/shelf/shelf_background_animator.h" 5 #include "ash/common/shelf/shelf_background_animator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/animation/animation_change_type.h" 9 #include "ash/animation/animation_change_type.h"
10 #include "ash/common/shelf/shelf_background_animator_observer.h" 10 #include "ash/common/shelf/shelf_background_animator_observer.h"
11 #include "ash/common/shelf/shelf_constants.h" 11 #include "ash/common/shelf/shelf_constants.h"
12 #include "ash/common/shelf/wm_shelf.h" 12 #include "ash/common/shelf/wm_shelf.h"
13 #include "ash/common/wallpaper/wallpaper_controller.h"
13 #include "ui/gfx/animation/slide_animation.h" 14 #include "ui/gfx/animation/slide_animation.h"
15 #include "ui/gfx/color_utils.h"
14 16
15 namespace ash { 17 namespace ash {
16 18
17 ShelfBackgroundAnimator::AnimationValues::AnimationValues() {} 19 ShelfBackgroundAnimator::AnimationValues::AnimationValues() {}
18 20
19 ShelfBackgroundAnimator::AnimationValues::~AnimationValues() {} 21 ShelfBackgroundAnimator::AnimationValues::~AnimationValues() {}
20 22
21 void ShelfBackgroundAnimator::AnimationValues::UpdateCurrentValues(double t) { 23 void ShelfBackgroundAnimator::AnimationValues::UpdateCurrentValues(double t) {
22 current_alpha_ = 24 current_color_ =
23 gfx::Tween::IntValueBetween(t, initial_alpha_, target_alpha_); 25 gfx::Tween::ColorValueBetween(t, initial_color_, target_color_);
24 } 26 }
25 27
26 void ShelfBackgroundAnimator::AnimationValues::SetTargetValues( 28 void ShelfBackgroundAnimator::AnimationValues::SetTargetValues(
27 int target_alpha) { 29 SkColor target_color) {
28 DCHECK_LE(target_alpha, kMaxAlpha); 30 initial_color_ = current_color_;
29 DCHECK_GE(target_alpha, 0); 31 target_color_ = target_color;
30 initial_alpha_ = current_alpha_;
31 target_alpha_ = target_alpha;
32 } 32 }
33 33
34 bool ShelfBackgroundAnimator::AnimationValues::InitialValuesEqualTargetValuesOf( 34 bool ShelfBackgroundAnimator::AnimationValues::InitialValuesEqualTargetValuesOf(
35 const AnimationValues& other) const { 35 const AnimationValues& other) const {
36 return initial_alpha_ == other.target_alpha_; 36 return initial_color_ == other.target_color_;
37 } 37 }
38 38
39 ShelfBackgroundAnimator::ShelfBackgroundAnimator( 39 ShelfBackgroundAnimator::ShelfBackgroundAnimator(
40 ShelfBackgroundType background_type, 40 ShelfBackgroundType background_type,
41 WmShelf* wm_shelf) 41 WmShelf* wm_shelf,
42 : wm_shelf_(wm_shelf) { 42 WallpaperController* wallpaper_controller)
43 : wm_shelf_(wm_shelf), wallpaper_controller_(wallpaper_controller) {
44 if (wallpaper_controller_)
45 wallpaper_controller_->AddObserver(this);
43 if (wm_shelf_) 46 if (wm_shelf_)
44 wm_shelf_->AddObserver(this); 47 wm_shelf_->AddObserver(this);
48
45 // Initialize animators so that adding observers get notified with consistent 49 // Initialize animators so that adding observers get notified with consistent
46 // values. 50 // values.
47 AnimateBackground(background_type, AnimationChangeType::IMMEDIATE); 51 AnimateBackground(background_type, AnimationChangeType::IMMEDIATE);
48 } 52 }
49 53
50 ShelfBackgroundAnimator::~ShelfBackgroundAnimator() { 54 ShelfBackgroundAnimator::~ShelfBackgroundAnimator() {
55 if (wallpaper_controller_)
56 wallpaper_controller_->RemoveObserver(this);
51 if (wm_shelf_) 57 if (wm_shelf_)
52 wm_shelf_->RemoveObserver(this); 58 wm_shelf_->RemoveObserver(this);
53 } 59 }
54 60
55 void ShelfBackgroundAnimator::AddObserver( 61 void ShelfBackgroundAnimator::AddObserver(
56 ShelfBackgroundAnimatorObserver* observer) { 62 ShelfBackgroundAnimatorObserver* observer) {
57 observers_.AddObserver(observer); 63 observers_.AddObserver(observer);
58 NotifyObserver(observer); 64 NotifyObserver(observer);
59 } 65 }
60 66
61 void ShelfBackgroundAnimator::RemoveObserver( 67 void ShelfBackgroundAnimator::RemoveObserver(
62 ShelfBackgroundAnimatorObserver* observer) { 68 ShelfBackgroundAnimatorObserver* observer) {
63 observers_.RemoveObserver(observer); 69 observers_.RemoveObserver(observer);
64 } 70 }
65 71
66 void ShelfBackgroundAnimator::NotifyObserver( 72 void ShelfBackgroundAnimator::NotifyObserver(
67 ShelfBackgroundAnimatorObserver* observer) { 73 ShelfBackgroundAnimatorObserver* observer) {
68 observer->UpdateShelfBackground(shelf_background_values_.current_alpha()); 74 observer->UpdateShelfBackground(shelf_background_values_.current_color());
69 observer->UpdateShelfItemBackground(item_background_values_.current_alpha()); 75 observer->UpdateShelfItemBackground(item_background_values_.current_color());
70 } 76 }
71 77
72 void ShelfBackgroundAnimator::PaintBackground( 78 void ShelfBackgroundAnimator::PaintBackground(
73 ShelfBackgroundType background_type, 79 ShelfBackgroundType background_type,
74 AnimationChangeType change_type) { 80 AnimationChangeType change_type) {
75 if (target_background_type_ == background_type && 81 if (target_background_type_ == background_type &&
76 change_type == AnimationChangeType::ANIMATE) { 82 change_type == AnimationChangeType::ANIMATE) {
77 return; 83 return;
78 } 84 }
79 85
(...skipping 13 matching lines...) Expand all
93 } 99 }
94 100
95 void ShelfBackgroundAnimator::AnimationCanceled( 101 void ShelfBackgroundAnimator::AnimationCanceled(
96 const gfx::Animation* animation) { 102 const gfx::Animation* animation) {
97 DCHECK_EQ(animation, animator_.get()); 103 DCHECK_EQ(animation, animator_.get());
98 SetAnimationValues(animator_->IsShowing() ? 1.0 : 0.0); 104 SetAnimationValues(animator_->IsShowing() ? 1.0 : 0.0);
99 // Animations are only cancelled when they are being pre-empted so we don't 105 // Animations are only cancelled when they are being pre-empted so we don't
100 // destroy the |animator_| because it may be re-used immediately. 106 // destroy the |animator_| because it may be re-used immediately.
101 } 107 }
102 108
109 void ShelfBackgroundAnimator::OnWallpaperDataChanged() {}
110
111 void ShelfBackgroundAnimator::OnWallpaperColorsChanged() {
112 AnimateBackground(target_background_type_, AnimationChangeType::ANIMATE);
113 }
114
103 void ShelfBackgroundAnimator::OnBackgroundTypeChanged( 115 void ShelfBackgroundAnimator::OnBackgroundTypeChanged(
104 ShelfBackgroundType background_type, 116 ShelfBackgroundType background_type,
105 AnimationChangeType change_type) { 117 AnimationChangeType change_type) {
106 PaintBackground(background_type, change_type); 118 PaintBackground(background_type, change_type);
107 } 119 }
108 120
109 void ShelfBackgroundAnimator::NotifyObservers() { 121 void ShelfBackgroundAnimator::NotifyObservers() {
110 for (auto& observer : observers_) 122 for (auto& observer : observers_)
111 NotifyObserver(&observer); 123 NotifyObserver(&observer);
112 } 124 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 void ShelfBackgroundAnimator::SetTargetValues( 196 void ShelfBackgroundAnimator::SetTargetValues(
185 ShelfBackgroundType background_type) { 197 ShelfBackgroundType background_type) {
186 GetTargetValues(background_type, &shelf_background_values_, 198 GetTargetValues(background_type, &shelf_background_values_,
187 &item_background_values_); 199 &item_background_values_);
188 } 200 }
189 201
190 void ShelfBackgroundAnimator::GetTargetValues( 202 void ShelfBackgroundAnimator::GetTargetValues(
191 ShelfBackgroundType background_type, 203 ShelfBackgroundType background_type,
192 AnimationValues* shelf_background_values, 204 AnimationValues* shelf_background_values,
193 AnimationValues* item_background_values) const { 205 AnimationValues* item_background_values) const {
194 int target_shelf_background = 0; 206 int target_shelf_background_alpha = 0;
195 int target_shelf_item_background = 0; 207 int target_shelf_item_background_alpha = 0;
196 208
197 switch (background_type) { 209 switch (background_type) {
198 case SHELF_BACKGROUND_DEFAULT: 210 case SHELF_BACKGROUND_DEFAULT:
199 target_shelf_background = 0; 211 target_shelf_background_alpha = 0;
200 target_shelf_item_background = kShelfTranslucentAlpha; 212 target_shelf_item_background_alpha = kShelfTranslucentAlpha;
201 break; 213 break;
202 case SHELF_BACKGROUND_OVERLAP: 214 case SHELF_BACKGROUND_OVERLAP:
203 target_shelf_background = kShelfTranslucentAlpha; 215 target_shelf_background_alpha = kShelfTranslucentAlpha;
204 target_shelf_item_background = 0; 216 target_shelf_item_background_alpha = 0;
205 break; 217 break;
206 case SHELF_BACKGROUND_MAXIMIZED: 218 case SHELF_BACKGROUND_MAXIMIZED:
207 target_shelf_background = kMaxAlpha; 219 target_shelf_background_alpha = kMaxAlpha;
208 target_shelf_item_background = 0; 220 target_shelf_item_background_alpha = 0;
209 break; 221 break;
210 } 222 }
211 shelf_background_values->SetTargetValues(target_shelf_background); 223
212 item_background_values->SetTargetValues(target_shelf_item_background); 224 SkColor target_color = wallpaper_controller_
225 ? wallpaper_controller_->prominent_color()
226 : kShelfDefaultBaseColor;
227
228 if (target_color == SK_ColorTRANSPARENT)
229 target_color = kShelfDefaultBaseColor;
230
231 shelf_background_values->SetTargetValues(
232 SkColorSetA(target_color, target_shelf_background_alpha));
233 item_background_values->SetTargetValues(
234 SkColorSetA(target_color, target_shelf_item_background_alpha));
213 } 235 }
214 236
215 void ShelfBackgroundAnimator::SetAnimationValues(double t) { 237 void ShelfBackgroundAnimator::SetAnimationValues(double t) {
216 DCHECK_GE(t, 0.0); 238 DCHECK_GE(t, 0.0);
217 DCHECK_LE(t, 1.0); 239 DCHECK_LE(t, 1.0);
218 shelf_background_values_.UpdateCurrentValues(t); 240 shelf_background_values_.UpdateCurrentValues(t);
219 item_background_values_.UpdateCurrentValues(t); 241 item_background_values_.UpdateCurrentValues(t);
220 NotifyObservers(); 242 NotifyObservers();
221 } 243 }
222 244
223 } // namespace ash 245 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_background_animator.h ('k') | ash/common/shelf/shelf_background_animator_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698