| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 @end | 89 @end |
| 90 | 90 |
| 91 #pragma mark - | 91 #pragma mark - |
| 92 #pragma mark OmniboxTextFieldIOS | 92 #pragma mark OmniboxTextFieldIOS |
| 93 | 93 |
| 94 @implementation OmniboxTextFieldIOS { | 94 @implementation OmniboxTextFieldIOS { |
| 95 // Currently selected chip text. Nil if no chip. | 95 // Currently selected chip text. Nil if no chip. |
| 96 base::scoped_nsobject<NSString> _chipText; | 96 base::scoped_nsobject<NSString> _chipText; |
| 97 base::scoped_nsobject<UILabel> _selection; | 97 base::scoped_nsobject<UILabel> _selection; |
| 98 base::scoped_nsobject<UILabel> _preEditStaticLabel; | 98 base::scoped_nsobject<UILabel> _preEditStaticLabel; |
| 99 NSString* _preEditText; | |
| 100 base::scoped_nsobject<UIFont> _font; | 99 base::scoped_nsobject<UIFont> _font; |
| 101 base::scoped_nsobject<UIColor> _displayedTextColor; | 100 base::scoped_nsobject<UIColor> _displayedTextColor; |
| 102 base::scoped_nsobject<UIColor> _displayedTintColor; | 101 base::scoped_nsobject<UIColor> _displayedTintColor; |
| 103 UIColor* _selectedTextBackgroundColor; | |
| 104 UIColor* _placeholderTextColor; | |
| 105 | 102 |
| 106 // The 'Copy URL' menu item is sometimes shown in the edit menu, so keep it | 103 // The 'Copy URL' menu item is sometimes shown in the edit menu, so keep it |
| 107 // around to make adding/removing easier. | 104 // around to make adding/removing easier. |
| 108 base::scoped_nsobject<UIMenuItem> _copyUrlMenuItem; | 105 base::scoped_nsobject<UIMenuItem> _copyUrlMenuItem; |
| 109 | |
| 110 base::mac::ObjCPropertyReleaser _propertyReleaser_OmniboxTextFieldIOS; | |
| 111 } | 106 } |
| 112 | 107 |
| 113 @synthesize leftViewImageId = _leftViewImageId; | 108 @synthesize leftViewImageId = _leftViewImageId; |
| 114 @synthesize preEditText = _preEditText; | 109 @synthesize preEditText = _preEditText; |
| 115 @synthesize clearingPreEditText = _clearingPreEditText; | 110 @synthesize clearingPreEditText = _clearingPreEditText; |
| 116 @synthesize selectedTextBackgroundColor = _selectedTextBackgroundColor; | 111 @synthesize selectedTextBackgroundColor = _selectedTextBackgroundColor; |
| 117 @synthesize placeholderTextColor = _placeholderTextColor; | 112 @synthesize placeholderTextColor = _placeholderTextColor; |
| 118 @synthesize incognito = _incognito; | 113 @synthesize incognito = _incognito; |
| 119 | 114 |
| 120 // Overload to allow for code-based initialization. | 115 // Overload to allow for code-based initialization. |
| 121 - (instancetype)initWithFrame:(CGRect)frame { | 116 - (instancetype)initWithFrame:(CGRect)frame { |
| 122 return [self initWithFrame:frame | 117 return [self initWithFrame:frame |
| 123 font:[UIFont systemFontOfSize:kFontSize] | 118 font:[UIFont systemFontOfSize:kFontSize] |
| 124 textColor:TextColor() | 119 textColor:TextColor() |
| 125 tintColor:nil]; | 120 tintColor:nil]; |
| 126 } | 121 } |
| 127 | 122 |
| 128 - (instancetype)initWithFrame:(CGRect)frame | 123 - (instancetype)initWithFrame:(CGRect)frame |
| 129 font:(UIFont*)font | 124 font:(UIFont*)font |
| 130 textColor:(UIColor*)textColor | 125 textColor:(UIColor*)textColor |
| 131 tintColor:(UIColor*)tintColor { | 126 tintColor:(UIColor*)tintColor { |
| 132 self = [super initWithFrame:frame]; | 127 self = [super initWithFrame:frame]; |
| 133 if (self) { | 128 if (self) { |
| 134 _propertyReleaser_OmniboxTextFieldIOS.Init(self, | |
| 135 [OmniboxTextFieldIOS class]); | |
| 136 _font.reset([font retain]); | 129 _font.reset([font retain]); |
| 137 _displayedTextColor.reset([textColor retain]); | 130 _displayedTextColor.reset([textColor retain]); |
| 138 if (tintColor) { | 131 if (tintColor) { |
| 139 [self setTintColor:tintColor]; | 132 [self setTintColor:tintColor]; |
| 140 _displayedTintColor.reset([tintColor retain]); | 133 _displayedTintColor.reset([tintColor retain]); |
| 141 } else { | 134 } else { |
| 142 _displayedTintColor.reset([self.tintColor retain]); | 135 _displayedTintColor.reset([self.tintColor retain]); |
| 143 } | 136 } |
| 144 [self setFont:_font]; | 137 [self setFont:_font]; |
| 145 [self setTextColor:_displayedTextColor]; | 138 [self setTextColor:_displayedTextColor]; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 157 // Sanity check: | 150 // Sanity check: |
| 158 DCHECK([self conformsToProtocol:@protocol(UITextInput)]); | 151 DCHECK([self conformsToProtocol:@protocol(UITextInput)]); |
| 159 | 152 |
| 160 // Force initial layout of internal text label. Needed for omnibox | 153 // Force initial layout of internal text label. Needed for omnibox |
| 161 // animations that will otherwise animate the text label from origin {0, 0}. | 154 // animations that will otherwise animate the text label from origin {0, 0}. |
| 162 [super setText:@" "]; | 155 [super setText:@" "]; |
| 163 } | 156 } |
| 164 return self; | 157 return self; |
| 165 } | 158 } |
| 166 | 159 |
| 160 - (void)dealloc { |
| 161 base::mac::ReleaseProperties(self); |
| 162 [super dealloc]; |
| 163 } |
| 164 |
| 167 - (instancetype)initWithCoder:(nonnull NSCoder*)aDecoder { | 165 - (instancetype)initWithCoder:(nonnull NSCoder*)aDecoder { |
| 168 NOTREACHED(); | 166 NOTREACHED(); |
| 169 return nil; | 167 return nil; |
| 170 } | 168 } |
| 171 | 169 |
| 172 // Enforces that the delegate is an OmniboxTextFieldDelegate. | 170 // Enforces that the delegate is an OmniboxTextFieldDelegate. |
| 173 - (id<OmniboxTextFieldDelegate>)delegate { | 171 - (id<OmniboxTextFieldDelegate>)delegate { |
| 174 id delegate = [super delegate]; | 172 id delegate = [super delegate]; |
| 175 DCHECK(delegate == nil || | 173 DCHECK(delegate == nil || |
| 176 [[delegate class] | 174 [[delegate class] |
| (...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 // Disable the RTL arrow menu item. The omnibox sets alignment based on the | 1039 // Disable the RTL arrow menu item. The omnibox sets alignment based on the |
| 1042 // text in the field, and should not be overridden. | 1040 // text in the field, and should not be overridden. |
| 1043 if ([NSStringFromSelector(action) hasPrefix:@"makeTextWritingDirection"]) { | 1041 if ([NSStringFromSelector(action) hasPrefix:@"makeTextWritingDirection"]) { |
| 1044 return NO; | 1042 return NO; |
| 1045 } | 1043 } |
| 1046 | 1044 |
| 1047 return [super canPerformAction:action withSender:sender]; | 1045 return [super canPerformAction:action withSender:sender]; |
| 1048 } | 1046 } |
| 1049 | 1047 |
| 1050 @end | 1048 @end |
| OLD | NEW |