| Index: ios/chrome/browser/ui/stack_view/stack_view_controller.mm
|
| diff --git a/ios/chrome/browser/ui/stack_view/stack_view_controller.mm b/ios/chrome/browser/ui/stack_view/stack_view_controller.mm
|
| index f736b018fc571638106ed5a40d37088207a96822..2dabb01b3b8b8e71a5568ec758f8950f9b8a035a 100644
|
| --- a/ios/chrome/browser/ui/stack_view/stack_view_controller.mm
|
| +++ b/ios/chrome/browser/ui/stack_view/stack_view_controller.mm
|
| @@ -12,11 +12,13 @@
|
|
|
| #include "base/format_macros.h"
|
| #import "base/ios/block_types.h"
|
| +#import "base/ios/weak_nsobject.h"
|
| #include "base/logging.h"
|
| #import "base/mac/bundle_locations.h"
|
| #import "base/mac/foundation_util.h"
|
| -
|
| +#import "base/mac/objc_property_releaser.h"
|
| #include "base/mac/scoped_block.h"
|
| +#import "base/mac/scoped_nsobject.h"
|
| #include "base/metrics/histogram_macros.h"
|
| #include "base/metrics/user_metrics.h"
|
| #include "base/metrics/user_metrics_action.h"
|
| @@ -55,10 +57,6 @@
|
| #include "ios/web/public/referrer.h"
|
| #import "net/base/mac/url_conversions.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| -
|
| -#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| -#error "This file requires ARC support."
|
| -#endif
|
|
|
| using base::UserMetricsAction;
|
|
|
| @@ -443,44 +441,45 @@
|
| @end
|
|
|
| @implementation StackViewController {
|
| - UIScrollView* _scrollView;
|
| + base::scoped_nsobject<UIScrollView> _scrollView;
|
| // The view containing the stack view's background.
|
| - UIView* _backgroundView;
|
| + base::scoped_nsobject<UIView> _backgroundView;
|
| // The main card set.
|
| - CardSet* _mainCardSet;
|
| + base::scoped_nsobject<CardSet> _mainCardSet;
|
| // The off-the-record card set.
|
| - CardSet* _otrCardSet;
|
| + base::scoped_nsobject<CardSet> _otrCardSet;
|
| // The currently active card set; one of _mainCardSet or _otrCardSet.
|
| - __weak CardSet* _activeCardSet;
|
| - __weak id<TabSwitcherDelegate> _delegate;
|
| - __weak id<StackViewControllerTestDelegate> _testDelegate;
|
| + CardSet* _activeCardSet; // weak
|
| + id<TabSwitcherDelegate> _delegate; // weak
|
| + id<StackViewControllerTestDelegate> _testDelegate; // weak
|
| // Controller for the stack view toolbar.
|
| - StackViewToolbarController* _toolbarController;
|
| + base::scoped_nsobject<StackViewToolbarController> _toolbarController;
|
| // The size of a card at the time the stack was first shown.
|
| CGSize _initialCardSize;
|
| // The previous orientation of the interface.
|
| UIInterfaceOrientation _lastInterfaceOrientation;
|
| // Gesture recognizer to catch taps on the inactive stack.
|
| - UITapGestureRecognizer* _modeSwitchRecognizer;
|
| + base::scoped_nsobject<UITapGestureRecognizer> _modeSwitchRecognizer;
|
| // Gesture recognizer to catch pinches in the active scroll view.
|
| - UIGestureRecognizer* _pinchRecognizer;
|
| + base::scoped_nsobject<UIGestureRecognizer> _pinchRecognizer;
|
| // Gesture recognizer to catch swipes to switch decks/dismiss cards.
|
| - UIGestureRecognizer* _swipeGestureRecognizer;
|
| + base::scoped_nsobject<UIGestureRecognizer> _swipeGestureRecognizer;
|
| // Gesture recognizer that determines whether an ambiguous swipe action
|
| // (i.e., a swipe on an active card in the direction that would cause a deck
|
| // change) should trigger a change of decks or a card dismissal.
|
| - UILongPressGestureRecognizer* _swipeDismissesCardRecognizer;
|
| + base::scoped_nsobject<UILongPressGestureRecognizer>
|
| + _swipeDismissesCardRecognizer;
|
| // Tracks the parameters of gesture-related events.
|
| - GestureStateTracker* _gestureStateTracker;
|
| + base::scoped_nsobject<GestureStateTracker> _gestureStateTracker;
|
| // If |YES|, callbacks to |scrollViewDidScroll:| do not trigger scrolling.
|
| // Default is |NO|.
|
| BOOL _ignoreScrollCallbacks;
|
| // The scroll view's pan gesture recognizer.
|
| - __weak UIPanGestureRecognizer* _scrollGestureRecognizer;
|
| + UIPanGestureRecognizer* _scrollGestureRecognizer; // weak
|
| // Because the removal of the StackCard during a swipe happens in a callback,
|
| // track which direction the animation should dismiss with.
|
| // |_reverseDismissCard| is only set when the dismissal happens in reverse.
|
| - StackCard* _reverseDismissCard;
|
| + base::scoped_nsobject<StackCard> _reverseDismissCard;
|
| // |YES| if the stack view is in the process of being dismissed.
|
| BOOL _isBeingDismissed;
|
| // |YES| if the stack view is currently active.
|
| @@ -490,6 +489,8 @@
|
| // |YES| if there is card set animation being processed. For testing only.
|
| // Save last touch point used by new tab animation.
|
| CGPoint _lastTapPoint;
|
| +
|
| + base::mac::ObjCPropertyReleaser _propertyReleaserStackViewController;
|
| }
|
|
|
| @synthesize activeCardSet = _activeCardSet;
|
| @@ -512,23 +513,25 @@
|
| DCHECK(activeCardSet == otrCardSet || activeCardSet == mainCardSet);
|
| self = [super initWithNibName:nil bundle:nil];
|
| if (self) {
|
| + _propertyReleaserStackViewController.Init(self,
|
| + [StackViewController class]);
|
| [self setUpWithMainCardSet:mainCardSet
|
| otrCardSet:otrCardSet
|
| activeCardSet:activeCardSet];
|
| - _swipeDismissesCardRecognizer = [[UILongPressGestureRecognizer alloc]
|
| + _swipeDismissesCardRecognizer.reset([[UILongPressGestureRecognizer alloc]
|
| initWithTarget:self
|
| - action:@selector(handleLongPressFrom:)];
|
| + action:@selector(handleLongPressFrom:)]);
|
| [_swipeDismissesCardRecognizer
|
| setMinimumPressDuration:
|
| kPressDurationForAmbiguousSwipeToTriggerDismissal];
|
| [_swipeDismissesCardRecognizer setDelegate:self];
|
| - _pinchRecognizer = [[CardStackPinchGestureRecognizer alloc]
|
| + _pinchRecognizer.reset([[CardStackPinchGestureRecognizer alloc]
|
| initWithTarget:self
|
| - action:@selector(handlePinchFrom:)];
|
| + action:@selector(handlePinchFrom:)]);
|
| [_pinchRecognizer setDelegate:self];
|
| - _modeSwitchRecognizer = [[UITapGestureRecognizer alloc]
|
| + _modeSwitchRecognizer.reset([[UITapGestureRecognizer alloc]
|
| initWithTarget:self
|
| - action:@selector(handleTapFrom:)];
|
| + action:@selector(handleTapFrom:)]);
|
| [_modeSwitchRecognizer setDelegate:self];
|
| }
|
| return self;
|
| @@ -540,10 +543,12 @@
|
| DCHECK(mainModel);
|
| DCHECK(otrModel);
|
| DCHECK(activeModel == otrModel || activeModel == mainModel);
|
| - CardSet* mainCardSet = [[CardSet alloc] initWithModel:mainModel];
|
| - CardSet* otrCardSet = [[CardSet alloc] initWithModel:otrModel];
|
| + base::scoped_nsobject<CardSet> mainCardSet(
|
| + [[CardSet alloc] initWithModel:mainModel]);
|
| + base::scoped_nsobject<CardSet> otrCardSet(
|
| + [[CardSet alloc] initWithModel:otrModel]);
|
| CardSet* activeCardSet =
|
| - (activeModel == mainModel) ? mainCardSet : otrCardSet;
|
| + (activeModel == mainModel) ? mainCardSet.get() : otrCardSet.get();
|
| return [self initWithMainCardSet:mainCardSet
|
| otrCardSet:otrCardSet
|
| activeCardSet:activeCardSet];
|
| @@ -563,21 +568,21 @@
|
| - (void)setUpWithMainCardSet:(CardSet*)mainCardSet
|
| otrCardSet:(CardSet*)otrCardSet
|
| activeCardSet:(CardSet*)activeCardSet {
|
| - _mainCardSet = mainCardSet;
|
| - _otrCardSet = otrCardSet;
|
| + _mainCardSet.reset([mainCardSet retain]);
|
| + _otrCardSet.reset([otrCardSet retain]);
|
| if (experimental_flags::IsLRUSnapshotCacheEnabled()) {
|
| [_mainCardSet setKeepOnlyVisibleCardViewsAlive:YES];
|
| [_otrCardSet setKeepOnlyVisibleCardViewsAlive:YES];
|
| }
|
| _activeCardSet = (activeCardSet == mainCardSet) ? mainCardSet : otrCardSet;
|
| - _gestureStateTracker = [[GestureStateTracker alloc] init];
|
| - _pinchRecognizer = [[CardStackPinchGestureRecognizer alloc]
|
| + _gestureStateTracker.reset([[GestureStateTracker alloc] init]);
|
| + _pinchRecognizer.reset([[CardStackPinchGestureRecognizer alloc]
|
| initWithTarget:self
|
| - action:@selector(handlePinchFrom:)];
|
| + action:@selector(handlePinchFrom:)]);
|
| [_pinchRecognizer setDelegate:self];
|
| - _modeSwitchRecognizer =
|
| - [[UITapGestureRecognizer alloc] initWithTarget:self
|
| - action:@selector(handleTapFrom:)];
|
| + _modeSwitchRecognizer.reset([[UITapGestureRecognizer alloc]
|
| + initWithTarget:self
|
| + action:@selector(handleTapFrom:)]);
|
| [_modeSwitchRecognizer setDelegate:self];
|
| }
|
|
|
| @@ -588,10 +593,12 @@
|
| DCHECK(otrModel);
|
| DCHECK(activeModel == otrModel || activeModel == mainModel);
|
| DCHECK(!_isActive);
|
| - CardSet* mainCardSet = [[CardSet alloc] initWithModel:mainModel];
|
| - CardSet* otrCardSet = [[CardSet alloc] initWithModel:otrModel];
|
| + base::scoped_nsobject<CardSet> mainCardSet(
|
| + [[CardSet alloc] initWithModel:mainModel]);
|
| + base::scoped_nsobject<CardSet> otrCardSet(
|
| + [[CardSet alloc] initWithModel:otrModel]);
|
| CardSet* activeCardSet =
|
| - (activeModel == mainModel) ? mainCardSet : otrCardSet;
|
| + (activeModel == mainModel) ? mainCardSet.get() : otrCardSet.get();
|
| [self setUpWithMainCardSet:mainCardSet
|
| otrCardSet:otrCardSet
|
| activeCardSet:activeCardSet];
|
| @@ -623,16 +630,16 @@
|
| // memory notification is not received and the view is never unloaded.
|
| [self deregisterForNotifications];
|
|
|
| - _mainCardSet = nil;
|
| - _otrCardSet = nil;
|
| + _mainCardSet.reset();
|
| + _otrCardSet.reset();
|
| _activeCardSet = nil;
|
|
|
| // Remove gesture recognizers and notifications.
|
| [self prepareForDismissal];
|
| - _gestureStateTracker = nil;
|
| - _pinchRecognizer = nil;
|
| - _modeSwitchRecognizer = nil;
|
| - _swipeGestureRecognizer = nil;
|
| + _gestureStateTracker.reset();
|
| + _pinchRecognizer.reset();
|
| + _modeSwitchRecognizer.reset();
|
| + _swipeGestureRecognizer.reset();
|
|
|
| // The cards need to recompute their sizes the next time they are shown.
|
| _initialCardSize.height = _initialCardSize.width = 0.0f;
|
| @@ -669,10 +676,12 @@
|
| - (void)setUpDisplayViews {
|
| CGRect displayViewFrame = CGRectMake(0, 0, [_scrollView frame].size.width,
|
| [_scrollView frame].size.height);
|
| - UIView* mainDisplayView = [[UIView alloc] initWithFrame:displayViewFrame];
|
| + base::scoped_nsobject<UIView> mainDisplayView(
|
| + [[UIView alloc] initWithFrame:displayViewFrame]);
|
| [mainDisplayView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
|
| UIViewAutoresizingFlexibleHeight];
|
| - UIView* otrDisplayView = [[UIView alloc] initWithFrame:displayViewFrame];
|
| + base::scoped_nsobject<UIView> otrDisplayView(
|
| + [[UIView alloc] initWithFrame:displayViewFrame]);
|
| [otrDisplayView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
|
| UIViewAutoresizingFlexibleHeight];
|
|
|
| @@ -705,7 +714,7 @@
|
| [[UIPanGestureRecognizer alloc] initWithTarget:self
|
| action:@selector(handlePanFrom:)];
|
| [panGestureRecognizer setMaximumNumberOfTouches:1];
|
| - _swipeGestureRecognizer = panGestureRecognizer;
|
| + _swipeGestureRecognizer.reset(panGestureRecognizer);
|
| [[self view] addGestureRecognizer:_swipeGestureRecognizer];
|
| [_swipeGestureRecognizer setDelegate:self];
|
| }
|
| @@ -713,13 +722,13 @@
|
| - (void)loadView {
|
| [super loadView];
|
|
|
| - _backgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
|
| + _backgroundView.reset([[UIView alloc] initWithFrame:self.view.bounds]);
|
| [_backgroundView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight |
|
| UIViewAutoresizingFlexibleWidth)];
|
| [self.view addSubview:_backgroundView];
|
|
|
| - _toolbarController =
|
| - [[StackViewToolbarController alloc] initWithStackViewToolbar];
|
| + _toolbarController.reset(
|
| + [[StackViewToolbarController alloc] initWithStackViewToolbar]);
|
| CGRect toolbarFrame = [self.view bounds];
|
| toolbarFrame.origin.y = CGRectGetMinY([[_toolbarController view] frame]);
|
| toolbarFrame.size.height = CGRectGetHeight([[_toolbarController view] frame]);
|
| @@ -733,7 +742,7 @@
|
| toolbarFrame.size.height - kVerticalToolbarOverlap, 0.0, 0.0, 0.0);
|
| CGRect scrollViewFrame =
|
| UIEdgeInsetsInsetRect(self.view.bounds, contentInsets);
|
| - _scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
|
| + _scrollView.reset([[UIScrollView alloc] initWithFrame:scrollViewFrame]);
|
| [self.view addSubview:_scrollView];
|
| [_scrollView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight |
|
| UIViewAutoresizingFlexibleWidth)];
|
| @@ -774,7 +783,7 @@
|
|
|
| // Reset the gesture state tracker to clear gesture-related information from
|
| // the last time the stack view was shown.
|
| - _gestureStateTracker = [[GestureStateTracker alloc] init];
|
| + _gestureStateTracker.reset([[GestureStateTracker alloc] init]);
|
|
|
| [super viewWillAppear:animated];
|
| }
|
| @@ -807,6 +816,7 @@
|
| [_mainCardSet setObserver:nil];
|
| [_otrCardSet setObserver:nil];
|
| [self cleanUpViewsAndNotifications];
|
| + [super dealloc];
|
| }
|
|
|
| // Overridden to always return NO, ensuring that the status bar shows in
|
| @@ -950,8 +960,8 @@
|
| // Stop pre-loading cards.
|
| [NSObject cancelPreviousPerformRequestsWithTarget:self];
|
| [_scrollView setDelegate:nil];
|
| - _scrollView = nil;
|
| - _backgroundView = nil;
|
| + _scrollView.reset();
|
| + _backgroundView.reset();
|
| [[NSNotificationCenter defaultCenter] removeObserver:self];
|
| }
|
|
|
| @@ -1067,8 +1077,8 @@
|
| // world.
|
| // (see the comment in -cardSet:willRemoveCard:atIndex for details).
|
| [_scrollView setScrollEnabled:NO];
|
| - _pinchRecognizer.enabled = NO;
|
| - _swipeGestureRecognizer.enabled = NO;
|
| + _pinchRecognizer.get().enabled = NO;
|
| + _swipeGestureRecognizer.get().enabled = NO;
|
| }
|
|
|
| - (void)enableGestureHandlers {
|
| @@ -1077,8 +1087,8 @@
|
| // world.
|
| // (see the comment in -cardSet:willRemoveCard:atIndex for details).
|
| [_scrollView setScrollEnabled:YES];
|
| - _pinchRecognizer.enabled = YES;
|
| - _swipeGestureRecognizer.enabled = YES;
|
| + _pinchRecognizer.get().enabled = YES;
|
| + _swipeGestureRecognizer.get().enabled = YES;
|
| }
|
|
|
| - (void)activeCardCountChanged {
|
| @@ -1207,11 +1217,11 @@
|
| #pragma mark Current Set Handling
|
|
|
| - (BOOL)isCurrentSetIncognito {
|
| - return _activeCardSet == _otrCardSet;
|
| + return _activeCardSet == _otrCardSet.get();
|
| }
|
|
|
| - (CardSet*)inactiveCardSet {
|
| - return [self isCurrentSetIncognito] ? _mainCardSet : _otrCardSet;
|
| + return [self isCurrentSetIncognito] ? _mainCardSet.get() : _otrCardSet.get();
|
| }
|
|
|
| - (void)setActiveCardSet:(CardSet*)cardSet {
|
| @@ -1464,7 +1474,7 @@
|
| [_activeCardSet fanOutCardsWithStartIndex:0];
|
| [self postOpenTabsAccessibilityNotification];
|
| UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification,
|
| - _toolbarController.view);
|
| + _toolbarController.get().view);
|
| }
|
| }
|
|
|
| @@ -1575,7 +1585,8 @@
|
| self.transitionToolbarFrame = self.transitionToolbarController.view.frame;
|
|
|
| // Create dummy toolbar background view.
|
| - self.dummyToolbarBackgroundView = [[UIView alloc] initWithFrame:CGRectZero];
|
| + self.dummyToolbarBackgroundView =
|
| + [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
|
| [self.dummyToolbarBackgroundView setClipsToBounds:YES];
|
|
|
| // Set the transition completion block.
|
| @@ -2050,7 +2061,8 @@
|
| CGRect viewBounds, remainder;
|
| CGRectDivide([self.view bounds], &remainder, &viewBounds, statusBarHeight,
|
| CGRectMinYEdge);
|
| - UIImageView* newCard = [[UIImageView alloc] initWithFrame:viewBounds];
|
| + UIImageView* newCard =
|
| + [[[UIImageView alloc] initWithFrame:viewBounds] autorelease];
|
| // Temporarily resize the tab's view to ensure it matches the card while
|
| // generating a snapshot, but then restore the original frame.
|
| CGRect originalTabFrame = [tab view].frame;
|
| @@ -2087,7 +2099,7 @@
|
| return NO;
|
|
|
| if ((recognizer == _pinchRecognizer) ||
|
| - (recognizer == _swipeGestureRecognizer))
|
| + (recognizer == _swipeGestureRecognizer.get()))
|
| return YES;
|
|
|
| // Only the mode switch recognizer should be triggered in the inactive deck
|
| @@ -2095,7 +2107,7 @@
|
| CGPoint touchLocation = [touch locationInView:_scrollView];
|
| BOOL inInactiveDeckRegion =
|
| CGRectContainsPoint([self inactiveDeckRegion], touchLocation);
|
| - if (recognizer == _modeSwitchRecognizer)
|
| + if (recognizer == _modeSwitchRecognizer.get())
|
| return inInactiveDeckRegion;
|
| else if (inInactiveDeckRegion)
|
| return NO;
|
| @@ -2103,7 +2115,7 @@
|
| // Extract the card on which the touch is occurring.
|
| CardView* cardView = nil;
|
| StackCard* card = nil;
|
| - if (recognizer == _swipeDismissesCardRecognizer) {
|
| + if (recognizer == _swipeDismissesCardRecognizer.get()) {
|
| UIView* activeView = _activeCardSet.displayView;
|
| CGPoint locationInActiveView = [touch locationInView:activeView];
|
| NSUInteger cardIndex = [self indexOfCardAtPoint:locationInActiveView];
|
| @@ -2155,8 +2167,8 @@
|
| (gestureRecognizer == _swipeGestureRecognizer ||
|
| otherGestureRecognizer == _swipeGestureRecognizer);
|
| BOOL swipeDismissesCardRecognizerInvolved =
|
| - (gestureRecognizer == _swipeDismissesCardRecognizer ||
|
| - otherGestureRecognizer == _swipeDismissesCardRecognizer);
|
| + (gestureRecognizer == _swipeDismissesCardRecognizer.get() ||
|
| + otherGestureRecognizer == _swipeDismissesCardRecognizer.get());
|
| if (swipeRecognizerInvolved && swipeDismissesCardRecognizerInvolved)
|
| return YES;
|
|
|
| @@ -2219,7 +2231,7 @@
|
| DCHECK(!_isBeingDismissed);
|
| DCHECK(_isActive);
|
|
|
| - if (recognizer == _swipeDismissesCardRecognizer)
|
| + if (recognizer == _swipeDismissesCardRecognizer.get())
|
| return;
|
|
|
| UIGestureRecognizerState state = [recognizer state];
|
| @@ -2394,7 +2406,7 @@
|
| if (recognizer.state != UIGestureRecognizerStateEnded)
|
| return;
|
|
|
| - if (recognizer == _modeSwitchRecognizer) {
|
| + if (recognizer == _modeSwitchRecognizer.get()) {
|
| DCHECK(CGRectContainsPoint([self inactiveDeckRegion],
|
| [recognizer locationInView:_scrollView]));
|
| [self setActiveCardSet:[self inactiveCardSet]];
|
| @@ -2634,7 +2646,7 @@
|
| // Track card if animation should dismiss in reverse from the norm of
|
| // clockwise in portrait, counter-clockwise in landscape.
|
| if ((isPortrait && !clockwise) || (!isPortrait && clockwise))
|
| - _reverseDismissCard = card;
|
| + _reverseDismissCard.reset([card retain]);
|
| // This will trigger the completion of the close card animation.
|
| [self closeTab:card.view];
|
| } else {
|
| @@ -2704,8 +2716,8 @@
|
| }
|
|
|
| - (void)showToolsMenuPopup {
|
| - ToolsMenuConfiguration* configuration =
|
| - [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]];
|
| + base::scoped_nsobject<ToolsMenuConfiguration> configuration(
|
| + [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]);
|
| [configuration setInTabSwitcher:YES];
|
| // When checking for the existence of tabs, catch the case where the main set
|
| // is both active and empty, but the incognito set has some cards.
|
| @@ -2894,7 +2906,7 @@
|
| completion:nil];
|
| // Reset |reverseDismissCard| if that card was the one dismissed.
|
| if ((isPortrait && !clockwise) || (!isPortrait && clockwise))
|
| - _reverseDismissCard = nil;
|
| + _reverseDismissCard.reset();
|
| }
|
| // Nil out the the closing card after all closing animations have finished.
|
| [CATransaction begin];
|
| @@ -2902,7 +2914,7 @@
|
| cardSet.closingCard = nil;
|
| }];
|
| // If the last incognito card closes, switch back to just the main set.
|
| - if ([cardSet.cards count] == 0 && cardSet == _otrCardSet) {
|
| + if ([cardSet.cards count] == 0 && cardSet == _otrCardSet.get()) {
|
| [self displayMainCardSetOnly];
|
| } else {
|
| NSUInteger numCards = [[cardSet cards] count];
|
| @@ -2951,18 +2963,18 @@
|
| [card.view addAccessibilityTarget:self
|
| action:@selector(accessibilityFocusedOnElement:)];
|
|
|
| - UIGestureRecognizer* tapRecognizer =
|
| - [[UITapGestureRecognizer alloc] initWithTarget:self
|
| - action:@selector(handleTapFrom:)];
|
| - tapRecognizer.delegate = self;
|
| - [card.view addGestureRecognizer:tapRecognizer];
|
| -
|
| - UIGestureRecognizer* longPressRecognizer =
|
| + base::scoped_nsobject<UIGestureRecognizer> tapRecognizer([
|
| + [UITapGestureRecognizer alloc] initWithTarget:self
|
| + action:@selector(handleTapFrom:)]);
|
| + tapRecognizer.get().delegate = self;
|
| + [card.view addGestureRecognizer:tapRecognizer.get()];
|
| +
|
| + base::scoped_nsobject<UIGestureRecognizer> longPressRecognizer(
|
| [[UILongPressGestureRecognizer alloc]
|
| initWithTarget:self
|
| - action:@selector(handleLongPressFrom:)];
|
| - longPressRecognizer.delegate = self;
|
| - [card.view addGestureRecognizer:longPressRecognizer];
|
| + action:@selector(handleLongPressFrom:)]);
|
| + longPressRecognizer.get().delegate = self;
|
| + [card.view addGestureRecognizer:longPressRecognizer.get()];
|
| }
|
|
|
| - (void)cardSetRecreatedCards:(CardSet*)cardSet {
|
| @@ -3448,12 +3460,15 @@
|
| #pragma mark - UIResponder
|
|
|
| - (NSArray*)keyCommands {
|
| - __weak StackViewController* weakSelf = self;
|
| + base::WeakNSObject<StackViewController> weakSelf(self);
|
|
|
| // Block to execute a command from the |tag|.
|
| - void (^execute)(NSInteger) = ^(NSInteger tag) {
|
| - [weakSelf chromeExecuteCommand:[GenericChromeCommand commandWithTag:tag]];
|
| - };
|
| + base::mac::ScopedBlock<void (^)(NSInteger)> execute(
|
| + ^(NSInteger tag) {
|
| + [weakSelf
|
| + chromeExecuteCommand:[GenericChromeCommand commandWithTag:tag]];
|
| + },
|
| + base::scoped_policy::RETAIN);
|
|
|
| return @[
|
| [UIKeyCommand cr_keyCommandWithInput:@"t"
|
| @@ -3462,9 +3477,9 @@
|
| IDS_IOS_TOOLS_MENU_NEW_TAB)
|
| action:^{
|
| if ([weakSelf isCurrentSetIncognito])
|
| - execute(IDC_NEW_INCOGNITO_TAB);
|
| + execute.get()(IDC_NEW_INCOGNITO_TAB);
|
| else
|
| - execute(IDC_NEW_TAB);
|
| + execute.get()(IDC_NEW_TAB);
|
| }],
|
| [UIKeyCommand
|
| cr_keyCommandWithInput:@"n"
|
| @@ -3472,16 +3487,16 @@
|
| title:l10n_util::GetNSStringWithFixup(
|
| IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB)
|
| action:^{
|
| - execute(IDC_NEW_INCOGNITO_TAB);
|
| + execute.get()(IDC_NEW_INCOGNITO_TAB);
|
| }],
|
| [UIKeyCommand cr_keyCommandWithInput:@"n"
|
| modifierFlags:UIKeyModifierCommand
|
| title:nil
|
| action:^{
|
| if ([weakSelf isCurrentSetIncognito])
|
| - execute(IDC_NEW_INCOGNITO_TAB);
|
| + execute.get()(IDC_NEW_INCOGNITO_TAB);
|
| else
|
| - execute(IDC_NEW_TAB);
|
| + execute.get()(IDC_NEW_TAB);
|
| }],
|
| ];
|
| }
|
| @@ -3491,7 +3506,7 @@
|
| @implementation StackViewController (Testing)
|
|
|
| - (UIScrollView*)scrollView {
|
| - return _scrollView;
|
| + return _scrollView.get();
|
| }
|
|
|
| @end
|
|
|