| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/omnibox/omnibox_text_field_ios.h" | 5 #import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h" |
| 6 | 6 |
| 7 #import <CoreText/CoreText.h> | 7 #import <CoreText/CoreText.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/ios/ios_util.h" | 10 #include "base/ios/ios_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
| 13 #include "base/mac/objc_property_releaser.h" | 13 #include "base/mac/objc_release_properties.h" |
| 14 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 16 #include "components/grit/components_scaled_resources.h" | 16 #include "components/grit/components_scaled_resources.h" |
| 17 #include "components/omnibox/browser/autocomplete_input.h" | 17 #include "components/omnibox/browser/autocomplete_input.h" |
| 18 #include "ios/chrome/browser/autocomplete/autocomplete_scheme_classifier_impl.h" | 18 #include "ios/chrome/browser/autocomplete/autocomplete_scheme_classifier_impl.h" |
| 19 #import "ios/chrome/browser/ui/animation_util.h" | 19 #import "ios/chrome/browser/ui/animation_util.h" |
| 20 #include "ios/chrome/browser/ui/omnibox/omnibox_util.h" | 20 #include "ios/chrome/browser/ui/omnibox/omnibox_util.h" |
| 21 #import "ios/chrome/browser/ui/reversed_animation.h" | 21 #import "ios/chrome/browser/ui/reversed_animation.h" |
| 22 #include "ios/chrome/browser/ui/rtl_geometry.h" | 22 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 23 #include "ios/chrome/browser/ui/ui_util.h" | 23 #include "ios/chrome/browser/ui/ui_util.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 NSString* _preEditText; | 99 NSString* _preEditText; |
| 100 base::scoped_nsobject<UIFont> _font; | 100 base::scoped_nsobject<UIFont> _font; |
| 101 base::scoped_nsobject<UIColor> _displayedTextColor; | 101 base::scoped_nsobject<UIColor> _displayedTextColor; |
| 102 base::scoped_nsobject<UIColor> _displayedTintColor; | 102 base::scoped_nsobject<UIColor> _displayedTintColor; |
| 103 UIColor* _selectedTextBackgroundColor; | 103 UIColor* _selectedTextBackgroundColor; |
| 104 UIColor* _placeholderTextColor; | 104 UIColor* _placeholderTextColor; |
| 105 | 105 |
| 106 // The 'Copy URL' menu item is sometimes shown in the edit menu, so keep it | 106 // The 'Copy URL' menu item is sometimes shown in the edit menu, so keep it |
| 107 // around to make adding/removing easier. | 107 // around to make adding/removing easier. |
| 108 base::scoped_nsobject<UIMenuItem> _copyUrlMenuItem; | 108 base::scoped_nsobject<UIMenuItem> _copyUrlMenuItem; |
| 109 | |
| 110 base::mac::ObjCPropertyReleaser _propertyReleaser_OmniboxTextFieldIOS; | |
| 111 } | 109 } |
| 112 | 110 |
| 113 @synthesize leftViewImageId = _leftViewImageId; | 111 @synthesize leftViewImageId = _leftViewImageId; |
| 114 @synthesize preEditText = _preEditText; | 112 @synthesize preEditText = _preEditText; |
| 115 @synthesize clearingPreEditText = _clearingPreEditText; | 113 @synthesize clearingPreEditText = _clearingPreEditText; |
| 116 @synthesize selectedTextBackgroundColor = _selectedTextBackgroundColor; | 114 @synthesize selectedTextBackgroundColor = _selectedTextBackgroundColor; |
| 117 @synthesize placeholderTextColor = _placeholderTextColor; | 115 @synthesize placeholderTextColor = _placeholderTextColor; |
| 118 @synthesize incognito = _incognito; | 116 @synthesize incognito = _incognito; |
| 119 | 117 |
| 120 // Overload to allow for code-based initialization. | 118 // Overload to allow for code-based initialization. |
| 121 - (instancetype)initWithFrame:(CGRect)frame { | 119 - (instancetype)initWithFrame:(CGRect)frame { |
| 122 return [self initWithFrame:frame | 120 return [self initWithFrame:frame |
| 123 font:[UIFont systemFontOfSize:kFontSize] | 121 font:[UIFont systemFontOfSize:kFontSize] |
| 124 textColor:TextColor() | 122 textColor:TextColor() |
| 125 tintColor:nil]; | 123 tintColor:nil]; |
| 126 } | 124 } |
| 127 | 125 |
| 128 - (instancetype)initWithFrame:(CGRect)frame | 126 - (instancetype)initWithFrame:(CGRect)frame |
| 129 font:(UIFont*)font | 127 font:(UIFont*)font |
| 130 textColor:(UIColor*)textColor | 128 textColor:(UIColor*)textColor |
| 131 tintColor:(UIColor*)tintColor { | 129 tintColor:(UIColor*)tintColor { |
| 132 self = [super initWithFrame:frame]; | 130 self = [super initWithFrame:frame]; |
| 133 if (self) { | 131 if (self) { |
| 134 _propertyReleaser_OmniboxTextFieldIOS.Init(self, | |
| 135 [OmniboxTextFieldIOS class]); | |
| 136 _font.reset([font retain]); | 132 _font.reset([font retain]); |
| 137 _displayedTextColor.reset([textColor retain]); | 133 _displayedTextColor.reset([textColor retain]); |
| 138 if (tintColor) { | 134 if (tintColor) { |
| 139 [self setTintColor:tintColor]; | 135 [self setTintColor:tintColor]; |
| 140 _displayedTintColor.reset([tintColor retain]); | 136 _displayedTintColor.reset([tintColor retain]); |
| 141 } else { | 137 } else { |
| 142 _displayedTintColor.reset([self.tintColor retain]); | 138 _displayedTintColor.reset([self.tintColor retain]); |
| 143 } | 139 } |
| 144 [self setFont:_font]; | 140 [self setFont:_font]; |
| 145 [self setTextColor:_displayedTextColor]; | 141 [self setTextColor:_displayedTextColor]; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 157 // Sanity check: | 153 // Sanity check: |
| 158 DCHECK([self conformsToProtocol:@protocol(UITextInput)]); | 154 DCHECK([self conformsToProtocol:@protocol(UITextInput)]); |
| 159 | 155 |
| 160 // Force initial layout of internal text label. Needed for omnibox | 156 // Force initial layout of internal text label. Needed for omnibox |
| 161 // animations that will otherwise animate the text label from origin {0, 0}. | 157 // animations that will otherwise animate the text label from origin {0, 0}. |
| 162 [super setText:@" "]; | 158 [super setText:@" "]; |
| 163 } | 159 } |
| 164 return self; | 160 return self; |
| 165 } | 161 } |
| 166 | 162 |
| 163 - (void)dealloc { |
| 164 base::mac::ReleaseProperties(self); |
| 165 [super dealloc]; |
| 166 } |
| 167 |
| 167 - (instancetype)initWithCoder:(nonnull NSCoder*)aDecoder { | 168 - (instancetype)initWithCoder:(nonnull NSCoder*)aDecoder { |
| 168 NOTREACHED(); | 169 NOTREACHED(); |
| 169 return nil; | 170 return nil; |
| 170 } | 171 } |
| 171 | 172 |
| 172 // Enforces that the delegate is an OmniboxTextFieldDelegate. | 173 // Enforces that the delegate is an OmniboxTextFieldDelegate. |
| 173 - (id<OmniboxTextFieldDelegate>)delegate { | 174 - (id<OmniboxTextFieldDelegate>)delegate { |
| 174 id delegate = [super delegate]; | 175 id delegate = [super delegate]; |
| 175 DCHECK(delegate == nil || | 176 DCHECK(delegate == nil || |
| 176 [[delegate class] | 177 [[delegate class] |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 // Disable the RTL arrow menu item. The omnibox sets alignment based on the | 1044 // Disable the RTL arrow menu item. The omnibox sets alignment based on the |
| 1044 // text in the field, and should not be overridden. | 1045 // text in the field, and should not be overridden. |
| 1045 if ([NSStringFromSelector(action) hasPrefix:@"makeTextWritingDirection"]) { | 1046 if ([NSStringFromSelector(action) hasPrefix:@"makeTextWritingDirection"]) { |
| 1046 return NO; | 1047 return NO; |
| 1047 } | 1048 } |
| 1048 | 1049 |
| 1049 return [super canPerformAction:action withSender:sender]; | 1050 return [super canPerformAction:action withSender:sender]; |
| 1050 } | 1051 } |
| 1051 | 1052 |
| 1052 @end | 1053 @end |
| OLD | NEW |