Index: ash/shelf/shelf_background_animator.cc |
diff --git a/ash/shelf/shelf_background_animator.cc b/ash/shelf/shelf_background_animator.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ed6e0148131988bc07e2f36cfc035af443b53fe4 |
--- /dev/null |
+++ b/ash/shelf/shelf_background_animator.cc |
@@ -0,0 +1,149 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/shelf/shelf_background_animator.h" |
+ |
+#include "ash/common/shelf/shelf_constants.h" |
+#include "ash/shelf/shelf_background_animator_delegate.h" |
+#include "base/logging.h" |
+ |
+namespace ash { |
+ |
+ShelfBackgroundAnimator::ShelfBackgroundAnimator() |
+ : target_background_type_(SHELF_BACKGROUND_DEFAULT), |
+ previous_background_type_(SHELF_BACKGROUND_DEFAULT), |
+ previous_shelf_alpha_(0), |
+ previous_shelf_item_alpha_(255) {} |
+ |
+ShelfBackgroundAnimator::~ShelfBackgroundAnimator() {} |
+ |
+void ShelfBackgroundAnimator::AddShelfBackgroundDelegate( |
+ ShelfBackgroundAnimatorDelegate* delegate) { |
+ LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; |
+ shelf_background_delegates_.push_back(delegate); |
+} |
+ |
+void ShelfBackgroundAnimator::AddShelfItemBackgroundDelegate( |
+ ShelfBackgroundAnimatorDelegate* delegate) { |
+ LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; |
+ shelf_item_background_delegates_.push_back(delegate); |
+} |
+ |
+void ShelfBackgroundAnimator::PaintBackground( |
+ ShelfBackgroundType background_type, |
+ BackgroundAnimatorChangeType change_type) { |
+ LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ |
+ << " background_type=" << background_type |
+ << " change_type=" << change_type; |
+ if (shelf_background_animator_ && shelf_item_background_animator_ && |
+ previous_background_type_ == background_type) { |
+ LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; |
+ shelf_background_animator_->SetPaintsBackground(false, change_type); |
+ shelf_item_background_animator_->SetPaintsBackground(false, change_type); |
+ |
+ previous_background_type_ = target_background_type_; |
+ target_background_type_ = background_type; |
+ |
+ return; |
+ } |
+ |
+ CreateAnimators(background_type, change_type); |
+ ConfigureAnimatorsDuration(background_type, change_type); |
+ |
+ shelf_background_animator_->SetPaintsBackground(true, change_type); |
+ shelf_item_background_animator_->SetPaintsBackground(true, change_type); |
+ |
+ previous_background_type_ = target_background_type_; |
+ target_background_type_ = background_type; |
+} |
+ |
+void ShelfBackgroundAnimator::OnBackgroundUpdated( |
+ ShelfBackgroundType background_type, |
+ BackgroundAnimatorChangeType change_type) { |
+ LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ |
+ << " background_type=" << background_type |
+ << " change_type=" << change_type; |
+ PaintBackground(background_type, change_type); |
+} |
+ |
+void ShelfBackgroundAnimator::UpdateBackground(BackgroundAnimator* animator, |
+ int alpha) { |
+ LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ |
+ << " alpha=" << alpha; |
+ if (animator == shelf_background_animator_.get()) { |
+ UpdateDelegates(shelf_background_delegates_, alpha); |
+ previous_shelf_alpha_ = alpha; |
+ } else if (animator == shelf_item_background_animator_.get()) { |
+ UpdateDelegates(shelf_item_background_delegates_, alpha); |
+ previous_shelf_item_alpha_ = alpha; |
+ } else { |
+ NOTREACHED(); |
+ } |
+} |
+ |
+void ShelfBackgroundAnimator::BackgroundAnimationEnded(bool successfully) { |
+ LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; |
+ shelf_background_animator_.reset(); |
+ shelf_item_background_animator_.reset(); |
+} |
+ |
+void ShelfBackgroundAnimator::UpdateDelegates(DelegateList delegates, |
+ int alpha) { |
+ LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; |
+ for (auto delegate : delegates) |
James Cook
2016/06/09 23:40:37
nit: don't use raw "auto" in ranged-for loops. Pre
bruthig
2016/06/14 16:40:44
Done.
|
+ delegate->UpdateBackgroundAlpha(alpha); |
+} |
+ |
+void ShelfBackgroundAnimator::CreateAnimators( |
+ ShelfBackgroundType background_type, |
+ BackgroundAnimatorChangeType change_type) { |
+ LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; |
+ switch (background_type) { |
+ case SHELF_BACKGROUND_DEFAULT: |
+ shelf_background_animator_.reset( |
+ new BackgroundAnimator(this, previous_shelf_alpha_, 0)); |
+ shelf_item_background_animator_.reset( |
+ new BackgroundAnimator(this, previous_shelf_item_alpha_, |
+ GetShelfConstant(SHELF_BACKGROUND_ALPHA))); |
+ break; |
+ case SHELF_BACKGROUND_OVERLAP: |
+ shelf_background_animator_.reset( |
+ new BackgroundAnimator(this, previous_shelf_alpha_, |
+ GetShelfConstant(SHELF_BACKGROUND_ALPHA))); |
+ shelf_item_background_animator_.reset( |
+ new BackgroundAnimator(this, previous_shelf_item_alpha_, 0)); |
+ break; |
+ case SHELF_BACKGROUND_MAXIMIZED: |
+ shelf_background_animator_.reset( |
+ new BackgroundAnimator(this, previous_shelf_alpha_, 255)); |
+ shelf_item_background_animator_.reset( |
+ new BackgroundAnimator(this, previous_shelf_item_alpha_, 0)); |
+ break; |
+ } |
+} |
+ |
+void ShelfBackgroundAnimator::ConfigureAnimatorsDuration( |
+ ShelfBackgroundType background_type, |
+ BackgroundAnimatorChangeType change_type) { |
+ int duration_ms = 0; |
+ if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { |
+ switch (background_type) { |
+ case SHELF_BACKGROUND_DEFAULT: |
+ duration_ms = 1000; |
+ break; |
+ case SHELF_BACKGROUND_OVERLAP: |
+ duration_ms = 1000; |
+ break; |
+ case SHELF_BACKGROUND_MAXIMIZED: |
+ duration_ms = 500; |
+ break; |
+ } |
+ } |
+ LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ |
+ << " duration=" << duration_ms; |
+ shelf_background_animator_->SetDuration(duration_ms); |
+ shelf_item_background_animator_->SetDuration(duration_ms); |
+} |
+ |
+} // namespace ash |