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

Side by Side Diff: ios/chrome/browser/ui/settings/settings_root_collection_view_controller.mm

Issue 2813223002: [ObjC ARC] Converts ios/chrome/browser/ui/settings:settings to ARC. (Closed)
Patch Set: reabse 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/settings/settings_root_collection_view_controller .h" 5 #import "ios/chrome/browser/ui/settings/settings_root_collection_view_controller .h"
6 6
7 #include "base/ios/ios_util.h" 7 #include "base/ios/ios_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #import "base/mac/foundation_util.h" 9 #import "base/mac/foundation_util.h"
10 #import "base/mac/objc_property_releaser.h" 10
11 #import "base/mac/scoped_nsobject.h"
12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
13 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" 12 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
14 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" 13 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
15 #import "ios/chrome/browser/ui/commands/open_url_command.h" 14 #import "ios/chrome/browser/ui/commands/open_url_command.h"
16 #import "ios/chrome/browser/ui/settings/bar_button_activity_indicator.h" 15 #import "ios/chrome/browser/ui/settings/bar_button_activity_indicator.h"
17 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" 16 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
18 #import "ios/chrome/browser/ui/settings/settings_utils.h" 17 #import "ios/chrome/browser/ui/settings/settings_utils.h"
19 #include "ios/chrome/browser/ui/ui_util.h" 18 #include "ios/chrome/browser/ui/ui_util.h"
20 #import "ios/chrome/browser/ui/uikit_ui_util.h" 19 #import "ios/chrome/browser/ui/uikit_ui_util.h"
21 #include "ios/chrome/grit/ios_strings.h" 20 #include "ios/chrome/grit/ios_strings.h"
22 #import "ios/third_party/material_components_ios/src/components/Collections/src/ MaterialCollections.h" 21 #import "ios/third_party/material_components_ios/src/components/Collections/src/ MaterialCollections.h"
23 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
24 23
24 #if !defined(__has_feature) || !__has_feature(objc_arc)
25 #error "This file requires ARC support."
26 #endif
27
25 namespace { 28 namespace {
26 enum SavedBarButtomItemPositionEnum { 29 enum SavedBarButtomItemPositionEnum {
27 kUndefinedBarButtonItemPosition, 30 kUndefinedBarButtonItemPosition,
28 kLeftBarButtonItemPosition, 31 kLeftBarButtonItemPosition,
29 kRightBarButtonItemPosition 32 kRightBarButtonItemPosition
30 }; 33 };
31 34
32 // Dimension of the authentication operation activity indicator frame. 35 // Dimension of the authentication operation activity indicator frame.
33 const CGFloat kActivityIndicatorDimensionIPad = 64; 36 const CGFloat kActivityIndicatorDimensionIPad = 64;
34 const CGFloat kActivityIndicatorDimensionIPhone = 56; 37 const CGFloat kActivityIndicatorDimensionIPhone = 56;
35 38
36 } // namespace 39 } // namespace
37 40
38 @implementation SettingsRootCollectionViewController { 41 @implementation SettingsRootCollectionViewController {
39 SavedBarButtomItemPositionEnum savedBarButtonItemPosition_; 42 SavedBarButtomItemPositionEnum savedBarButtonItemPosition_;
40 base::scoped_nsobject<UIBarButtonItem> savedBarButtonItem_; 43 UIBarButtonItem* savedBarButtonItem_;
41 base::scoped_nsobject<UIView> veil_; 44 UIView* veil_;
42
43 base::mac::ObjCPropertyReleaser
44 propertyReleaser_SettingsRootCollectionViewController_;
45 } 45 }
46 46
47 @synthesize shouldHideDoneButton = shouldHideDoneButton_; 47 @synthesize shouldHideDoneButton = shouldHideDoneButton_;
48 @synthesize collectionViewAccessibilityIdentifier = 48 @synthesize collectionViewAccessibilityIdentifier =
49 collectionViewAccessibilityIdentifier_; 49 collectionViewAccessibilityIdentifier_;
50 50
51 - (instancetype)initWithStyle:(CollectionViewControllerStyle)style {
52 self = [super initWithStyle:style];
53 if (self) {
54 propertyReleaser_SettingsRootCollectionViewController_.Init(
55 self, [SettingsRootCollectionViewController class]);
56 }
57 return self;
58 }
59
60 - (void)viewDidLoad { 51 - (void)viewDidLoad {
61 [super viewDidLoad]; 52 [super viewDidLoad];
62 self.collectionView.accessibilityIdentifier = 53 self.collectionView.accessibilityIdentifier =
63 self.collectionViewAccessibilityIdentifier; 54 self.collectionViewAccessibilityIdentifier;
64 55
65 // Customize collection view settings. 56 // Customize collection view settings.
66 self.styler.cellStyle = MDCCollectionViewCellStyleCard; 57 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
67 self.styler.separatorInset = UIEdgeInsetsMake(0, 16, 0, 16); 58 self.styler.separatorInset = UIEdgeInsetsMake(0, 16, 0, 16);
68 } 59 }
69 60
(...skipping 11 matching lines...) Expand all
81 } 72 }
82 SettingsNavigationController* navigationController = 73 SettingsNavigationController* navigationController =
83 base::mac::ObjCCast<SettingsNavigationController>( 74 base::mac::ObjCCast<SettingsNavigationController>(
84 self.navigationController); 75 self.navigationController);
85 return [navigationController doneButton]; 76 return [navigationController doneButton];
86 } 77 }
87 78
88 - (UIBarButtonItem*)createEditButton { 79 - (UIBarButtonItem*)createEditButton {
89 // Create a custom Edit bar button item, as Material Navigation Bar does not 80 // Create a custom Edit bar button item, as Material Navigation Bar does not
90 // handle a system UIBarButtonSystemItemEdit item. 81 // handle a system UIBarButtonSystemItemEdit item.
91 UIBarButtonItem* button = [[[UIBarButtonItem alloc] 82 UIBarButtonItem* button = [[UIBarButtonItem alloc]
92 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON) 83 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON)
93 style:UIBarButtonItemStyleDone 84 style:UIBarButtonItemStyleDone
94 target:self 85 target:self
95 action:@selector(editButtonPressed)] autorelease]; 86 action:@selector(editButtonPressed)];
96 [button setEnabled:[self editButtonEnabled]]; 87 [button setEnabled:[self editButtonEnabled]];
97 return button; 88 return button;
98 } 89 }
99 90
100 - (UIBarButtonItem*)createEditDoneButton { 91 - (UIBarButtonItem*)createEditDoneButton {
101 // Create a custom Done bar button item, as Material Navigation Bar does not 92 // Create a custom Done bar button item, as Material Navigation Bar does not
102 // handle a system UIBarButtonSystemItemDone item. 93 // handle a system UIBarButtonSystemItemDone item.
103 return [[[UIBarButtonItem alloc] 94 return [[UIBarButtonItem alloc]
104 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON) 95 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)
105 style:UIBarButtonItemStyleDone 96 style:UIBarButtonItemStyleDone
106 target:self 97 target:self
107 action:@selector(editButtonPressed)] autorelease]; 98 action:@selector(editButtonPressed)];
108 } 99 }
109 100
110 - (void)updateEditButton { 101 - (void)updateEditButton {
111 if ([self.editor isEditing]) { 102 if ([self.editor isEditing]) {
112 self.navigationItem.rightBarButtonItem = [self createEditDoneButton]; 103 self.navigationItem.rightBarButtonItem = [self createEditDoneButton];
113 } else if ([self shouldShowEditButton]) { 104 } else if ([self shouldShowEditButton]) {
114 self.navigationItem.rightBarButtonItem = [self createEditButton]; 105 self.navigationItem.rightBarButtonItem = [self createEditButton];
115 } else { 106 } else {
116 self.navigationItem.rightBarButtonItem = [self doneButtonIfNeeded]; 107 self.navigationItem.rightBarButtonItem = [self doneButtonIfNeeded];
117 } 108 }
118 } 109 }
119 110
120 - (void)editButtonPressed { 111 - (void)editButtonPressed {
121 [self.editor setEditing:![self.editor isEditing] animated:YES]; 112 [self.editor setEditing:![self.editor isEditing] animated:YES];
122 [self updateEditButton]; 113 [self updateEditButton];
123 } 114 }
124 115
125 - (void)reloadData { 116 - (void)reloadData {
126 [self loadModel]; 117 [self loadModel];
127 [self.collectionView reloadData]; 118 [self.collectionView reloadData];
128 } 119 }
129 120
130 #pragma mark - CollectionViewFooterLinkDelegate 121 #pragma mark - CollectionViewFooterLinkDelegate
131 122
132 - (void)cell:(CollectionViewFooterCell*)cell didTapLinkURL:(GURL)URL { 123 - (void)cell:(CollectionViewFooterCell*)cell didTapLinkURL:(GURL)URL {
133 base::scoped_nsobject<OpenUrlCommand> command( 124 OpenUrlCommand* command = [[OpenUrlCommand alloc] initWithURLFromChrome:URL];
134 [[OpenUrlCommand alloc] initWithURLFromChrome:URL]);
135 [command setTag:IDC_CLOSE_SETTINGS_AND_OPEN_URL]; 125 [command setTag:IDC_CLOSE_SETTINGS_AND_OPEN_URL];
136 [self chromeExecuteCommand:command]; 126 [self chromeExecuteCommand:command];
137 } 127 }
138 128
139 #pragma mark - Status bar 129 #pragma mark - Status bar
140 130
141 - (UIViewController*)childViewControllerForStatusBarHidden { 131 - (UIViewController*)childViewControllerForStatusBarHidden {
142 if (!base::ios::IsRunningOnIOS10OrLater()) { 132 if (!base::ios::IsRunningOnIOS10OrLater()) {
143 // TODO(crbug.com/620361): Remove the entire method override when iOS 9 is 133 // TODO(crbug.com/620361): Remove the entire method override when iOS 9 is
144 // dropped. 134 // dropped.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 - (void)preventUserInteraction { 185 - (void)preventUserInteraction {
196 DCHECK(!savedBarButtonItem_); 186 DCHECK(!savedBarButtonItem_);
197 DCHECK_EQ(kUndefinedBarButtonItemPosition, savedBarButtonItemPosition_); 187 DCHECK_EQ(kUndefinedBarButtonItemPosition, savedBarButtonItemPosition_);
198 188
199 // Create |waitButton|. 189 // Create |waitButton|.
200 BOOL displayActivityIndicatorOnTheRight = 190 BOOL displayActivityIndicatorOnTheRight =
201 self.navigationItem.rightBarButtonItem != nil; 191 self.navigationItem.rightBarButtonItem != nil;
202 CGFloat activityIndicatorDimension = IsIPadIdiom() 192 CGFloat activityIndicatorDimension = IsIPadIdiom()
203 ? kActivityIndicatorDimensionIPad 193 ? kActivityIndicatorDimensionIPad
204 : kActivityIndicatorDimensionIPhone; 194 : kActivityIndicatorDimensionIPhone;
205 base::scoped_nsobject<BarButtonActivityIndicator> indicator( 195 BarButtonActivityIndicator* indicator = [[BarButtonActivityIndicator alloc]
206 [[BarButtonActivityIndicator alloc] 196 initWithFrame:CGRectMake(0.0, 0.0, activityIndicatorDimension,
207 initWithFrame:CGRectMake(0.0, 0.0, activityIndicatorDimension, 197 activityIndicatorDimension)];
208 activityIndicatorDimension)]); 198 UIBarButtonItem* waitButton =
209 base::scoped_nsobject<UIBarButtonItem> waitButton( 199 [[UIBarButtonItem alloc] initWithCustomView:indicator];
210 [[UIBarButtonItem alloc] initWithCustomView:indicator]);
211 200
212 if (displayActivityIndicatorOnTheRight) { 201 if (displayActivityIndicatorOnTheRight) {
213 // If there is a right bar button item, then it is the "Done" button. 202 // If there is a right bar button item, then it is the "Done" button.
214 savedBarButtonItem_.reset([self.navigationItem.rightBarButtonItem retain]); 203 savedBarButtonItem_ = self.navigationItem.rightBarButtonItem;
215 savedBarButtonItemPosition_ = kRightBarButtonItemPosition; 204 savedBarButtonItemPosition_ = kRightBarButtonItemPosition;
216 self.navigationItem.rightBarButtonItem = waitButton; 205 self.navigationItem.rightBarButtonItem = waitButton;
217 [self.navigationItem.leftBarButtonItem setEnabled:NO]; 206 [self.navigationItem.leftBarButtonItem setEnabled:NO];
218 } else { 207 } else {
219 savedBarButtonItem_.reset([self.navigationItem.leftBarButtonItem retain]); 208 savedBarButtonItem_ = self.navigationItem.leftBarButtonItem;
220 savedBarButtonItemPosition_ = kLeftBarButtonItemPosition; 209 savedBarButtonItemPosition_ = kLeftBarButtonItemPosition;
221 self.navigationItem.leftBarButtonItem = waitButton; 210 self.navigationItem.leftBarButtonItem = waitButton;
222 } 211 }
223 212
224 // Adds a veil that covers the collection view and prevents user interaction. 213 // Adds a veil that covers the collection view and prevents user interaction.
225 DCHECK(self.view); 214 DCHECK(self.view);
226 DCHECK(!veil_); 215 DCHECK(!veil_);
227 veil_.reset([[UIView alloc] initWithFrame:self.view.bounds]); 216 veil_ = [[UIView alloc] initWithFrame:self.view.bounds];
228 [veil_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | 217 [veil_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth |
229 UIViewAutoresizingFlexibleHeight)]; 218 UIViewAutoresizingFlexibleHeight)];
230 [veil_ setBackgroundColor:[UIColor colorWithWhite:1.0 alpha:0.5]]; 219 [veil_ setBackgroundColor:[UIColor colorWithWhite:1.0 alpha:0.5]];
231 [self.view addSubview:veil_]; 220 [self.view addSubview:veil_];
232 221
233 // Disable user interaction for the navigation controller view to ensure 222 // Disable user interaction for the navigation controller view to ensure
234 // that the user cannot go back by swipping the navigation's top view 223 // that the user cannot go back by swipping the navigation's top view
235 // controller 224 // controller
236 [self.navigationController.view setUserInteractionEnabled:NO]; 225 [self.navigationController.view setUserInteractionEnabled:NO];
237 } 226 }
238 227
239 - (void)allowUserInteraction { 228 - (void)allowUserInteraction {
240 DCHECK(self.navigationController) 229 DCHECK(self.navigationController)
241 << "|allowUserInteraction| should always be called before this settings" 230 << "|allowUserInteraction| should always be called before this settings"
242 " controller is popped or dismissed."; 231 " controller is popped or dismissed.";
243 [self.navigationController.view setUserInteractionEnabled:YES]; 232 [self.navigationController.view setUserInteractionEnabled:YES];
244 233
245 // Removes the veil that prevents user interaction. 234 // Removes the veil that prevents user interaction.
246 DCHECK(veil_); 235 DCHECK(veil_);
247 [UIView animateWithDuration:0.3 236 [UIView animateWithDuration:0.3
248 animations:^{ 237 animations:^{
249 [veil_ removeFromSuperview]; 238 [veil_ removeFromSuperview];
250 } 239 }
251 completion:^(BOOL finished) { 240 completion:^(BOOL finished) {
252 veil_.reset(); 241 veil_ = nil;
253 }]; 242 }];
254 243
255 DCHECK(savedBarButtonItem_); 244 DCHECK(savedBarButtonItem_);
256 switch (savedBarButtonItemPosition_) { 245 switch (savedBarButtonItemPosition_) {
257 case kLeftBarButtonItemPosition: 246 case kLeftBarButtonItemPosition:
258 self.navigationItem.leftBarButtonItem = savedBarButtonItem_; 247 self.navigationItem.leftBarButtonItem = savedBarButtonItem_;
259 break; 248 break;
260 case kRightBarButtonItemPosition: 249 case kRightBarButtonItemPosition:
261 self.navigationItem.rightBarButtonItem = savedBarButtonItem_; 250 self.navigationItem.rightBarButtonItem = savedBarButtonItem_;
262 [self.navigationItem.leftBarButtonItem setEnabled:YES]; 251 [self.navigationItem.leftBarButtonItem setEnabled:YES];
263 break; 252 break;
264 default: 253 default:
265 NOTREACHED(); 254 NOTREACHED();
266 break; 255 break;
267 } 256 }
268 savedBarButtonItem_.reset(); 257 savedBarButtonItem_ = nil;
269 savedBarButtonItemPosition_ = kUndefinedBarButtonItemPosition; 258 savedBarButtonItemPosition_ = kUndefinedBarButtonItemPosition;
270 } 259 }
271 260
272 @end 261 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698