Chromium Code Reviews| Index: ios/chrome/browser/ui/contextual_search/contextual_search_panel_view.mm |
| diff --git a/ios/chrome/browser/ui/contextual_search/contextual_search_panel_view.mm b/ios/chrome/browser/ui/contextual_search/contextual_search_panel_view.mm |
| index 1b556aa9945c38874c29a1d9778e1f4f5fe39f12..fc0f9cee2437bdd3dd55842eafdb355c591a91a8 100644 |
| --- a/ios/chrome/browser/ui/contextual_search/contextual_search_panel_view.mm |
| +++ b/ios/chrome/browser/ui/contextual_search/contextual_search_panel_view.mm |
| @@ -5,10 +5,8 @@ |
| #import "ios/chrome/browser/ui/contextual_search/contextual_search_panel_view.h" |
| #import "base/ios/crb_protocol_observers.h" |
| -#include "base/ios/weak_nsobject.h" |
| #include "base/logging.h" |
| #include "base/mac/scoped_block.h" |
| -#include "base/mac/scoped_nsobject.h" |
| #import "ios/chrome/browser/procedural_block_types.h" |
| #import "ios/chrome/browser/ui/contextual_search/contextual_search_panel_protocols.h" |
| #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| @@ -16,6 +14,10 @@ |
| #import "ios/third_party/material_components_ios/src/components/ShadowElevations/src/MaterialShadowElevations.h" |
| #import "ios/third_party/material_components_ios/src/components/ShadowLayer/src/MaterialShadowLayer.h" |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| namespace { |
| // Animation timings. |
| @@ -42,12 +44,12 @@ const CGFloat kShadowElevation = MDCShadowElevationMenu; |
| // that motion will not cause the panel to move, but if the scrolling reaches |
| // the end of its possible range, the gesture will then start dragging the |
| // panel. |
| -@property(nonatomic, assign) |
| +@property(nonatomic, weak) |
| UIView<ContextualSearchPanelScrollSynchronizer>* scrollSynchronizer; |
| // Private readonly property to be used by weak pointers to |self| for non- |
| // retaining access to the underlying ivar in blocks. |
| -@property(nonatomic, readonly) ContextualSearchPanelObservers* observers; |
| +@property(weak, nonatomic, readonly) ContextualSearchPanelObservers* observers; |
|
marq (ping after 24h)
2017/01/13 10:38:17
nonatomic, weak, readonly
stkhapugin
2017/01/17 15:57:44
Done, and actually changed to strong.
|
| // Utility to generate a PanelMotion struct for the panel's current position. |
| - (ContextualSearch::PanelMotion)motion; |
| @@ -58,26 +60,25 @@ const CGFloat kShadowElevation = MDCShadowElevationMenu; |
| // Constraints that define the size of this view. These will be cleared and |
| // regenerated when the horizontal size class changes. |
| - base::scoped_nsobject<NSArray> _sizingConstraints; |
| + NSArray* _sizingConstraints; |
| CGPoint _draggingStartPosition; |
| CGPoint _scrolledOffset; |
| - base::scoped_nsobject<UIPanGestureRecognizer> _dragRecognizer; |
| + UIPanGestureRecognizer* _dragRecognizer; |
| - base::scoped_nsobject<ContextualSearchPanelObservers> _observers; |
| + ContextualSearchPanelObservers* _observers; |
| - base::scoped_nsobject<PanelConfiguration> _configuration; |
| + PanelConfiguration* _configuration; |
| - base::WeakNSProtocol<id<ContextualSearchPanelScrollSynchronizer>> |
| - _scrollSynchronizer; |
| + __weak id<ContextualSearchPanelScrollSynchronizer> _scrollSynchronizer; |
| // Guide that's used to position this view. |
| - base::WeakNSObject<UILayoutGuide> _positioningGuide; |
| + __weak UILayoutGuide* _positioningGuide; |
| // Constraint that sets the size of |_positioningView| so this view is |
| // positioned correctly for its state. |
| - base::WeakNSObject<NSLayoutConstraint> _positioningViewConstraint; |
| + __weak NSLayoutConstraint* _positioningViewConstraint; |
| // Other constraints that determine the position of this view. |
| - base::scoped_nsobject<NSArray> _positioningConstraints; |
| + NSArray* _positioningConstraints; |
| // Promotion state variables. |
| BOOL _resizingForPromotion; |
| @@ -102,27 +103,26 @@ const CGFloat kShadowElevation = MDCShadowElevationMenu; |
| - (instancetype)initWithConfiguration:(PanelConfiguration*)configuration { |
| if ((self = [super initWithFrame:CGRectZero])) { |
| - _configuration.reset([configuration retain]); |
| + _configuration = configuration; |
| _state = ContextualSearch::DISMISSED; |
| self.translatesAutoresizingMaskIntoConstraints = NO; |
| self.backgroundColor = [UIColor whiteColor]; |
| self.accessibilityIdentifier = @"contextualSearchPanel"; |
| - _observers.reset([[ContextualSearchPanelObservers |
| - observersWithProtocol:@protocol(ContextualSearchPanelMotionObserver)] |
| - retain]); |
| + _observers = [ContextualSearchPanelObservers |
| + observersWithProtocol:@protocol(ContextualSearchPanelMotionObserver)]; |
| [self addMotionObserver:self]; |
| // Add gesture recognizer. |
| - _dragRecognizer.reset([[UIPanGestureRecognizer alloc] |
| + _dragRecognizer = [[UIPanGestureRecognizer alloc] |
| initWithTarget:self |
| - action:@selector(handleDragFrom:)]); |
| + action:@selector(handleDragFrom:)]; |
| [self addGestureRecognizer:_dragRecognizer]; |
| [_dragRecognizer setDelegate:self]; |
| // Set up the stack view that holds the panel content |
| - _contents = [[[UIStackView alloc] initWithFrame:self.bounds] autorelease]; |
| + _contents = [[UIStackView alloc] initWithFrame:self.bounds]; |
| [self addSubview:_contents]; |
| _contents.translatesAutoresizingMaskIntoConstraints = NO; |
| _contents.accessibilityIdentifier = @"panelContents"; |
| @@ -197,12 +197,12 @@ const CGFloat kShadowElevation = MDCShadowElevationMenu; |
| #pragma mark - Public property getters/setters |
| - (PanelConfiguration*)configuration { |
| - return _configuration.get(); |
| + return _configuration; |
| } |
| - (void)setScrollSynchronizer: |
| (id<ContextualSearchPanelScrollSynchronizer>)scrollSynchronizer { |
| - _scrollSynchronizer.reset(scrollSynchronizer); |
| + _scrollSynchronizer = scrollSynchronizer; |
| } |
| - (id<ContextualSearchPanelScrollSynchronizer>)scrollSynchronizer { |
| @@ -218,11 +218,10 @@ const CGFloat kShadowElevation = MDCShadowElevationMenu; |
| return; |
| [_positioningViewConstraint setActive:NO]; |
| - _positioningViewConstraint.reset(); |
| - base::WeakNSObject<ContextualSearchPanelView> weakSelf(self); |
| + _positioningViewConstraint = nil; |
| + __weak ContextualSearchPanelView* weakSelf = self; |
| void (^transform)(void) = ^{ |
| - base::scoped_nsobject<ContextualSearchPanelView> strongSelf( |
| - [weakSelf retain]); |
| + ContextualSearchPanelView* strongSelf = weakSelf; |
| if (strongSelf) { |
| [strongSelf setNeedsUpdateConstraints]; |
| [[strongSelf superview] layoutIfNeeded]; |
| @@ -235,11 +234,9 @@ const CGFloat kShadowElevation = MDCShadowElevationMenu; |
| NSTimeInterval animationDuration; |
| if (state == ContextualSearch::DISMISSED) { |
| animationDuration = kDismissAnimationDuration; |
| - completion.reset( |
| - ^(BOOL) { |
| - [weakSelf setHidden:YES]; |
| - }, |
| - base::scoped_policy::RETAIN); |
| + completion.reset([^(BOOL) { |
| + [weakSelf setHidden:YES]; |
| + } copy]); |
| } else { |
| self.hidden = NO; |
| animationDuration = kPanelAnimationDuration; |
| @@ -282,8 +279,7 @@ const CGFloat kShadowElevation = MDCShadowElevationMenu; |
| if (self.traitCollection.horizontalSizeClass != |
| UIUserInterfaceSizeClassUnspecified && |
| !_sizingConstraints) { |
| - _sizingConstraints.reset( |
| - [[_configuration constraintsForSizingPanel:self] retain]); |
| + _sizingConstraints = [_configuration constraintsForSizingPanel:self]; |
| [NSLayoutConstraint activateConstraints:_sizingConstraints]; |
| } |
| // Update positioning constraints if they don't exist. |
| @@ -296,12 +292,12 @@ const CGFloat kShadowElevation = MDCShadowElevationMenu; |
| ]; |
| [NSLayoutConstraint activateConstraints:positioningConstraints]; |
| - _positioningConstraints.reset([positioningConstraints retain]); |
| + _positioningConstraints = positioningConstraints; |
| } |
| // Always update the positioning view constraint. |
| - _positioningViewConstraint.reset([self.configuration |
| - constraintForPositioningGuide:_positioningGuide |
| - atState:self.state]); |
| + _positioningViewConstraint = |
| + [self.configuration constraintForPositioningGuide:_positioningGuide |
| + atState:self.state]; |
| [_positioningViewConstraint setActive:YES]; |
| } |
| [super updateConstraints]; |
| @@ -312,10 +308,10 @@ const CGFloat kShadowElevation = MDCShadowElevationMenu; |
| return; |
| // Set up the invisible positioning view used to constrain this view's |
| // position. |
| - UILayoutGuide* positioningGuide = [[[UILayoutGuide alloc] init] autorelease]; |
| + UILayoutGuide* positioningGuide = [[UILayoutGuide alloc] init]; |
| positioningGuide.identifier = @"contextualSearchPosition"; |
| [self.superview addLayoutGuide:positioningGuide]; |
| - _positioningGuide.reset(positioningGuide); |
| + _positioningGuide = positioningGuide; |
| [self setNeedsUpdateConstraints]; |
| } |
| @@ -330,7 +326,7 @@ const CGFloat kShadowElevation = MDCShadowElevationMenu; |
| [_configuration |
| setHorizontalSizeClass:self.traitCollection.horizontalSizeClass]; |
| [NSLayoutConstraint deactivateConstraints:_sizingConstraints]; |
| - _sizingConstraints.reset(); |
| + _sizingConstraints = nil; |
| [self setNeedsUpdateConstraints]; |
| } |
| @@ -360,7 +356,6 @@ const CGFloat kShadowElevation = MDCShadowElevationMenu; |
| [self removeMotionObserver:self]; |
| [self removeGestureRecognizer:_dragRecognizer]; |
| [[_positioningGuide owningView] removeLayoutGuide:_positioningGuide]; |
| - [super dealloc]; |
| } |
| #pragma mark - Gesture recognizer callbacks |
| @@ -465,12 +460,12 @@ const CGFloat kShadowElevation = MDCShadowElevationMenu; |
| (UIGestureRecognizer*)otherGestureRecognizer { |
| // Allow the drag recognizer and the panel content scroll recognizer to |
| // co-recognize. |
| - if (gestureRecognizer == _dragRecognizer.get() && |
| + if (gestureRecognizer == _dragRecognizer && |
| otherGestureRecognizer == self.scrollSynchronizer.scrollRecognizer) { |
| return YES; |
| } |
| - if (gestureRecognizer == _dragRecognizer.get() && |
| + if (gestureRecognizer == _dragRecognizer && |
| [_dragRecognizer state] == UIGestureRecognizerStateChanged) { |
| [gestureRecognizer setEnabled:NO]; |
| } |