Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/chrome/browser/infobars/infobar_picker_view.h" | |
| 6 | |
| 7 #import "base/mac/objc_property_releaser.h" | |
| 8 #import "ios/chrome/browser/ui/uikit_ui_util.h" | |
| 9 | |
| 10 @interface InfoBarPickerView () { | |
| 11 id<InfoBarPickerViewDelegate> _delegate; // weak | |
| 12 base::mac::ObjCPropertyReleaser _propertyReleaser_InfoBarPickerView; | |
| 13 } | |
| 14 | |
| 15 @end | |
| 16 | |
| 17 @implementation InfoBarPickerView | |
| 18 | |
| 19 @synthesize navigationBar = _navigationBar; | |
| 20 @synthesize pickerView = _pickerView; | |
| 21 | |
| 22 - (instancetype)initWithFrame:(CGRect)frame { | |
| 23 if (self = [super initWithFrame:frame]) { | |
| 24 _propertyReleaser_InfoBarPickerView.Init(self, [InfoBarPickerView class]); | |
| 25 self.backgroundColor = [UIColor whiteColor]; | |
| 26 | |
| 27 _pickerView = [[UIPickerView alloc] initWithFrame:CGRectZero]; | |
| 28 [_pickerView setShowsSelectionIndicator:YES]; | |
| 29 | |
| 30 _navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectZero]; | |
| 31 UIBarButtonItem* doneButton = [[[UIBarButtonItem alloc] | |
| 32 initWithBarButtonSystemItem:UIBarButtonSystemItemDone | |
| 33 target:self | |
|
marq (ping after 24h)
2016/06/28 13:43:18
Better to set a target of nil, so the action will
| |
| 34 action:@selector(doneButtonPressed)] autorelease]; | |
| 35 UIBarButtonItem* cancelButton = [[[UIBarButtonItem alloc] | |
| 36 initWithBarButtonSystemItem:UIBarButtonSystemItemCancel | |
| 37 target:self | |
| 38 action:@selector(cancelButtonPressed)] | |
| 39 autorelease]; | |
| 40 UINavigationItem* navigationItem = | |
| 41 [[UINavigationItem alloc] initWithTitle:@""]; | |
| 42 [navigationItem setRightBarButtonItem:doneButton]; | |
| 43 [navigationItem setLeftBarButtonItem:cancelButton]; | |
| 44 [navigationItem setHidesBackButton:YES]; | |
| 45 [_navigationBar pushNavigationItem:navigationItem animated:NO]; | |
| 46 | |
| 47 _pickerView.translatesAutoresizingMaskIntoConstraints = NO; | |
| 48 _navigationBar.translatesAutoresizingMaskIntoConstraints = NO; | |
| 49 UIStackView* stackView = [[[UIStackView alloc] | |
| 50 initWithArrangedSubviews:@[ _navigationBar, _pickerView ]] autorelease]; | |
| 51 stackView.axis = UILayoutConstraintAxisVertical; | |
| 52 stackView.translatesAutoresizingMaskIntoConstraints = NO; | |
| 53 | |
| 54 [self addSubview:stackView]; | |
| 55 AddSameSizeConstraint(stackView, self); | |
| 56 AddSameCenterConstraints(stackView, self); | |
| 57 } | |
| 58 return self; | |
| 59 } | |
| 60 | |
| 61 - (void)setDelegate:(id<InfoBarPickerViewDelegate>)delegate { | |
| 62 _delegate = delegate; | |
| 63 } | |
| 64 | |
| 65 - (id<InfoBarPickerViewDelegate>)delegate { | |
| 66 return _delegate; | |
| 67 } | |
| 68 | |
| 69 - (void)setPickerDelegate:(id<UIPickerViewDelegate>)pickerDelegate { | |
| 70 _pickerView.delegate = pickerDelegate; | |
| 71 } | |
| 72 | |
| 73 - (id<UIPickerViewDelegate>)pickerDelegate { | |
| 74 return _pickerView.delegate; | |
| 75 } | |
| 76 | |
| 77 - (void)setPickerDataSource:(id<UIPickerViewDataSource>)pickerDataSource { | |
| 78 _pickerView.dataSource = pickerDataSource; | |
| 79 } | |
| 80 | |
| 81 - (id<UIPickerViewDataSource>)pickerDataSource { | |
| 82 return _pickerView.dataSource; | |
| 83 } | |
| 84 | |
| 85 - (void)doneButtonPressed { | |
| 86 [_delegate infoBarPickerViewPressedDone:self]; | |
| 87 } | |
| 88 | |
| 89 - (void)cancelButtonPressed { | |
| 90 [_delegate infoBarPickerViewPressedCancel:self]; | |
| 91 } | |
| 92 | |
| 93 @end | |
| OLD | NEW |