OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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_popup_material_row.h" | 5 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_row.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/objc_property_releaser.h" | 8 |
9 #import "ios/chrome/browser/ui/omnibox/truncating_attributed_label.h" | 9 #import "ios/chrome/browser/ui/omnibox/truncating_attributed_label.h" |
10 #include "ios/chrome/browser/ui/rtl_geometry.h" | 10 #include "ios/chrome/browser/ui/rtl_geometry.h" |
11 #include "ios/chrome/browser/ui/ui_util.h" | 11 #include "ios/chrome/browser/ui/ui_util.h" |
12 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 12 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
13 #include "ios/chrome/grit/ios_theme_resources.h" | 13 #include "ios/chrome/grit/ios_theme_resources.h" |
14 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." |
| 17 #endif |
| 18 |
15 namespace { | 19 namespace { |
16 const CGFloat kImageDimensionLength = 19.0; | 20 const CGFloat kImageDimensionLength = 19.0; |
17 const CGFloat kLeadingPaddingIpad = 164; | 21 const CGFloat kLeadingPaddingIpad = 164; |
18 const CGFloat kLeadingPaddingIpadCompact = 71; | 22 const CGFloat kLeadingPaddingIpadCompact = 71; |
19 const CGFloat kAppendButtonTrailingMargin = 4; | 23 const CGFloat kAppendButtonTrailingMargin = 4; |
20 const CGFloat kAppendButtonSize = 48.0; | 24 const CGFloat kAppendButtonSize = 48.0; |
21 } | 25 } |
22 | 26 |
23 @interface OmniboxPopupMaterialRow () { | 27 @interface OmniboxPopupMaterialRow () { |
24 BOOL _incognito; | 28 BOOL _incognito; |
25 base::mac::ObjCPropertyReleaser _propertyReleaser_OmniboxPopupMaterialRow; | |
26 } | 29 } |
27 | 30 |
28 // Set the append button normal and highlighted images. | 31 // Set the append button normal and highlighted images. |
29 - (void)updateAppendButtonImages; | 32 - (void)updateAppendButtonImages; |
30 | 33 |
31 @end | 34 @end |
32 | 35 |
33 @implementation OmniboxPopupMaterialRow | 36 @implementation OmniboxPopupMaterialRow |
34 | 37 |
35 @synthesize textTruncatingLabel = _textTruncatingLabel; | 38 @synthesize textTruncatingLabel = _textTruncatingLabel; |
36 @synthesize detailTruncatingLabel = _detailTruncatingLabel; | 39 @synthesize detailTruncatingLabel = _detailTruncatingLabel; |
37 @synthesize appendButton = _appendButton; | 40 @synthesize appendButton = _appendButton; |
38 @synthesize answerImageView = _answerImageView; | 41 @synthesize answerImageView = _answerImageView; |
39 @synthesize imageView = _imageView; | 42 @synthesize imageView = _imageView; |
40 @synthesize rowHeight = _rowHeight; | 43 @synthesize rowHeight = _rowHeight; |
41 | 44 |
42 - (instancetype)initWithStyle:(UITableViewCellStyle)style | 45 - (instancetype)initWithStyle:(UITableViewCellStyle)style |
43 reuseIdentifier:(NSString*)reuseIdentifier { | 46 reuseIdentifier:(NSString*)reuseIdentifier { |
44 return [self initWithIncognito:NO]; | 47 return [self initWithIncognito:NO]; |
45 } | 48 } |
46 | 49 |
47 - (instancetype)initWithIncognito:(BOOL)incognito { | 50 - (instancetype)initWithIncognito:(BOOL)incognito { |
48 self = [super initWithStyle:UITableViewCellStyleDefault | 51 self = [super initWithStyle:UITableViewCellStyleDefault |
49 reuseIdentifier:@"OmniboxPopupMaterialRow"]; | 52 reuseIdentifier:@"OmniboxPopupMaterialRow"]; |
50 if (self) { | 53 if (self) { |
51 self.isAccessibilityElement = YES; | 54 self.isAccessibilityElement = YES; |
52 self.backgroundColor = [UIColor clearColor]; | 55 self.backgroundColor = [UIColor clearColor]; |
53 _incognito = incognito; | 56 _incognito = incognito; |
54 _propertyReleaser_OmniboxPopupMaterialRow.Init( | |
55 self, [OmniboxPopupMaterialRow class]); | |
56 | 57 |
57 _textTruncatingLabel = | 58 _textTruncatingLabel = |
58 [[OmniboxPopupTruncatingLabel alloc] initWithFrame:CGRectZero]; | 59 [[OmniboxPopupTruncatingLabel alloc] initWithFrame:CGRectZero]; |
59 _textTruncatingLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth; | 60 _textTruncatingLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
60 _textTruncatingLabel.userInteractionEnabled = NO; | 61 _textTruncatingLabel.userInteractionEnabled = NO; |
61 [self addSubview:_textTruncatingLabel]; | 62 [self addSubview:_textTruncatingLabel]; |
62 | 63 |
63 _detailTruncatingLabel = | 64 _detailTruncatingLabel = |
64 [[OmniboxPopupTruncatingLabel alloc] initWithFrame:CGRectZero]; | 65 [[OmniboxPopupTruncatingLabel alloc] initWithFrame:CGRectZero]; |
65 _detailTruncatingLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth; | 66 _detailTruncatingLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
66 _detailTruncatingLabel.userInteractionEnabled = NO; | 67 _detailTruncatingLabel.userInteractionEnabled = NO; |
67 [self addSubview:_detailTruncatingLabel]; | 68 [self addSubview:_detailTruncatingLabel]; |
68 | 69 |
69 _appendButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; | 70 _appendButton = [UIButton buttonWithType:UIButtonTypeCustom]; |
70 [_appendButton setContentMode:UIViewContentModeRight]; | 71 [_appendButton setContentMode:UIViewContentModeRight]; |
71 [self updateAppendButtonImages]; | 72 [self updateAppendButtonImages]; |
72 // TODO(justincohen): Consider using the UITableViewCell's accessory view. | 73 // TODO(justincohen): Consider using the UITableViewCell's accessory view. |
73 // The current implementation is from before using a UITableViewCell. | 74 // The current implementation is from before using a UITableViewCell. |
74 [self addSubview:_appendButton]; | 75 [self addSubview:_appendButton]; |
75 | 76 |
76 // Leading icon is only displayed on iPad. | 77 // Leading icon is only displayed on iPad. |
77 if (IsIPadIdiom()) { | 78 if (IsIPadIdiom()) { |
78 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; | 79 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; |
79 _imageView.userInteractionEnabled = NO; | 80 _imageView.userInteractionEnabled = NO; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 162 |
162 - (NSString*)accessibilityLabel { | 163 - (NSString*)accessibilityLabel { |
163 return _textTruncatingLabel.attributedText.string; | 164 return _textTruncatingLabel.attributedText.string; |
164 } | 165 } |
165 | 166 |
166 - (NSString*)accessibilityValue { | 167 - (NSString*)accessibilityValue { |
167 return _detailTruncatingLabel.attributedText.string; | 168 return _detailTruncatingLabel.attributedText.string; |
168 } | 169 } |
169 | 170 |
170 @end | 171 @end |
OLD | NEW |