| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ios/chrome/browser/ui/reversed_animation.h" | 5 #include "ios/chrome/browser/ui/reversed_animation.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/objc_property_releaser.h" | 12 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." |
| 15 #endif |
| 13 | 16 |
| 14 @protocol ReversedAnimationProtocol; | 17 @protocol ReversedAnimationProtocol; |
| 15 typedef CAAnimation<ReversedAnimationProtocol> ReversedAnimation; | 18 typedef CAAnimation<ReversedAnimationProtocol> ReversedAnimation; |
| 16 | 19 |
| 17 namespace { | 20 namespace { |
| 18 // Enum type used to denote the direction of a reversed animation relative to | 21 // Enum type used to denote the direction of a reversed animation relative to |
| 19 // the original animation's direction. | 22 // the original animation's direction. |
| 20 typedef enum { | 23 typedef enum { |
| 21 ANIMATION_DIRECTION_NORMAL, | 24 ANIMATION_DIRECTION_NORMAL, |
| 22 ANIMATION_DIRECTION_REVERSE | 25 ANIMATION_DIRECTION_REVERSE |
| (...skipping 30 matching lines...) Expand all Loading... |
| 53 // The current direction for the animation. | 56 // The current direction for the animation. |
| 54 @property(nonatomic, assign) AnimationDirection animationDirection; | 57 @property(nonatomic, assign) AnimationDirection animationDirection; |
| 55 // The offset into the original animation's duration at the begining of the | 58 // The offset into the original animation's duration at the begining of the |
| 56 // reverse animation. | 59 // reverse animation. |
| 57 @property(nonatomic, assign) CFTimeInterval animationTimeOffset; | 60 @property(nonatomic, assign) CFTimeInterval animationTimeOffset; |
| 58 | 61 |
| 59 @end | 62 @end |
| 60 | 63 |
| 61 #pragma mark - ReversedBasicAnimation | 64 #pragma mark - ReversedBasicAnimation |
| 62 | 65 |
| 63 @interface ReversedBasicAnimation | 66 @interface ReversedBasicAnimation : CABasicAnimation<ReversedAnimationProtocol> |
| 64 : CABasicAnimation<ReversedAnimationProtocol> { | |
| 65 base::mac::ObjCPropertyReleaser _propertyReleaser_ReversedBasicAnimation; | |
| 66 } | |
| 67 | 67 |
| 68 // Returns an animation that performs |animation| in reverse when added to | 68 // Returns an animation that performs |animation| in reverse when added to |
| 69 // |layer|. |parentBeginTime| should be set to the beginTime in absolute time | 69 // |layer|. |parentBeginTime| should be set to the beginTime in absolute time |
| 70 // of |animation|'s parent in the timing hierarchy. | 70 // of |animation|'s parent in the timing hierarchy. |
| 71 + (instancetype)reversedAnimationForAnimation:(CABasicAnimation*)animation | 71 + (instancetype)reversedAnimationForAnimation:(CABasicAnimation*)animation |
| 72 forLayer:(CALayer*)layer | 72 forLayer:(CALayer*)layer |
| 73 parent:(CAAnimationGroup*)parent | 73 parent:(CAAnimationGroup*)parent |
| 74 parentBeginTime:(CFTimeInterval)parentBeginTime; | 74 parentBeginTime:(CFTimeInterval)parentBeginTime; |
| 75 | 75 |
| 76 @end | 76 @end |
| 77 | 77 |
| 78 @implementation ReversedBasicAnimation | 78 @implementation ReversedBasicAnimation |
| 79 | 79 |
| 80 @synthesize originalAnimation = _originalAnimation; | 80 @synthesize originalAnimation = _originalAnimation; |
| 81 @synthesize animationDirection = _animationDirection; | 81 @synthesize animationDirection = _animationDirection; |
| 82 @synthesize animationTimeOffset = _animationTimeOffset; | 82 @synthesize animationTimeOffset = _animationTimeOffset; |
| 83 | 83 |
| 84 - (instancetype)init { | |
| 85 self = [super init]; | |
| 86 if (self) { | |
| 87 _propertyReleaser_ReversedBasicAnimation.Init( | |
| 88 self, [ReversedBasicAnimation class]); | |
| 89 } | |
| 90 return self; | |
| 91 } | |
| 92 | |
| 93 - (instancetype)copyWithZone:(NSZone*)zone { | 84 - (instancetype)copyWithZone:(NSZone*)zone { |
| 94 ReversedBasicAnimation* copy = [super copyWithZone:zone]; | 85 ReversedBasicAnimation* copy = [super copyWithZone:zone]; |
| 95 copy.originalAnimation = self.originalAnimation; | 86 copy.originalAnimation = self.originalAnimation; |
| 96 copy.animationDirection = self.animationDirection; | 87 copy.animationDirection = self.animationDirection; |
| 97 copy.animationTimeOffset = self.animationTimeOffset; | 88 copy.animationTimeOffset = self.animationTimeOffset; |
| 98 return copy; | 89 return copy; |
| 99 } | 90 } |
| 100 | 91 |
| 101 + (instancetype)reversedAnimationForAnimation:(CABasicAnimation*)animation | 92 + (instancetype)reversedAnimationForAnimation:(CABasicAnimation*)animation |
| 102 forLayer:(CALayer*)layer | 93 forLayer:(CALayer*)layer |
| (...skipping 26 matching lines...) Expand all Loading... |
| 129 reversedAnimation.fromValue = isReversed ? originalBasicAnimation.toValue | 120 reversedAnimation.fromValue = isReversed ? originalBasicAnimation.toValue |
| 130 : originalBasicAnimation.fromValue; | 121 : originalBasicAnimation.fromValue; |
| 131 } | 122 } |
| 132 return reversedAnimation; | 123 return reversedAnimation; |
| 133 } | 124 } |
| 134 | 125 |
| 135 @end | 126 @end |
| 136 | 127 |
| 137 #pragma mark - ReversedAnimationGroup | 128 #pragma mark - ReversedAnimationGroup |
| 138 | 129 |
| 139 @interface ReversedAnimationGroup | 130 @interface ReversedAnimationGroup : CAAnimationGroup<ReversedAnimationProtocol> |
| 140 : CAAnimationGroup<ReversedAnimationProtocol> { | |
| 141 base::mac::ObjCPropertyReleaser _propertyReleaser_ReversedAnimationGroup; | |
| 142 } | |
| 143 | 131 |
| 144 // Returns an animation that performs |animation| in reverse when added to | 132 // Returns an animation that performs |animation| in reverse when added to |
| 145 // |layer|. |parentBeginTime| should be set to the beginTime in absolute time | 133 // |layer|. |parentBeginTime| should be set to the beginTime in absolute time |
| 146 // of the animation group to which |animation| belongs. | 134 // of the animation group to which |animation| belongs. |
| 147 + (instancetype)reversedAnimationGroupForGroup:(CAAnimationGroup*)group | 135 + (instancetype)reversedAnimationGroupForGroup:(CAAnimationGroup*)group |
| 148 forLayer:(CALayer*)layer | 136 forLayer:(CALayer*)layer |
| 149 parent:(CAAnimationGroup*)parent | 137 parent:(CAAnimationGroup*)parent |
| 150 parentBeginTime:(CFTimeInterval)parentBeginTime; | 138 parentBeginTime:(CFTimeInterval)parentBeginTime; |
| 151 | 139 |
| 152 @end | 140 @end |
| 153 | 141 |
| 154 @implementation ReversedAnimationGroup | 142 @implementation ReversedAnimationGroup |
| 155 | 143 |
| 156 @synthesize originalAnimation = _originalAnimation; | 144 @synthesize originalAnimation = _originalAnimation; |
| 157 @synthesize animationDirection = _animationDirection; | 145 @synthesize animationDirection = _animationDirection; |
| 158 @synthesize animationTimeOffset = _animationTimeOffset; | 146 @synthesize animationTimeOffset = _animationTimeOffset; |
| 159 | 147 |
| 160 - (instancetype)init { | |
| 161 self = [super init]; | |
| 162 if (self) { | |
| 163 _propertyReleaser_ReversedAnimationGroup.Init( | |
| 164 self, [ReversedAnimationGroup class]); | |
| 165 } | |
| 166 return self; | |
| 167 } | |
| 168 | |
| 169 - (instancetype)copyWithZone:(NSZone*)zone { | 148 - (instancetype)copyWithZone:(NSZone*)zone { |
| 170 ReversedAnimationGroup* copy = [super copyWithZone:zone]; | 149 ReversedAnimationGroup* copy = [super copyWithZone:zone]; |
| 171 copy.originalAnimation = self.originalAnimation; | 150 copy.originalAnimation = self.originalAnimation; |
| 172 copy.animationDirection = self.animationDirection; | 151 copy.animationDirection = self.animationDirection; |
| 173 copy.animationTimeOffset = self.animationTimeOffset; | 152 copy.animationTimeOffset = self.animationTimeOffset; |
| 174 return copy; | 153 return copy; |
| 175 } | 154 } |
| 176 | 155 |
| 177 + (instancetype)reversedAnimationGroupForGroup:(CAAnimationGroup*)group | 156 + (instancetype)reversedAnimationGroupForGroup:(CAAnimationGroup*)group |
| 178 forLayer:(CALayer*)layer | 157 forLayer:(CALayer*)layer |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } | 289 } |
| 311 | 290 |
| 312 void ReverseAnimationsForKeyForLayers(NSString* key, NSArray* layers) { | 291 void ReverseAnimationsForKeyForLayers(NSString* key, NSArray* layers) { |
| 313 for (CALayer* layer in layers) { | 292 for (CALayer* layer in layers) { |
| 314 CAAnimation* reversedAnimation = | 293 CAAnimation* reversedAnimation = |
| 315 CAAnimationMakeReverse([layer animationForKey:key], layer); | 294 CAAnimationMakeReverse([layer animationForKey:key], layer); |
| 316 [layer removeAnimationForKey:key]; | 295 [layer removeAnimationForKey:key]; |
| 317 [layer addAnimation:reversedAnimation forKey:key]; | 296 [layer addAnimation:reversedAnimation forKey:key]; |
| 318 } | 297 } |
| 319 } | 298 } |
| OLD | NEW |