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

Side by Side Diff: ios/chrome/browser/ui/alert_coordinator/loading_alert_coordinator.mm

Issue 2825023002: [ObjC ARC] Converts ios/chrome/browser/ui/alert_coordinator:alert_coordinator_internal to ARC. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « ios/chrome/browser/ui/alert_coordinator/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/alert_coordinator/loading_alert_coordinator.h" 5 #import "ios/chrome/browser/ui/alert_coordinator/loading_alert_coordinator.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/ios/block_types.h" 9 #include "base/ios/block_types.h"
10 #import "base/ios/weak_nsobject.h"
11 #import "base/mac/scoped_block.h" 10 #import "base/mac/scoped_block.h"
12 #import "base/mac/scoped_nsobject.h"
13 #include "components/strings/grit/components_strings.h" 11 #include "components/strings/grit/components_strings.h"
14 #import "ios/chrome/browser/ui/material_components/activity_indicator.h" 12 #import "ios/chrome/browser/ui/material_components/activity_indicator.h"
15 #import "ios/chrome/browser/ui/uikit_ui_util.h" 13 #import "ios/chrome/browser/ui/uikit_ui_util.h"
16 #import "ios/third_party/material_components_ios/src/components/ActivityIndicato r/src/MaterialActivityIndicator.h" 14 #import "ios/third_party/material_components_ios/src/components/ActivityIndicato r/src/MaterialActivityIndicator.h"
17 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 15 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
18 #import "ios/third_party/material_components_ios/src/components/Dialogs/src/Mate rialDialogs.h" 16 #import "ios/third_party/material_components_ios/src/components/Dialogs/src/Mate rialDialogs.h"
19 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" 17 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
20 #include "ui/base/l10n/l10n_util_mac.h" 18 #include "ui/base/l10n/l10n_util_mac.h"
21 19
20 #if !defined(__has_feature) || !__has_feature(objc_arc)
21 #error "This file requires ARC support."
22 #endif
23
22 namespace { 24 namespace {
23 25
24 // MDC constraints. 26 // MDC constraints.
25 const CGFloat kMDCPadding = 24.0; 27 const CGFloat kMDCPadding = 24.0;
26 const CGFloat kMDCMargin = 40.0; 28 const CGFloat kMDCMargin = 40.0;
27 const CGFloat kButtonPadding = 8.0; 29 const CGFloat kButtonPadding = 8.0;
28 30
29 // Size of the activity indicator. 31 // Size of the activity indicator.
30 const CGFloat kActivityIndicatorPadding = 50.0; 32 const CGFloat kActivityIndicatorPadding = 50.0;
31 33
32 // Constant for the title 34 // Constant for the title
33 const int kTitleLabelFontColor = 0x333333; 35 const int kTitleLabelFontColor = 0x333333;
34 const int kTitleLabelFontSize = 16; 36 const int kTitleLabelFontSize = 16;
35 37
36 // Maximum size of the dialog 38 // Maximum size of the dialog
37 const CGFloat kPrefWidth = 330; 39 const CGFloat kPrefWidth = 330;
38 const CGFloat kPrefHeight = 300; 40 const CGFloat kPrefHeight = 300;
39 41
40 } // namespace 42 } // namespace
41 43
42 @interface LoadingAlertCoordinator () { 44 @interface LoadingAlertCoordinator () {
43 // Title of the alert. 45 // Title of the alert.
44 base::scoped_nsobject<NSString> _title; 46 NSString* _title;
45 // Callback for the cancel button. 47 // Callback for the cancel button.
46 base::mac::ScopedBlock<ProceduralBlock> _cancelHandler; 48 ProceduralBlock _cancelHandler;
47 // View Controller which will be displayed on |baseViewController|. 49 // View Controller which will be displayed on |baseViewController|.
48 base::scoped_nsobject<UIViewController> _presentedViewController; 50 UIViewController* _presentedViewController;
49 } 51 }
50 52
51 // Callback called when the cancel button is pressed. 53 // Callback called when the cancel button is pressed.
52 - (void)cancelCallback; 54 - (void)cancelCallback;
53 55
54 @end 56 @end
55 57
56 // View Controller handling the layout of the dialog. 58 // View Controller handling the layout of the dialog.
57 @interface LoadingViewController : UIViewController { 59 @interface LoadingViewController : UIViewController {
58 // Title of the dialog. 60 // Title of the dialog.
59 base::scoped_nsobject<NSString> _title; 61 NSString* _title;
60 // View containing the elements of the dialog. 62 // View containing the elements of the dialog.
61 base::scoped_nsobject<UIView> _contentView; 63 UIView* _contentView;
62 // Coordinator used for the cancel callback. 64 // Coordinator used for the cancel callback.
63 base::WeakNSObject<LoadingAlertCoordinator> _coordinator; 65 __weak LoadingAlertCoordinator* _coordinator;
64 // Transitioning delegate for this ViewController. 66 // Transitioning delegate for this ViewController.
65 base::scoped_nsobject<MDCDialogTransitionController> _transitionDelegate; 67 MDCDialogTransitionController* _transitionDelegate;
66 } 68 }
67 69
68 // Initializes with the |title| of the dialog and the |coordinator| which will 70 // Initializes with the |title| of the dialog and the |coordinator| which will
69 // be notified if the cancel callback occurs. 71 // be notified if the cancel callback occurs.
70 - (instancetype)initWithTitle:(NSString*)title 72 - (instancetype)initWithTitle:(NSString*)title
71 coordinator:(LoadingAlertCoordinator*)coordinator; 73 coordinator:(LoadingAlertCoordinator*)coordinator;
72 74
73 // Returns the maximum possible width for the dialog, taking into account the 75 // Returns the maximum possible width for the dialog, taking into account the
74 // MDC constraints. 76 // MDC constraints.
75 - (CGFloat)maxDialogWidth; 77 - (CGFloat)maxDialogWidth;
76 // Callback for the cancel button, calling the coordinator's callback. 78 // Callback for the cancel button, calling the coordinator's callback.
77 - (void)cancelCallback; 79 - (void)cancelCallback;
78 80
79 @end 81 @end
80 82
81 @implementation LoadingViewController 83 @implementation LoadingViewController
82 84
83 - (instancetype)initWithTitle:(NSString*)title 85 - (instancetype)initWithTitle:(NSString*)title
84 coordinator:(LoadingAlertCoordinator*)coordinator { 86 coordinator:(LoadingAlertCoordinator*)coordinator {
85 self = [super initWithNibName:nil bundle:nil]; 87 self = [super initWithNibName:nil bundle:nil];
86 if (self) { 88 if (self) {
87 _title.reset([title copy]); 89 _title = [title copy];
88 _coordinator.reset(coordinator); 90 _coordinator = coordinator;
89 self.modalPresentationStyle = UIModalPresentationCustom; 91 self.modalPresentationStyle = UIModalPresentationCustom;
90 _transitionDelegate.reset([[MDCDialogTransitionController alloc] init]); 92 _transitionDelegate = [[MDCDialogTransitionController alloc] init];
91 self.transitioningDelegate = _transitionDelegate; 93 self.transitioningDelegate = _transitionDelegate;
92 } 94 }
93 return self; 95 return self;
94 } 96 }
95 97
96 - (void)viewDidLoad { 98 - (void)viewDidLoad {
97 [super viewDidLoad]; 99 [super viewDidLoad];
98 100
99 self.preferredContentSize = CGSizeMake([self maxDialogWidth], kPrefHeight); 101 self.preferredContentSize = CGSizeMake([self maxDialogWidth], kPrefHeight);
100 self.view.backgroundColor = [UIColor whiteColor]; 102 self.view.backgroundColor = [UIColor whiteColor];
101 103
102 // Cancel button. 104 // Cancel button.
103 NSString* cancelTitle = l10n_util::GetNSString(IDS_CANCEL); 105 NSString* cancelTitle = l10n_util::GetNSString(IDS_CANCEL);
104 MDCFlatButton* cancelButton = [[[MDCFlatButton alloc] init] autorelease]; 106 MDCFlatButton* cancelButton = [[MDCFlatButton alloc] init];
105 [cancelButton sizeToFit]; 107 [cancelButton sizeToFit];
106 [cancelButton setCustomTitleColor:[UIColor blackColor]]; 108 [cancelButton setCustomTitleColor:[UIColor blackColor]];
107 [cancelButton setTitle:cancelTitle forState:UIControlStateNormal]; 109 [cancelButton setTitle:cancelTitle forState:UIControlStateNormal];
108 [cancelButton addTarget:self 110 [cancelButton addTarget:self
109 action:@selector(cancelCallback) 111 action:@selector(cancelCallback)
110 forControlEvents:UIControlEventTouchUpInside]; 112 forControlEvents:UIControlEventTouchUpInside];
111 113
112 // Activity indicator. 114 // Activity indicator.
113 base::scoped_nsobject<MDCActivityIndicator> activityIndicator( 115 MDCActivityIndicator* activityIndicator =
114 [[MDCActivityIndicator alloc] initWithFrame:CGRectZero]); 116 [[MDCActivityIndicator alloc] initWithFrame:CGRectZero];
115 [activityIndicator setCycleColors:ActivityIndicatorBrandedCycleColors()]; 117 [activityIndicator setCycleColors:ActivityIndicatorBrandedCycleColors()];
116 [activityIndicator startAnimating]; 118 [activityIndicator startAnimating];
117 119
118 // Title. 120 // Title.
119 NSMutableDictionary* attrsDictionary = [NSMutableDictionary 121 NSMutableDictionary* attrsDictionary = [NSMutableDictionary
120 dictionaryWithObject:[[MDFRobotoFontLoader sharedInstance] 122 dictionaryWithObject:[[MDFRobotoFontLoader sharedInstance]
121 mediumFontOfSize:kTitleLabelFontSize] 123 mediumFontOfSize:kTitleLabelFontSize]
122 forKey:NSFontAttributeName]; 124 forKey:NSFontAttributeName];
123 [attrsDictionary setObject:UIColorFromRGB(kTitleLabelFontColor) 125 [attrsDictionary setObject:UIColorFromRGB(kTitleLabelFontColor)
124 forKey:NSForegroundColorAttributeName]; 126 forKey:NSForegroundColorAttributeName];
125 127
126 NSMutableAttributedString* string = [[[NSMutableAttributedString alloc] 128 NSMutableAttributedString* string =
127 initWithString:_title 129 [[NSMutableAttributedString alloc] initWithString:_title
128 attributes:attrsDictionary] autorelease]; 130 attributes:attrsDictionary];
129 131
130 UILabel* title = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease]; 132 UILabel* title = [[UILabel alloc] initWithFrame:CGRectZero];
131 title.attributedText = string; 133 title.attributedText = string;
132 134
133 // Content view. 135 // Content view.
134 _contentView.reset([[UIView alloc] initWithFrame:CGRectZero]); 136 _contentView = [[UIView alloc] initWithFrame:CGRectZero];
135 137
136 // Constraints. 138 // Constraints.
137 [activityIndicator setTranslatesAutoresizingMaskIntoConstraints:NO]; 139 [activityIndicator setTranslatesAutoresizingMaskIntoConstraints:NO];
138 [cancelButton setTranslatesAutoresizingMaskIntoConstraints:NO]; 140 [cancelButton setTranslatesAutoresizingMaskIntoConstraints:NO];
139 [title setTranslatesAutoresizingMaskIntoConstraints:NO]; 141 [title setTranslatesAutoresizingMaskIntoConstraints:NO];
140 [_contentView setTranslatesAutoresizingMaskIntoConstraints:NO]; 142 [_contentView setTranslatesAutoresizingMaskIntoConstraints:NO];
141 143
142 [_contentView addSubview:title]; 144 [_contentView addSubview:title];
143 [_contentView addSubview:activityIndicator]; 145 [_contentView addSubview:activityIndicator];
144 [_contentView addSubview:cancelButton]; 146 [_contentView addSubview:cancelButton];
145 147
146 [[self view] addSubview:_contentView]; 148 [[self view] addSubview:_contentView];
147 149
148 NSDictionary* viewsDictionary = @{ 150 NSDictionary* viewsDictionary = @{
149 @"spinner" : activityIndicator, 151 @"spinner" : activityIndicator,
150 @"cancel" : cancelButton, 152 @"cancel" : cancelButton,
151 @"title" : title, 153 @"title" : title,
152 @"contentView" : _contentView.get() 154 @"contentView" : _contentView
153 }; 155 };
154 NSDictionary* metrics = @{ 156 NSDictionary* metrics = @{
155 @"padding" : @(kMDCPadding), 157 @"padding" : @(kMDCPadding),
156 @"buttonPadding" : @(kButtonPadding), 158 @"buttonPadding" : @(kButtonPadding),
157 @"spinnerButtonPadding" : @(kButtonPadding + kMDCPadding), 159 @"spinnerButtonPadding" : @(kButtonPadding + kMDCPadding),
158 @"spinnerPadding" : @(kActivityIndicatorPadding) 160 @"spinnerPadding" : @(kActivityIndicatorPadding)
159 }; 161 };
160 162
161 NSString* verticalConstaint = @"V:|-(padding)-[title]-(spinnerPadding)-[" 163 NSString* verticalConstaint = @"V:|-(padding)-[title]-(spinnerPadding)-["
162 @"spinner]-(spinnerButtonPadding)-[cancel]-(" 164 @"spinner]-(spinnerButtonPadding)-[cancel]-("
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 - (instancetype)initWithBaseViewController:(UIViewController*)viewController { 203 - (instancetype)initWithBaseViewController:(UIViewController*)viewController {
202 NOTREACHED(); 204 NOTREACHED();
203 return nil; 205 return nil;
204 } 206 }
205 207
206 - (instancetype)initWithBaseViewController:(UIViewController*)viewController 208 - (instancetype)initWithBaseViewController:(UIViewController*)viewController
207 title:(NSString*)title 209 title:(NSString*)title
208 cancelHandler:(ProceduralBlock)cancelHandler { 210 cancelHandler:(ProceduralBlock)cancelHandler {
209 self = [super initWithBaseViewController:viewController]; 211 self = [super initWithBaseViewController:viewController];
210 if (self) { 212 if (self) {
211 _title.reset([title copy]); 213 _title = [title copy];
212 _cancelHandler.reset(cancelHandler, base::scoped_policy::RETAIN); 214 _cancelHandler = cancelHandler;
213 } 215 }
214 return self; 216 return self;
215 } 217 }
216 218
217 - (void)start { 219 - (void)start {
218 _presentedViewController.reset( 220 _presentedViewController =
219 [[LoadingViewController alloc] initWithTitle:_title coordinator:self]); 221 [[LoadingViewController alloc] initWithTitle:_title coordinator:self];
220 [self.baseViewController presentViewController:_presentedViewController 222 [self.baseViewController presentViewController:_presentedViewController
221 animated:YES 223 animated:YES
222 completion:nil]; 224 completion:nil];
223 } 225 }
224 226
225 - (void)stop { 227 - (void)stop {
226 [[_presentedViewController presentingViewController] 228 [[_presentedViewController presentingViewController]
227 dismissViewControllerAnimated:NO 229 dismissViewControllerAnimated:NO
228 completion:nil]; 230 completion:nil];
229 _presentedViewController.reset(); 231 _presentedViewController = nil;
230 _cancelHandler.reset(); 232 _cancelHandler = nil;
231 } 233 }
232 234
233 - (void)cancelCallback { 235 - (void)cancelCallback {
234 if (_cancelHandler) 236 if (_cancelHandler)
235 _cancelHandler.get()(); 237 _cancelHandler();
236 [self stop]; 238 [self stop];
237 } 239 }
238 240
239 @end 241 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/alert_coordinator/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698