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

Unified Diff: ios/chrome/browser/ui/infobars/infobar_view.mm

Issue 2831213005: [ObjC ARC] Converts ios/chrome/browser/ui/infobars:infobars to ARC. (Closed)
Patch Set: Remove weak Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/ui/infobars/infobar_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/infobars/infobar_view.mm
diff --git a/ios/chrome/browser/ui/infobars/infobar_view.mm b/ios/chrome/browser/ui/infobars/infobar_view.mm
index 88d913b3f893bcc7da6e1216947b71a761022c90..dc3471dd17e6611a0fac48ddd23b204740a08889 100644
--- a/ios/chrome/browser/ui/infobars/infobar_view.mm
+++ b/ios/chrome/browser/ui/infobars/infobar_view.mm
@@ -9,7 +9,6 @@
#include "base/format_macros.h"
#include "base/i18n/rtl.h"
-#include "base/ios/weak_nsobject.h"
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
@@ -26,6 +25,10 @@
#import "ui/gfx/ios/uikit_util.h"
#include "url/gurl.h"
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
namespace {
const char kChromeInfobarURL[] = "chromeinternal://infobar/";
@@ -82,16 +85,15 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
@end
@implementation SwitchView {
- base::scoped_nsobject<UILabel> label_;
- base::scoped_nsobject<UISwitch> switch_;
+ UILabel* label_;
+ UISwitch* switch_;
CGFloat preferredTotalWidth_;
CGFloat preferredLabelWidth_;
}
- (id)initWithLabel:(NSString*)labelText isOn:(BOOL)isOn {
// Creates switch and label.
- base::scoped_nsobject<UILabel> tempLabel(
- [[UILabel alloc] initWithFrame:CGRectZero]);
+ UILabel* tempLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[tempLabel setTextAlignment:NSTextAlignmentNatural];
[tempLabel setFont:[MDCTypography body1Font]];
[tempLabel setText:labelText];
@@ -99,8 +101,7 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
[tempLabel setLineBreakMode:NSLineBreakByWordWrapping];
[tempLabel setNumberOfLines:0];
[tempLabel setAdjustsFontSizeToFitWidth:NO];
- base::scoped_nsobject<UISwitch> tempSwitch(
- [[UISwitch alloc] initWithFrame:CGRectZero]);
+ UISwitch* tempSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
[tempSwitch setExclusiveTouch:YES];
[tempSwitch setAccessibilityLabel:labelText];
[tempSwitch setOnTintColor:[[MDCPalette cr_bluePalette] tint500]];
@@ -117,8 +118,8 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
self = [super initWithFrame:frameRect];
if (!self)
return nil;
- label_.reset([tempLabel retain]);
- switch_.reset([tempSwitch retain]);
+ label_ = tempLabel;
+ switch_ = tempSwitch;
// Sets the position of the label and the switch. The label is left aligned
// and the switch is right aligned. Both are vertically centered.
@@ -223,37 +224,37 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
@implementation InfoBarView {
// Delegates UIView events.
- InfoBarViewDelegate* delegate_; // weak
+ InfoBarViewDelegate* delegate_; // weak.
// The current height of this infobar (used for animations where part of the
// infobar is hidden).
CGFloat visibleHeight_;
// The height of this infobar when fully visible.
CGFloat targetHeight_;
// View containing |imageView_|. Exists to apply drop shadows to the view.
- base::scoped_nsobject<UIView> imageViewContainer_;
+ UIView* imageViewContainer_;
// View containing the icon.
- base::scoped_nsobject<UIImageView> imageView_;
+ UIImageView* imageView_;
// Close button.
- base::scoped_nsobject<UIButton> closeButton_;
+ UIButton* closeButton_;
// View containing the switch and its label.
- base::scoped_nsobject<SwitchView> switchView_;
+ SwitchView* switchView_;
// We are using a LabelLinkController with an UILabel to be able to have
// parts of the label underlined and clickable. This label_ may be nil if
// the delegate returns an empty string for GetMessageText().
- base::scoped_nsobject<LabelLinkController> labelLinkController_;
- UILabel* label_; // Weak.
+ LabelLinkController* labelLinkController_;
+ UILabel* label_;
// Array of range information. The first element of the pair is the tag of
// the action and the second element is the range defining the link.
std::vector<std::pair<NSUInteger, NSRange>> linkRanges_;
// Text for the label with link markers included.
- base::scoped_nsobject<NSString> markedLabel_;
+ NSString* markedLabel_;
// Buttons.
// button1_ is tagged with ConfirmInfoBarDelegate::BUTTON_OK .
// button2_ is tagged with ConfirmInfoBarDelegate::BUTTON_CANCEL .
- base::scoped_nsobject<UIButton> button1_;
- base::scoped_nsobject<UIButton> button2_;
+ UIButton* button1_;
+ UIButton* button2_;
// Drop shadow.
- base::scoped_nsobject<UIImageView> shadow_;
+ UIImageView* shadow_;
}
@synthesize visibleHeight = visibleHeight_;
@@ -265,7 +266,7 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
delegate_ = delegate;
// Make the drop shadow.
UIImage* shadowImage = [UIImage imageNamed:@"infobar_shadow"];
- shadow_.reset([[UIImageView alloc] initWithImage:shadowImage]);
+ shadow_ = [[UIImageView alloc] initWithImage:shadowImage];
[self addSubview:shadow_];
[self setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight];
@@ -274,9 +275,6 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
return self;
}
-- (void)dealloc {
- [super dealloc];
-}
- (NSString*)markedLabel {
return markedLabel_;
@@ -663,7 +661,7 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
NSString* imagePath =
[[NSBundle mainBundle] pathForResource:@"infobar_close" ofType:@"png"];
UIImage* image = [UIImage imageWithContentsOfFile:imagePath];
- closeButton_.reset([[UIButton buttonWithType:UIButtonTypeCustom] retain]);
+ closeButton_ = [UIButton buttonWithType:UIButtonTypeCustom];
[closeButton_ setExclusiveTouch:YES];
[closeButton_ setImage:image forState:UIControlStateNormal];
[closeButton_ addTarget:target
@@ -679,17 +677,17 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
tag:(NSInteger)tag
target:(id)target
action:(SEL)action {
- switchView_.reset([[SwitchView alloc] initWithLabel:label isOn:isOn]);
+ switchView_ = [[SwitchView alloc] initWithLabel:label isOn:isOn];
[switchView_ setTag:tag target:target action:action];
[self addSubview:switchView_];
}
- (void)addLeftIcon:(UIImage*)image {
if (!imageViewContainer_) {
- imageViewContainer_.reset([[UIView alloc] init]);
+ imageViewContainer_ = [[UIView alloc] init];
[self addSubview:imageViewContainer_];
}
- imageView_.reset([[UIImageView alloc] initWithImage:image]);
+ imageView_ = [[UIImageView alloc] initWithImage:image];
[imageViewContainer_ addSubview:imageView_];
}
@@ -726,7 +724,7 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
[string rangeOfString:[[InfoBarView openingMarkerForLink]
stringByAppendingString:@"("]];
if (!startingRange.length)
- return [[string copy] autorelease];
+ return [string copy];
// Read the tag.
NSUInteger beginTag = NSMaxRange(startingRange);
NSRange closingParenthesis = [string
@@ -734,13 +732,13 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
options:NSLiteralSearch
range:NSMakeRange(beginTag, [string length] - beginTag)];
if (closingParenthesis.location == NSNotFound)
- return [[string copy] autorelease];
+ return [string copy];
NSInteger tag = [[string
substringWithRange:NSMakeRange(beginTag, closingParenthesis.location -
beginTag)] integerValue];
// If the parsing fails, |tag| is 0. Negative values are not allowed.
if (tag <= 0)
- return [[string copy] autorelease];
+ return [string copy];
// Find the closing marker.
startingRange.length =
closingParenthesis.location - startingRange.location + 1;
@@ -768,21 +766,21 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
}
- (void)addLabel:(NSString*)text action:(void (^)(NSUInteger))action {
- markedLabel_.reset([text copy]);
+ markedLabel_ = [text copy];
if (action)
text = [self stripMarkersFromString:text];
if ([label_ superview]) {
[label_ removeFromSuperview];
}
- label_ = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
+ label_ = [[UILabel alloc] initWithFrame:CGRectZero];
UIFont* font = [MDCTypography subheadFont];
[label_ setBackgroundColor:[UIColor clearColor]];
NSMutableParagraphStyle* paragraphStyle =
- [[[NSMutableParagraphStyle alloc] init] autorelease];
+ [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
paragraphStyle.lineSpacing = kLabelLineSpacing;
NSDictionary* attributes = @{
@@ -791,16 +789,16 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
};
[label_ setNumberOfLines:0];
- [label_ setAttributedText:[[[NSAttributedString alloc]
- initWithString:text
- attributes:attributes] autorelease]];
+ [label_
+ setAttributedText:[[NSAttributedString alloc] initWithString:text
+ attributes:attributes]];
[self addSubview:label_];
if (linkRanges_.empty())
return;
- labelLinkController_.reset([[LabelLinkController alloc]
+ labelLinkController_ = [[LabelLinkController alloc]
initWithLabel:label_
action:^(const GURL& gurl) {
if (action) {
@@ -808,7 +806,7 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
gurl.ExtractFileName()) integerValue];
action(actionTag);
}
- }]);
+ }];
[labelLinkController_ setLinkUnderlineStyle:NSUnderlineStyleSingle];
[labelLinkController_ setLinkColor:[UIColor blackColor]];
@@ -829,20 +827,20 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
tag2:(NSInteger)tag2
target:(id)target
action:(SEL)action {
- button1_.reset([[self infoBarButton:title1
- palette:[MDCPalette cr_bluePalette]
- customTitleColor:[UIColor whiteColor]
- tag:tag1
- target:target
- action:action] retain]);
+ button1_ = [self infoBarButton:title1
+ palette:[MDCPalette cr_bluePalette]
+ customTitleColor:[UIColor whiteColor]
+ tag:tag1
+ target:target
+ action:action];
[self addSubview:button1_];
- button2_.reset([[self infoBarButton:title2
- palette:nil
- customTitleColor:UIColorFromRGB(kButton2TitleColor)
- tag:tag2
- target:target
- action:action] retain]);
+ button2_ = [self infoBarButton:title2
+ palette:nil
+ customTitleColor:UIColorFromRGB(kButton2TitleColor)
+ tag:tag2
+ target:target
+ action:action];
[self addSubview:button2_];
}
@@ -852,12 +850,12 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
action:(SEL)action {
if (![title length])
return;
- button1_.reset([[self infoBarButton:title
- palette:[MDCPalette cr_bluePalette]
- customTitleColor:[UIColor whiteColor]
- tag:tag
- target:target
- action:action] retain]);
+ button1_ = [self infoBarButton:title
+ palette:[MDCPalette cr_bluePalette]
+ customTitleColor:[UIColor whiteColor]
+ tag:tag
+ target:target
+ action:action];
[self addSubview:button1_];
}
@@ -869,19 +867,19 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
tag:(NSInteger)tag
target:(id)target
action:(SEL)action {
- base::scoped_nsobject<MDCFlatButton> button([[MDCFlatButton alloc] init]);
- button.get().inkColor = [[palette tint300] colorWithAlphaComponent:0.5f];
+ MDCFlatButton* button = [[MDCFlatButton alloc] init];
+ button.inkColor = [[palette tint300] colorWithAlphaComponent:0.5f];
[button setBackgroundColor:[palette tint500] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor colorWithWhite:0.8f alpha:1.0f]
forState:UIControlStateDisabled];
if (palette)
- button.get().hasOpaqueBackground = YES;
+ button.hasOpaqueBackground = YES;
if (customTitleColor) {
- button.get().tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
- button.get().customTitleColor = customTitleColor;
+ button.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
+ button.customTitleColor = customTitleColor;
}
- button.get().titleLabel.adjustsFontSizeToFitWidth = YES;
- button.get().titleLabel.minimumScaleFactor = 0.6f;
+ button.titleLabel.adjustsFontSizeToFitWidth = YES;
+ button.titleLabel.minimumScaleFactor = 0.6f;
[button setTitle:message forState:UIControlStateNormal];
[button setTag:tag];
[button addTarget:target
@@ -890,7 +888,7 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
// Without the call to layoutIfNeeded, |button| returns an incorrect
// titleLabel the first time it is accessed in |narrowestWidthOfButton|.
[button layoutIfNeeded];
- return button.autorelease();
+ return button;
}
- (CGRect)frameOfCloseButton:(BOOL)singleLineMode {
« no previous file with comments | « ios/chrome/browser/ui/infobars/infobar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698