| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/overscroll_actions/overscroll_actions_view.h" | 5 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_view.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/objc_property_releaser.h" | |
| 11 #include "base/mac/scoped_nsobject.h" | |
| 12 #include "ios/chrome/browser/ui/rtl_geometry.h" | 10 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 13 #include "ios/chrome/browser/ui/uikit_ui_util.h" | 11 #include "ios/chrome/browser/ui/uikit_ui_util.h" |
| 14 #include "ios/chrome/grit/ios_theme_resources.h" | 12 #include "ios/chrome/grit/ios_theme_resources.h" |
| 15 | 13 |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 15 #error "This file requires ARC support." |
| 16 #endif |
| 17 |
| 16 namespace { | 18 namespace { |
| 17 // Actions images. | 19 // Actions images. |
| 18 NSString* const kNewTabActionImage = @"ptr_new_tab"; | 20 NSString* const kNewTabActionImage = @"ptr_new_tab"; |
| 19 NSString* const kNewTabActionActiveImage = @"ptr_new_tab_active"; | 21 NSString* const kNewTabActionActiveImage = @"ptr_new_tab_active"; |
| 20 NSString* const kRefreshActionImage = @"ptr_reload"; | 22 NSString* const kRefreshActionImage = @"ptr_reload"; |
| 21 NSString* const kRefreshActionActiveImage = @"ptr_reload_active"; | 23 NSString* const kRefreshActionActiveImage = @"ptr_reload_active"; |
| 22 NSString* const kCloseActionImage = @"ptr_close"; | 24 NSString* const kCloseActionImage = @"ptr_close"; |
| 23 NSString* const kCloseActionActiveImage = @"ptr_close_active"; | 25 NSString* const kCloseActionActiveImage = @"ptr_close_active"; |
| 24 | 26 |
| 25 // Represents a simple min/max range. | 27 // Represents a simple min/max range. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 CGFloat _snappedActionOffset; | 124 CGFloat _snappedActionOffset; |
| 123 // The value of the horizontalOffset when a snap animation has been triggered. | 125 // The value of the horizontalOffset when a snap animation has been triggered. |
| 124 CGFloat _horizontalOffsetOnAnimationStart; | 126 CGFloat _horizontalOffsetOnAnimationStart; |
| 125 // The last vertical offset. | 127 // The last vertical offset. |
| 126 CGFloat _lastVerticalOffset; | 128 CGFloat _lastVerticalOffset; |
| 127 // Last recorded pull start absolute time. | 129 // Last recorded pull start absolute time. |
| 128 // Unit is in seconds. | 130 // Unit is in seconds. |
| 129 CFTimeInterval _pullStartTimeInSeconds; | 131 CFTimeInterval _pullStartTimeInSeconds; |
| 130 // Tap gesture recognizer that allow the user to tap on an action to activate | 132 // Tap gesture recognizer that allow the user to tap on an action to activate |
| 131 // it. | 133 // it. |
| 132 base::scoped_nsobject<UITapGestureRecognizer> _tapGesture; | 134 UITapGestureRecognizer* _tapGesture; |
| 133 // Array of layers that will be centered vertically. | 135 // Array of layers that will be centered vertically. |
| 134 // The array is built the first time the method -layersToCenterVertically is | 136 // The array is built the first time the method -layersToCenterVertically is |
| 135 // called. | 137 // called. |
| 136 base::scoped_nsobject<NSArray> _layersToCenterVertically; | 138 NSArray* _layersToCenterVertically; |
| 137 base::mac::ObjCPropertyReleaser _propertyReleaser_OverscrollActionsView; | |
| 138 } | 139 } |
| 139 | 140 |
| 140 // Redefined to readwrite. | 141 // Redefined to readwrite. |
| 141 @property(nonatomic, assign, readwrite) OverscrollAction selectedAction; | 142 @property(nonatomic, assign, readwrite) OverscrollAction selectedAction; |
| 142 | 143 |
| 143 // Actions image views. | 144 // Actions image views. |
| 144 @property(nonatomic, retain) UIImageView* addTabActionImageView; | 145 @property(nonatomic, retain) UIImageView* addTabActionImageView; |
| 145 @property(nonatomic, retain) UIImageView* refreshActionImageView; | 146 @property(nonatomic, retain) UIImageView* refreshActionImageView; |
| 146 @property(nonatomic, retain) UIImageView* closeTabActionImageView; | 147 @property(nonatomic, retain) UIImageView* closeTabActionImageView; |
| 147 | 148 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 @synthesize overscrollState = _overscrollState; | 236 @synthesize overscrollState = _overscrollState; |
| 236 @synthesize shadowView = _shadowView; | 237 @synthesize shadowView = _shadowView; |
| 237 @synthesize backgroundView = _backgroundView; | 238 @synthesize backgroundView = _backgroundView; |
| 238 @synthesize snapshotView = _snapshotView; | 239 @synthesize snapshotView = _snapshotView; |
| 239 @synthesize selectionCircleCroppingLayer = _selectionCircleCroppingLayer; | 240 @synthesize selectionCircleCroppingLayer = _selectionCircleCroppingLayer; |
| 240 @synthesize delegate = _delegate; | 241 @synthesize delegate = _delegate; |
| 241 | 242 |
| 242 - (instancetype)initWithFrame:(CGRect)frame { | 243 - (instancetype)initWithFrame:(CGRect)frame { |
| 243 self = [super initWithFrame:frame]; | 244 self = [super initWithFrame:frame]; |
| 244 if (self) { | 245 if (self) { |
| 245 _propertyReleaser_OverscrollActionsView.Init(self, | |
| 246 [OverscrollActionsView class]); | |
| 247 _deformationBehaviorEnabled = YES; | 246 _deformationBehaviorEnabled = YES; |
| 248 self.autoresizingMask = | 247 self.autoresizingMask = |
| 249 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 248 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| 250 _selectionCircleLayer = [self newSelectionCircleLayer]; | 249 _selectionCircleLayer = [self newSelectionCircleLayer]; |
| 251 _selectionCircleMaskLayer = [self newSelectionCircleLayer]; | 250 _selectionCircleMaskLayer = [self newSelectionCircleLayer]; |
| 252 _selectionCircleMaskLayer.contentsGravity = kCAGravityCenter; | 251 _selectionCircleMaskLayer.contentsGravity = kCAGravityCenter; |
| 253 _selectionCircleCroppingLayer = [[CALayer alloc] init]; | 252 _selectionCircleCroppingLayer = [[CALayer alloc] init]; |
| 254 _selectionCircleCroppingLayer.frame = self.bounds; | 253 _selectionCircleCroppingLayer.frame = self.bounds; |
| 255 [_selectionCircleCroppingLayer setMasksToBounds:YES]; | 254 [_selectionCircleCroppingLayer setMasksToBounds:YES]; |
| 256 | 255 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 287 _shadowView = | 286 _shadowView = |
| 288 [[UIImageView alloc] initWithImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW)]; | 287 [[UIImageView alloc] initWithImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW)]; |
| 289 [self addSubview:_shadowView]; | 288 [self addSubview:_shadowView]; |
| 290 | 289 |
| 291 _backgroundView = [[UIView alloc] initWithFrame:CGRectZero]; | 290 _backgroundView = [[UIView alloc] initWithFrame:CGRectZero]; |
| 292 [self addSubview:_backgroundView]; | 291 [self addSubview:_backgroundView]; |
| 293 | 292 |
| 294 if (UseRTLLayout()) | 293 if (UseRTLLayout()) |
| 295 [self setTransform:CGAffineTransformMakeScale(-1, 1)]; | 294 [self setTransform:CGAffineTransformMakeScale(-1, 1)]; |
| 296 | 295 |
| 297 _tapGesture.reset([[UITapGestureRecognizer alloc] | 296 _tapGesture = |
| 298 initWithTarget:self | 297 [[UITapGestureRecognizer alloc] initWithTarget:self |
| 299 action:@selector(tapGesture:)]); | 298 action:@selector(tapGesture:)]; |
| 300 [_tapGesture setDelegate:self]; | 299 [_tapGesture setDelegate:self]; |
| 301 [self addGestureRecognizer:_tapGesture]; | 300 [self addGestureRecognizer:_tapGesture]; |
| 302 } | 301 } |
| 303 return self; | 302 return self; |
| 304 } | 303 } |
| 305 | 304 |
| 306 - (void)dealloc { | 305 - (void)dealloc { |
| 307 [self.snapshotView removeFromSuperview]; | 306 [self.snapshotView removeFromSuperview]; |
| 308 [super dealloc]; | 307 ; |
| 309 } | 308 } |
| 310 | 309 |
| 311 - (BOOL)selectionCroppingEnabled { | 310 - (BOOL)selectionCroppingEnabled { |
| 312 return [_selectionCircleCroppingLayer masksToBounds]; | 311 return [_selectionCircleCroppingLayer masksToBounds]; |
| 313 } | 312 } |
| 314 | 313 |
| 315 - (void)setSelectionCroppingEnabled:(BOOL)enableSelectionCropping { | 314 - (void)setSelectionCroppingEnabled:(BOOL)enableSelectionCropping { |
| 316 [_selectionCircleCroppingLayer setMasksToBounds:enableSelectionCropping]; | 315 [_selectionCircleCroppingLayer setMasksToBounds:enableSelectionCropping]; |
| 317 } | 316 } |
| 318 | 317 |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 self.selectionCircleLayer.transform = CATransform3DMakeScale(1, 1, 1); | 687 self.selectionCircleLayer.transform = CATransform3DMakeScale(1, 1, 1); |
| 689 self.selectionCircleMaskLayer.transform = | 688 self.selectionCircleMaskLayer.transform = |
| 690 self.selectionCircleLayer.transform; | 689 self.selectionCircleLayer.transform; |
| 691 } | 690 } |
| 692 [UIView commitAnimations]; | 691 [UIView commitAnimations]; |
| 693 | 692 |
| 694 [self.delegate overscrollActionsView:self | 693 [self.delegate overscrollActionsView:self |
| 695 selectedActionDidChange:self.selectedAction]; | 694 selectedActionDidChange:self.selectedAction]; |
| 696 } | 695 } |
| 697 | 696 |
| 698 - (base::scoped_nsobject<NSArray>&)layersToCenterVertically { | 697 - (NSArray*)layersToCenterVertically { |
| 699 if (!_layersToCenterVertically) { | 698 if (!_layersToCenterVertically) { |
| 700 NSArray* layersToCenterVertically = @[ | 699 _layersToCenterVertically = @[ |
| 701 _selectionCircleLayer, _selectionCircleMaskLayer, | 700 _selectionCircleLayer, _selectionCircleMaskLayer, |
| 702 _addTabActionImageView.layer, _refreshActionImageView.layer, | 701 _addTabActionImageView.layer, _refreshActionImageView.layer, |
| 703 _closeTabActionImageView.layer, _addTabActionImageViewHighlighted.layer, | 702 _closeTabActionImageView.layer, _addTabActionImageViewHighlighted.layer, |
| 704 _refreshActionImageViewHighlighted.layer, | 703 _refreshActionImageViewHighlighted.layer, |
| 705 _closeTabActionImageViewHighlighted.layer, _backgroundView.layer | 704 _closeTabActionImageViewHighlighted.layer, _backgroundView.layer |
| 706 ]; | 705 ]; |
| 707 _layersToCenterVertically.reset([layersToCenterVertically retain]); | |
| 708 } | 706 } |
| 709 return _layersToCenterVertically; | 707 return _layersToCenterVertically; |
| 710 } | 708 } |
| 711 | 709 |
| 712 - (void)centerSubviewsVertically { | 710 - (void)centerSubviewsVertically { |
| 713 [CATransaction begin]; | 711 [CATransaction begin]; |
| 714 [CATransaction setDisableActions:YES]; | 712 [CATransaction setDisableActions:YES]; |
| 715 for (CALayer* layer in [self layersToCenterVertically].get()) { | 713 for (CALayer* layer in self.layersToCenterVertically) { |
| 716 CGPoint position = layer.position; | 714 CGPoint position = layer.position; |
| 717 position.y = self.bounds.size.height / 2; | 715 position.y = self.bounds.size.height / 2; |
| 718 layer.position = position; | 716 layer.position = position; |
| 719 } | 717 } |
| 720 [CATransaction commit]; | 718 [CATransaction commit]; |
| 721 } | 719 } |
| 722 | 720 |
| 723 - (void)updateState { | 721 - (void)updateState { |
| 724 if (self.verticalOffset > 1) { | 722 if (self.verticalOffset > 1) { |
| 725 const CFTimeInterval elapsedTime = | 723 const CFTimeInterval elapsedTime = |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 CGPoint tapLocation = [tapRecognizer locationInView:self]; | 989 CGPoint tapLocation = [tapRecognizer locationInView:self]; |
| 992 OverscrollAction action = [self actionAtLocation:tapLocation]; | 990 OverscrollAction action = [self actionAtLocation:tapLocation]; |
| 993 if (action != OverscrollAction::NONE) { | 991 if (action != OverscrollAction::NONE) { |
| 994 [self updateSelectionForTouchedAction:action]; | 992 [self updateSelectionForTouchedAction:action]; |
| 995 [self setSelectedAction:action]; | 993 [self setSelectedAction:action]; |
| 996 [self.delegate overscrollActionsViewDidTapTriggerAction:self]; | 994 [self.delegate overscrollActionsViewDidTapTriggerAction:self]; |
| 997 } | 995 } |
| 998 } | 996 } |
| 999 | 997 |
| 1000 @end | 998 @end |
| OLD | NEW |