OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/history/history_entry_item.h" | 5 #import "ios/chrome/browser/ui/history/history_entry_item.h" |
6 | 6 |
7 #include "base/i18n/time_formatting.h" | 7 #include "base/i18n/time_formatting.h" |
8 #include "base/ios/weak_nsobject.h" | |
9 #import "base/mac/foundation_util.h" | 8 #import "base/mac/foundation_util.h" |
10 #import "base/mac/objc_property_releaser.h" | |
11 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
13 #include "components/history/core/browser/url_row.h" | 11 #include "components/history/core/browser/url_row.h" |
14 #include "components/strings/grit/components_strings.h" | 12 #include "components/strings/grit/components_strings.h" |
15 #include "components/url_formatter/url_formatter.h" | 13 #include "components/url_formatter/url_formatter.h" |
16 #include "ios/chrome/browser/favicon/ios_chrome_large_icon_service_factory.h" | 14 #include "ios/chrome/browser/favicon/ios_chrome_large_icon_service_factory.h" |
17 #import "ios/chrome/browser/ui/history/favicon_view.h" | 15 #import "ios/chrome/browser/ui/history/favicon_view.h" |
18 #import "ios/chrome/browser/ui/history/favicon_view_provider.h" | 16 #import "ios/chrome/browser/ui/history/favicon_view_provider.h" |
19 #import "ios/chrome/browser/ui/history/history_entry.h" | 17 #import "ios/chrome/browser/ui/history/history_entry.h" |
20 #include "ios/chrome/browser/ui/rtl_geometry.h" | 18 #include "ios/chrome/browser/ui/rtl_geometry.h" |
21 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 19 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
22 #include "ios/chrome/grit/ios_strings.h" | 20 #include "ios/chrome/grit/ios_strings.h" |
23 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 21 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
24 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 22 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
25 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
26 | 24 |
| 25 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 26 #error "This file requires ARC support." |
| 27 #endif |
| 28 |
27 namespace { | 29 namespace { |
28 // Size at which the favicon will be displayed. | 30 // Size at which the favicon will be displayed. |
29 const CGFloat kFaviconSize = 24.0; | 31 const CGFloat kFaviconSize = 24.0; |
30 // Minimum size at which to fetch favicons. | 32 // Minimum size at which to fetch favicons. |
31 const CGFloat kMinFaviconSize = 16.0; | 33 const CGFloat kMinFaviconSize = 16.0; |
32 // Horizontal spacing between edge of the cell and the cell content. | 34 // Horizontal spacing between edge of the cell and the cell content. |
33 const CGFloat kMargin = 16.0; | 35 const CGFloat kMargin = 16.0; |
34 // Horizontal spacing between the leading edge of the cell and the text. | 36 // Horizontal spacing between the leading edge of the cell and the text. |
35 const CGFloat kHeaderMargin = 56.0; | 37 const CGFloat kHeaderMargin = 56.0; |
36 | 38 |
(...skipping 15 matching lines...) Expand all Loading... |
52 else | 54 else |
53 base::i18n::AdjustStringForLocaleDirection(&formatted_title); | 55 base::i18n::AdjustStringForLocaleDirection(&formatted_title); |
54 } | 56 } |
55 return base::SysUTF16ToNSString(formatted_title); | 57 return base::SysUTF16ToNSString(formatted_title); |
56 } | 58 } |
57 } // namespace | 59 } // namespace |
58 | 60 |
59 #pragma mark - HistoryEntryItem | 61 #pragma mark - HistoryEntryItem |
60 | 62 |
61 @interface HistoryEntryItem ()<FaviconViewProviderDelegate> { | 63 @interface HistoryEntryItem ()<FaviconViewProviderDelegate> { |
62 // Property releaser for HistoryEntryItem. | |
63 base::mac::ObjCPropertyReleaser _propertyReleaser_HistoryEntryItem; | |
64 // Delegate for HistoryEntryItem. | 64 // Delegate for HistoryEntryItem. |
65 base::WeakNSProtocol<id<HistoryEntryItemDelegate>> _delegate; | 65 __weak id<HistoryEntryItemDelegate> _delegate; |
66 } | 66 } |
67 | 67 |
68 // FaviconViewProvider to fetch the favicon and format the favicon view. | 68 // FaviconViewProvider to fetch the favicon and format the favicon view. |
69 @property(nonatomic, retain) FaviconViewProvider* faviconViewProvider; | 69 @property(nonatomic, strong) FaviconViewProvider* faviconViewProvider; |
70 | 70 |
71 // Custom accessibility actions for the history entry view. | 71 // Custom accessibility actions for the history entry view. |
72 - (NSArray*)accessibilityActions; | 72 - (NSArray*)accessibilityActions; |
73 // Custom accessibility action to delete the history entry. | 73 // Custom accessibility action to delete the history entry. |
74 - (BOOL)deleteHistoryEntry; | 74 - (BOOL)deleteHistoryEntry; |
75 // Custom accessibility action to open the history entry's URL in a new tab. | 75 // Custom accessibility action to open the history entry's URL in a new tab. |
76 - (BOOL)openInNewTab; | 76 - (BOOL)openInNewTab; |
77 // Custom accessibility action to open the history entry's URL in a new | 77 // Custom accessibility action to open the history entry's URL in a new |
78 // incognito tab. | 78 // incognito tab. |
79 - (BOOL)openInNewIncognitoTab; | 79 - (BOOL)openInNewIncognitoTab; |
80 // Custom accessibility action to copy the history entry's URL to the clipboard. | 80 // Custom accessibility action to copy the history entry's URL to the clipboard. |
81 - (BOOL)copyURL; | 81 - (BOOL)copyURL; |
82 @end | 82 @end |
83 | 83 |
84 @implementation HistoryEntryItem | 84 @implementation HistoryEntryItem |
85 | 85 |
86 @synthesize faviconViewProvider = _faviconViewProvider; | 86 @synthesize faviconViewProvider = _faviconViewProvider; |
87 @synthesize text = _text; | 87 @synthesize text = _text; |
88 @synthesize detailText = _detailText; | 88 @synthesize detailText = _detailText; |
89 @synthesize timeText = _timeText; | 89 @synthesize timeText = _timeText; |
90 @synthesize URL = _URL; | 90 @synthesize URL = _URL; |
91 @synthesize timestamp = _timestamp; | 91 @synthesize timestamp = _timestamp; |
92 | 92 |
93 - (instancetype)initWithType:(NSInteger)type | 93 - (instancetype)initWithType:(NSInteger)type |
94 historyEntry:(const history::HistoryEntry&)entry | 94 historyEntry:(const history::HistoryEntry&)entry |
95 browserState:(ios::ChromeBrowserState*)browserState | 95 browserState:(ios::ChromeBrowserState*)browserState |
96 delegate:(id<HistoryEntryItemDelegate>)delegate { | 96 delegate:(id<HistoryEntryItemDelegate>)delegate { |
97 self = [super initWithType:type]; | 97 self = [super initWithType:type]; |
98 if (self) { | 98 if (self) { |
99 _propertyReleaser_HistoryEntryItem.Init(self, [HistoryEntryItem class]); | |
100 self.cellClass = [HistoryEntryCell class]; | 99 self.cellClass = [HistoryEntryCell class]; |
101 favicon::LargeIconService* largeIconService = | 100 favicon::LargeIconService* largeIconService = |
102 IOSChromeLargeIconServiceFactory::GetForBrowserState(browserState); | 101 IOSChromeLargeIconServiceFactory::GetForBrowserState(browserState); |
103 _faviconViewProvider = | 102 _faviconViewProvider = |
104 [[FaviconViewProvider alloc] initWithURL:entry.url | 103 [[FaviconViewProvider alloc] initWithURL:entry.url |
105 faviconSize:kFaviconSize | 104 faviconSize:kFaviconSize |
106 minFaviconSize:kMinFaviconSize | 105 minFaviconSize:kMinFaviconSize |
107 largeIconService:largeIconService | 106 largeIconService:largeIconService |
108 delegate:self]; | 107 delegate:self]; |
109 _text = [FormattedTitle(entry.title, entry.url) copy]; | 108 _text = [FormattedTitle(entry.title, entry.url) copy]; |
110 _detailText = [base::SysUTF8ToNSString(entry.url.spec()) copy]; | 109 _detailText = [base::SysUTF8ToNSString(entry.url.spec()) copy]; |
111 _timeText = | 110 _timeText = |
112 [base::SysUTF16ToNSString(base::TimeFormatTimeOfDay(entry.time)) copy]; | 111 [base::SysUTF16ToNSString(base::TimeFormatTimeOfDay(entry.time)) copy]; |
113 _URL = GURL(entry.url); | 112 _URL = GURL(entry.url); |
114 _timestamp = entry.time; | 113 _timestamp = entry.time; |
115 _delegate.reset(delegate); | 114 _delegate = delegate; |
116 } | 115 } |
117 return self; | 116 return self; |
118 } | 117 } |
119 | 118 |
120 - (instancetype)initWithType:(NSInteger)type { | 119 - (instancetype)initWithType:(NSInteger)type { |
121 NOTREACHED(); | 120 NOTREACHED(); |
122 return nil; | 121 return nil; |
123 } | 122 } |
124 | 123 |
125 - (BOOL)isEqualToHistoryEntryItem:(HistoryEntryItem*)item { | 124 - (BOOL)isEqualToHistoryEntryItem:(HistoryEntryItem*)item { |
(...skipping 10 matching lines...) Expand all Loading... |
136 return [self isEqualToHistoryEntryItem:object]; | 135 return [self isEqualToHistoryEntryItem:object]; |
137 } | 136 } |
138 | 137 |
139 - (NSUInteger)hash { | 138 - (NSUInteger)hash { |
140 return [base::SysUTF8ToNSString(self.URL.spec()) hash] ^ | 139 return [base::SysUTF8ToNSString(self.URL.spec()) hash] ^ |
141 self.timestamp.ToInternalValue(); | 140 self.timestamp.ToInternalValue(); |
142 } | 141 } |
143 | 142 |
144 - (NSArray*)accessibilityActions { | 143 - (NSArray*)accessibilityActions { |
145 UIAccessibilityCustomAction* deleteAction = | 144 UIAccessibilityCustomAction* deleteAction = |
146 [[[UIAccessibilityCustomAction alloc] | 145 [[UIAccessibilityCustomAction alloc] |
147 initWithName:l10n_util::GetNSString( | 146 initWithName:l10n_util::GetNSString( |
148 IDS_HISTORY_ENTRY_ACCESSIBILITY_DELETE) | 147 IDS_HISTORY_ENTRY_ACCESSIBILITY_DELETE) |
149 target:self | 148 target:self |
150 selector:@selector(deleteHistoryEntry)] autorelease]; | 149 selector:@selector(deleteHistoryEntry)]; |
151 UIAccessibilityCustomAction* openInNewTabAction = | 150 UIAccessibilityCustomAction* openInNewTabAction = |
152 [[[UIAccessibilityCustomAction alloc] | 151 [[UIAccessibilityCustomAction alloc] |
153 initWithName:l10n_util::GetNSString( | 152 initWithName:l10n_util::GetNSString( |
154 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB) | 153 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB) |
155 target:self | 154 target:self |
156 selector:@selector(openInNewTab)] autorelease]; | 155 selector:@selector(openInNewTab)]; |
157 UIAccessibilityCustomAction* openInNewIncognitoTabAction = | 156 UIAccessibilityCustomAction* openInNewIncognitoTabAction = |
158 [[[UIAccessibilityCustomAction alloc] | 157 [[UIAccessibilityCustomAction alloc] |
159 initWithName:l10n_util::GetNSString( | 158 initWithName:l10n_util::GetNSString( |
160 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB) | 159 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB) |
161 target:self | 160 target:self |
162 selector:@selector(openInNewIncognitoTab)] autorelease]; | 161 selector:@selector(openInNewIncognitoTab)]; |
163 UIAccessibilityCustomAction* copyURLAction = | 162 UIAccessibilityCustomAction* copyURLAction = |
164 [[[UIAccessibilityCustomAction alloc] | 163 [[UIAccessibilityCustomAction alloc] |
165 initWithName:l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_COPY) | 164 initWithName:l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_COPY) |
166 target:self | 165 target:self |
167 selector:@selector(copyURL)] autorelease]; | 166 selector:@selector(copyURL)]; |
168 return @[ | 167 return @[ |
169 deleteAction, openInNewTabAction, openInNewIncognitoTabAction, copyURLAction | 168 deleteAction, openInNewTabAction, openInNewIncognitoTabAction, copyURLAction |
170 ]; | 169 ]; |
171 } | 170 } |
172 | 171 |
173 - (BOOL)deleteHistoryEntry { | 172 - (BOOL)deleteHistoryEntry { |
174 [_delegate historyEntryItemDidRequestDelete:self]; | 173 [_delegate historyEntryItemDidRequestDelete:self]; |
175 return YES; | 174 return YES; |
176 } | 175 } |
177 | 176 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } | 212 } |
214 | 213 |
215 - (void)faviconViewProviderFaviconDidLoad:(FaviconViewProvider*)provider { | 214 - (void)faviconViewProviderFaviconDidLoad:(FaviconViewProvider*)provider { |
216 [_delegate historyEntryItemShouldUpdateView:self]; | 215 [_delegate historyEntryItemShouldUpdateView:self]; |
217 } | 216 } |
218 | 217 |
219 @end | 218 @end |
220 | 219 |
221 #pragma mark - HistoryEntryCell | 220 #pragma mark - HistoryEntryCell |
222 | 221 |
223 @interface HistoryEntryCell () { | 222 @interface HistoryEntryCell () |
224 // Property releaser for HistoryEntryCell. | |
225 base::mac::ObjCPropertyReleaser _propertyReleaser_HistoryEntryCell; | |
226 } | |
227 | 223 |
228 // Redeclare as readwrite to allow property releaser to handle these properties. | 224 // Redeclare as readwrite. |
229 @property(nonatomic, readwrite, retain) UILabel* textLabel; | 225 @property(nonatomic, readwrite, strong) UILabel* textLabel; |
230 @property(nonatomic, readwrite, retain) UILabel* detailTextLabel; | 226 @property(nonatomic, readwrite, strong) UILabel* detailTextLabel; |
231 @property(nonatomic, readwrite, retain) UILabel* timeLabel; | 227 @property(nonatomic, readwrite, strong) UILabel* timeLabel; |
232 @end | 228 @end |
233 | 229 |
234 @implementation HistoryEntryCell | 230 @implementation HistoryEntryCell |
235 | 231 |
236 @synthesize faviconViewContainer = _faviconViewContainer; | 232 @synthesize faviconViewContainer = _faviconViewContainer; |
237 @synthesize textLabel = _textLabel; | 233 @synthesize textLabel = _textLabel; |
238 @synthesize detailTextLabel = _detailTextLabel; | 234 @synthesize detailTextLabel = _detailTextLabel; |
239 @synthesize timeLabel = _timeLabel; | 235 @synthesize timeLabel = _timeLabel; |
240 | 236 |
241 - (id)initWithFrame:(CGRect)frame { | 237 - (id)initWithFrame:(CGRect)frame { |
242 self = [super initWithFrame:frame]; | 238 self = [super initWithFrame:frame]; |
243 if (self) { | 239 if (self) { |
244 _propertyReleaser_HistoryEntryCell.Init(self, [HistoryEntryCell class]); | |
245 | 240 |
246 _faviconViewContainer = [[UIView alloc] initWithFrame:CGRectZero]; | 241 _faviconViewContainer = [[UIView alloc] initWithFrame:CGRectZero]; |
247 | 242 |
248 _textLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 243 _textLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
249 [_textLabel | 244 [_textLabel |
250 setFont:[[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:16]]; | 245 setFont:[[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:16]]; |
251 [_textLabel setTextColor:[[MDCPalette greyPalette] tint900]]; | 246 [_textLabel setTextColor:[[MDCPalette greyPalette] tint900]]; |
252 | 247 |
253 _detailTextLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 248 _detailTextLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
254 [_detailTextLabel | 249 [_detailTextLabel |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 [super prepareForReuse]; | 301 [super prepareForReuse]; |
307 _textLabel.text = nil; | 302 _textLabel.text = nil; |
308 _detailTextLabel.text = nil; | 303 _detailTextLabel.text = nil; |
309 _timeLabel.text = nil; | 304 _timeLabel.text = nil; |
310 for (UIView* subview in _faviconViewContainer.subviews) { | 305 for (UIView* subview in _faviconViewContainer.subviews) { |
311 [subview removeFromSuperview]; | 306 [subview removeFromSuperview]; |
312 } | 307 } |
313 } | 308 } |
314 | 309 |
315 @end | 310 @end |
OLD | NEW |