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

Side by Side Diff: ios/chrome/browser/ui/history/history_search_view.mm

Issue 2624963003: [ObjC ARC] Converts ios/chrome/browser/ui/history:history to ARC. (Closed)
Patch Set: Removes the rest of weak and scoped nsobjects. Created 3 years, 11 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 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/history/history_search_view.h" 5 #import "ios/chrome/browser/ui/history/history_search_view.h"
6 6
7 #include "base/mac/objc_property_releaser.h"
8 #include "components/strings/grit/components_strings.h" 7 #include "components/strings/grit/components_strings.h"
9 #include "ios/chrome/browser/ui/uikit_ui_util.h" 8 #include "ios/chrome/browser/ui/uikit_ui_util.h"
10 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 9 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
11 #include "ui/base/l10n/l10n_util_mac.h" 10 #include "ui/base/l10n/l10n_util_mac.h"
12 11
12 #if !defined(__has_feature) || !__has_feature(objc_arc)
13 #error "This file requires ARC support."
14 #endif
15
13 namespace { 16 namespace {
14 // Shadow opacity for the search view. 17 // Shadow opacity for the search view.
15 CGFloat kShadowOpacity = 0.2f; 18 CGFloat kShadowOpacity = 0.2f;
16 // Margin for the search view. 19 // Margin for the search view.
17 CGFloat kHorizontalMargin = 16.0f; 20 CGFloat kHorizontalMargin = 16.0f;
18 } // namespace 21 } // namespace
19 22
20 @interface HistorySearchView () { 23 @interface HistorySearchView ()
21 base::mac::ObjCPropertyReleaser propertyReleaser_HistorySearchView_;
22 }
23 24
24 // Stack view for laying out the text field and cancel button. 25 // Stack view for laying out the text field and cancel button.
25 @property(nonatomic, strong) UIStackView* stackView; 26 @property(nonatomic, strong) UIStackView* stackView;
26 // Text field for the search view. 27 // Text field for the search view.
27 @property(nonatomic, strong) UITextField* textField; 28 @property(nonatomic, strong) UITextField* textField;
28 // Cancel button for dismissing the search view. 29 // Cancel button for dismissing the search view.
29 @property(nonatomic, strong) UIButton* cancelButton; 30 @property(nonatomic, strong) UIButton* cancelButton;
30 // Constraint for the top anchor. 31 // Constraint for the top anchor.
31 @property(nonatomic, strong) NSLayoutConstraint* topAnchorConstraint; 32 @property(nonatomic, strong) NSLayoutConstraint* topAnchorConstraint;
32 33
(...skipping 18 matching lines...) Expand all
51 UIControlContentVerticalAlignmentCenter; 52 UIControlContentVerticalAlignmentCenter;
52 _textField.backgroundColor = [UIColor whiteColor]; 53 _textField.backgroundColor = [UIColor whiteColor];
53 _textField.textColor = 54 _textField.textColor =
54 [UIColor colorWithWhite:0 alpha:[MDCTypography body1FontOpacity]]; 55 [UIColor colorWithWhite:0 alpha:[MDCTypography body1FontOpacity]];
55 _textField.font = [MDCTypography subheadFont]; 56 _textField.font = [MDCTypography subheadFont];
56 _textField.borderStyle = UITextBorderStyleNone; 57 _textField.borderStyle = UITextBorderStyleNone;
57 [_textField setLeftViewMode:UITextFieldViewModeNever]; 58 [_textField setLeftViewMode:UITextFieldViewModeNever];
58 _textField.clearButtonMode = UITextFieldViewModeAlways; 59 _textField.clearButtonMode = UITextFieldViewModeAlways;
59 _textField.placeholder = l10n_util::GetNSString(IDS_HISTORY_SEARCH_BUTTON); 60 _textField.placeholder = l10n_util::GetNSString(IDS_HISTORY_SEARCH_BUTTON);
60 61
61 _cancelButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; 62 _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
62 [_cancelButton setImage:[UIImage imageNamed:@"collapse"] 63 [_cancelButton setImage:[UIImage imageNamed:@"collapse"]
63 forState:UIControlStateNormal]; 64 forState:UIControlStateNormal];
64 [_cancelButton setImage:[UIImage imageNamed:@"collapse_pressed"] 65 [_cancelButton setImage:[UIImage imageNamed:@"collapse_pressed"]
65 forState:UIControlStateHighlighted]; 66 forState:UIControlStateHighlighted];
66 [_cancelButton 67 [_cancelButton
67 setContentCompressionResistancePriority:UILayoutPriorityRequired 68 setContentCompressionResistancePriority:UILayoutPriorityRequired
68 forAxis: 69 forAxis:
69 UILayoutConstraintAxisHorizontal]; 70 UILayoutConstraintAxisHorizontal];
70 [_cancelButton setContentHuggingPriority:UILayoutPriorityRequired 71 [_cancelButton setContentHuggingPriority:UILayoutPriorityRequired
71 forAxis:UILayoutConstraintAxisHorizontal]; 72 forAxis:UILayoutConstraintAxisHorizontal];
72 [_cancelButton setAccessibilityLabel:l10n_util::GetNSString(IDS_CANCEL)]; 73 [_cancelButton setAccessibilityLabel:l10n_util::GetNSString(IDS_CANCEL)];
73 74
74 _stackView = [[UIStackView alloc] 75 _stackView = [[UIStackView alloc]
75 initWithArrangedSubviews:@[ _textField, _cancelButton ]]; 76 initWithArrangedSubviews:@[ _textField, _cancelButton ]];
76 _stackView.alignment = UIStackViewAlignmentFill; 77 _stackView.alignment = UIStackViewAlignmentFill;
77 _stackView.axis = UILayoutConstraintAxisHorizontal; 78 _stackView.axis = UILayoutConstraintAxisHorizontal;
78 _stackView.distribution = UIStackViewDistributionFill; 79 _stackView.distribution = UIStackViewDistributionFill;
79 [self addSubview:_stackView]; 80 [self addSubview:_stackView];
80 _stackView.translatesAutoresizingMaskIntoConstraints = NO; 81 _stackView.translatesAutoresizingMaskIntoConstraints = NO;
81 _stackView.layoutMarginsRelativeArrangement = YES; 82 _stackView.layoutMarginsRelativeArrangement = YES;
82 83
83 CGFloat topAnchorConstant = IsCompact() ? StatusBarHeight() : 0; 84 CGFloat topAnchorConstant = IsCompact() ? StatusBarHeight() : 0;
84 _topAnchorConstraint = [[_stackView.topAnchor 85 _topAnchorConstraint =
85 constraintEqualToAnchor:self.topAnchor 86 [_stackView.topAnchor constraintEqualToAnchor:self.topAnchor
86 constant:topAnchorConstant] retain]; 87 constant:topAnchorConstant];
87 [NSLayoutConstraint activateConstraints:@[ 88 [NSLayoutConstraint activateConstraints:@[
88 _topAnchorConstraint, 89 _topAnchorConstraint,
89 [_stackView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor], 90 [_stackView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
90 [_stackView.layoutMarginsGuide.leadingAnchor 91 [_stackView.layoutMarginsGuide.leadingAnchor
91 constraintEqualToAnchor:self.leadingAnchor 92 constraintEqualToAnchor:self.leadingAnchor
92 constant:kHorizontalMargin], 93 constant:kHorizontalMargin],
93 [_stackView.layoutMarginsGuide.trailingAnchor 94 [_stackView.layoutMarginsGuide.trailingAnchor
94 constraintEqualToAnchor:self.trailingAnchor 95 constraintEqualToAnchor:self.trailingAnchor
95 constant:-kHorizontalMargin], 96 constant:-kHorizontalMargin],
96 ]]; 97 ]];
97
98 propertyReleaser_HistorySearchView_.Init(self, [HistorySearchView class]);
99 } 98 }
100 return self; 99 return self;
101 } 100 }
102 101
103 - (BOOL)becomeFirstResponder { 102 - (BOOL)becomeFirstResponder {
104 return [self.textField becomeFirstResponder]; 103 return [self.textField becomeFirstResponder];
105 } 104 }
106 105
107 - (void)setEnabled:(BOOL)enabled { 106 - (void)setEnabled:(BOOL)enabled {
108 _enabled = enabled; 107 _enabled = enabled;
(...skipping 17 matching lines...) Expand all
126 self.textField.text = nil; 125 self.textField.text = nil;
127 } 126 }
128 127
129 #pragma mark - UITraitEnvironment 128 #pragma mark - UITraitEnvironment
130 129
131 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { 130 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
132 self.topAnchorConstraint.constant = IsCompact() ? StatusBarHeight() : 0; 131 self.topAnchorConstraint.constant = IsCompact() ? StatusBarHeight() : 0;
133 } 132 }
134 133
135 @end 134 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698