| Index: ios/chrome/browser/infobars/infobar_picker_view_controller.mm
|
| diff --git a/ios/chrome/browser/infobars/infobar_picker_view_controller.mm b/ios/chrome/browser/infobars/infobar_picker_view_controller.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d74df0bd41a0a23799d392f22b3cc298f43fa4a3
|
| --- /dev/null
|
| +++ b/ios/chrome/browser/infobars/infobar_picker_view_controller.mm
|
| @@ -0,0 +1,136 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import "ios/chrome/browser/infobars/infobar_picker_view_controller.h"
|
| +
|
| +#include "base/logging.h"
|
| +#import "base/mac/objc_property_releaser.h"
|
| +
|
| +namespace {
|
| +// Font size of text in the picker view.
|
| +CGFloat kUIPickerFontSize = 26;
|
| +} // namespace
|
| +
|
| +@interface InfoBarPickerViewController ()<UIPickerViewDelegate,
|
| + UIPickerViewDataSource> {
|
| + base::mac::ObjCPropertyReleaser _propertyReleaser_InfoBarPickerViewController;
|
| + id<InfoBarPickerViewControllerDelegate> _delegate; // weak
|
| +}
|
| +// "Done" button presented in the navigation bar.
|
| +@property(nonatomic, retain) UIBarButtonItem* doneButton;
|
| +// "Cancel" button presented in the navigation bar.
|
| +@property(nonatomic, retain) UIBarButtonItem* cancelButton;
|
| +@end
|
| +
|
| +@implementation InfoBarPickerViewController
|
| +
|
| +@synthesize pickerView = _pickerView;
|
| +@synthesize navigationBar = _navigationBar;
|
| +@synthesize doneButton = _doneButton;
|
| +@synthesize cancelButton = _cancelButton;
|
| +
|
| +- (instancetype)initWithNibName:(NSString*)nibName bundle:(NSBundle*)nibBundle {
|
| + self = [super initWithNibName:nibName bundle:nil];
|
| + if (self) {
|
| + _propertyReleaser_InfoBarPickerViewController.Init(
|
| + self, [InfoBarPickerViewController class]);
|
| + _pickerView = [[UIPickerView alloc] initWithFrame:CGRectZero];
|
| + _doneButton = [[UIBarButtonItem alloc]
|
| + initWithBarButtonSystemItem:UIBarButtonSystemItemDone
|
| + target:nil
|
| + action:nil];
|
| + _cancelButton = [[UIBarButtonItem alloc]
|
| + initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
|
| + target:nil
|
| + action:nil];
|
| + }
|
| + return self;
|
| +}
|
| +
|
| +- (void)loadView {
|
| + self.pickerView.showsSelectionIndicator = YES;
|
| + self.pickerView.backgroundColor = [UIColor whiteColor];
|
| + self.pickerView.delegate = self;
|
| + self.pickerView.dataSource = self;
|
| + NSInteger initialRow =
|
| + [self.delegate infoBarPickerViewControllerInitialRow:self];
|
| + [self.pickerView selectRow:initialRow inComponent:0 animated:NO];
|
| +
|
| + self.navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectZero];
|
| + UINavigationItem* navigationItem =
|
| + [[[UINavigationItem alloc] initWithTitle:@""] autorelease];
|
| + [navigationItem setRightBarButtonItem:self.doneButton];
|
| + [navigationItem setLeftBarButtonItem:self.cancelButton];
|
| + [navigationItem setHidesBackButton:YES];
|
| + [self.navigationBar pushNavigationItem:navigationItem animated:NO];
|
| +
|
| + self.pickerView.translatesAutoresizingMaskIntoConstraints = NO;
|
| + self.navigationBar.translatesAutoresizingMaskIntoConstraints = NO;
|
| + UIStackView* stackView = [[[UIStackView alloc]
|
| + initWithArrangedSubviews:@[ self.navigationBar, self.pickerView ]]
|
| + autorelease];
|
| + stackView.backgroundColor = [UIColor whiteColor];
|
| + stackView.axis = UILayoutConstraintAxisVertical;
|
| + stackView.translatesAutoresizingMaskIntoConstraints = NO;
|
| + self.view = stackView;
|
| +}
|
| +
|
| +- (void)setDoneTarget:(id)target action:(SEL)action {
|
| + self.doneButton.target = target;
|
| + self.doneButton.action = action;
|
| +}
|
| +
|
| +- (void)setCancelTarget:(id)target action:(SEL)action {
|
| + self.cancelButton.target = target;
|
| + self.cancelButton.action = action;
|
| +}
|
| +
|
| +- (id<InfoBarPickerViewControllerDelegate>)delegate {
|
| + return _delegate;
|
| +}
|
| +
|
| +- (void)setDelegate:(id<InfoBarPickerViewControllerDelegate>)delegate {
|
| + _delegate = delegate;
|
| +}
|
| +
|
| +#pragma mark - UIPickerViewDataSource
|
| +
|
| +- (NSInteger)numberOfComponentsInPickerView:(UIPickerView*)pickerView {
|
| + return 1;
|
| +}
|
| +
|
| +- (NSInteger)pickerView:(UIPickerView*)pickerView
|
| + numberOfRowsInComponent:(NSInteger)component {
|
| + return [self.delegate infoBarPickerViewControllerNumberOfRows:self];
|
| +}
|
| +
|
| +#pragma mark - UIPickerViewDelegate
|
| +
|
| +- (UIView*)pickerView:(UIPickerView*)pickerView
|
| + viewForRow:(NSInteger)row
|
| + forComponent:(NSInteger)component
|
| + reusingView:(UIView*)view {
|
| + DCHECK_EQ(0, component);
|
| + UILabel* label = [view isKindOfClass:[UILabel class]]
|
| + ? (UILabel*)view
|
| + : [[[UILabel alloc] init] autorelease];
|
| + [label
|
| + setText:[self.delegate infoBarPickerViewController:self textForRow:row]];
|
| + [label setTextAlignment:NSTextAlignmentCenter];
|
| + UIFont* font = [UIFont systemFontOfSize:kUIPickerFontSize];
|
| + if (row == [self.delegate infoBarPickerViewControllerInitialRow:self]) {
|
| + font = [UIFont boldSystemFontOfSize:kUIPickerFontSize];
|
| + }
|
| + if ([self.delegate
|
| + respondsToSelector:@selector(
|
| + infoBarPickerViewControllerDisabledRow:)]) {
|
| + if (row == [self.delegate infoBarPickerViewControllerDisabledRow:self]) {
|
| + label.enabled = NO;
|
| + }
|
| + }
|
| + [label setFont:font];
|
| + return label;
|
| +}
|
| +
|
| +@end
|
|
|