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

Side by Side Diff: ios/chrome/browser/autofill/form_suggestion_label.mm

Issue 2933093003: [ObjC ARC] Converts ios/chrome/browser/autofill:autofill to ARC. (Closed)
Patch Set: Fix nil assignment. Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/autofill/form_suggestion_label.h" 5 #import "ios/chrome/browser/autofill/form_suggestion_label.h"
6 6
7 #import <QuartzCore/QuartzCore.h> 7 #import <QuartzCore/QuartzCore.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <cmath> 10 #include <cmath>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
15 #include "components/autofill/core/browser/credit_card.h" 15 #include "components/autofill/core/browser/credit_card.h"
16 #import "components/autofill/ios/browser/form_suggestion.h" 16 #import "components/autofill/ios/browser/form_suggestion.h"
17 #import "ios/chrome/browser/autofill/form_suggestion_view_client.h" 17 #import "ios/chrome/browser/autofill/form_suggestion_view_client.h"
18 #include "ios/chrome/browser/ui/ui_util.h" 18 #include "ios/chrome/browser/ui/ui_util.h"
19 #import "ios/chrome/browser/ui/uikit_ui_util.h" 19 #import "ios/chrome/browser/ui/uikit_ui_util.h"
20 #include "ios/chrome/grit/ios_strings.h" 20 #include "ios/chrome/grit/ios_strings.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
22 22
23 #if !defined(__has_feature) || !__has_feature(objc_arc)
24 #error "This file requires ARC support."
25 #endif
26
23 namespace { 27 namespace {
24 28
25 // The button corner radius. 29 // The button corner radius.
26 const CGFloat kCornerRadius = 2.0f; 30 const CGFloat kCornerRadius = 2.0f;
27 31
28 // Font size of button titles. 32 // Font size of button titles.
29 const CGFloat kIpadFontSize = 15.0f; 33 const CGFloat kIpadFontSize = 15.0f;
30 const CGFloat kIphoneFontSize = 14.0f; 34 const CGFloat kIphoneFontSize = 14.0f;
31 35
32 // The alpha values of the suggestion's main and description labels. 36 // The alpha values of the suggestion's main and description labels.
(...skipping 24 matching lines...) Expand all
57 {autofill::kVisaCard, @"autofill_card_visa"}, 61 {autofill::kVisaCard, @"autofill_card_visa"},
58 {autofill::kDinersCard, @"autofill_card_diners"}, 62 {autofill::kDinersCard, @"autofill_card_diners"},
59 {autofill::kGenericCard, @"autofill_card_generic"}, 63 {autofill::kGenericCard, @"autofill_card_generic"},
60 {autofill::kJCBCard, @"autofill_card_jcb"}, 64 {autofill::kJCBCard, @"autofill_card_jcb"},
61 {autofill::kUnionPay, @"autofill_card_unionpay"}, 65 {autofill::kUnionPay, @"autofill_card_unionpay"},
62 }; 66 };
63 67
64 // Creates a label with the given |text| and |alpha| suitable for use in a 68 // Creates a label with the given |text| and |alpha| suitable for use in a
65 // suggestion button in the keyboard accessory view. 69 // suggestion button in the keyboard accessory view.
66 UILabel* TextLabel(NSString* text, CGFloat alpha, BOOL bold) { 70 UILabel* TextLabel(NSString* text, CGFloat alpha, BOOL bold) {
67 base::scoped_nsobject<UILabel> label([[UILabel alloc] init]); 71 UILabel* label = [[UILabel alloc] init];
68 [label setText:text]; 72 [label setText:text];
69 CGFloat fontSize = IsIPadIdiom() ? kIpadFontSize : kIphoneFontSize; 73 CGFloat fontSize = IsIPadIdiom() ? kIpadFontSize : kIphoneFontSize;
70 UIFont* font = bold ? [UIFont boldSystemFontOfSize:fontSize] 74 UIFont* font = bold ? [UIFont boldSystemFontOfSize:fontSize]
71 : [UIFont systemFontOfSize:fontSize]; 75 : [UIFont systemFontOfSize:fontSize];
72 [label setFont:font]; 76 [label setFont:font];
73 [label setTextColor:[UIColor colorWithWhite:0.0f alpha:alpha]]; 77 [label setTextColor:[UIColor colorWithWhite:0.0f alpha:alpha]];
74 [label setBackgroundColor:[UIColor clearColor]]; 78 [label setBackgroundColor:[UIColor clearColor]];
75 [label sizeToFit]; 79 [label sizeToFit];
76 return label.autorelease(); 80 return label;
77 } 81 }
78 82
79 } // namespace 83 } // namespace
80 84
81 @interface FormSuggestionLabel () 85 @interface FormSuggestionLabel ()
82 86
83 // Returns the name of the image for credit card icon. 87 // Returns the name of the image for credit card icon.
84 + (NSString*)imageNameForCreditCardIcon:(NSString*)icon; 88 + (NSString*)imageNameForCreditCardIcon:(NSString*)icon;
85 @end 89 @end
86 90
87 @implementation FormSuggestionLabel { 91 @implementation FormSuggestionLabel {
88 // Client of this view. 92 // Client of this view.
89 base::WeakNSProtocol<id<FormSuggestionViewClient>> client_; 93 __weak id<FormSuggestionViewClient> client_;
90 base::scoped_nsobject<FormSuggestion> suggestion_; 94 FormSuggestion* suggestion_;
91 } 95 }
92 96
93 - (id)initWithSuggestion:(FormSuggestion*)suggestion 97 - (id)initWithSuggestion:(FormSuggestion*)suggestion
94 proposedFrame:(CGRect)proposedFrame 98 proposedFrame:(CGRect)proposedFrame
95 index:(NSUInteger)index 99 index:(NSUInteger)index
96 numSuggestions:(NSUInteger)numSuggestions 100 numSuggestions:(NSUInteger)numSuggestions
97 client:(id<FormSuggestionViewClient>)client { 101 client:(id<FormSuggestionViewClient>)client {
98 // TODO(jimblackler): implement sizeThatFits: and layoutSubviews, and perform 102 // TODO(jimblackler): implement sizeThatFits: and layoutSubviews, and perform
99 // layout in those methods instead of in the designated initializer. 103 // layout in those methods instead of in the designated initializer.
100 self = [super initWithFrame:CGRectZero]; 104 self = [super initWithFrame:CGRectZero];
101 if (self) { 105 if (self) {
102 suggestion_.reset([suggestion retain]); 106 suggestion_ = suggestion;
103 client_.reset(client); 107 client_ = client;
104 108
105 const CGFloat frameHeight = CGRectGetHeight(proposedFrame); 109 const CGFloat frameHeight = CGRectGetHeight(proposedFrame);
106 CGFloat currentX = kBorderWidth; 110 CGFloat currentX = kBorderWidth;
107 111
108 // [UIImage imageNamed:] writes error message if nil is passed. Prevent 112 // [UIImage imageNamed:] writes error message if nil is passed. Prevent
109 // console spam by checking the name first. 113 // console spam by checking the name first.
110 NSString* iconImageName = 114 NSString* iconImageName =
111 [FormSuggestionLabel imageNameForCreditCardIcon:suggestion.icon]; 115 [FormSuggestionLabel imageNameForCreditCardIcon:suggestion.icon];
112 UIImage* iconImage = nil; 116 UIImage* iconImage = nil;
113 if (iconImageName) 117 if (iconImageName)
114 iconImage = [UIImage imageNamed:iconImageName]; 118 iconImage = [UIImage imageNamed:iconImageName];
115 if (iconImage) { 119 if (iconImage) {
116 UIImageView* iconView = 120 UIImageView* iconView = [[UIImageView alloc] initWithImage:iconImage];
117 [[[UIImageView alloc] initWithImage:iconImage] autorelease];
118 const CGFloat iconY = 121 const CGFloat iconY =
119 std::floor((frameHeight - iconImage.size.height) / 2.0f); 122 std::floor((frameHeight - iconImage.size.height) / 2.0f);
120 iconView.frame = CGRectMake(currentX, iconY, iconImage.size.width, 123 iconView.frame = CGRectMake(currentX, iconY, iconImage.size.width,
121 iconImage.size.height); 124 iconImage.size.height);
122 [self addSubview:iconView]; 125 [self addSubview:iconView];
123 currentX += CGRectGetWidth(iconView.frame) + kSpacing; 126 currentX += CGRectGetWidth(iconView.frame) + kSpacing;
124 } 127 }
125 128
126 UILabel* label = TextLabel(suggestion.value, kMainLabelAlpha, YES); 129 UILabel* label = TextLabel(suggestion.value, kMainLabelAlpha, YES);
127 const CGFloat labelY = 130 const CGFloat labelY =
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 std::string iconName(base::SysNSStringToUTF8(icon)); 200 std::string iconName(base::SysNSStringToUTF8(icon));
198 for (size_t i = 0; i < arraysize(kCreditCardIconImageMap); ++i) { 201 for (size_t i = 0; i < arraysize(kCreditCardIconImageMap); ++i) {
199 if (iconName.compare(kCreditCardIconImageMap[i].icon_name) == 0) { 202 if (iconName.compare(kCreditCardIconImageMap[i].icon_name) == 0) {
200 return kCreditCardIconImageMap[i].image_name; 203 return kCreditCardIconImageMap[i].image_name;
201 } 204 }
202 } 205 }
203 return nil; 206 return nil;
204 } 207 }
205 208
206 @end 209 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/autofill/form_suggestion_controller.mm ('k') | ios/chrome/browser/autofill/form_suggestion_view.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698