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

Side by Side Diff: ios/chrome/browser/ui/find_bar/find_bar_controller_ios.mm

Issue 2664233004: [ObjC ARC] Converts ios/chrome/browser/ui/find_bar:find_bar to ARC. (Closed)
Patch Set: reorder keywords Created 3 years, 10 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/find_bar/find_bar_controller_ios.h" 5 #import "ios/chrome/browser/ui/find_bar/find_bar_controller_ios.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/ios/ios_util.h" 9 #include "base/ios/ios_util.h"
10 #include "base/mac/bundle_locations.h" 10 #include "base/mac/bundle_locations.h"
11 #include "base/mac/foundation_util.h" 11 #include "base/mac/foundation_util.h"
12 #include "base/mac/objc_property_releaser.h"
13 #include "base/mac/scoped_nsobject.h"
14 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
15 #include "components/strings/grit/components_strings.h" 13 #include "components/strings/grit/components_strings.h"
16 #import "ios/chrome/browser/find_in_page/find_in_page_controller.h" 14 #import "ios/chrome/browser/find_in_page/find_in_page_controller.h"
17 #import "ios/chrome/browser/find_in_page/find_in_page_model.h" 15 #import "ios/chrome/browser/find_in_page/find_in_page_model.h"
18 #import "ios/chrome/browser/ui/UIView+SizeClassSupport.h" 16 #import "ios/chrome/browser/ui/UIView+SizeClassSupport.h"
19 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" 17 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
20 #import "ios/chrome/browser/ui/find_bar/find_bar_view.h" 18 #import "ios/chrome/browser/ui/find_bar/find_bar_view.h"
21 #include "ios/chrome/browser/ui/ui_util.h" 19 #include "ios/chrome/browser/ui/ui_util.h"
22 #include "ui/base/l10n/l10n_util_mac.h" 20 #include "ui/base/l10n/l10n_util_mac.h"
23 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
24 22
23 #if !defined(__has_feature) || !__has_feature(objc_arc)
24 #error "This file requires ARC support."
25 #endif
26
25 NSString* const kFindInPageContainerViewId = @"kFindInPageContainerViewId"; 27 NSString* const kFindInPageContainerViewId = @"kFindInPageContainerViewId";
26 28
27 namespace { 29 namespace {
28 30
29 // Find Bar height. 31 // Find Bar height.
30 // Right padding on iPad find bar. 32 // Right padding on iPad find bar.
31 const CGFloat kFindBarIPhoneHeight = 56; 33 const CGFloat kFindBarIPhoneHeight = 56;
32 const CGFloat kFindBarIPadHeight = 62; 34 const CGFloat kFindBarIPadHeight = 62;
33 35
34 // Find Bar animation drop down duration. 36 // Find Bar animation drop down duration.
35 const CGFloat kAnimationDuration = 0.15; 37 const CGFloat kAnimationDuration = 0.15;
36 38
37 // For the first |kSearchDelayChars| characters, delay by |kSearchLongDelay| 39 // For the first |kSearchDelayChars| characters, delay by |kSearchLongDelay|
38 // For the remaining characters, delay by |kSearchShortDelay|. 40 // For the remaining characters, delay by |kSearchShortDelay|.
39 const NSUInteger kSearchDelayChars = 3; 41 const NSUInteger kSearchDelayChars = 3;
40 const NSTimeInterval kSearchLongDelay = 1.0; 42 const NSTimeInterval kSearchLongDelay = 1.0;
41 const NSTimeInterval kSearchShortDelay = 0.100; 43 const NSTimeInterval kSearchShortDelay = 0.100;
42 44
43 } // anonymous namespace 45 } // anonymous namespace
44 46
45 #pragma mark - FindBarControllerIOS 47 #pragma mark - FindBarControllerIOS
46 48
47 @interface FindBarControllerIOS ()<UITextFieldDelegate> { 49 @interface FindBarControllerIOS ()<UITextFieldDelegate>
48 base::mac::ObjCPropertyReleaser _propertyReleaser_FindInPageController;
49 }
50 50
51 // Set up iPad UI 51 // Set up iPad UI
52 - (void)setUpIPad; 52 - (void)setUpIPad;
53 // Set up iPhone UI 53 // Set up iPhone UI
54 - (void)setUpIPhone; 54 - (void)setUpIPhone;
55 // Animate find bar to iPad top right, or, when possible, to align find bar 55 // Animate find bar to iPad top right, or, when possible, to align find bar
56 // horizontally with |alignmentFrame|. 56 // horizontally with |alignmentFrame|.
57 - (void)showIPadFindBarView:(BOOL)animate 57 - (void)showIPadFindBarView:(BOOL)animate
58 intoView:(UIView*)parentView 58 intoView:(UIView*)parentView
59 withFrame:(CGRect)targetFrame 59 withFrame:(CGRect)targetFrame
(...skipping 17 matching lines...) Expand all
77 // Selects text in such way that selection menu does not appear and 77 // Selects text in such way that selection menu does not appear and
78 // a11y label is read. When -[UITextField selectAll:] is used, iOS 78 // a11y label is read. When -[UITextField selectAll:] is used, iOS
79 // will read "Select All" instead of a11y label. 79 // will read "Select All" instead of a11y label.
80 - (void)selectAllText; 80 - (void)selectAllText;
81 81
82 // Redefined to be readwrite. This view acts as background for |findBarView| and 82 // Redefined to be readwrite. This view acts as background for |findBarView| and
83 // contains it as a subview. 83 // contains it as a subview.
84 @property(nonatomic, readwrite, strong) UIView* view; 84 @property(nonatomic, readwrite, strong) UIView* view;
85 // The view containing all the buttons and textfields that is common between 85 // The view containing all the buttons and textfields that is common between
86 // iPhone and iPad. 86 // iPhone and iPad.
87 @property(nonatomic, retain) FindBarView* findBarView; 87 @property(nonatomic, strong) FindBarView* findBarView;
88 // Typing delay timer. 88 // Typing delay timer.
89 @property(nonatomic, retain) NSTimer* delayTimer; 89 @property(nonatomic, strong) NSTimer* delayTimer;
90 // Yes if incognito. 90 // Yes if incognito.
91 @property(nonatomic, assign) BOOL isIncognito; 91 @property(nonatomic, assign) BOOL isIncognito;
92 @end 92 @end
93 93
94 @implementation FindBarControllerIOS 94 @implementation FindBarControllerIOS
95 95
96 @synthesize view = _view; 96 @synthesize view = _view;
97 @synthesize findBarView = _findBarView; 97 @synthesize findBarView = _findBarView;
98 @synthesize delayTimer = _delayTimer; 98 @synthesize delayTimer = _delayTimer;
99 @synthesize isIncognito = _isIncognito; 99 @synthesize isIncognito = _isIncognito;
100 100
101 #pragma mark - Lifecycle 101 #pragma mark - Lifecycle
102 102
103 - (instancetype)initWithIncognito:(BOOL)isIncognito { 103 - (instancetype)initWithIncognito:(BOOL)isIncognito {
104 self = [super init]; 104 self = [super init];
105 if (self) { 105 if (self) {
106 _propertyReleaser_FindInPageController.Init(self,
107 [FindBarControllerIOS class]);
108 _isIncognito = isIncognito; 106 _isIncognito = isIncognito;
109 } 107 }
110 return self; 108 return self;
111 } 109 }
112 110
113 #pragma mark View Setup & Teardown 111 #pragma mark View Setup & Teardown
114 112
115 - (UIView*)newFindBarView { 113 - (UIView*)constructFindBarView {
116 BOOL isIPad = IsIPadIdiom(); 114 BOOL isIPad = IsIPadIdiom();
117 UIView* findBarBackground = nil; 115 UIView* findBarBackground = nil;
118 if (isIPad) { 116 if (isIPad) {
119 // Future self.view. Contains only |contentView|. Is an image view that is 117 // Future self.view. Contains only |contentView|. Is an image view that is
120 // typecast elsewhere but always is exposed as a UIView. 118 // typecast elsewhere but always is exposed as a UIView.
121 findBarBackground = 119 findBarBackground =
122 [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 345, 62)]; 120 [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 345, 62)];
123 findBarBackground.backgroundColor = [UIColor clearColor]; 121 findBarBackground.backgroundColor = [UIColor clearColor];
124 findBarBackground.userInteractionEnabled = YES; 122 findBarBackground.userInteractionEnabled = YES;
125 } else { 123 } else {
126 findBarBackground = 124 findBarBackground =
127 [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 56)]; 125 [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 56)];
128 findBarBackground.backgroundColor = [UIColor whiteColor]; 126 findBarBackground.backgroundColor = [UIColor whiteColor];
129 } 127 }
130 128
131 self.findBarView = [[[FindBarView alloc] 129 self.findBarView = [[FindBarView alloc]
132 initWithDarkAppearance:self.isIncognito && !IsIPadIdiom()] autorelease]; 130 initWithDarkAppearance:self.isIncognito && !IsIPadIdiom()];
133 [findBarBackground addSubview:self.findBarView]; 131 [findBarBackground addSubview:self.findBarView];
134 self.findBarView.translatesAutoresizingMaskIntoConstraints = NO; 132 self.findBarView.translatesAutoresizingMaskIntoConstraints = NO;
135 base::scoped_nsobject<NSMutableArray> constraints( 133 NSMutableArray* constraints = [[NSMutableArray alloc] init];
136 [[NSMutableArray alloc] init]);
137 [constraints addObjectsFromArray:@[ 134 [constraints addObjectsFromArray:@[
138 [self.findBarView.trailingAnchor 135 [self.findBarView.trailingAnchor
139 constraintEqualToAnchor:findBarBackground.trailingAnchor], 136 constraintEqualToAnchor:findBarBackground.trailingAnchor],
140 [self.findBarView.leadingAnchor 137 [self.findBarView.leadingAnchor
141 constraintEqualToAnchor:findBarBackground.leadingAnchor], 138 constraintEqualToAnchor:findBarBackground.leadingAnchor],
142 [self.findBarView.heightAnchor constraintEqualToConstant:56.0f] 139 [self.findBarView.heightAnchor constraintEqualToConstant:56.0f]
143 ]]; 140 ]];
144 141
145 if (isIPad) { 142 if (isIPad) {
146 [constraints 143 [constraints
(...skipping 16 matching lines...) Expand all
163 action:@selector(hideKeyboard:) 160 action:@selector(hideKeyboard:)
164 forControlEvents:UIControlEventTouchUpInside]; 161 forControlEvents:UIControlEventTouchUpInside];
165 [self.findBarView.previousButton addTarget:self 162 [self.findBarView.previousButton addTarget:self
166 action:@selector(hideKeyboard:) 163 action:@selector(hideKeyboard:)
167 forControlEvents:UIControlEventTouchUpInside]; 164 forControlEvents:UIControlEventTouchUpInside];
168 165
169 return findBarBackground; 166 return findBarBackground;
170 } 167 }
171 168
172 - (void)setupViewInView:(UIView*)view { 169 - (void)setupViewInView:(UIView*)view {
173 self.view = [[self newFindBarView] autorelease]; 170 self.view = [self constructFindBarView];
174 171
175 // Idiom specific setup. 172 // Idiom specific setup.
176 if ([self shouldShowCompactSearchBarInView:view]) 173 if ([self shouldShowCompactSearchBarInView:view])
177 [self setUpIPhone]; 174 [self setUpIPhone];
178 else 175 else
179 [self setUpIPad]; 176 [self setUpIPad];
180 177
181 self.view.accessibilityIdentifier = kFindInPageContainerViewId; 178 self.view.accessibilityIdentifier = kFindInPageContainerViewId;
182 } 179 }
183 180
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 object:self]; 468 object:self];
472 } 469 }
473 470
474 - (BOOL)textFieldShouldReturn:(UITextField*)textField { 471 - (BOOL)textFieldShouldReturn:(UITextField*)textField {
475 DCHECK(textField == self.findBarView.inputField); 472 DCHECK(textField == self.findBarView.inputField);
476 [self.findBarView.inputField resignFirstResponder]; 473 [self.findBarView.inputField resignFirstResponder];
477 return YES; 474 return YES;
478 } 475 }
479 476
480 @end 477 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698