Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/shelf/shelf_background_animator.h" | |
| 6 | |
| 7 #include "ash/common/shelf/shelf_constants.h" | |
| 8 #include "ash/shelf/shelf_background_animator_delegate.h" | |
| 9 #include "base/logging.h" | |
| 10 | |
| 11 namespace ash { | |
| 12 | |
| 13 ShelfBackgroundAnimator::ShelfBackgroundAnimator() | |
| 14 : target_background_type_(SHELF_BACKGROUND_DEFAULT), | |
| 15 previous_background_type_(SHELF_BACKGROUND_DEFAULT), | |
| 16 previous_shelf_alpha_(0), | |
| 17 previous_shelf_item_alpha_(255) {} | |
| 18 | |
| 19 ShelfBackgroundAnimator::~ShelfBackgroundAnimator() {} | |
| 20 | |
| 21 void ShelfBackgroundAnimator::AddShelfBackgroundDelegate( | |
| 22 ShelfBackgroundAnimatorDelegate* delegate) { | |
| 23 LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; | |
| 24 shelf_background_delegates_.push_back(delegate); | |
| 25 } | |
| 26 | |
| 27 void ShelfBackgroundAnimator::AddShelfItemBackgroundDelegate( | |
| 28 ShelfBackgroundAnimatorDelegate* delegate) { | |
| 29 LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; | |
| 30 shelf_item_background_delegates_.push_back(delegate); | |
| 31 } | |
| 32 | |
| 33 void ShelfBackgroundAnimator::PaintBackground( | |
| 34 ShelfBackgroundType background_type, | |
| 35 BackgroundAnimatorChangeType change_type) { | |
| 36 LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ | |
| 37 << " background_type=" << background_type | |
| 38 << " change_type=" << change_type; | |
| 39 if (shelf_background_animator_ && shelf_item_background_animator_ && | |
| 40 previous_background_type_ == background_type) { | |
| 41 LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; | |
| 42 shelf_background_animator_->SetPaintsBackground(false, change_type); | |
| 43 shelf_item_background_animator_->SetPaintsBackground(false, change_type); | |
| 44 | |
| 45 previous_background_type_ = target_background_type_; | |
| 46 target_background_type_ = background_type; | |
| 47 | |
| 48 return; | |
| 49 } | |
| 50 | |
| 51 CreateAnimators(background_type, change_type); | |
| 52 ConfigureAnimatorsDuration(background_type, change_type); | |
| 53 | |
| 54 shelf_background_animator_->SetPaintsBackground(true, change_type); | |
| 55 shelf_item_background_animator_->SetPaintsBackground(true, change_type); | |
| 56 | |
| 57 previous_background_type_ = target_background_type_; | |
| 58 target_background_type_ = background_type; | |
| 59 } | |
| 60 | |
| 61 void ShelfBackgroundAnimator::OnBackgroundUpdated( | |
| 62 ShelfBackgroundType background_type, | |
| 63 BackgroundAnimatorChangeType change_type) { | |
| 64 LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ | |
| 65 << " background_type=" << background_type | |
| 66 << " change_type=" << change_type; | |
| 67 PaintBackground(background_type, change_type); | |
| 68 } | |
| 69 | |
| 70 void ShelfBackgroundAnimator::UpdateBackground(BackgroundAnimator* animator, | |
| 71 int alpha) { | |
| 72 LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ | |
| 73 << " alpha=" << alpha; | |
| 74 if (animator == shelf_background_animator_.get()) { | |
| 75 UpdateDelegates(shelf_background_delegates_, alpha); | |
| 76 previous_shelf_alpha_ = alpha; | |
| 77 } else if (animator == shelf_item_background_animator_.get()) { | |
| 78 UpdateDelegates(shelf_item_background_delegates_, alpha); | |
| 79 previous_shelf_item_alpha_ = alpha; | |
| 80 } else { | |
| 81 NOTREACHED(); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 void ShelfBackgroundAnimator::BackgroundAnimationEnded(bool successfully) { | |
| 86 LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; | |
| 87 shelf_background_animator_.reset(); | |
| 88 shelf_item_background_animator_.reset(); | |
| 89 } | |
| 90 | |
| 91 void ShelfBackgroundAnimator::UpdateDelegates(DelegateList delegates, | |
| 92 int alpha) { | |
| 93 LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; | |
| 94 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.
| |
| 95 delegate->UpdateBackgroundAlpha(alpha); | |
| 96 } | |
| 97 | |
| 98 void ShelfBackgroundAnimator::CreateAnimators( | |
| 99 ShelfBackgroundType background_type, | |
| 100 BackgroundAnimatorChangeType change_type) { | |
| 101 LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ << ""; | |
| 102 switch (background_type) { | |
| 103 case SHELF_BACKGROUND_DEFAULT: | |
| 104 shelf_background_animator_.reset( | |
| 105 new BackgroundAnimator(this, previous_shelf_alpha_, 0)); | |
| 106 shelf_item_background_animator_.reset( | |
| 107 new BackgroundAnimator(this, previous_shelf_item_alpha_, | |
| 108 GetShelfConstant(SHELF_BACKGROUND_ALPHA))); | |
| 109 break; | |
| 110 case SHELF_BACKGROUND_OVERLAP: | |
| 111 shelf_background_animator_.reset( | |
| 112 new BackgroundAnimator(this, previous_shelf_alpha_, | |
| 113 GetShelfConstant(SHELF_BACKGROUND_ALPHA))); | |
| 114 shelf_item_background_animator_.reset( | |
| 115 new BackgroundAnimator(this, previous_shelf_item_alpha_, 0)); | |
| 116 break; | |
| 117 case SHELF_BACKGROUND_MAXIMIZED: | |
| 118 shelf_background_animator_.reset( | |
| 119 new BackgroundAnimator(this, previous_shelf_alpha_, 255)); | |
| 120 shelf_item_background_animator_.reset( | |
| 121 new BackgroundAnimator(this, previous_shelf_item_alpha_, 0)); | |
| 122 break; | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 void ShelfBackgroundAnimator::ConfigureAnimatorsDuration( | |
| 127 ShelfBackgroundType background_type, | |
| 128 BackgroundAnimatorChangeType change_type) { | |
| 129 int duration_ms = 0; | |
| 130 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { | |
| 131 switch (background_type) { | |
| 132 case SHELF_BACKGROUND_DEFAULT: | |
| 133 duration_ms = 1000; | |
| 134 break; | |
| 135 case SHELF_BACKGROUND_OVERLAP: | |
| 136 duration_ms = 1000; | |
| 137 break; | |
| 138 case SHELF_BACKGROUND_MAXIMIZED: | |
| 139 duration_ms = 500; | |
| 140 break; | |
| 141 } | |
| 142 } | |
| 143 LOG(ERROR) << " *** " << __FUNCTION__ << "() line=" << __LINE__ | |
| 144 << " duration=" << duration_ms; | |
| 145 shelf_background_animator_->SetDuration(duration_ms); | |
| 146 shelf_item_background_animator_->SetDuration(duration_ms); | |
| 147 } | |
| 148 | |
| 149 } // namespace ash | |
| OLD | NEW |