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

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

Issue 2680113002: [ash-md] Remove non-md code from the Shelf background animations. (Closed)
Patch Set: Merge branch 'master' into colorize_shelf_1_remove_non_md_code 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/common/material_design/material_design_controller.h"
10 #include "ash/common/shelf/shelf_background_animator_observer.h" 9 #include "ash/common/shelf/shelf_background_animator_observer.h"
11 #include "ash/common/shelf/shelf_constants.h" 10 #include "ash/common/shelf/shelf_constants.h"
12 #include "ash/common/shelf/wm_shelf.h" 11 #include "ash/common/shelf/wm_shelf.h"
13 12
14 namespace ash { 13 namespace ash {
15 14
16 namespace { 15 namespace {
17 // The total number of animators that will call BackgroundAnimationEnded(). 16 // The total number of animators that will call BackgroundAnimationEnded().
18 const int kNumAnimators = 3; 17 const int kNumAnimators = 2;
19 18
20 const int kMaxAlpha = 255; 19 const int kMaxAlpha = 255;
21 } // namespace 20 } // namespace
22 21
23 ShelfBackgroundAnimator::ShelfBackgroundAnimator( 22 ShelfBackgroundAnimator::ShelfBackgroundAnimator(
24 ShelfBackgroundType background_type, 23 ShelfBackgroundType background_type,
25 WmShelf* wm_shelf) 24 WmShelf* wm_shelf)
26 : wm_shelf_(wm_shelf) { 25 : wm_shelf_(wm_shelf) {
27 if (wm_shelf_) 26 if (wm_shelf_)
28 wm_shelf_->AddObserver(this); 27 wm_shelf_->AddObserver(this);
(...skipping 14 matching lines...) Expand all
43 } 42 }
44 43
45 void ShelfBackgroundAnimator::RemoveObserver( 44 void ShelfBackgroundAnimator::RemoveObserver(
46 ShelfBackgroundAnimatorObserver* observer) { 45 ShelfBackgroundAnimatorObserver* observer) {
47 observers_.RemoveObserver(observer); 46 observers_.RemoveObserver(observer);
48 } 47 }
49 48
50 void ShelfBackgroundAnimator::Initialize( 49 void ShelfBackgroundAnimator::Initialize(
51 ShelfBackgroundAnimatorObserver* observer) const { 50 ShelfBackgroundAnimatorObserver* observer) const {
52 observer->UpdateShelfOpaqueBackground(opaque_background_animator_->alpha()); 51 observer->UpdateShelfOpaqueBackground(opaque_background_animator_->alpha());
53 observer->UpdateShelfAssetBackground(asset_background_animator_->alpha());
54 observer->UpdateShelfItemBackground(item_background_animator_->alpha()); 52 observer->UpdateShelfItemBackground(item_background_animator_->alpha());
55 } 53 }
56 54
57 void ShelfBackgroundAnimator::PaintBackground( 55 void ShelfBackgroundAnimator::PaintBackground(
58 ShelfBackgroundType background_type, 56 ShelfBackgroundType background_type,
59 BackgroundAnimatorChangeType change_type) { 57 BackgroundAnimatorChangeType change_type) {
60 if (target_background_type_ == background_type && 58 if (target_background_type_ == background_type &&
61 change_type == BACKGROUND_CHANGE_ANIMATE) { 59 change_type == BACKGROUND_CHANGE_ANIMATE) {
62 return; 60 return;
63 } 61 }
(...skipping 19 matching lines...) Expand all
83 // UpdateBackground() is only called when alpha values change, this ensures 81 // UpdateBackground() is only called when alpha values change, this ensures
84 // observers are always notified for every background change. 82 // observers are always notified for every background change.
85 OnAlphaChanged(animator, animator->alpha()); 83 OnAlphaChanged(animator, animator->alpha());
86 } 84 }
87 85
88 void ShelfBackgroundAnimator::OnAlphaChanged(BackgroundAnimator* animator, 86 void ShelfBackgroundAnimator::OnAlphaChanged(BackgroundAnimator* animator,
89 int alpha) { 87 int alpha) {
90 if (animator == opaque_background_animator_.get()) { 88 if (animator == opaque_background_animator_.get()) {
91 for (auto& observer : observers_) 89 for (auto& observer : observers_)
92 observer.UpdateShelfOpaqueBackground(alpha); 90 observer.UpdateShelfOpaqueBackground(alpha);
93 } else if (animator == asset_background_animator_.get()) {
94 for (auto& observer : observers_)
95 observer.UpdateShelfAssetBackground(alpha);
96 } else if (animator == item_background_animator_.get()) { 91 } else if (animator == item_background_animator_.get()) {
97 for (auto& observer : observers_) 92 for (auto& observer : observers_)
98 observer.UpdateShelfItemBackground(alpha); 93 observer.UpdateShelfItemBackground(alpha);
99 } else { 94 } else {
100 NOTREACHED(); 95 NOTREACHED();
101 } 96 }
102 } 97 }
103 98
104 void ShelfBackgroundAnimator::AnimateBackground( 99 void ShelfBackgroundAnimator::AnimateBackground(
105 ShelfBackgroundType background_type, 100 ShelfBackgroundType background_type,
106 BackgroundAnimatorChangeType change_type) { 101 BackgroundAnimatorChangeType change_type) {
107 // Ensure BackgroundAnimationEnded() has been called for all the 102 // Ensure BackgroundAnimationEnded() has been called for all the
108 // BackgroundAnimators owned by this so that |successful_animator_count_| 103 // BackgroundAnimators owned by this so that |successful_animator_count_|
109 // is stable and doesn't get updated as a side effect of destroying/animating 104 // is stable and doesn't get updated as a side effect of destroying/animating
110 // the animators. 105 // the animators.
111 StopAnimators(); 106 StopAnimators();
112 107
113 bool show_background = true; 108 bool show_background = true;
114 if (can_reuse_animators_ && previous_background_type_ == background_type) { 109 if (can_reuse_animators_ && previous_background_type_ == background_type) {
115 DCHECK_EQ(opaque_background_animator_->paints_background(), 110 DCHECK_EQ(opaque_background_animator_->paints_background(),
116 asset_background_animator_->paints_background());
117 DCHECK_EQ(asset_background_animator_->paints_background(),
118 item_background_animator_->paints_background()); 111 item_background_animator_->paints_background());
119 112
120 show_background = !opaque_background_animator_->paints_background(); 113 show_background = !opaque_background_animator_->paints_background();
121 } else { 114 } else {
122 CreateAnimators(background_type, change_type); 115 CreateAnimators(background_type, change_type);
123 116
124 // If all the previous animators completed successfully and the animation 117 // If all the previous animators completed successfully and the animation
125 // was between 2 distinct states, then the last alpha values are valid 118 // was between 2 distinct states, then the last alpha values are valid
126 // end state values. 119 // end state values.
127 can_reuse_animators_ = target_background_type_ != background_type && 120 can_reuse_animators_ = target_background_type_ != background_type &&
128 successful_animator_count_ == kNumAnimators; 121 successful_animator_count_ == kNumAnimators;
129 } 122 }
130 123
131 successful_animator_count_ = 0; 124 successful_animator_count_ = 0;
132 125
133 opaque_background_animator_->SetPaintsBackground(show_background, 126 opaque_background_animator_->SetPaintsBackground(show_background,
134 change_type); 127 change_type);
135 asset_background_animator_->SetPaintsBackground(show_background, change_type);
136 item_background_animator_->SetPaintsBackground(show_background, change_type); 128 item_background_animator_->SetPaintsBackground(show_background, change_type);
137 129
138 if (target_background_type_ != background_type) { 130 if (target_background_type_ != background_type) {
139 previous_background_type_ = target_background_type_; 131 previous_background_type_ = target_background_type_;
140 target_background_type_ = background_type; 132 target_background_type_ = background_type;
141 } 133 }
142 } 134 }
143 135
144 void ShelfBackgroundAnimator::CreateAnimators( 136 void ShelfBackgroundAnimator::CreateAnimators(
145 ShelfBackgroundType background_type, 137 ShelfBackgroundType background_type,
146 BackgroundAnimatorChangeType change_type) { 138 BackgroundAnimatorChangeType change_type) {
147 const int opaque_background_alpha = 139 const int opaque_background_alpha =
148 opaque_background_animator_ ? opaque_background_animator_->alpha() : 0; 140 opaque_background_animator_ ? opaque_background_animator_->alpha() : 0;
149 const int asset_background_alpha =
150 asset_background_animator_ ? asset_background_animator_->alpha() : 0;
151 const int item_background_alpha = 141 const int item_background_alpha =
152 item_background_animator_ ? item_background_animator_->alpha() : 0; 142 item_background_animator_ ? item_background_animator_->alpha() : 0;
153 143
154 const bool is_material = MaterialDesignController::IsShelfMaterial();
155 int duration_ms = 0; 144 int duration_ms = 0;
156 145
157 switch (background_type) { 146 switch (background_type) {
158 case SHELF_BACKGROUND_DEFAULT: 147 case SHELF_BACKGROUND_DEFAULT:
159 duration_ms = is_material ? 500 : 1000; 148 duration_ms = 500;
160 opaque_background_animator_.reset( 149 opaque_background_animator_.reset(
161 new BackgroundAnimator(this, opaque_background_alpha, 0)); 150 new BackgroundAnimator(this, opaque_background_alpha, 0));
162 asset_background_animator_.reset( 151 item_background_animator_.reset(new BackgroundAnimator(
163 new BackgroundAnimator(this, asset_background_alpha, 0)); 152 this, item_background_alpha, kShelfTranslucentAlpha));
164 item_background_animator_.reset(
165 new BackgroundAnimator(this, item_background_alpha,
166 GetShelfConstant(SHELF_BACKGROUND_ALPHA)));
167 break; 153 break;
168 case SHELF_BACKGROUND_OVERLAP: 154 case SHELF_BACKGROUND_OVERLAP:
169 duration_ms = is_material ? 500 : 1000; 155 duration_ms = 500;
170 opaque_background_animator_.reset(new BackgroundAnimator( 156 opaque_background_animator_.reset(new BackgroundAnimator(
171 this, opaque_background_alpha, 157 this, opaque_background_alpha, kShelfTranslucentAlpha));
172 is_material ? GetShelfConstant(SHELF_BACKGROUND_ALPHA) : 0)); 158 item_background_animator_.reset(
173 asset_background_animator_.reset(new BackgroundAnimator( 159 new BackgroundAnimator(this, item_background_alpha, 0));
174 this, asset_background_alpha,
175 is_material ? 0 : GetShelfConstant(SHELF_BACKGROUND_ALPHA)));
176 item_background_animator_.reset(new BackgroundAnimator(
177 this, item_background_alpha,
178 is_material ? 0 : GetShelfConstant(SHELF_BACKGROUND_ALPHA)));
179 break; 160 break;
180 case SHELF_BACKGROUND_MAXIMIZED: 161 case SHELF_BACKGROUND_MAXIMIZED:
181 duration_ms = is_material ? 250 : 1000; 162 duration_ms = 250;
182 opaque_background_animator_.reset( 163 opaque_background_animator_.reset(
183 new BackgroundAnimator(this, opaque_background_alpha, kMaxAlpha)); 164 new BackgroundAnimator(this, opaque_background_alpha, kMaxAlpha));
184 asset_background_animator_.reset(new BackgroundAnimator( 165 item_background_animator_.reset(
185 this, asset_background_alpha, 166 new BackgroundAnimator(this, item_background_alpha, 0));
186 is_material ? 0 : GetShelfConstant(SHELF_BACKGROUND_ALPHA)));
187 item_background_animator_.reset(new BackgroundAnimator(
188 this, item_background_alpha, is_material ? 0 : kMaxAlpha));
189 break; 167 break;
190 } 168 }
191 169
192 opaque_background_animator_->SetDuration(duration_ms); 170 opaque_background_animator_->SetDuration(duration_ms);
193 asset_background_animator_->SetDuration(duration_ms);
194 item_background_animator_->SetDuration(duration_ms); 171 item_background_animator_->SetDuration(duration_ms);
195 } 172 }
196 173
197 void ShelfBackgroundAnimator::StopAnimators() { 174 void ShelfBackgroundAnimator::StopAnimators() {
198 if (opaque_background_animator_) 175 if (opaque_background_animator_)
199 opaque_background_animator_->Stop(); 176 opaque_background_animator_->Stop();
200 if (asset_background_animator_)
201 asset_background_animator_->Stop();
202 if (item_background_animator_) 177 if (item_background_animator_)
203 item_background_animator_->Stop(); 178 item_background_animator_->Stop();
204 } 179 }
205 180
206 } // namespace ash 181 } // 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