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

Side by Side Diff: ios/chrome/browser/ui/find_bar/find_bar_view.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
« no previous file with comments | « ios/chrome/browser/ui/find_bar/find_bar_view.h ('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/find_bar/find_bar_view.h" 5 #import "ios/chrome/browser/ui/find_bar/find_bar_view.h"
6 6
7 #include "base/mac/scoped_nsobject.h"
8 #include "components/strings/grit/components_strings.h" 7 #include "components/strings/grit/components_strings.h"
9 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" 8 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
10 #import "ios/chrome/browser/ui/commands/ios_command_ids.h" 9 #import "ios/chrome/browser/ui/commands/ios_command_ids.h"
11 #import "ios/chrome/browser/ui/find_bar/find_bar_touch_forwarding_view.h" 10 #import "ios/chrome/browser/ui/find_bar/find_bar_touch_forwarding_view.h"
12 #import "ios/chrome/browser/ui/uikit_ui_util.h" 11 #import "ios/chrome/browser/ui/uikit_ui_util.h"
13 #include "ios/chrome/grit/ios_strings.h" 12 #include "ios/chrome/grit/ios_strings.h"
14 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 13 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
15 #include "ui/base/l10n/l10n_util_mac.h" 14 #include "ui/base/l10n/l10n_util_mac.h"
16 #import "ui/gfx/ios/NSString+CrStringDrawing.h" 15 #import "ui/gfx/ios/NSString+CrStringDrawing.h"
17 16
17 #if !defined(__has_feature) || !__has_feature(objc_arc)
18 #error "This file requires ARC support."
19 #endif
20
18 NSString* const kFindInPageInputFieldId = @"kFindInPageInputFieldId"; 21 NSString* const kFindInPageInputFieldId = @"kFindInPageInputFieldId";
19 NSString* const kFindInPageNextButtonId = @"kFindInPageNextButtonId"; 22 NSString* const kFindInPageNextButtonId = @"kFindInPageNextButtonId";
20 NSString* const kFindInPagePreviousButtonId = @"kFindInPagePreviousButtonId"; 23 NSString* const kFindInPagePreviousButtonId = @"kFindInPagePreviousButtonId";
21 NSString* const kFindInPageCloseButtonId = @"kFindInPageCloseButtonId"; 24 NSString* const kFindInPageCloseButtonId = @"kFindInPageCloseButtonId";
22 25
23 @interface FindBarView () 26 @interface FindBarView ()
24 27
25 // The overlay that shows number of results in format "1 of 13". 28 // The overlay that shows number of results in format "1 of 13".
26 @property(nonatomic, assign) UILabel* resultsLabel; 29 @property(nonatomic, weak) UILabel* resultsLabel;
27 @property(nonatomic, assign) UIView* separator; 30 @property(nonatomic, weak) UIView* separator;
28 31
29 // Initializes all subviews. 32 // Initializes all subviews.
30 - (void)setupSubviews; 33 - (void)setupSubviews;
31 // Sets up appearance of subviews, such as fonts, background colors. 34 // Sets up appearance of subviews, such as fonts, background colors.
32 - (void)configureApperance:(BOOL)isDark; 35 - (void)configureApperance:(BOOL)isDark;
33 // Convenience method that returns images for light and dark appearances. 36 // Convenience method that returns images for light and dark appearances.
34 - (UIImage*)imageWithName:(NSString*)imageName isDark:(BOOL)isDark; 37 - (UIImage*)imageWithName:(NSString*)imageName isDark:(BOOL)isDark;
35 38
36 @end 39 @end
37 40
(...skipping 20 matching lines...) Expand all
58 self.resultsLabel.hidden = (text.length == 0); 61 self.resultsLabel.hidden = (text.length == 0);
59 self.resultsLabel.text = text; 62 self.resultsLabel.text = text;
60 } 63 }
61 64
62 #pragma mark - Internal 65 #pragma mark - Internal
63 66
64 - (void)setupSubviews { 67 - (void)setupSubviews {
65 [self setBackgroundColor:[UIColor clearColor]]; 68 [self setBackgroundColor:[UIColor clearColor]];
66 69
67 // Input field. 70 // Input field.
68 base::scoped_nsobject<UITextField> inputFieldScoped( 71 UITextField* inputFieldScoped =
69 [[UITextField alloc] initWithFrame:CGRectZero]); 72 [[UITextField alloc] initWithFrame:CGRectZero];
70 self.inputField = inputFieldScoped; 73 self.inputField = inputFieldScoped;
71 self.inputField.backgroundColor = [UIColor clearColor]; 74 self.inputField.backgroundColor = [UIColor clearColor];
72 self.inputField.tag = IDC_FIND_UPDATE; 75 self.inputField.tag = IDC_FIND_UPDATE;
73 self.inputField.translatesAutoresizingMaskIntoConstraints = NO; 76 self.inputField.translatesAutoresizingMaskIntoConstraints = NO;
74 self.inputField.placeholder = 77 self.inputField.placeholder =
75 l10n_util::GetNSString(IDS_IOS_PLACEHOLDER_FIND_IN_PAGE); 78 l10n_util::GetNSString(IDS_IOS_PLACEHOLDER_FIND_IN_PAGE);
76 79
77 // Label containing number of found results. 80 // Label containing number of found results.
78 base::scoped_nsobject<UILabel> resultsLabelScoped( 81 UILabel* resultsLabelScoped = [[UILabel alloc] initWithFrame:CGRectZero];
79 [[UILabel alloc] initWithFrame:CGRectZero]);
80 self.resultsLabel = resultsLabelScoped; 82 self.resultsLabel = resultsLabelScoped;
81 self.resultsLabel.textColor = [UIColor lightGrayColor]; 83 self.resultsLabel.textColor = [UIColor lightGrayColor];
82 self.resultsLabel.font = [UIFont systemFontOfSize:14]; 84 self.resultsLabel.font = [UIFont systemFontOfSize:14];
83 [self.resultsLabel 85 [self.resultsLabel
84 setContentCompressionResistancePriority:UILayoutPriorityRequired 86 setContentCompressionResistancePriority:UILayoutPriorityRequired
85 forAxis:UILayoutConstraintAxisHorizontal]; 87 forAxis:UILayoutConstraintAxisHorizontal];
86 [self.resultsLabel 88 [self.resultsLabel
87 setContentHuggingPriority:UILayoutPriorityRequired 89 setContentHuggingPriority:UILayoutPriorityRequired
88 forAxis:UILayoutConstraintAxisHorizontal]; 90 forAxis:UILayoutConstraintAxisHorizontal];
89 91
90 // Stack view that holds |inputField| and |resultsLabel|. 92 // Stack view that holds |inputField| and |resultsLabel|.
91 base::scoped_nsobject<UIStackView> inputStackView([[UIStackView alloc] 93 UIStackView* inputStackView = [[UIStackView alloc]
92 initWithArrangedSubviews:@[ inputFieldScoped, resultsLabelScoped ]]); 94 initWithArrangedSubviews:@[ inputFieldScoped, resultsLabelScoped ]];
93 [inputStackView setLayoutMargins:UIEdgeInsetsMake(0, 12, 0, 12)]; 95 [inputStackView setLayoutMargins:UIEdgeInsetsMake(0, 12, 0, 12)];
94 [inputStackView setLayoutMarginsRelativeArrangement:YES]; 96 [inputStackView setLayoutMarginsRelativeArrangement:YES];
95 [inputStackView setSpacing:12]; 97 [inputStackView setSpacing:12];
96 [inputStackView setTranslatesAutoresizingMaskIntoConstraints:NO]; 98 [inputStackView setTranslatesAutoresizingMaskIntoConstraints:NO];
97 [self addSubview:inputStackView]; 99 [self addSubview:inputStackView];
98 100
99 base::scoped_nsobject<NSMutableArray> constraints( 101 NSMutableArray* constraints = [[NSMutableArray alloc] init];
100 [[NSMutableArray alloc] init]);
101 [constraints addObjectsFromArray:@[ 102 [constraints addObjectsFromArray:@[
102 [[inputStackView leadingAnchor] constraintEqualToAnchor:self.leadingAnchor], 103 [[inputStackView leadingAnchor] constraintEqualToAnchor:self.leadingAnchor],
103 [[inputStackView topAnchor] constraintEqualToAnchor:self.topAnchor], 104 [[inputStackView topAnchor] constraintEqualToAnchor:self.topAnchor],
104 [[inputStackView bottomAnchor] constraintEqualToAnchor:self.bottomAnchor], 105 [[inputStackView bottomAnchor] constraintEqualToAnchor:self.bottomAnchor],
105 ]]; 106 ]];
106 107
107 // Touch-forwarding view is put on top of |inputStackView| to forward touches 108 // Touch-forwarding view is put on top of |inputStackView| to forward touches
108 // to |inputField|. 109 // to |inputField|.
109 // Unlike a gesture recognizer, forwarding all touch events allows for using 110 // Unlike a gesture recognizer, forwarding all touch events allows for using
110 // long press, pinch and other manipulatiosn on the target textfield. 111 // long press, pinch and other manipulatiosn on the target textfield.
111 base::scoped_nsobject<FindBarTouchForwardingView> forwarder( 112 FindBarTouchForwardingView* forwarder =
112 [[FindBarTouchForwardingView alloc] init]); 113 [[FindBarTouchForwardingView alloc] init];
113 [forwarder setTargetView:self.inputField]; 114 [forwarder setTargetView:self.inputField];
114 [self addSubview:forwarder]; 115 [self addSubview:forwarder];
115 [constraints addObjectsFromArray:@[ 116 [constraints addObjectsFromArray:@[
116 [[forwarder leadingAnchor] 117 [[forwarder leadingAnchor]
117 constraintEqualToAnchor:[inputStackView leadingAnchor]], 118 constraintEqualToAnchor:[inputStackView leadingAnchor]],
118 [[forwarder topAnchor] constraintEqualToAnchor:[inputStackView topAnchor]], 119 [[forwarder topAnchor] constraintEqualToAnchor:[inputStackView topAnchor]],
119 [[forwarder bottomAnchor] 120 [[forwarder bottomAnchor]
120 constraintEqualToAnchor:[inputStackView bottomAnchor]], 121 constraintEqualToAnchor:[inputStackView bottomAnchor]],
121 [[forwarder trailingAnchor] 122 [[forwarder trailingAnchor]
122 constraintEqualToAnchor:[inputStackView trailingAnchor]], 123 constraintEqualToAnchor:[inputStackView trailingAnchor]],
123 ]]; 124 ]];
124 [forwarder setTranslatesAutoresizingMaskIntoConstraints:NO]; 125 [forwarder setTranslatesAutoresizingMaskIntoConstraints:NO];
125 126
126 // Thin line separator between buttons and input. 127 // Thin line separator between buttons and input.
127 base::scoped_nsobject<UIView> separatorScoped( 128 UIView* separatorScoped = [[UIView alloc] initWithFrame:CGRectZero];
128 [[UIView alloc] initWithFrame:CGRectZero]);
129 UIView* separator = separatorScoped; 129 UIView* separator = separatorScoped;
130 separator.backgroundColor = [UIColor colorWithWhite:0.83 alpha:1]; 130 separator.backgroundColor = [UIColor colorWithWhite:0.83 alpha:1];
131 [self addSubview:separator]; 131 [self addSubview:separator];
132 [constraints addObjectsFromArray:@[ 132 [constraints addObjectsFromArray:@[
133 [separator.widthAnchor constraintEqualToConstant:1], 133 [separator.widthAnchor constraintEqualToConstant:1],
134 [separator.bottomAnchor constraintEqualToAnchor:self.bottomAnchor 134 [separator.bottomAnchor constraintEqualToAnchor:self.bottomAnchor
135 constant:-8], 135 constant:-8],
136 [separator.topAnchor constraintEqualToAnchor:self.topAnchor constant:8], 136 [separator.topAnchor constraintEqualToAnchor:self.topAnchor constant:8],
137 [separator.leadingAnchor 137 [separator.leadingAnchor
138 constraintEqualToAnchor:inputStackView.get().trailingAnchor], 138 constraintEqualToAnchor:inputStackView.trailingAnchor],
139 ]]; 139 ]];
140 separator.translatesAutoresizingMaskIntoConstraints = NO; 140 separator.translatesAutoresizingMaskIntoConstraints = NO;
141 self.separator = separator; 141 self.separator = separator;
142 142
143 // Previous button with an arrow. 143 // Previous button with an arrow.
144 base::scoped_nsobject<UIButton> previousButtonScoped( 144 UIButton* previousButtonScoped = [[UIButton alloc] initWithFrame:CGRectZero];
145 [[UIButton alloc] initWithFrame:CGRectZero]);
146 self.previousButton = previousButtonScoped; 145 self.previousButton = previousButtonScoped;
147 [self addSubview:self.previousButton]; 146 [self addSubview:self.previousButton];
148 [constraints addObjectsFromArray:@[ 147 [constraints addObjectsFromArray:@[
149 [self.previousButton.centerYAnchor 148 [self.previousButton.centerYAnchor
150 constraintEqualToAnchor:self.centerYAnchor], 149 constraintEqualToAnchor:self.centerYAnchor],
151 [self.previousButton.widthAnchor constraintEqualToConstant:48], 150 [self.previousButton.widthAnchor constraintEqualToConstant:48],
152 [self.previousButton.heightAnchor constraintEqualToConstant:56], 151 [self.previousButton.heightAnchor constraintEqualToConstant:56],
153 [self.previousButton.leadingAnchor 152 [self.previousButton.leadingAnchor
154 constraintEqualToAnchor:separator.trailingAnchor], 153 constraintEqualToAnchor:separator.trailingAnchor],
155 ]]; 154 ]];
156 self.previousButton.isAccessibilityElement = YES; 155 self.previousButton.isAccessibilityElement = YES;
157 self.previousButton.accessibilityTraits = UIAccessibilityTraitButton; 156 self.previousButton.accessibilityTraits = UIAccessibilityTraitButton;
158 self.previousButton.tag = IDC_FIND_PREVIOUS; 157 self.previousButton.tag = IDC_FIND_PREVIOUS;
159 self.previousButton.translatesAutoresizingMaskIntoConstraints = NO; 158 self.previousButton.translatesAutoresizingMaskIntoConstraints = NO;
160 159
161 // Next button with an arrow. 160 // Next button with an arrow.
162 base::scoped_nsobject<UIButton> nextButtonScoped( 161 UIButton* nextButtonScoped = [[UIButton alloc] initWithFrame:CGRectZero];
163 [[UIButton alloc] initWithFrame:CGRectZero]);
164 self.nextButton = nextButtonScoped; 162 self.nextButton = nextButtonScoped;
165 [self addSubview:self.nextButton]; 163 [self addSubview:self.nextButton];
166 [constraints addObjectsFromArray:@[ 164 [constraints addObjectsFromArray:@[
167 [self.nextButton.centerYAnchor constraintEqualToAnchor:self.centerYAnchor], 165 [self.nextButton.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
168 [self.nextButton.widthAnchor constraintEqualToConstant:48], 166 [self.nextButton.widthAnchor constraintEqualToConstant:48],
169 [self.nextButton.heightAnchor constraintEqualToConstant:56], 167 [self.nextButton.heightAnchor constraintEqualToConstant:56],
170 [self.nextButton.leadingAnchor 168 [self.nextButton.leadingAnchor
171 constraintEqualToAnchor:self.previousButton.trailingAnchor], 169 constraintEqualToAnchor:self.previousButton.trailingAnchor],
172 ]]; 170 ]];
173 self.nextButton.tag = IDC_FIND_NEXT; 171 self.nextButton.tag = IDC_FIND_NEXT;
174 self.nextButton.translatesAutoresizingMaskIntoConstraints = NO; 172 self.nextButton.translatesAutoresizingMaskIntoConstraints = NO;
175 173
176 // Close button with a cross. 174 // Close button with a cross.
177 base::scoped_nsobject<UIButton> closeButtonScoped( 175 UIButton* closeButtonScoped = [[UIButton alloc] initWithFrame:CGRectZero];
178 [[UIButton alloc] initWithFrame:CGRectZero]);
179 self.closeButton = closeButtonScoped; 176 self.closeButton = closeButtonScoped;
180 [self addSubview:self.closeButton]; 177 [self addSubview:self.closeButton];
181 [constraints addObjectsFromArray:@[ 178 [constraints addObjectsFromArray:@[
182 [self.closeButton.centerYAnchor constraintEqualToAnchor:self.centerYAnchor], 179 [self.closeButton.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
183 [self.closeButton.trailingAnchor constraintEqualToAnchor:self.trailingAnchor 180 [self.closeButton.trailingAnchor constraintEqualToAnchor:self.trailingAnchor
184 constant:-4], 181 constant:-4],
185 [self.closeButton.widthAnchor constraintEqualToConstant:48], 182 [self.closeButton.widthAnchor constraintEqualToConstant:48],
186 [self.closeButton.heightAnchor constraintEqualToConstant:56], 183 [self.closeButton.heightAnchor constraintEqualToConstant:56],
187 [self.closeButton.leadingAnchor 184 [self.closeButton.leadingAnchor
188 constraintEqualToAnchor:self.nextButton.trailingAnchor], 185 constraintEqualToAnchor:self.nextButton.trailingAnchor],
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 243
247 if (!isDark) { 244 if (!isDark) {
248 return; 245 return;
249 } 246 }
250 247
251 // Setup dark appearance. 248 // Setup dark appearance.
252 [self.inputField setTextColor:[UIColor whiteColor]]; 249 [self.inputField setTextColor:[UIColor whiteColor]];
253 NSString* placeholder = [self.inputField placeholder]; 250 NSString* placeholder = [self.inputField placeholder];
254 UIColor* inputTextColor = [UIColor colorWithWhite:1 alpha:0.7]; 251 UIColor* inputTextColor = [UIColor colorWithWhite:1 alpha:0.7];
255 NSDictionary* attributes = @{NSForegroundColorAttributeName : inputTextColor}; 252 NSDictionary* attributes = @{NSForegroundColorAttributeName : inputTextColor};
256 [self.inputField 253 [self.inputField setAttributedPlaceholder:[[NSAttributedString alloc]
257 setAttributedPlaceholder:[[[NSAttributedString alloc] 254 initWithString:placeholder
258 initWithString:placeholder 255 attributes:attributes]];
259 attributes:attributes] autorelease]];
260 UIColor* resultTextColor = [UIColor colorWithWhite:1 alpha:0.3]; 256 UIColor* resultTextColor = [UIColor colorWithWhite:1 alpha:0.3];
261 [self.resultsLabel setTextColor:resultTextColor]; 257 [self.resultsLabel setTextColor:resultTextColor];
262 UIColor* separatorColor = [UIColor colorWithWhite:0 alpha:0.1]; 258 UIColor* separatorColor = [UIColor colorWithWhite:0 alpha:0.1];
263 [self.separator setBackgroundColor:separatorColor]; 259 [self.separator setBackgroundColor:separatorColor];
264 } 260 }
265 261
266 - (UIImage*)imageWithName:(NSString*)imageName isDark:(BOOL)isDark { 262 - (UIImage*)imageWithName:(NSString*)imageName isDark:(BOOL)isDark {
267 NSString* name = 263 NSString* name =
268 isDark ? [imageName stringByAppendingString:@"_incognito"] : imageName; 264 isDark ? [imageName stringByAppendingString:@"_incognito"] : imageName;
269 return [UIImage imageNamed:name]; 265 return [UIImage imageNamed:name];
270 } 266 }
271 267
272 @end 268 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/find_bar/find_bar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698