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

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

Powered by Google App Engine
This is Rietveld 408576698