OLD | NEW |
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_view.h" | 5 #import "ios/chrome/browser/autofill/form_suggestion_view.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/mac/scoped_nsobject.h" | |
9 #import "components/autofill/ios/browser/form_suggestion.h" | 8 #import "components/autofill/ios/browser/form_suggestion.h" |
10 #import "ios/chrome/browser/autofill/form_suggestion_label.h" | 9 #import "ios/chrome/browser/autofill/form_suggestion_label.h" |
11 #import "ios/chrome/browser/autofill/form_suggestion_view_client.h" | 10 #import "ios/chrome/browser/autofill/form_suggestion_view_client.h" |
12 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." |
| 14 #endif |
| 15 |
13 namespace { | 16 namespace { |
14 | 17 |
15 // Vertical margin between suggestions and the edge of the suggestion content | 18 // Vertical margin between suggestions and the edge of the suggestion content |
16 // frame. | 19 // frame. |
17 const CGFloat kSuggestionVerticalMargin = 6; | 20 const CGFloat kSuggestionVerticalMargin = 6; |
18 | 21 |
19 // Horizontal margin around suggestions (i.e. between suggestions, and between | 22 // Horizontal margin around suggestions (i.e. between suggestions, and between |
20 // the end suggestions and the suggestion content frame). | 23 // the end suggestions and the suggestion content frame). |
21 const CGFloat kSuggestionHorizontalMargin = 6; | 24 const CGFloat kSuggestionHorizontalMargin = 6; |
22 | 25 |
23 } // namespace | 26 } // namespace |
24 | 27 |
25 @implementation FormSuggestionView { | 28 @implementation FormSuggestionView { |
26 // The FormSuggestions that are displayed by this view. | 29 // The FormSuggestions that are displayed by this view. |
27 base::scoped_nsobject<NSArray> _suggestions; | 30 NSArray* _suggestions; |
28 } | 31 } |
29 | 32 |
30 - (instancetype)initWithFrame:(CGRect)frame | 33 - (instancetype)initWithFrame:(CGRect)frame |
31 client:(id<FormSuggestionViewClient>)client | 34 client:(id<FormSuggestionViewClient>)client |
32 suggestions:(NSArray*)suggestions { | 35 suggestions:(NSArray*)suggestions { |
33 self = [super initWithFrame:frame]; | 36 self = [super initWithFrame:frame]; |
34 if (self) { | 37 if (self) { |
35 _suggestions.reset([suggestions copy]); | 38 _suggestions = [suggestions copy]; |
36 | 39 |
37 self.showsVerticalScrollIndicator = NO; | 40 self.showsVerticalScrollIndicator = NO; |
38 self.showsHorizontalScrollIndicator = NO; | 41 self.showsHorizontalScrollIndicator = NO; |
39 self.bounces = NO; | 42 self.bounces = NO; |
40 self.canCancelContentTouches = YES; | 43 self.canCancelContentTouches = YES; |
41 | 44 |
42 // Total height occupied by the label content, padding, border and margin. | 45 // Total height occupied by the label content, padding, border and margin. |
43 const CGFloat labelHeight = | 46 const CGFloat labelHeight = |
44 CGRectGetHeight(frame) - kSuggestionVerticalMargin * 2; | 47 CGRectGetHeight(frame) - kSuggestionVerticalMargin * 2; |
45 | 48 |
46 __block CGFloat currentX = kSuggestionHorizontalMargin; | 49 __block CGFloat currentX = kSuggestionHorizontalMargin; |
47 void (^setupBlock)(FormSuggestion* suggestion, NSUInteger idx, BOOL* stop) = | 50 void (^setupBlock)(FormSuggestion* suggestion, NSUInteger idx, BOOL* stop) = |
48 ^(FormSuggestion* suggestion, NSUInteger idx, BOOL* stop) { | 51 ^(FormSuggestion* suggestion, NSUInteger idx, BOOL* stop) { |
49 // FormSuggestionLabel will adjust the width, so here 0 is used for | 52 // FormSuggestionLabel will adjust the width, so here 0 is used for |
50 // the width. | 53 // the width. |
51 CGRect proposedFrame = | 54 CGRect proposedFrame = |
52 CGRectMake(currentX, kSuggestionVerticalMargin, 0, labelHeight); | 55 CGRectMake(currentX, kSuggestionVerticalMargin, 0, labelHeight); |
53 base::scoped_nsobject<UIView> label([[FormSuggestionLabel alloc] | 56 UIView* label = [[FormSuggestionLabel alloc] |
54 initWithSuggestion:suggestion | 57 initWithSuggestion:suggestion |
55 proposedFrame:proposedFrame | 58 proposedFrame:proposedFrame |
56 index:idx | 59 index:idx |
57 numSuggestions:[_suggestions count] | 60 numSuggestions:[_suggestions count] |
58 client:client]); | 61 client:client]; |
59 [self addSubview:label]; | 62 [self addSubview:label]; |
60 currentX += | 63 currentX += |
61 CGRectGetWidth([label frame]) + kSuggestionHorizontalMargin; | 64 CGRectGetWidth([label frame]) + kSuggestionHorizontalMargin; |
62 }; | 65 }; |
63 [_suggestions | 66 [_suggestions |
64 enumerateObjectsWithOptions:(base::i18n::IsRTL() ? NSEnumerationReverse | 67 enumerateObjectsWithOptions:(base::i18n::IsRTL() ? NSEnumerationReverse |
65 : 0) | 68 : 0) |
66 usingBlock:setupBlock]; | 69 usingBlock:setupBlock]; |
67 } | 70 } |
68 return self; | 71 return self; |
(...skipping 21 matching lines...) Expand all Loading... |
90 // initially visible. | 93 // initially visible. |
91 CGRect initRect = {{contentwidth - CGRectGetWidth(frame), 0}, frame.size}; | 94 CGRect initRect = {{contentwidth - CGRectGetWidth(frame), 0}, frame.size}; |
92 [self scrollRectToVisible:initRect animated:NO]; | 95 [self scrollRectToVisible:initRect animated:NO]; |
93 } | 96 } |
94 } else { | 97 } else { |
95 self.contentSize = CGSizeMake(contentwidth, CGRectGetHeight(frame)); | 98 self.contentSize = CGSizeMake(contentwidth, CGRectGetHeight(frame)); |
96 } | 99 } |
97 } | 100 } |
98 | 101 |
99 - (NSArray*)suggestions { | 102 - (NSArray*)suggestions { |
100 return _suggestions.get(); | 103 return _suggestions; |
101 } | 104 } |
102 | 105 |
103 @end | 106 @end |
OLD | NEW |