| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #import "ios/chrome/browser/ui/stack_view/page_animation_util.h" | 5 #import "ios/chrome/browser/ui/stack_view/page_animation_util.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 9 | 9 |
| 10 #import "base/mac/scoped_nsobject.h" |
| 10 #import "ios/chrome/browser/ui/animation_util.h" | 11 #import "ios/chrome/browser/ui/animation_util.h" |
| 11 #include "ios/chrome/browser/ui/rtl_geometry.h" | 12 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 12 #import "ios/chrome/browser/ui/stack_view/card_view.h" | 13 #import "ios/chrome/browser/ui/stack_view/card_view.h" |
| 13 #import "ios/chrome/common/material_timing.h" | 14 #import "ios/chrome/common/material_timing.h" |
| 14 | 15 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 16 #error "This file requires ARC support." | |
| 17 #endif | |
| 18 | |
| 19 using ios::material::TimingFunction; | 16 using ios::material::TimingFunction; |
| 20 | 17 |
| 21 namespace { | 18 namespace { |
| 22 | 19 |
| 23 const NSTimeInterval kAnimationDuration = 0.25; | 20 const NSTimeInterval kAnimationDuration = 0.25; |
| 24 const NSTimeInterval kAnimationHesitation = 0.2; | 21 const NSTimeInterval kAnimationHesitation = 0.2; |
| 25 | 22 |
| 26 // Constants used for rotating/translating in in transition-in animations and | 23 // Constants used for rotating/translating in in transition-in animations and |
| 27 // rotating/translating out in transition-out animations. | 24 // rotating/translating out in transition-out animations. |
| 28 const CGFloat kDefaultRotation = 0.2094; // 12 degrees. | 25 const CGFloat kDefaultRotation = 0.2094; // 12 degrees. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 52 @end | 49 @end |
| 53 | 50 |
| 54 @implementation PaperView | 51 @implementation PaperView |
| 55 | 52 |
| 56 - (id)initWithFrame:(CGRect)frame { | 53 - (id)initWithFrame:(CGRect)frame { |
| 57 self = [super initWithFrame:frame]; | 54 self = [super initWithFrame:frame]; |
| 58 if (self) { | 55 if (self) { |
| 59 const UIEdgeInsets kShadowStretchInsets = {28.0, 28.0, 28.0, 28.0}; | 56 const UIEdgeInsets kShadowStretchInsets = {28.0, 28.0, 28.0, 28.0}; |
| 60 const UIEdgeInsets kShadowLayoutOutset = {-10.0, -11.0, -12.0, -11.0}; | 57 const UIEdgeInsets kShadowLayoutOutset = {-10.0, -11.0, -12.0, -11.0}; |
| 61 CGRect shadowFrame = UIEdgeInsetsInsetRect(frame, kShadowLayoutOutset); | 58 CGRect shadowFrame = UIEdgeInsetsInsetRect(frame, kShadowLayoutOutset); |
| 62 UIImageView* frameShadowImageView = | 59 base::scoped_nsobject<UIImageView> frameShadowImageView( |
| 63 [[UIImageView alloc] initWithFrame:shadowFrame]; | 60 [[UIImageView alloc] initWithFrame:shadowFrame]); |
| 64 [frameShadowImageView | 61 [frameShadowImageView |
| 65 setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | | 62 setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | |
| 66 UIViewAutoresizingFlexibleHeight)]; | 63 UIViewAutoresizingFlexibleHeight)]; |
| 67 [self addSubview:frameShadowImageView]; | 64 [self addSubview:frameShadowImageView]; |
| 68 | 65 |
| 69 UIImage* image = [UIImage imageNamed:@"popup_background"]; | 66 UIImage* image = [UIImage imageNamed:@"popup_background"]; |
| 70 image = [image resizableImageWithCapInsets:kShadowStretchInsets]; | 67 image = [image resizableImageWithCapInsets:kShadowStretchInsets]; |
| 71 [frameShadowImageView setImage:image]; | 68 [frameShadowImageView setImage:image]; |
| 72 } | 69 } |
| 73 return self; | 70 return self; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 99 BOOL isOffTheRecord, | 96 BOOL isOffTheRecord, |
| 100 void (^extraAnimation)(void), | 97 void (^extraAnimation)(void), |
| 101 void (^completion)(void)) { | 98 void (^completion)(void)) { |
| 102 CGRect endFrame = view.frame; | 99 CGRect endFrame = view.frame; |
| 103 UIView* parent = [view superview]; | 100 UIView* parent = [view superview]; |
| 104 NSInteger index = [[parent subviews] indexOfObject:view]; | 101 NSInteger index = [[parent subviews] indexOfObject:view]; |
| 105 | 102 |
| 106 // Create paper background. | 103 // Create paper background. |
| 107 CGRect paperFrame = CGRectOffset(endFrame, 0, paperOffset); | 104 CGRect paperFrame = CGRectOffset(endFrame, 0, paperOffset); |
| 108 paperFrame.size.height -= paperOffset; | 105 paperFrame.size.height -= paperOffset; |
| 109 PaperView* paper = [[PaperView alloc] initWithFrame:paperFrame]; | 106 base::scoped_nsobject<PaperView> paper( |
| 107 [[PaperView alloc] initWithFrame:paperFrame]); |
| 110 [parent insertSubview:paper belowSubview:view]; | 108 [parent insertSubview:paper belowSubview:view]; |
| 111 [paper addSubview:view]; | 109 [paper addSubview:view]; |
| 112 [paper setBackgroundColor:isOffTheRecord | 110 [paper setBackgroundColor:isOffTheRecord |
| 113 ? [UIColor colorWithWhite:34 / 255 alpha:1] | 111 ? [UIColor colorWithWhite:34 / 255 alpha:1] |
| 114 : [UIColor whiteColor]]; | 112 : [UIColor whiteColor]]; |
| 115 | 113 |
| 116 [CATransaction begin]; | 114 [CATransaction begin]; |
| 117 [CATransaction setCompletionBlock:^{ | 115 [CATransaction setCompletionBlock:^{ |
| 118 | 116 |
| 119 // Put view back where it belongs, with its original frame. | 117 // Put view back where it belongs, with its original frame. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 if (completion) | 202 if (completion) |
| 205 completion(); | 203 completion(); |
| 206 }]; | 204 }]; |
| 207 } | 205 } |
| 208 | 206 |
| 209 void AnimateNewBackgroundPageWithCompletion(CardView* currentPageCard, | 207 void AnimateNewBackgroundPageWithCompletion(CardView* currentPageCard, |
| 210 CGRect displayFrame, | 208 CGRect displayFrame, |
| 211 BOOL isPortrait, | 209 BOOL isPortrait, |
| 212 void (^completion)(void)) { | 210 void (^completion)(void)) { |
| 213 // Create paper background. | 211 // Create paper background. |
| 214 PaperView* paper = [[PaperView alloc] initWithFrame:CGRectZero]; | 212 base::scoped_nsobject<PaperView> paper( |
| 213 [[PaperView alloc] initWithFrame:CGRectZero]); |
| 215 UIView* parent = [currentPageCard superview]; | 214 UIView* parent = [currentPageCard superview]; |
| 216 [parent insertSubview:paper aboveSubview:currentPageCard]; | 215 [parent insertSubview:paper aboveSubview:currentPageCard]; |
| 217 CGRect pageBounds = currentPageCard.bounds; | 216 CGRect pageBounds = currentPageCard.bounds; |
| 218 [paper setCenter:CGPointMake(CGRectGetMidX(pageBounds), | 217 [paper setCenter:CGPointMake(CGRectGetMidX(pageBounds), |
| 219 CGRectGetMidY(pageBounds))]; | 218 CGRectGetMidY(pageBounds))]; |
| 220 [paper setBackgroundColor:[UIColor whiteColor]]; | 219 [paper setBackgroundColor:[UIColor whiteColor]]; |
| 221 [paper setAlpha:0.0]; | 220 [paper setAlpha:0.0]; |
| 222 | 221 |
| 223 CGSize pageSize = currentPageCard.bounds.size; | 222 CGSize pageSize = currentPageCard.bounds.size; |
| 224 CGRect paperFrame = | 223 CGRect paperFrame = |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 return transform; | 465 return transform; |
| 467 } | 466 } |
| 468 | 467 |
| 469 CGFloat AnimateOutTransformBreadth() { | 468 CGFloat AnimateOutTransformBreadth() { |
| 470 return kDefaultShortSideAxisTranslation; | 469 return kDefaultShortSideAxisTranslation; |
| 471 } | 470 } |
| 472 | 471 |
| 473 } // namespace page_animation_util | 472 } // namespace page_animation_util |
| 474 | 473 |
| 475 } // namespace ios_internal | 474 } // namespace ios_internal |
| OLD | NEW |