1 // Copyright 2019 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 #ifndef UI_GFX_ANIMATION_ANIMATION_DELEGATE_NOTIFIER_H_ 6 #define UI_GFX_ANIMATION_ANIMATION_DELEGATE_NOTIFIER_H_ 7 8 #include "base/check.h" 9 #include "ui/gfx/animation/animation_delegate.h" 10 11 namespace gfx { 12 13 // AnimationDelegateNotifier adapts AnimationDelegate (which is used by 14 // inheritance) into an object that is used by composition. This can be useful 15 // to compose the functionality of an AnimationDelegate subclass into an object 16 // that inherits directly from AnimationDelegate. 17 template <class AnimationDelegateType = gfx::AnimationDelegate> 18 class AnimationDelegateNotifier : public AnimationDelegateType { 19 public: 20 template <typename... Args> AnimationDelegateNotifier(gfx::AnimationDelegate * owner,Args &&...args)21 AnimationDelegateNotifier(gfx::AnimationDelegate* owner, Args&&... args) 22 : AnimationDelegateType(std::forward<Args>(args)...), owner_(owner) { 23 DCHECK(owner_); 24 } 25 26 ~AnimationDelegateNotifier() override = default; 27 28 // AnimationDelegateType: AnimationEnded(const Animation * animation)29 void AnimationEnded(const Animation* animation) override { 30 AnimationDelegateType::AnimationEnded(animation); 31 owner_->AnimationEnded(animation); 32 } 33 AnimationProgressed(const Animation * animation)34 void AnimationProgressed(const Animation* animation) override { 35 AnimationDelegateType::AnimationProgressed(animation); 36 owner_->AnimationProgressed(animation); 37 } 38 AnimationCanceled(const Animation * animation)39 void AnimationCanceled(const Animation* animation) override { 40 AnimationDelegateType::AnimationCanceled(animation); 41 owner_->AnimationCanceled(animation); 42 } 43 AnimationContainerWasSet(AnimationContainer * container)44 void AnimationContainerWasSet(AnimationContainer* container) override { 45 AnimationDelegateType::AnimationContainerWasSet(container); 46 owner_->AnimationContainerWasSet(container); 47 } 48 49 private: 50 gfx::AnimationDelegate* const owner_; 51 }; 52 53 } // namespace gfx 54 55 #endif // UI_GFX_ANIMATION_ANIMATION_DELEGATE_NOTIFIER_H_ 56