| OLD | NEW |
| 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" | 7 #include "base/mac/objc_release_properties.h" |
| 8 #include "components/strings/grit/components_strings.h" | 8 #include "components/strings/grit/components_strings.h" |
| 9 #include "ios/chrome/browser/ui/uikit_ui_util.h" | 9 #include "ios/chrome/browser/ui/uikit_ui_util.h" |
| 10 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 10 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 11 #include "ui/base/l10n/l10n_util_mac.h" | 11 #include "ui/base/l10n/l10n_util_mac.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 // Shadow opacity for the search view. | 14 // Shadow opacity for the search view. |
| 15 CGFloat kShadowOpacity = 0.2f; | 15 CGFloat kShadowOpacity = 0.2f; |
| 16 // Margin for the search view. | 16 // Margin for the search view. |
| 17 CGFloat kHorizontalMargin = 16.0f; | 17 CGFloat kHorizontalMargin = 16.0f; |
| 18 } // namespace | 18 } // namespace |
| 19 | 19 |
| 20 @interface HistorySearchView () { | 20 @interface HistorySearchView () |
| 21 base::mac::ObjCPropertyReleaser propertyReleaser_HistorySearchView_; | |
| 22 } | |
| 23 | 21 |
| 24 // Stack view for laying out the text field and cancel button. | 22 // Stack view for laying out the text field and cancel button. |
| 25 @property(nonatomic, strong) UIStackView* stackView; | 23 @property(nonatomic, strong) UIStackView* stackView; |
| 26 // Text field for the search view. | 24 // Text field for the search view. |
| 27 @property(nonatomic, strong) UITextField* textField; | 25 @property(nonatomic, strong) UITextField* textField; |
| 28 // Cancel button for dismissing the search view. | 26 // Cancel button for dismissing the search view. |
| 29 @property(nonatomic, strong) UIButton* cancelButton; | 27 @property(nonatomic, strong) UIButton* cancelButton; |
| 30 // Constraint for the top anchor. | 28 // Constraint for the top anchor. |
| 31 @property(nonatomic, strong) NSLayoutConstraint* topAnchorConstraint; | 29 @property(nonatomic, strong) NSLayoutConstraint* topAnchorConstraint; |
| 32 | 30 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 [NSLayoutConstraint activateConstraints:@[ | 85 [NSLayoutConstraint activateConstraints:@[ |
| 88 _topAnchorConstraint, | 86 _topAnchorConstraint, |
| 89 [_stackView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor], | 87 [_stackView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor], |
| 90 [_stackView.layoutMarginsGuide.leadingAnchor | 88 [_stackView.layoutMarginsGuide.leadingAnchor |
| 91 constraintEqualToAnchor:self.leadingAnchor | 89 constraintEqualToAnchor:self.leadingAnchor |
| 92 constant:kHorizontalMargin], | 90 constant:kHorizontalMargin], |
| 93 [_stackView.layoutMarginsGuide.trailingAnchor | 91 [_stackView.layoutMarginsGuide.trailingAnchor |
| 94 constraintEqualToAnchor:self.trailingAnchor | 92 constraintEqualToAnchor:self.trailingAnchor |
| 95 constant:-kHorizontalMargin], | 93 constant:-kHorizontalMargin], |
| 96 ]]; | 94 ]]; |
| 97 | |
| 98 propertyReleaser_HistorySearchView_.Init(self, [HistorySearchView class]); | |
| 99 } | 95 } |
| 100 return self; | 96 return self; |
| 101 } | 97 } |
| 102 | 98 |
| 99 - (void)dealloc { |
| 100 base::mac::ReleaseProperties(self); |
| 101 [super dealloc]; |
| 102 } |
| 103 |
| 103 - (BOOL)becomeFirstResponder { | 104 - (BOOL)becomeFirstResponder { |
| 104 return [self.textField becomeFirstResponder]; | 105 return [self.textField becomeFirstResponder]; |
| 105 } | 106 } |
| 106 | 107 |
| 107 - (void)setEnabled:(BOOL)enabled { | 108 - (void)setEnabled:(BOOL)enabled { |
| 108 _enabled = enabled; | 109 _enabled = enabled; |
| 109 self.cancelButton.enabled = enabled; | 110 self.cancelButton.enabled = enabled; |
| 110 self.textField.enabled = enabled; | 111 self.textField.enabled = enabled; |
| 111 self.textField.clearButtonMode = | 112 self.textField.clearButtonMode = |
| 112 enabled ? UITextFieldViewModeAlways : UITextFieldViewModeNever; | 113 enabled ? UITextFieldViewModeAlways : UITextFieldViewModeNever; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 126 self.textField.text = nil; | 127 self.textField.text = nil; |
| 127 } | 128 } |
| 128 | 129 |
| 129 #pragma mark - UITraitEnvironment | 130 #pragma mark - UITraitEnvironment |
| 130 | 131 |
| 131 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { | 132 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { |
| 132 self.topAnchorConstraint.constant = IsCompact() ? StatusBarHeight() : 0; | 133 self.topAnchorConstraint.constant = IsCompact() ? StatusBarHeight() : 0; |
| 133 } | 134 } |
| 134 | 135 |
| 135 @end | 136 @end |
| OLD | NEW |