Chromium Code Reviews| Index: ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.mm |
| diff --git a/ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.mm b/ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.mm |
| index d449366364a691180f361af28c0f90a964b41573..671ecaaca34347e9d65f5991742f30d4eb3f6223 100644 |
| --- a/ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.mm |
| +++ b/ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.mm |
| @@ -10,8 +10,7 @@ |
| #include "base/ios/ios_util.h" |
| #include "base/logging.h" |
| #include "base/mac/foundation_util.h" |
| -#include "base/mac/objc_property_releaser.h" |
| -#include "base/mac/scoped_nsobject.h" |
| + |
| #include "base/strings/sys_string_conversions.h" |
| #include "components/grit/components_scaled_resources.h" |
| #include "components/omnibox/browser/autocomplete_input.h" |
| @@ -33,6 +32,10 @@ |
| #import "ui/gfx/ios/NSString+CrStringDrawing.h" |
| #include "ui/gfx/scoped_cg_context_save_gstate_mac.h" |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| namespace { |
| const CGFloat kFontSize = 16; |
| const CGFloat kEditingRectX = 16; |
| @@ -93,21 +96,19 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| @implementation OmniboxTextFieldIOS { |
| // Currently selected chip text. Nil if no chip. |
| - base::scoped_nsobject<NSString> _chipText; |
| - base::scoped_nsobject<UILabel> _selection; |
| - base::scoped_nsobject<UILabel> _preEditStaticLabel; |
| + NSString* _chipText; |
| + UILabel* _selection; |
| + UILabel* _preEditStaticLabel; |
| NSString* _preEditText; |
|
rohitrao (ping after 24h)
2017/02/24 13:40:32
Should we just remove this and let the storage be
stkhapugin
2017/03/01 17:43:58
Removed every redeclaration that was backed by a p
|
| - base::scoped_nsobject<UIFont> _font; |
| - base::scoped_nsobject<UIColor> _displayedTextColor; |
| - base::scoped_nsobject<UIColor> _displayedTintColor; |
| + UIFont* _font; |
| + UIColor* _displayedTextColor; |
| + UIColor* _displayedTintColor; |
| UIColor* _selectedTextBackgroundColor; |
|
rohitrao (ping after 24h)
2017/02/24 13:40:32
Should we remove this and _placeholderTextColor?
stkhapugin
2017/03/01 17:43:58
I can do this in a follow-up CL to reserve this on
|
| UIColor* _placeholderTextColor; |
| // The 'Copy URL' menu item is sometimes shown in the edit menu, so keep it |
| // around to make adding/removing easier. |
| - base::scoped_nsobject<UIMenuItem> _copyUrlMenuItem; |
| - |
| - base::mac::ObjCPropertyReleaser _propertyReleaser_OmniboxTextFieldIOS; |
| + UIMenuItem* _copyUrlMenuItem; |
| } |
| @synthesize leftViewImageId = _leftViewImageId; |
| @@ -131,15 +132,13 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| tintColor:(UIColor*)tintColor { |
| self = [super initWithFrame:frame]; |
| if (self) { |
| - _propertyReleaser_OmniboxTextFieldIOS.Init(self, |
| - [OmniboxTextFieldIOS class]); |
| - _font.reset([font retain]); |
| - _displayedTextColor.reset([textColor retain]); |
| + _font = font; |
| + _displayedTextColor = textColor; |
| if (tintColor) { |
| [self setTintColor:tintColor]; |
| - _displayedTintColor.reset([tintColor retain]); |
| + _displayedTintColor = tintColor; |
| } else { |
| - _displayedTintColor.reset([self.tintColor retain]); |
| + _displayedTintColor = self.tintColor; |
| } |
| [self setFont:_font]; |
| [self setTextColor:_displayedTextColor]; |
| @@ -211,7 +210,7 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| [super selectAll:nil]; |
| } |
| - if (!_selection.get()) { |
| + if (!_selection) { |
| [super touchesBegan:touches withEvent:event]; |
| return; |
| } |
| @@ -222,7 +221,7 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| return; |
| // Accept selection. |
| - base::scoped_nsobject<NSString> newText([[self nsDisplayedText] copy]); |
| + NSString* newText = [[self nsDisplayedText] copy]; |
| [self clearAutocompleteText]; |
| [self setText:newText]; |
| } |
| @@ -245,22 +244,22 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| [self setPreEditText:self.text]; |
| // Adjusts the placement so static URL lines up perfectly with UITextField. |
| - DCHECK(!_preEditStaticLabel.get()); |
| + DCHECK(!_preEditStaticLabel); |
| CGRect rect = [self preEditLabelRectForBounds:self.bounds]; |
| - _preEditStaticLabel.reset([[UILabel alloc] initWithFrame:rect]); |
| - _preEditStaticLabel.get().backgroundColor = [UIColor clearColor]; |
| - _preEditStaticLabel.get().opaque = YES; |
| - _preEditStaticLabel.get().font = _font; |
| - _preEditStaticLabel.get().textColor = _displayedTextColor; |
| - _preEditStaticLabel.get().lineBreakMode = NSLineBreakByTruncatingHead; |
| + _preEditStaticLabel = [[UILabel alloc] initWithFrame:rect]; |
| + _preEditStaticLabel.backgroundColor = [UIColor clearColor]; |
| + _preEditStaticLabel.opaque = YES; |
| + _preEditStaticLabel.font = _font; |
| + _preEditStaticLabel.textColor = _displayedTextColor; |
| + _preEditStaticLabel.lineBreakMode = NSLineBreakByTruncatingHead; |
| NSDictionary* attributes = |
| @{NSBackgroundColorAttributeName : [self selectedTextBackgroundColor]}; |
| - base::scoped_nsobject<NSAttributedString> preEditString( |
| + NSAttributedString* preEditString = |
| [[NSAttributedString alloc] initWithString:self.text |
| - attributes:attributes]); |
| + attributes:attributes]; |
| [_preEditStaticLabel setAttributedText:preEditString]; |
| - _preEditStaticLabel.get().textAlignment = [self preEditTextAlignment]; |
| + _preEditStaticLabel.textAlignment = [self preEditTextAlignment]; |
| [self addSubview:_preEditStaticLabel]; |
| } |
| @@ -288,9 +287,9 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| // If the pre-edit text is wider than the omnibox, right-align the text so it |
| // ends at the same x coord as the blue selection box. |
| CGSize textSize = |
| - [_preEditStaticLabel.get().text cr_pixelAlignedSizeWithFont:_font]; |
| + [_preEditStaticLabel.text cr_pixelAlignedSizeWithFont:_font]; |
| BOOL isLTR = [self bestTextAlignment] == NSTextAlignmentLeft; |
| - return textSize.width < _preEditStaticLabel.get().frame.size.width |
| + return textSize.width < _preEditStaticLabel.frame.size.width |
| ? (isLTR ? NSTextAlignmentLeft : NSTextAlignmentRight) |
| : (isLTR ? NSTextAlignmentRight : NSTextAlignmentLeft); |
| } |
| @@ -302,7 +301,7 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| [_preEditStaticLabel setFrame:rect]; |
| // Update text alignment since the pre-edit label's frame changed. |
| - _preEditStaticLabel.get().textAlignment = [self preEditTextAlignment]; |
| + _preEditStaticLabel.textAlignment = [self preEditTextAlignment]; |
| [self hideTextAndCursor]; |
| } else if (!_selection) { |
| [self showTextAndCursor]; |
| @@ -314,7 +313,7 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| [self setPreEditText:nil]; |
| if (_preEditStaticLabel) { |
| [_preEditStaticLabel removeFromSuperview]; |
| - _preEditStaticLabel.reset(nil); |
| + _preEditStaticLabel = nil; |
| [self showTextAndCursor]; |
| } |
| } |
| @@ -334,7 +333,7 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| } |
| - (NSString*)nsDisplayedText { |
| - if (_selection.get()) |
| + if (_selection) |
| return [_selection text]; |
| return [self text]; |
| } |
| @@ -347,7 +346,7 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| DCHECK_LT([[self text] length], [[_selection text] length]) |
| << "[_selection text] and [self text] are out of sync. " |
| << "Please email justincohen@ and rohitrao@ if you see this."; |
| - if (_selection.get() && [[_selection text] length] > [[self text] length]) { |
| + if (_selection && [[_selection text] length] > [[self text] length]) { |
| return base::SysNSStringToUTF16( |
| [[_selection text] substringFromIndex:[[self text] length]]); |
| } |
| @@ -365,8 +364,8 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| if ([self isPreEditing]) { |
| [self exitPreEditState]; |
| } |
| - if (_selection.get()) { |
| - base::scoped_nsobject<NSString> newText([[self nsDisplayedText] copy]); |
| + if (_selection) { |
| + NSString* newText = [[self nsDisplayedText] copy]; |
| [self clearAutocompleteText]; |
| [self setText:newText]; |
| } |
| @@ -376,10 +375,10 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| // Creates the SelectedTextLabel if it doesn't already exist and adds it as a |
| // subview. |
| - (void)createSelectionViewIfNecessary { |
| - if (_selection.get()) |
| + if (_selection) |
| return; |
| - _selection.reset([[UILabel alloc] initWithFrame:CGRectZero]); |
| + _selection = [[UILabel alloc] initWithFrame:CGRectZero]; |
| [_selection setFont:_font]; |
| [_selection setTextColor:_displayedTextColor]; |
| [_selection setOpaque:NO]; |
| @@ -409,8 +408,7 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| } else if (_leftViewImageId && (IsIPadIdiom() || ![self isFirstResponder])) { |
| UIImage* image = [NativeImage(_leftViewImageId) |
| imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
| - UIImageView* imageView = |
| - [[[UIImageView alloc] initWithImage:image] autorelease]; |
| + UIImageView* imageView = [[UIImageView alloc] initWithImage:image]; |
| [leftViewButton setImage:imageView.image forState:UIControlStateNormal]; |
| [leftViewButton setTitle:nil forState:UIControlStateNormal]; |
| UIColor* tint = [UIColor whiteColor]; |
| @@ -476,11 +474,11 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| // Creating |autocompleteText| from |[text string]| has the added bonus of |
| // removing all the previously set attributes. This way the autocomplete |
| // text doesn't have a highlighted protocol, etc. |
| - base::scoped_nsobject<NSMutableAttributedString> autocompleteText( |
| - [[NSMutableAttributedString alloc] initWithString:[text string]]); |
| + NSMutableAttributedString* autocompleteText = |
| + [[NSMutableAttributedString alloc] initWithString:[text string]]; |
| [self createSelectionViewIfNecessary]; |
| - DCHECK(_selection.get()); |
| + DCHECK(_selection); |
| [autocompleteText |
| addAttribute:NSBackgroundColorAttributeName |
| value:[self selectedTextBackgroundColor] |
| @@ -513,8 +511,7 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| // Ensures that attributedText always uses the proper style attributes. |
| - (void)setAttributedText:(NSAttributedString*)attributedText { |
| - base::scoped_nsobject<NSMutableAttributedString> mutableText( |
| - [attributedText mutableCopy]); |
| + NSMutableAttributedString* mutableText = [attributedText mutableCopy]; |
| NSRange entireString = NSMakeRange(0, [mutableText length]); |
| // Set the font. |
| @@ -524,13 +521,12 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| if (self.editing) { |
| // Hide the text when the |_selection| label is displayed. |
| UIColor* textColor = |
| - _selection ? [UIColor clearColor] : _displayedTextColor.get(); |
| + _selection ? [UIColor clearColor] : _displayedTextColor; |
| [mutableText addAttribute:NSForegroundColorAttributeName |
| value:textColor |
| range:entireString]; |
| } else { |
| - base::scoped_nsobject<NSMutableParagraphStyle> style( |
| - [[NSMutableParagraphStyle alloc] init]); |
| + NSMutableParagraphStyle* style = [[NSMutableParagraphStyle alloc] init]; |
| // URLs have their text direction set to to LTR (avoids RTL characters |
| // making the URL render from right to left, as per RFC 3987 Section 4.1). |
| [style setBaseWritingDirection:NSWritingDirectionLeftToRight]; |
| @@ -580,16 +576,15 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| NSDictionary* attributes = |
| @{NSForegroundColorAttributeName : _placeholderTextColor}; |
| self.attributedPlaceholder = |
| - [[[NSAttributedString alloc] initWithString:placeholder |
| - attributes:attributes] autorelease]; |
| + [[NSAttributedString alloc] initWithString:placeholder |
| + attributes:attributes]; |
| } else { |
| [super setPlaceholder:placeholder]; |
| } |
| } |
| - (void)setText:(NSString*)text { |
| - NSAttributedString* as = |
| - [[[NSAttributedString alloc] initWithString:text] autorelease]; |
| + NSAttributedString* as = [[NSAttributedString alloc] initWithString:text]; |
| if (self.text.length > 0 && as.length == 0) { |
| // Remove the fade animations before the subviews are removed. |
| [self cleanUpFadeAnimations]; |
| @@ -606,23 +601,23 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| } |
| - (void)setChipText:(NSString*)chipName { |
| - _chipText.reset(); |
| + _chipText = nil; |
| if ([chipName length]) { |
| if ([self bestAlignmentForText:chipName] == NSTextAlignmentLeft) |
| chipName = [chipName stringByAppendingString:@":"]; |
| - _chipText.reset([chipName copy]); |
| + _chipText = [chipName copy]; |
| } |
| [self updateLeftView]; |
| } |
| - (BOOL)hasAutocompleteText { |
| - return !!_selection.get(); |
| + return !!_selection; |
| } |
| - (void)clearAutocompleteText { |
| if (_selection) { |
| [_selection removeFromSuperview]; |
| - _selection.reset(nil); |
| + _selection = nil; |
| [self showTextAndCursor]; |
| } |
| } |
| @@ -993,10 +988,10 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; |
| if (![super becomeFirstResponder]) |
| return NO; |
| - if (!_copyUrlMenuItem.get()) { |
| + if (!_copyUrlMenuItem) { |
| NSString* const kTitle = l10n_util::GetNSString(IDS_IOS_COPY_URL); |
| - _copyUrlMenuItem.reset( |
| - [[UIMenuItem alloc] initWithTitle:kTitle action:@selector(copyUrl:)]); |
| + _copyUrlMenuItem = |
| + [[UIMenuItem alloc] initWithTitle:kTitle action:@selector(copyUrl:)]; |
| } |
| // Add the "Copy URL" menu item to the |sharedMenuController| if necessary. |