OLD | NEW |
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/shelf/shelf_background_animator.h" | 5 #include "ash/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/shelf/shelf.h" |
10 #include "ash/shelf/shelf_background_animator_observer.h" | 11 #include "ash/shelf/shelf_background_animator_observer.h" |
11 #include "ash/shelf/shelf_constants.h" | 12 #include "ash/shelf/shelf_constants.h" |
12 #include "ash/shelf/wm_shelf.h" | |
13 #include "ash/wallpaper/wallpaper_controller.h" | 13 #include "ash/wallpaper/wallpaper_controller.h" |
14 #include "ui/gfx/animation/slide_animation.h" | 14 #include "ui/gfx/animation/slide_animation.h" |
15 #include "ui/gfx/color_utils.h" | 15 #include "ui/gfx/color_utils.h" |
16 | 16 |
17 namespace ash { | 17 namespace ash { |
18 | 18 |
19 ShelfBackgroundAnimator::AnimationValues::AnimationValues() {} | 19 ShelfBackgroundAnimator::AnimationValues::AnimationValues() {} |
20 | 20 |
21 ShelfBackgroundAnimator::AnimationValues::~AnimationValues() {} | 21 ShelfBackgroundAnimator::AnimationValues::~AnimationValues() {} |
22 | 22 |
23 void ShelfBackgroundAnimator::AnimationValues::UpdateCurrentValues(double t) { | 23 void ShelfBackgroundAnimator::AnimationValues::UpdateCurrentValues(double t) { |
24 current_color_ = | 24 current_color_ = |
25 gfx::Tween::ColorValueBetween(t, initial_color_, target_color_); | 25 gfx::Tween::ColorValueBetween(t, initial_color_, target_color_); |
26 } | 26 } |
27 | 27 |
28 void ShelfBackgroundAnimator::AnimationValues::SetTargetValues( | 28 void ShelfBackgroundAnimator::AnimationValues::SetTargetValues( |
29 SkColor target_color) { | 29 SkColor target_color) { |
30 initial_color_ = current_color_; | 30 initial_color_ = current_color_; |
31 target_color_ = target_color; | 31 target_color_ = target_color; |
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_color_ == other.target_color_; | 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 Shelf* shelf, |
42 WallpaperController* wallpaper_controller) | 42 WallpaperController* wallpaper_controller) |
43 : wm_shelf_(wm_shelf), wallpaper_controller_(wallpaper_controller) { | 43 : shelf_(shelf), wallpaper_controller_(wallpaper_controller) { |
44 if (wallpaper_controller_) | 44 if (wallpaper_controller_) |
45 wallpaper_controller_->AddObserver(this); | 45 wallpaper_controller_->AddObserver(this); |
46 if (wm_shelf_) | 46 if (shelf_) |
47 wm_shelf_->AddObserver(this); | 47 shelf_->AddObserver(this); |
48 | 48 |
49 // Initialize animators so that adding observers get notified with consistent | 49 // Initialize animators so that adding observers get notified with consistent |
50 // values. | 50 // values. |
51 AnimateBackground(background_type, AnimationChangeType::IMMEDIATE); | 51 AnimateBackground(background_type, AnimationChangeType::IMMEDIATE); |
52 } | 52 } |
53 | 53 |
54 ShelfBackgroundAnimator::~ShelfBackgroundAnimator() { | 54 ShelfBackgroundAnimator::~ShelfBackgroundAnimator() { |
55 if (wallpaper_controller_) | 55 if (wallpaper_controller_) |
56 wallpaper_controller_->RemoveObserver(this); | 56 wallpaper_controller_->RemoveObserver(this); |
57 if (wm_shelf_) | 57 if (shelf_) |
58 wm_shelf_->RemoveObserver(this); | 58 shelf_->RemoveObserver(this); |
59 } | 59 } |
60 | 60 |
61 void ShelfBackgroundAnimator::AddObserver( | 61 void ShelfBackgroundAnimator::AddObserver( |
62 ShelfBackgroundAnimatorObserver* observer) { | 62 ShelfBackgroundAnimatorObserver* observer) { |
63 observers_.AddObserver(observer); | 63 observers_.AddObserver(observer); |
64 NotifyObserver(observer); | 64 NotifyObserver(observer); |
65 } | 65 } |
66 | 66 |
67 void ShelfBackgroundAnimator::RemoveObserver( | 67 void ShelfBackgroundAnimator::RemoveObserver( |
68 ShelfBackgroundAnimatorObserver* observer) { | 68 ShelfBackgroundAnimatorObserver* observer) { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 242 |
243 void ShelfBackgroundAnimator::SetAnimationValues(double t) { | 243 void ShelfBackgroundAnimator::SetAnimationValues(double t) { |
244 DCHECK_GE(t, 0.0); | 244 DCHECK_GE(t, 0.0); |
245 DCHECK_LE(t, 1.0); | 245 DCHECK_LE(t, 1.0); |
246 shelf_background_values_.UpdateCurrentValues(t); | 246 shelf_background_values_.UpdateCurrentValues(t); |
247 item_background_values_.UpdateCurrentValues(t); | 247 item_background_values_.UpdateCurrentValues(t); |
248 NotifyObservers(); | 248 NotifyObservers(); |
249 } | 249 } |
250 | 250 |
251 } // namespace ash | 251 } // namespace ash |
OLD | NEW |