Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Unified Diff: ios/chrome/browser/ui/ntp/google_landing_view_controller.mm

Issue 2889963002: [ObjC ARC] Converts ios/chrome/browser/ui/ntp:ntp_internal to ARC.
Patch Set: Moved testing method accessing ivars to a category Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/ntp/google_landing_view_controller.mm
diff --git a/ios/chrome/browser/ui/ntp/google_landing_view_controller.mm b/ios/chrome/browser/ui/ntp/google_landing_view_controller.mm
index 5eac738e696ef9a2a60bcaaf9e86a73659606182..9266e1f9a91e04f507b7ac82ffb33a284cabe98f 100644
--- a/ios/chrome/browser/ui/ntp/google_landing_view_controller.mm
+++ b/ios/chrome/browser/ui/ntp/google_landing_view_controller.mm
@@ -35,6 +35,10 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/page_transition_types.h"
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
using base::UserMetricsAction;
namespace {
@@ -99,28 +103,27 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
UIGestureRecognizerDelegate,
WhatsNewHeaderViewDelegate> {
// Fake omnibox.
- base::scoped_nsobject<UIButton> _searchTapTarget;
+ UIButton* _searchTapTarget;
// A collection view for the most visited sites.
- base::scoped_nsobject<UICollectionView> _mostVisitedView;
+ UICollectionView* _mostVisitedView;
// The overscroll actions controller managing accelerators over the toolbar.
- base::scoped_nsobject<OverscrollActionsController>
- _overscrollActionsController;
+ OverscrollActionsController* _overscrollActionsController;
// |YES| when notifications indicate the omnibox is focused.
BOOL _omniboxFocused;
// Tap and swipe gesture recognizers when the omnibox is focused.
- base::scoped_nsobject<UITapGestureRecognizer> _tapGestureRecognizer;
- base::scoped_nsobject<UISwipeGestureRecognizer> _swipeGestureRecognizer;
+ UITapGestureRecognizer* _tapGestureRecognizer;
+ UISwipeGestureRecognizer* _swipeGestureRecognizer;
// Handles displaying the context menu for all form factors.
- base::scoped_nsobject<ContextMenuCoordinator> _contextMenuCoordinator;
+ ContextMenuCoordinator* _contextMenuCoordinator;
// URL of the last deleted most viewed entry. If present the UI to restore it
// is shown.
- base::scoped_nsobject<NSURL> _deletedUrl;
+ NSURL* _deletedUrl;
// |YES| if the view has finished its first layout. This is useful when
// determining if the view has sized itself for tablet.
@@ -139,11 +142,11 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
CFTimeInterval _shiftTilesDownStartTime;
CGSize _mostVisitedCellSize;
- base::scoped_nsobject<NSLayoutConstraint> _hintLabelLeadingConstraint;
- base::scoped_nsobject<NSLayoutConstraint> _voiceTapTrailingConstraint;
- base::scoped_nsobject<NSMutableArray> _supplementaryViews;
- base::scoped_nsobject<NewTabPageHeaderView> _headerView;
- base::scoped_nsobject<WhatsNewHeaderView> _promoHeaderView;
+ NSLayoutConstraint* _hintLabelLeadingConstraint;
+ NSLayoutConstraint* _voiceTapTrailingConstraint;
+ NSMutableArray* _supplementaryViews;
+ NewTabPageHeaderView* _headerView;
+ WhatsNewHeaderView* _promoHeaderView;
}
// Redeclare the |view| property to be the GoogleLandingView subclass instead of
@@ -154,7 +157,7 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
@property(nonatomic, assign) BOOL logoIsShowing;
// Exposes view and methods to drive the doodle.
-@property(nonatomic, assign) id<LogoVendor> logoVendor;
+@property(nonatomic, weak) id<LogoVendor> logoVendor;
// |YES| if this consumer is incognito.
@property(nonatomic, assign) BOOL isOffTheRecord;
@@ -166,7 +169,7 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
@property(nonatomic, assign) NSUInteger maximumMostVisitedSitesShown;
// Gets the text of a what's new promo.
-@property(nonatomic, retain) NSString* promoText;
+@property(nonatomic, strong) NSString* promoText;
// Gets the icon of a what's new promo.
// TODO(crbug.com/694750): This should not be WhatsNewIcon.
@@ -250,8 +253,8 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
@synthesize voiceSearchIsEnabled = _voiceSearchIsEnabled;
- (void)loadView {
- self.view = [[[GoogleLandingView alloc]
- initWithFrame:[UIScreen mainScreen].bounds] autorelease];
+ self.view =
+ [[GoogleLandingView alloc] initWithFrame:[UIScreen mainScreen].bounds];
}
- (void)viewDidLoad {
@@ -268,13 +271,13 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
_scrolledToTop = NO;
_animateHeader = YES;
- _tapGestureRecognizer.reset([[UITapGestureRecognizer alloc]
- initWithTarget:self
- action:@selector(blurOmnibox)]);
+ _tapGestureRecognizer =
+ [[UITapGestureRecognizer alloc] initWithTarget:self
+ action:@selector(blurOmnibox)];
[_tapGestureRecognizer setDelegate:self];
- _swipeGestureRecognizer.reset([[UISwipeGestureRecognizer alloc]
- initWithTarget:self
- action:@selector(blurOmnibox)]);
+ _swipeGestureRecognizer =
+ [[UISwipeGestureRecognizer alloc] initWithTarget:self
+ action:@selector(blurOmnibox)];
[_swipeGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionDown];
[self addSearchField];
@@ -319,7 +322,6 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
[_mostVisitedView setDelegate:nil];
[_mostVisitedView setDataSource:nil];
[_overscrollActionsController invalidate];
- [super dealloc];
}
#pragma mark - Private
@@ -398,7 +400,7 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
- (void)addSearchField {
CGRect searchFieldFrame = content_suggestions::searchFieldFrame(
[self viewWidth], self.logoIsShowing);
- _searchTapTarget.reset([[UIButton alloc] initWithFrame:searchFieldFrame]);
+ _searchTapTarget = [[UIButton alloc] initWithFrame:searchFieldFrame];
if (IsIPadIdiom()) {
UIImage* searchBoxImage = [[UIImage imageNamed:@"ntp_google_search_box"]
resizableImageWithCapInsets:kSearchBoxStretchInsets];
@@ -415,22 +417,22 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
[_searchTapTarget setIsAccessibilityElement:NO];
// Set up fakebox hint label.
- UILabel* searchHintLabel = [[[UILabel alloc] init] autorelease];
+ UILabel* searchHintLabel = [[UILabel alloc] init];
content_suggestions::configureSearchHintLabel(
- searchHintLabel, _searchTapTarget.get(), searchFieldFrame.size.width);
+ searchHintLabel, _searchTapTarget, searchFieldFrame.size.width);
- _hintLabelLeadingConstraint.reset([[searchHintLabel.leadingAnchor
+ _hintLabelLeadingConstraint = [searchHintLabel.leadingAnchor
constraintEqualToAnchor:[_searchTapTarget leadingAnchor]
- constant:kHintLabelSidePadding] retain]);
+ constant:kHintLabelSidePadding];
[_hintLabelLeadingConstraint setActive:YES];
// Add a voice search button.
- UIButton* voiceTapTarget = [[[UIButton alloc] init] autorelease];
+ UIButton* voiceTapTarget = [[UIButton alloc] init];
content_suggestions::configureVoiceSearchButton(voiceTapTarget,
- _searchTapTarget.get());
+ _searchTapTarget);
- _voiceTapTrailingConstraint.reset([[voiceTapTarget.trailingAnchor
- constraintEqualToAnchor:[_searchTapTarget trailingAnchor]] retain]);
+ _voiceTapTrailingConstraint = [voiceTapTarget.trailingAnchor
+ constraintEqualToAnchor:[_searchTapTarget trailingAnchor]];
[NSLayoutConstraint activateConstraints:@[
[searchHintLabel.trailingAnchor
constraintEqualToAnchor:voiceTapTarget.leadingAnchor],
@@ -463,8 +465,8 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
// Use a GenericChromeCommand because |sender| already has a tag set for a
// different command.
- base::scoped_nsobject<GenericChromeCommand> command(
- [[GenericChromeCommand alloc] initWithTag:IDC_PRELOAD_VOICE_SEARCH]);
+ GenericChromeCommand* command =
+ [[GenericChromeCommand alloc] initWithTag:IDC_PRELOAD_VOICE_SEARCH];
[sender chromeExecuteCommand:command];
}
@@ -502,7 +504,7 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
// crbug.com/491131
CGFloat collectionViewWidth = CGRectGetWidth([_mostVisitedView bounds]);
CGFloat collectionViewMinX = CGRectGetMinX([_mostVisitedView bounds]);
- for (UIView* supplementaryView in _supplementaryViews.get()) {
+ for (UIView* supplementaryView in _supplementaryViews) {
CGRect supplementaryViewFrame = supplementaryView.frame;
supplementaryViewFrame.origin.x = collectionViewMinX;
supplementaryViewFrame.size.width = collectionViewWidth;
@@ -534,20 +536,19 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
// Initialize and add a panel with most visited sites.
- (void)addMostVisited {
CGRect mostVisitedFrame = [self.view bounds];
- base::scoped_nsobject<UICollectionViewFlowLayout> flowLayout;
+ UICollectionViewFlowLayout* flowLayout;
if (IsIPadIdiom())
- flowLayout.reset([[UICollectionViewFlowLayout alloc] init]);
+ flowLayout = [[UICollectionViewFlowLayout alloc] init];
else
- flowLayout.reset([[MostVisitedLayout alloc] init]);
+ flowLayout = [[MostVisitedLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
[flowLayout setItemSize:_mostVisitedCellSize];
[flowLayout setMinimumInteritemSpacing:8];
[flowLayout setMinimumLineSpacing:content_suggestions::spacingBetweenTiles()];
DCHECK(!_mostVisitedView);
- _mostVisitedView.reset([[UICollectionView alloc]
- initWithFrame:mostVisitedFrame
- collectionViewLayout:flowLayout]);
+ _mostVisitedView = [[UICollectionView alloc] initWithFrame:mostVisitedFrame
+ collectionViewLayout:flowLayout];
[_mostVisitedView setAutoresizingMask:UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth];
[_mostVisitedView setDelegate:self];
@@ -581,8 +582,8 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
- (void)addOverscrollActions {
if (!IsIPadIdiom()) {
- _overscrollActionsController.reset([[OverscrollActionsController alloc]
- initWithScrollView:_mostVisitedView]);
+ _overscrollActionsController = [[OverscrollActionsController alloc]
+ initWithScrollView:_mostVisitedView];
[_overscrollActionsController setStyle:OverscrollStyle::NTP_NON_INCOGNITO];
[_overscrollActionsController setDelegate:self];
}
@@ -781,11 +782,11 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
// TODO(jif): This needs a radar, since it is almost certainly a
// UIKit accessibility bug. crbug.com/529271
if (UIAccessibilityIsVoiceOverRunning()) {
- UICollectionView* blockView = [_mostVisitedView retain];
+ __block UICollectionView* blockView = _mostVisitedView;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
static_cast<int64_t>(1 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
- [blockView release];
+ blockView = nil;
});
}
@@ -807,15 +808,15 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
DCHECK(kind == UICollectionElementKindSectionHeader);
if (!_supplementaryViews)
- _supplementaryViews.reset([[NSMutableArray alloc] init]);
+ _supplementaryViews = [[NSMutableArray alloc] init];
if (indexPath.section == SectionWithOmnibox) {
if (!_headerView) {
- _headerView.reset([[collectionView
- dequeueReusableSupplementaryViewOfKind:
- UICollectionElementKindSectionHeader
- withReuseIdentifier:@"header"
- forIndexPath:indexPath] retain]);
+ _headerView =
+ [collectionView dequeueReusableSupplementaryViewOfKind:
+ UICollectionElementKindSectionHeader
+ withReuseIdentifier:@"header"
+ forIndexPath:indexPath];
[_headerView addSubview:[self.logoVendor view]];
[_headerView addSubview:_searchTapTarget];
[_headerView addViewsToSearchField:_searchTapTarget];
@@ -836,11 +837,11 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
if (indexPath.section == SectionWithMostVisited) {
if (!_promoHeaderView) {
- _promoHeaderView.reset([[collectionView
- dequeueReusableSupplementaryViewOfKind:
- UICollectionElementKindSectionHeader
- withReuseIdentifier:@"whatsNew"
- forIndexPath:indexPath] retain]);
+ _promoHeaderView =
+ [collectionView dequeueReusableSupplementaryViewOfKind:
+ UICollectionElementKindSectionHeader
+ withReuseIdentifier:@"whatsNew"
+ forIndexPath:indexPath];
[_promoHeaderView
setSideMargin:content_suggestions::centeredTilesMarginForWidth(
[self viewWidth])];
@@ -905,10 +906,10 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
[cell setupWithURL:ntpTile.url title:title dataSource:self.dataSource];
- base::scoped_nsobject<UILongPressGestureRecognizer> longPress(
+ UILongPressGestureRecognizer* longPress =
[[UILongPressGestureRecognizer alloc]
initWithTarget:self
- action:@selector(handleMostVisitedLongPress:)]);
+ action:@selector(handleMostVisitedLongPress:)];
[cell addGestureRecognizer:longPress];
return cell;
@@ -935,25 +936,24 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
web::ContextMenuParams params;
// Get view coordinates in local space.
params.location = [sender locationInView:self.view];
- params.view.reset([self.view retain]);
+ params.view.reset(self.view);
// Present sheet/popover using controller that is added to view hierarchy.
UIViewController* topController = [params.view window].rootViewController;
while (topController.presentedViewController)
topController = topController.presentedViewController;
- _contextMenuCoordinator.reset([[ContextMenuCoordinator alloc]
- initWithBaseViewController:topController
- params:params]);
+ _contextMenuCoordinator =
+ [[ContextMenuCoordinator alloc] initWithBaseViewController:topController
+ params:params];
ProceduralBlock action;
// Open In New Tab.
GURL url = [self urlForIndex:index];
- base::WeakNSObject<GoogleLandingViewController> weakSelf(self);
+ __weak GoogleLandingViewController* weakSelf = self;
action = ^{
- base::scoped_nsobject<GoogleLandingViewController> strongSelf(
- [weakSelf retain]);
+ GoogleLandingViewController* strongSelf = weakSelf;
if (!strongSelf)
return;
MostVisitedCell* cell = (MostVisitedCell*)sender.view;
@@ -972,8 +972,7 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
if (!self.isOffTheRecord) {
// Open in Incognito Tab.
action = ^{
- base::scoped_nsobject<GoogleLandingViewController> strongSelf(
- [weakSelf retain]);
+ GoogleLandingViewController* strongSelf = weakSelf;
if (!strongSelf)
return;
MostVisitedCell* cell = (MostVisitedCell*)sender.view;
@@ -995,8 +994,7 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
NSString* title =
l10n_util::GetNSStringWithFixup(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK);
action = ^{
- base::scoped_nsobject<GoogleLandingViewController> strongSelf(
- [weakSelf retain]);
+ GoogleLandingViewController* strongSelf = weakSelf;
// Early return if the controller has been deallocated.
if (!strongSelf)
return;
@@ -1014,14 +1012,12 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
}
- (void)showMostVisitedUndoForURL:(NSURL*)url {
- _deletedUrl.reset([url retain]);
+ _deletedUrl = url;
- MDCSnackbarMessageAction* action =
- [[[MDCSnackbarMessageAction alloc] init] autorelease];
- base::WeakNSObject<GoogleLandingViewController> weakSelf(self);
+ MDCSnackbarMessageAction* action = [[MDCSnackbarMessageAction alloc] init];
+ __weak GoogleLandingViewController* weakSelf = self;
action.handler = ^{
- base::scoped_nsobject<GoogleLandingViewController> strongSelf(
- [weakSelf retain]);
+ GoogleLandingViewController* strongSelf = weakSelf;
if (!strongSelf)
return;
[[strongSelf dataSource]
@@ -1242,13 +1238,13 @@ const CGFloat kShiftTilesDownAnimationDuration = 0.2;
didTriggerAction:(OverscrollAction)action {
switch (action) {
case OverscrollAction::NEW_TAB: {
- base::scoped_nsobject<GenericChromeCommand> command(
- [[GenericChromeCommand alloc] initWithTag:IDC_NEW_TAB]);
+ GenericChromeCommand* command =
+ [[GenericChromeCommand alloc] initWithTag:IDC_NEW_TAB];
[[self view] chromeExecuteCommand:command];
} break;
case OverscrollAction::CLOSE_TAB: {
- base::scoped_nsobject<GenericChromeCommand> command(
- [[GenericChromeCommand alloc] initWithTag:IDC_CLOSE_TAB]);
+ GenericChromeCommand* command =
+ [[GenericChromeCommand alloc] initWithTag:IDC_CLOSE_TAB];
[[self view] chromeExecuteCommand:command];
} break;
case OverscrollAction::REFRESH:
« no previous file with comments | « ios/chrome/browser/ui/ntp/google_landing_view_controller.h ('k') | ios/chrome/browser/ui/ntp/incognito_panel_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698