Commit b103d6c6 authored by stkhapugin's avatar stkhapugin Committed by Commit bot

[ObjC ARC] Converts ios/chrome/browser/ui/history:history to ARC.

Semi-autogenerated ARCMigrate commit.
Notable issues:
 * Since one of the weak_nsobjects is exposed in a header and I change it to a __weak instead, converted two unit tests to ARC alongside this.
 * Fixed some assignments of newly created views to weak properties by introducing an intermediate local variable to retain the view until it's added as subview.

BUG=624363
TEST=None

Review-Url: https://codereview.chromium.org/2624963003
Cr-Commit-Position: refs/heads/master@{#443240}
parent a8b222fa
......@@ -3,6 +3,7 @@
# found in the LICENSE file.
source_set("history") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"clear_browsing_bar.h",
"clear_browsing_bar.mm",
......@@ -93,12 +94,10 @@ source_set("unit_tests") {
testonly = true
sources = [
"favicon_view_provider_unittest.mm",
"history_collection_view_controller_unittest.mm",
"history_entries_status_item_unittest.mm",
"history_entry_inserter_unittest.mm",
"history_entry_item_unittest.mm",
"history_search_view_controller_unittest.mm",
"history_service_facade_unittest.mm",
"history_util_unittest.mm",
"tab_history_popup_controller_unittest.mm",
]
......@@ -133,10 +132,59 @@ source_set("unit_tests") {
"//ui/gfx",
"//url",
]
public_deps = [
":unit_tests_arc",
]
allow_circular_includes_from = [ ":unit_tests_arc" ]
}
source_set("unit_tests_arc") {
testonly = true
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"history_collection_view_controller_unittest.mm",
"history_service_facade_unittest.mm",
]
deps = [
":history",
":resources_unit_tests",
"//base",
"//base/test:test_support",
"//components/favicon/core",
"//components/favicon_base",
"//components/history/core/browser",
"//components/keyed_service/core",
"//components/sessions",
"//components/strings",
"//ios/chrome/app/strings",
"//ios/chrome/browser",
"//ios/chrome/browser/browser_state:test_support",
"//ios/chrome/browser/history",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/signin:test_support",
"//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/collection_view",
"//ios/chrome/browser/ui/util",
"//ios/chrome/common",
"//ios/chrome/test:test_support",
"//ios/web",
"//ios/web:test_support",
"//skia",
"//testing/gtest",
"//third_party/ocmock",
"//ui/base",
"//ui/gfx",
"//url",
]
}
bundle_data("resources_unit_tests") {
visibility = [ ":unit_tests" ]
visibility = [
":unit_tests",
":unit_tests_arc",
]
testonly = true
sources = [
"//ios/chrome/test/data/favicon/test_favicon.png",
......
......@@ -5,7 +5,6 @@
#import "ios/chrome/browser/ui/history/clear_browsing_bar.h"
#include "base/logging.h"
#include "base/mac/objc_property_releaser.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
......@@ -13,6 +12,10 @@
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Shadow opacity for the clear browsing bar.
CGFloat kShadowOpacity = 0.2f;
......@@ -22,9 +25,7 @@ CGFloat kHorizontalMargin = 8.0f;
typedef NS_ENUM(BOOL, ButtonPlacement) { Leading, Trailing };
} // namespace
@interface ClearBrowsingBar () {
base::mac::ObjCPropertyReleaser propertyReleaser_ClearBrowsingBar_;
}
@interface ClearBrowsingBar ()
// Button that displays "Clear Browsing Data...".
@property(nonatomic, strong) UIButton* clearBrowsingDataButton;
......@@ -56,27 +57,26 @@ typedef NS_ENUM(BOOL, ButtonPlacement) { Leading, Trailing };
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
_clearBrowsingDataButton =
[[UIButton buttonWithType:UIButtonTypeCustom] retain];
_clearBrowsingDataButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_clearBrowsingDataButton
setTitle:l10n_util::GetNSStringWithFixup(
IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG)
forState:UIControlStateNormal];
[self styleButton:_clearBrowsingDataButton forPlacement:Leading];
_editButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
_editButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_editButton
setTitle:l10n_util::GetNSString(IDS_HISTORY_START_EDITING_BUTTON)
forState:UIControlStateNormal];
[self styleButton:_editButton forPlacement:Trailing];
_deleteButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
_deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_deleteButton setTitle:l10n_util::GetNSString(
IDS_HISTORY_DELETE_SELECTED_ENTRIES_BUTTON)
forState:UIControlStateNormal];
[self styleButton:_deleteButton forPlacement:Leading];
_cancelButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
_cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_cancelButton
setTitle:l10n_util::GetNSString(IDS_HISTORY_CANCEL_EDITING_BUTTON)
forState:UIControlStateNormal];
......@@ -106,7 +106,6 @@ typedef NS_ENUM(BOOL, ButtonPlacement) { Leading, Trailing };
[self setBackgroundColor:[UIColor whiteColor]];
[[self layer] setShadowOpacity:kShadowOpacity];
[self setEditing:NO];
propertyReleaser_ClearBrowsingBar_.Init(self, [ClearBrowsingBar class]);
}
return self;
}
......
......@@ -12,9 +12,9 @@
// Size for the favicon.
@property(nonatomic) CGFloat size;
// Image view for the favicon.
@property(nonatomic, retain) UIImageView* faviconImage;
@property(nonatomic, strong) UIImageView* faviconImage;
// Label for fallback favicon placeholder.
@property(nonatomic, retain) UILabel* faviconFallbackLabel;
@property(nonatomic, strong) UILabel* faviconFallbackLabel;
@end
......
......@@ -4,9 +4,12 @@
#import "ios/chrome/browser/ui/history/favicon_view.h"
#include "base/mac/objc_property_releaser.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Default corner radius for the favicon image view.
const CGFloat kDefaultCornerRadius = 3;
......@@ -14,7 +17,6 @@ const CGFloat kDefaultCornerRadius = 3;
@interface FaviconView () {
// Property releaser for FaviconView.
base::mac::ObjCPropertyReleaser _propertyReleaser_FaviconView;
}
// Size constraints for the favicon views.
@property(nonatomic, copy) NSArray* faviconSizeConstraints;
......@@ -30,7 +32,6 @@ const CGFloat kDefaultCornerRadius = 3;
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
_propertyReleaser_FaviconView.Init(self, [FaviconView class]);
_faviconImage = [[UIImageView alloc] init];
_faviconImage.clipsToBounds = YES;
_faviconImage.layer.cornerRadius = kDefaultCornerRadius;
......@@ -51,10 +52,10 @@ const CGFloat kDefaultCornerRadius = 3;
AddSameSizeConstraint(_faviconImage, self);
AddSameCenterConstraints(_faviconFallbackLabel, self);
AddSameSizeConstraint(_faviconFallbackLabel, self);
_faviconSizeConstraints = [@[
_faviconSizeConstraints = @[
[self.widthAnchor constraintEqualToConstant:0],
[self.heightAnchor constraintEqualToConstant:0],
] retain];
];
[NSLayoutConstraint activateConstraints:_faviconSizeConstraints];
}
return self;
......
......@@ -38,7 +38,7 @@ class GURL;
- (instancetype)init NS_UNAVAILABLE;
// View that displays a favicon or fallback icon.
@property(nonatomic, readonly) FaviconView* faviconView;
@property(strong, nonatomic, readonly) FaviconView* faviconView;
@end
......
......@@ -5,11 +5,8 @@
#import "ios/chrome/browser/ui/history/favicon_view_provider.h"
#include "base/i18n/case_conversion.h"
#include "base/ios/weak_nsobject.h"
#include "base/mac/bind_objc_block.h"
#import "base/mac/foundation_util.h"
#include "base/mac/objc_property_releaser.h"
#include "base/mac/scoped_nsobject.h"
#include "base/memory/ref_counted_memory.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
......@@ -24,30 +21,30 @@
#include "skia/ext/skia_utils_ios.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface FaviconViewProvider () {
// Property releaser for FaviconViewProvider.
base::mac::ObjCPropertyReleaser _propertyReleaser_FaviconViewProvider;
// Delegate for handling completion of favicon load.
base::WeakNSProtocol<id<FaviconViewProviderDelegate>> _delegate;
__weak id<FaviconViewProviderDelegate> _delegate;
// Used to cancel tasks for the LargeIconService.
base::CancelableTaskTracker _faviconTaskTracker;
// View that renders a favicon or a fallback image.
base::scoped_nsobject<FaviconView> _faviconView;
}
// Size to render the favicon.
@property(nonatomic, assign) CGFloat faviconSize;
// Favicon image for the favicon view.
@property(nonatomic, retain) UIImage* favicon;
@property(nonatomic, strong) UIImage* favicon;
// Fallback text for the favicon view if there is no appropriately sized
// favicon availabile.
@property(nonatomic, copy) NSString* fallbackText;
// Fallback background color for the favicon view if there is no appropriately
// sized favicon available.
@property(nonatomic, retain) UIColor* fallbackBackgroundColor;
@property(nonatomic, strong) UIColor* fallbackBackgroundColor;
// Fallback text color for the favicon view if there is no appropriately
// sized favicon available.
@property(nonatomic, retain) UIColor* fallbackTextColor;
@property(nonatomic, strong) UIColor* fallbackTextColor;
// Fetches favicon for |URL| from |faviconService|. Notifies delegate when
// favicon is retrieved.
......@@ -65,6 +62,7 @@
@synthesize fallbackText = _fallbackText;
@synthesize fallbackBackgroundColor = _fallbackBackgroundColor;
@synthesize fallbackTextColor = _fallbackTextColor;
@synthesize faviconView = _faviconView;
- (instancetype)initWithURL:(const GURL&)URL
faviconSize:(CGFloat)faviconSize
......@@ -73,12 +71,10 @@
delegate:(id<FaviconViewProviderDelegate>)delegate {
self = [super init];
if (self) {
_propertyReleaser_FaviconViewProvider.Init(self,
[FaviconViewProvider class]);
_faviconSize = faviconSize;
_delegate.reset(delegate);
_fallbackBackgroundColor = [[UIColor grayColor] retain];
_fallbackTextColor = [[UIColor whiteColor] retain];
_delegate = delegate;
_fallbackBackgroundColor = [UIColor grayColor];
_fallbackTextColor = [UIColor whiteColor];
[self fetchFaviconForURL:URL
size:faviconSize
minSize:minFaviconSize
......@@ -98,11 +94,11 @@
service:(favicon::LargeIconService*)largeIconService {
if (!largeIconService)
return;
base::WeakNSObject<FaviconViewProvider> weakSelf(self);
__weak FaviconViewProvider* weakSelf = self;
GURL blockURL(URL);
void (^faviconBlock)(const favicon_base::LargeIconResult&) = ^(
const favicon_base::LargeIconResult& result) {
base::scoped_nsobject<FaviconViewProvider> strongSelf([weakSelf retain]);
FaviconViewProvider* strongSelf = weakSelf;
if (!strongSelf)
return;
if (result.bitmap.is_valid()) {
......@@ -122,36 +118,35 @@
[strongSelf setFallbackText:base::SysUTF16ToNSString(
favicon::GetFallbackIconText(blockURL))];
}
[strongSelf.get()->_delegate faviconViewProviderFaviconDidLoad:strongSelf];
[strongSelf->_delegate faviconViewProviderFaviconDidLoad:strongSelf];
};
// Always call LargeIconService in case the favicon was updated.
CGFloat faviconSize = [UIScreen mainScreen].scale * size;
CGFloat minFaviconSize = [UIScreen mainScreen].scale * minSize;
largeIconService->GetLargeIconOrFallbackStyle(
URL, minFaviconSize, faviconSize, base::BindBlock(faviconBlock),
URL, minFaviconSize, faviconSize, base::BindBlockArc(faviconBlock),
&_faviconTaskTracker);
}
- (FaviconView*)faviconView {
if (!_faviconView) {
_faviconView.reset([[FaviconView alloc] initWithFrame:CGRectZero]);
_faviconView = [[FaviconView alloc] initWithFrame:CGRectZero];
}
_faviconView.get().size = _faviconSize;
_faviconView.size = _faviconSize;
// Update favicon view with current properties.
if (self.favicon) {
_faviconView.get().faviconImage.image = self.favicon;
_faviconView.get().faviconImage.backgroundColor = [UIColor whiteColor];
_faviconView.get().faviconFallbackLabel.text = nil;
_faviconView.faviconImage.image = self.favicon;
_faviconView.faviconImage.backgroundColor = [UIColor whiteColor];
_faviconView.faviconFallbackLabel.text = nil;
} else {
_faviconView.get().faviconImage.image = nil;
_faviconView.get().faviconImage.backgroundColor =
self.fallbackBackgroundColor;
_faviconView.get().faviconFallbackLabel.text = self.fallbackText;
_faviconView.get().faviconFallbackLabel.textColor = self.fallbackTextColor;
_faviconView.faviconImage.image = nil;
_faviconView.faviconImage.backgroundColor = self.fallbackBackgroundColor;
_faviconView.faviconFallbackLabel.text = self.fallbackText;
_faviconView.faviconFallbackLabel.textColor = self.fallbackTextColor;
CGFloat fontSize = floorf(_faviconSize / 2);
_faviconView.get().faviconFallbackLabel.font =
_faviconView.faviconFallbackLabel.font =
[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:fontSize];
}
return _faviconView;
......
......@@ -8,10 +8,7 @@
#include <memory>
#import "base/ios/weak_nsobject.h"
#include "base/mac/foundation_util.h"
#import "base/mac/objc_property_releaser.h"
#include "base/mac/scoped_nsobject.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/strings/sys_string_conversions.h"
......@@ -40,6 +37,7 @@
#include "ios/chrome/browser/ui/history/history_util.h"
#import "ios/chrome/browser/ui/url_loader.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/third_party/material_components_ios/src/components/ActivityIndicator/src/MDCActivityIndicator.h"
#import "ios/third_party/material_components_ios/src/components/Collections/src/MaterialCollections.h"
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
#import "ios/web/public/referrer.h"
......@@ -48,6 +46,10 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeHistoryEntry = kItemTypeEnumZero,
......@@ -66,30 +68,27 @@ const CGFloat kSeparatorInset = 10;
HistoryEntryInserterDelegate,
HistoryEntryItemDelegate,
HistoryServiceFacadeDelegate> {
base::mac::ObjCPropertyReleaser
_propertyReleaser_HistoryCollectionViewController;
// Facade for communicating with HistoryService and WebHistoryService.
std::unique_ptr<HistoryServiceFacade> _historyServiceFacade;
// The main browser state. Not owned by HistoryCollectionViewController.
ios::ChromeBrowserState* _browserState;
// Backing ivar for delegate property.
base::WeakNSProtocol<id<HistoryCollectionViewControllerDelegate>> _delegate;
__weak id<HistoryCollectionViewControllerDelegate> _delegate;
// Backing ivar for URLLoader property.
base::WeakNSProtocol<id<UrlLoader>> _URLLoader;
__weak id<UrlLoader> _URLLoader;
}
// Object to manage insertion of history entries into the collection view model.
@property(nonatomic, retain) HistoryEntryInserter* entryInserter;
@property(nonatomic, strong) HistoryEntryInserter* entryInserter;
// Delegate for the history collection view.
@property(nonatomic, assign, readonly)
id<HistoryCollectionViewControllerDelegate>
delegate;
@property(nonatomic, weak, readonly) id<HistoryCollectionViewControllerDelegate>
delegate;
// UrlLoader for navigating to history entries.
@property(nonatomic, assign, readonly) id<UrlLoader> URLLoader;
@property(nonatomic, weak, readonly) id<UrlLoader> URLLoader;
// The current query for visible history entries.
@property(nonatomic, copy) NSString* currentQuery;
// Coordinator for displaying context menus for history entries.
@property(nonatomic, assign) ContextMenuCoordinator* contextMenuCoordinator;
@property(nonatomic, strong) ContextMenuCoordinator* contextMenuCoordinator;
// Type of displayed history entries. Entries can be synced or local, or there
// may be no history entries.
@property(nonatomic, assign) HistoryEntriesStatus entriesType;
......@@ -151,12 +150,10 @@ const CGFloat kSeparatorInset = 10;
delegate {
self = [super initWithStyle:CollectionViewControllerStyleDefault];
if (self) {
_propertyReleaser_HistoryCollectionViewController.Init(
self, [HistoryCollectionViewController class]);
_historyServiceFacade.reset(new HistoryServiceFacade(browserState, self));
_browserState = browserState;
_delegate.reset(delegate);
_URLLoader.reset(loader);
_delegate = delegate;
_URLLoader = loader;
[self loadModel];
// Add initial info section as header.
[self.collectionViewModel
......@@ -181,10 +178,10 @@ const CGFloat kSeparatorInset = 10;
self.collectionView.keyboardDismissMode =
UIScrollViewKeyboardDismissModeOnDrag;
base::scoped_nsobject<UILongPressGestureRecognizer> longPressRecognizer([
UILongPressGestureRecognizer* longPressRecognizer = [
[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(displayContextMenuInvokedByGestureRecognizer:)]);
action:@selector(displayContextMenuInvokedByGestureRecognizer:)];
[self.collectionView addGestureRecognizer:longPressRecognizer];
}
......@@ -357,19 +354,17 @@ const CGFloat kSeparatorInset = 10;
// loading indicator removal will not be observed.
[self updateEntriesStatusMessage];
__block base::scoped_nsobject<NSMutableArray> filterResults(
[[NSMutableArray array] retain]);
__block base::scoped_nsobject<NSString> searchQuery(
[base::SysUTF16ToNSString(result.query) copy]);
__block NSMutableArray* filterResults = [NSMutableArray array];
__block NSString* searchQuery = [base::SysUTF16ToNSString(result.query) copy];
[self.collectionView performBatchUpdates:^{
// There should always be at least a header section present.
DCHECK([[self collectionViewModel] numberOfSections]);
for (const history::HistoryEntry& entry : entries) {
HistoryEntryItem* item =
[[[HistoryEntryItem alloc] initWithType:ItemTypeHistoryEntry
historyEntry:entry
browserState:_browserState
delegate:self] autorelease];
[[HistoryEntryItem alloc] initWithType:ItemTypeHistoryEntry
historyEntry:entry
browserState:_browserState
delegate:self];
[self.entryInserter insertHistoryEntryItem:item];
if ([self isSearching] || self.filterQueryResult) {
[filterResults addObject:item];
......@@ -573,16 +568,15 @@ const CGFloat kSeparatorInset = 10;
- (void)updateEntriesStatusMessage {
CollectionViewItem* entriesStatusItem = nil;
if (!self.hasHistoryEntries) {
CollectionViewTextItem* noResultsItem = [[[CollectionViewTextItem alloc]
initWithType:ItemTypeEntriesStatus] autorelease];
CollectionViewTextItem* noResultsItem =
[[CollectionViewTextItem alloc] initWithType:ItemTypeEntriesStatus];
noResultsItem.text =
self.isSearching ? l10n_util::GetNSString(IDS_HISTORY_NO_SEARCH_RESULTS)
: l10n_util::GetNSString(IDS_HISTORY_NO_RESULTS);
entriesStatusItem = noResultsItem;
} else {
HistoryEntriesStatusItem* historyEntriesStatusItem =
[[[HistoryEntriesStatusItem alloc] initWithType:ItemTypeEntriesStatus]
autorelease];
[[HistoryEntriesStatusItem alloc] initWithType:ItemTypeEntriesStatus];
historyEntriesStatusItem.delegate = self;
AuthenticationService* authService =
AuthenticationServiceFactory::GetForBrowserState(_browserState);
......@@ -691,8 +685,8 @@ const CGFloat kSeparatorInset = 10;
fromSectionWithIdentifier:kSectionIdentifierEnumZero];
[self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]];
}
CollectionViewItem* loadingIndicatorItem = [[[CollectionViewItem alloc]
initWithType:ItemTypeActivityIndicator] autorelease];
CollectionViewItem* loadingIndicatorItem =
[[CollectionViewItem alloc] initWithType:ItemTypeActivityIndicator];
loadingIndicatorItem.cellClass = [ActivityIndicatorCell class];
[self.collectionViewModel addItem:loadingIndicatorItem
toSectionWithIdentifier:kEntriesStatusSectionIdentifier];
......@@ -724,10 +718,10 @@ const CGFloat kSeparatorInset = 10;
HistoryEntryItem* entry = base::mac::ObjCCastStrict<HistoryEntryItem>(
[self.collectionViewModel itemAtIndexPath:touchedItemIndexPath]);
base::WeakNSObject<HistoryCollectionViewController> weakSelf(self);
__weak HistoryCollectionViewController* weakSelf = self;
web::ContextMenuParams params;
params.location = touchLocation;
params.view.reset([self.collectionView retain]);
params.view.reset(self.collectionView);
NSString* menuTitle =
base::SysUTF16ToNSString(url_formatter::FormatUrl(entry.URL));
params.menu_title.reset([menuTitle copy]);
......
......@@ -6,7 +6,6 @@
#include <memory>
#import "base/mac/scoped_nsobject.h"
#include "base/strings/string16.h"
#import "base/test/ios/wait_util.h"
#include "base/time/time.h"
......@@ -61,31 +60,27 @@ class HistoryCollectionViewControllerTest : public BlockCleanupTest {
AuthenticationServiceFactory::GetInstance(),
AuthenticationServiceFake::CreateAuthenticationService);
mock_browser_state_ = builder.Build();
mock_delegate_.reset([[OCMockObject
niceMockForProtocol:@protocol(HistoryCollectionViewControllerDelegate)]
retain]);
mock_url_loader_.reset(
[[OCMockObject niceMockForProtocol:@protocol(UrlLoader)] retain]);
history_collection_view_controller_.reset(
mock_delegate_ = [OCMockObject
niceMockForProtocol:@protocol(HistoryCollectionViewControllerDelegate)];
mock_url_loader_ = [OCMockObject niceMockForProtocol:@protocol(UrlLoader)];
history_collection_view_controller_ =
[[HistoryCollectionViewController alloc]
initWithLoader:mock_url_loader_
browserState:mock_browser_state_.get()
delegate:mock_delegate_]);
delegate:mock_delegate_];
}
void TearDown() override {
history_collection_view_controller_.reset();
history_collection_view_controller_ = nil;
BlockCleanupTest::TearDown();
}
protected:
web::TestWebThreadBundle thread_bundle_;
base::scoped_nsprotocol<id<UrlLoader>> mock_url_loader_;
id<UrlLoader> mock_url_loader_;
std::unique_ptr<TestChromeBrowserState> mock_browser_state_;
base::scoped_nsprotocol<id<HistoryCollectionViewControllerDelegate>>
mock_delegate_;
base::scoped_nsobject<HistoryCollectionViewController>
history_collection_view_controller_;
id<HistoryCollectionViewControllerDelegate> mock_delegate_;
HistoryCollectionViewController* history_collection_view_controller_;
bool privacy_settings_opened_;
DISALLOW_COPY_AND_ASSIGN(HistoryCollectionViewControllerTest);
};
......
......@@ -38,7 +38,7 @@ class GURL;
// YES if message for other forms of browsing data should be shown.
@property(nonatomic, assign) BOOL showsOtherBrowsingDataNotice;
// Delegate for HistoryEntriesStatusItem. Is notified when a link is pressed.
@property(nonatomic, assign) id<HistoryEntriesStatusItemDelegate> delegate;
@property(nonatomic, weak) id<HistoryEntriesStatusItemDelegate> delegate;
@end
// Cell for displaying status for history entry. Provides information on whether
......
......@@ -4,9 +4,7 @@
#import "ios/chrome/browser/ui/history/history_entries_status_item.h"
#include "base/ios/weak_nsobject.h"
#include "base/mac/foundation_util.h"
#import "base/mac/objc_property_releaser.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/chrome_url_constants.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item.h"
......@@ -18,6 +16,10 @@
#include "ui/base/l10n/l10n_util_mac.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// Delegate for HistoryEntriesStatusCell.
@protocol HistoryEntriesStatusCellDelegate<NSObject>
// Notifies the delegate that |URL| should be opened.
......@@ -25,33 +27,25 @@
didRequestOpenURL:(const GURL&)URL;
@end
@interface HistoryEntriesStatusCell () {
// Property releaser for HistoryEntriesStatusItem.
base::mac::ObjCPropertyReleaser _propertyReleaser_HistoryEntriesStatusCell;
// Delegate for the HistoryEntriesStatusCell. Is notified when a link is
// tapped.
base::WeakNSProtocol<id<HistoryEntriesStatusCellDelegate>> _delegate;
}
@interface HistoryEntriesStatusCell ()
// Redeclare as readwrite.
@property(nonatomic, retain, readwrite)
@property(nonatomic, strong, readwrite)
LabelLinkController* labelLinkController;
// Delegate for the HistoryEntriesStatusCell. Is notified when a link is
// tapped.
@property(nonatomic, assign) id<HistoryEntriesStatusCellDelegate> delegate;
// Delegate for the HistoryEntriesStatusCell. Is notified when a link is
// tapped.
@property(nonatomic, weak) id<HistoryEntriesStatusCellDelegate> delegate;
// Sets links on the cell label.
- (void)setLinksForSyncURL:(const GURL&)syncURL
browsingDataURL:(const GURL&)browsingDataURL;
@end
@interface HistoryEntriesStatusItem ()<HistoryEntriesStatusCellDelegate> {
// Delegate for the HistoryEntriesStatusItem. Is notified when a link is
// tapped.
base::WeakNSProtocol<id<HistoryEntriesStatusItemDelegate>> _delegate;
}
@interface HistoryEntriesStatusItem ()<HistoryEntriesStatusCellDelegate>
@end
@implementation HistoryEntriesStatusItem
@synthesize delegate = _delegate;
@synthesize entriesStatus = _entriesStatus;
@synthesize hidden = _hidden;
@synthesize showsOtherBrowsingDataNotice = _showsOtherBrowsingDataNotice;
......@@ -112,14 +106,6 @@
browsingDataURL:otherBrowsingDataURL];
}
- (void)setDelegate:(id<HistoryEntriesStatusItemDelegate>)delegate {
_delegate.reset(delegate);
}
- (id<HistoryEntriesStatusItemDelegate>)delegate {
return _delegate;
}
- (void)historyEntriesStatusCell:(HistoryEntriesStatusCell*)cell
didRequestOpenURL:(const GURL&)URL {
[self.delegate historyEntriesStatusItem:self didRequestOpenURL:URL];
......@@ -146,27 +132,18 @@
@end
@implementation HistoryEntriesStatusCell
@synthesize delegate = _delegate;
@synthesize labelLinkController = _labelLinkController;
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
_propertyReleaser_HistoryEntriesStatusCell.Init(
self, [HistoryEntriesStatusCell class]);
}
return self;
}
- (void)setLinksForSyncURL:(const GURL&)syncURL
browsingDataURL:(const GURL&)browsingDataURL {
base::WeakNSObject<HistoryEntriesStatusCell> weakSelf(self);
self.labelLinkController = [[[LabelLinkController alloc]
__weak HistoryEntriesStatusCell* weakSelf = self;
self.labelLinkController = [[LabelLinkController alloc]
initWithLabel:self.textLabel
action:^(const GURL& URL) {
[[weakSelf delegate] historyEntriesStatusCell:weakSelf
didRequestOpenURL:URL];
}] autorelease];
}];
[self.labelLinkController setLinkColor:[[MDCPalette cr_bluePalette] tint500]];
// Remove link delimiters from text and get ranges for links. Both links
......@@ -196,14 +173,6 @@
}
}
- (void)setDelegate:(id<HistoryEntriesStatusCellDelegate>)delegate {
_delegate.reset(delegate);
}
- (id<HistoryEntriesStatusCellDelegate>)delegate {
return _delegate;
}
- (void)prepareForReuse {
[super prepareForReuse];
self.labelLinkController = nil;
......
......@@ -36,7 +36,7 @@ class Time;
// Delegate for the HistoryEntryInserter. Receives callbacks upon item and
// section insertion and removal.
@property(nonatomic, assign) id<HistoryEntryInserterDelegate> delegate;
@property(nonatomic, weak) id<HistoryEntryInserterDelegate> delegate;
// Designated initializer for HistoryEntryInserter. collectionViewModel is the
// model into which entries are inserted. Sections for history entries are
......
......@@ -4,9 +4,7 @@
#import "ios/chrome/browser/ui/history/history_entry_inserter.h"
#import "base/ios/weak_nsobject.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "base/time/time.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h"
......@@ -15,42 +13,38 @@
#include "ios/chrome/browser/ui/history/history_util.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface HistoryEntryInserter () {
// Delegate for the HistoryEntryInserter.
base::WeakNSProtocol<id<HistoryEntryInserterDelegate>> _delegate;
// CollectionViewModel in which to insert history entries.
base::scoped_nsobject<CollectionViewModel> _collectionViewModel;
CollectionViewModel* _collectionViewModel;
// The index of the first section to contain history entries.
NSInteger _firstSectionIndex;
// Number of assigned section identifiers.
NSInteger _sectionIdentifierCount;
// Sorted set of dates that have history entries.
base::scoped_nsobject<NSMutableOrderedSet> _dates;
NSMutableOrderedSet* _dates;
// Mapping from dates to section identifiers.
base::scoped_nsobject<NSMutableDictionary> _sectionIdentifiers;
NSMutableDictionary* _sectionIdentifiers;
}
@end
@implementation HistoryEntryInserter
@synthesize delegate = _delegate;
- (instancetype)initWithModel:(CollectionViewModel*)collectionViewModel {
if ((self = [super init])) {
_collectionViewModel.reset([collectionViewModel retain]);
_collectionViewModel = collectionViewModel;
_firstSectionIndex = [collectionViewModel numberOfSections];
_dates.reset([[NSMutableOrderedSet alloc] init]);
_sectionIdentifiers.reset([[NSMutableDictionary dictionary] retain]);
_dates = [[NSMutableOrderedSet alloc] init];
_sectionIdentifiers = [NSMutableDictionary dictionary];
}
return self;
}
- (id<HistoryEntryInserterDelegate>)delegate {
return _delegate;
}
- (void)setDelegate:(id<HistoryEntryInserterDelegate>)delegate {
_delegate.reset(delegate);
}
- (void)insertHistoryEntryItem:(HistoryEntryItem*)item {
NSInteger sectionIdentifier =
......@@ -126,8 +120,8 @@
usingComparator:comparator];
[_dates insertObject:date atIndex:index];
NSInteger insertionIndex = _firstSectionIndex + index;
CollectionViewTextItem* header = [[[CollectionViewTextItem alloc]
initWithType:kItemTypeEnumZero] autorelease];
CollectionViewTextItem* header =
[[CollectionViewTextItem alloc] initWithType:kItemTypeEnumZero];
header.text =
base::SysUTF16ToNSString(history::GetRelativeDateLocalized(timestamp));
[_collectionViewModel insertSectionWithIdentifier:sectionIdentifier
......
......@@ -75,13 +75,13 @@ class GURL;
@interface HistoryEntryCell : MDCCollectionViewCell
// View for displaying the favicon for the history entry.
@property(nonatomic, retain) UIView* faviconViewContainer;
@property(nonatomic, strong) UIView* faviconViewContainer;
// Text label for history entry title.
@property(nonatomic, readonly, retain) UILabel* textLabel;
@property(nonatomic, readonly, strong) UILabel* textLabel;
// Text label for history entry URL.
@property(nonatomic, readonly, retain) UILabel* detailTextLabel;
@property(nonatomic, readonly, strong) UILabel* detailTextLabel;
// Text label for history entry timestamp.
@property(nonatomic, readonly, retain) UILabel* timeLabel;
@property(nonatomic, readonly, strong) UILabel* timeLabel;
@end
......
......@@ -5,9 +5,7 @@
#import "ios/chrome/browser/ui/history/history_entry_item.h"
#include "base/i18n/time_formatting.h"
#include "base/ios/weak_nsobject.h"
#import "base/mac/foundation_util.h"
#import "base/mac/objc_property_releaser.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "components/history/core/browser/url_row.h"
......@@ -24,6 +22,10 @@
#import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoFontLoader.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Size at which the favicon will be displayed.
const CGFloat kFaviconSize = 24.0;
......@@ -59,14 +61,12 @@ NSString* FormattedTitle(const base::string16& title, const GURL& url) {
#pragma mark - HistoryEntryItem
@interface HistoryEntryItem ()<FaviconViewProviderDelegate> {
// Property releaser for HistoryEntryItem.
base::mac::ObjCPropertyReleaser _propertyReleaser_HistoryEntryItem;
// Delegate for HistoryEntryItem.
base::WeakNSProtocol<id<HistoryEntryItemDelegate>> _delegate;
__weak id<HistoryEntryItemDelegate> _delegate;
}
// FaviconViewProvider to fetch the favicon and format the favicon view.
@property(nonatomic, retain) FaviconViewProvider* faviconViewProvider;
@property(nonatomic, strong) FaviconViewProvider* faviconViewProvider;
// Custom accessibility actions for the history entry view.
- (NSArray*)accessibilityActions;
......@@ -96,7 +96,6 @@ NSString* FormattedTitle(const base::string16& title, const GURL& url) {
delegate:(id<HistoryEntryItemDelegate>)delegate {
self = [super initWithType:type];
if (self) {
_propertyReleaser_HistoryEntryItem.Init(self, [HistoryEntryItem class]);
self.cellClass = [HistoryEntryCell class];
favicon::LargeIconService* largeIconService =
IOSChromeLargeIconServiceFactory::GetForBrowserState(browserState);
......@@ -112,7 +111,7 @@ NSString* FormattedTitle(const base::string16& title, const GURL& url) {
[base::SysUTF16ToNSString(base::TimeFormatTimeOfDay(entry.time)) copy];
_URL = GURL(entry.url);
_timestamp = entry.time;
_delegate.reset(delegate);
_delegate = delegate;
}
return self;
}
......@@ -143,28 +142,28 @@ NSString* FormattedTitle(const base::string16& title, const GURL& url) {
- (NSArray*)accessibilityActions {
UIAccessibilityCustomAction* deleteAction =
[[[UIAccessibilityCustomAction alloc]
[[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(
IDS_HISTORY_ENTRY_ACCESSIBILITY_DELETE)
target:self
selector:@selector(deleteHistoryEntry)] autorelease];
selector:@selector(deleteHistoryEntry)];
UIAccessibilityCustomAction* openInNewTabAction =
[[[UIAccessibilityCustomAction alloc]
[[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(
IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB)
target:self
selector:@selector(openInNewTab)] autorelease];
selector:@selector(openInNewTab)];
UIAccessibilityCustomAction* openInNewIncognitoTabAction =
[[[UIAccessibilityCustomAction alloc]
[[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(
IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB)
target:self
selector:@selector(openInNewIncognitoTab)] autorelease];
selector:@selector(openInNewIncognitoTab)];
UIAccessibilityCustomAction* copyURLAction =
[[[UIAccessibilityCustomAction alloc]
[[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_COPY)
target:self
selector:@selector(copyURL)] autorelease];
selector:@selector(copyURL)];
return @[
deleteAction, openInNewTabAction, openInNewIncognitoTabAction, copyURLAction
];
......@@ -220,15 +219,12 @@ NSString* FormattedTitle(const base::string16& title, const GURL& url) {
#pragma mark - HistoryEntryCell
@interface HistoryEntryCell () {
// Property releaser for HistoryEntryCell.
base::mac::ObjCPropertyReleaser _propertyReleaser_HistoryEntryCell;
}
@interface HistoryEntryCell ()
// Redeclare as readwrite to allow property releaser to handle these properties.
@property(nonatomic, readwrite, retain) UILabel* textLabel;
@property(nonatomic, readwrite, retain) UILabel* detailTextLabel;
@property(nonatomic, readwrite, retain) UILabel* timeLabel;
// Redeclare as readwrite.
@property(nonatomic, readwrite, strong) UILabel* textLabel;
@property(nonatomic, readwrite, strong) UILabel* detailTextLabel;
@property(nonatomic, readwrite, strong) UILabel* timeLabel;
@end
@implementation HistoryEntryCell
......@@ -241,7 +237,6 @@ NSString* FormattedTitle(const base::string16& title, const GURL& url) {
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
_propertyReleaser_HistoryEntryCell.Init(self, [HistoryEntryCell class]);
_faviconViewContainer = [[UIView alloc] initWithFrame:CGRectZero];
......
......@@ -4,12 +4,15 @@
#import "ios/chrome/browser/ui/history/history_search_view.h"
#include "base/mac/objc_property_releaser.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Shadow opacity for the search view.
CGFloat kShadowOpacity = 0.2f;
......@@ -17,9 +20,7 @@ CGFloat kShadowOpacity = 0.2f;
CGFloat kHorizontalMargin = 16.0f;
} // namespace
@interface HistorySearchView () {
base::mac::ObjCPropertyReleaser propertyReleaser_HistorySearchView_;
}
@interface HistorySearchView ()
// Stack view for laying out the text field and cancel button.
@property(nonatomic, strong) UIStackView* stackView;
......@@ -58,7 +59,7 @@ CGFloat kHorizontalMargin = 16.0f;
_textField.clearButtonMode = UITextFieldViewModeAlways;
_textField.placeholder = l10n_util::GetNSString(IDS_HISTORY_SEARCH_BUTTON);
_cancelButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
_cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_cancelButton setImage:[UIImage imageNamed:@"collapse"]
forState:UIControlStateNormal];
[_cancelButton setImage:[UIImage imageNamed:@"collapse_pressed"]
......@@ -81,9 +82,9 @@ CGFloat kHorizontalMargin = 16.0f;
_stackView.layoutMarginsRelativeArrangement = YES;
CGFloat topAnchorConstant = IsCompact() ? StatusBarHeight() : 0;
_topAnchorConstraint = [[_stackView.topAnchor
constraintEqualToAnchor:self.topAnchor
constant:topAnchorConstant] retain];
_topAnchorConstraint =
[_stackView.topAnchor constraintEqualToAnchor:self.topAnchor
constant:topAnchorConstant];
[NSLayoutConstraint activateConstraints:@[
_topAnchorConstraint,
[_stackView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
......@@ -94,8 +95,6 @@ CGFloat kHorizontalMargin = 16.0f;
constraintEqualToAnchor:self.trailingAnchor
constant:-kHorizontalMargin],
]];
propertyReleaser_HistorySearchView_.Init(self, [HistorySearchView class]);
}
return self;
}
......
......@@ -4,15 +4,15 @@
#import "ios/chrome/browser/ui/history/history_search_view_controller.h"
#include "base/ios/weak_nsobject.h"
#include "base/mac/scoped_nsobject.h"
#import "ios/chrome/browser/ui/history/history_search_view.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface HistorySearchViewController ()<UITextFieldDelegate> {
// Delegate for forwarding interactions with the search view.
base::WeakNSProtocol<id<HistorySearchViewControllerDelegate>> _delegate;
// View displayed by the HistorySearchViewController
base::scoped_nsobject<HistorySearchView> _searchView;
HistorySearchView* _searchView;
}
// Action for the cancel button.
......@@ -21,11 +21,11 @@
@end
@implementation HistorySearchViewController
@synthesize delegate = _delegate;
@synthesize enabled = _enabled;
- (void)loadView {
_searchView.reset([[HistorySearchView alloc] init]);
_searchView = [[HistorySearchView alloc] init];
[_searchView setSearchBarDelegate:self];
[_searchView setCancelTarget:self action:@selector(cancelButtonClicked:)];
self.view = _searchView;
......@@ -36,14 +36,6 @@
[_searchView becomeFirstResponder];
}
- (void)setDelegate:(id<HistorySearchViewControllerDelegate>)delegate {
_delegate.reset(delegate);
}
- (id<HistorySearchViewControllerDelegate>)delegate {
return _delegate;
}
- (void)setEnabled:(BOOL)enabled {
_enabled = enabled;
[_searchView setEnabled:enabled];
......
......@@ -8,7 +8,6 @@
#include <memory>
#include <string>
#include "base/ios/weak_nsobject.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
......@@ -165,7 +164,7 @@ class HistoryServiceFacade : public history::HistoryServiceObserver {
ios::ChromeBrowserState* browser_state_; // weak
// Delegate for HistoryServiceFacade. Serves as client for HistoryService.
base::WeakNSProtocol<id<HistoryServiceFacadeDelegate>> delegate_;
__weak id<HistoryServiceFacadeDelegate> delegate_;
base::WeakPtrFactory<HistoryServiceFacade> weak_factory_;
......
......@@ -37,6 +37,10 @@
#include "ios/chrome/browser/ui/history/history_service_facade_delegate.h"
#include "ios/chrome/browser/ui/history/history_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// The amount of time to wait for a response from the WebHistoryService.
static const int kWebHistoryTimeoutSeconds = 3;
......@@ -128,7 +132,7 @@ HistoryServiceFacade::HistoryServiceFacade(
HistoryServiceFacade::~HistoryServiceFacade() {
query_task_tracker_.TryCancelAll();
web_history_request_.reset();
delegate_.reset();
delegate_ = nil;
}
void HistoryServiceFacade::QueryHistory(const base::string16& search_text,
......
......@@ -6,7 +6,6 @@
#include <memory>
#import "base/mac/scoped_nsobject.h"
#include "base/run_loop.h"
#include "base/strings/string16.h"
#include "components/history/core/browser/history_service.h"
......@@ -106,7 +105,7 @@ class HistoryServiceFacadeTest : public PlatformTest,
bool success = browser_state_->CreateHistoryService(true);
EXPECT_TRUE(success);
mock_delegate_.reset([[MockHistoryServiceFacadeDelegate alloc] init]);
mock_delegate_ = [[MockHistoryServiceFacadeDelegate alloc] init];
history_service_facade_.reset(
new HistoryServiceFacade(browser_state_.get(), mock_delegate_));
}
......@@ -176,7 +175,7 @@ class HistoryServiceFacadeTest : public PlatformTest,
protected:
web::TestWebThreadBundle thread_bundle_;
std::unique_ptr<TestChromeBrowserState> browser_state_;
base::scoped_nsobject<MockHistoryServiceFacadeDelegate> mock_delegate_;
MockHistoryServiceFacadeDelegate* mock_delegate_;
std::unique_ptr<HistoryServiceFacade> history_service_facade_;
GURL visited_url_;
base::Time visited_time_;
......
......@@ -14,6 +14,10 @@
#include "ui/base/l10n/time_format.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace history {
base::string16 GetRelativeDateLocalized(const base::Time& visit_time) {
......
......@@ -11,14 +11,14 @@
// Table cell used in TabHistoryViewController.
@interface TabHistoryCell : UICollectionViewCell
@property(nonatomic, retain) CRWSessionEntry* entry;
@property(nonatomic, readonly) UILabel* titleLabel;
@property(strong, nonatomic) CRWSessionEntry* entry;
@property(weak, nonatomic, readonly) UILabel* titleLabel;
@end
// Header for a section of TabHistoryCells.
@interface TabHistorySectionHeader : UICollectionReusableView
@property(nonatomic, readonly) UIImageView* iconView;
@property(nonatomic, readonly) UIView* lineView;
@property(weak, nonatomic, readonly) UIImageView* iconView;
@property(weak, nonatomic, readonly) UIView* lineView;
@end
// Footer for a section of TabHistoryCells.
......
......@@ -4,7 +4,6 @@
#import "ios/chrome/browser/ui/history/tab_history_cell.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
......@@ -12,6 +11,10 @@
#import "ios/web/navigation/crw_session_entry.h"
#include "ios/web/public/navigation_item.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Header horizontal layout inset.
const CGFloat kHeaderHorizontalInset = 16;
......@@ -40,8 +43,8 @@ NS_INLINE CGFloat HeaderLineRadius() {
}
@implementation TabHistoryCell {
base::scoped_nsobject<CRWSessionEntry> _entry;
base::scoped_nsobject<UILabel> _titleLabel;
CRWSessionEntry* _entry;
UILabel* _titleLabel;
}
- (instancetype)initWithFrame:(CGRect)frame {
......@@ -61,7 +64,7 @@ NS_INLINE CGFloat HeaderLineRadius() {
}
- (void)commonInitialization {
_titleLabel.reset([[UILabel alloc] initWithFrame:CGRectZero]);
_titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[_titleLabel setTextColor:UIColorFromRGB(kTitleTextRGB)];
[_titleLabel
setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]];
......@@ -77,11 +80,11 @@ NS_INLINE CGFloat HeaderLineRadius() {
}
- (CRWSessionEntry*)entry {
return [[_entry retain] autorelease];
return _entry;
}
- (void)setEntry:(CRWSessionEntry*)entry {
_entry.reset([entry retain]);
_entry = entry;
NSString* title = nil;
web::NavigationItem* navigationItem = [_entry navigationItem];
......@@ -99,12 +102,12 @@ NS_INLINE CGFloat HeaderLineRadius() {
}
- (UILabel*)titleLabel {
return [[_titleLabel retain] autorelease];
return _titleLabel;
}
- (void)prepareForReuse {
[super prepareForReuse];
_entry.reset(nil);
_entry = nil;
[_titleLabel setText:nil];
[self setAccessibilityLabel:nil];
}
......@@ -112,28 +115,28 @@ NS_INLINE CGFloat HeaderLineRadius() {
@end
@implementation TabHistorySectionHeader {
base::scoped_nsobject<UIImageView> _iconView;
base::scoped_nsobject<UIView> _lineView;
UIImageView* _iconView;
UIView* _lineView;
}
- (UIImageView*)iconView {
return [[_iconView retain] autorelease];
return _iconView;
}
- (UIView*)lineView {
return [[_lineView retain] autorelease];
return _lineView;
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
CGRect iconFrame = CGRectMake(0, 0, kSiteIconViewWidth, kSiteIconViewWidth);
_iconView.reset([[UIImageView alloc] initWithFrame:iconFrame]);
_iconView = [[UIImageView alloc] initWithFrame:iconFrame];
[self addSubview:_iconView];
UIColor* lineColor = UIColorFromRGB(kHeaderLineRGB);
_lineView.reset([[UIView alloc] initWithFrame:CGRectZero]);
_lineView = [[UIView alloc] initWithFrame:CGRectZero];
[[_lineView layer] setCornerRadius:HeaderLineRadius()];
[_lineView setBackgroundColor:lineColor];
[self addSubview:_lineView];
......
......@@ -8,7 +8,6 @@
#include "base/logging.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/objc_property_releaser.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/ui/history/tab_history_view_controller.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_view.h"
......@@ -21,6 +20,10 @@
#import "ui/gfx/ios/NSString+CrStringDrawing.h"
#include "ui/gfx/ios/uikit_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
static const CGFloat kTabHistoryMinWidth = 250.0;
static const CGFloat kTabHistoryMaxWidthLandscapePhone = 350.0;
......@@ -44,17 +47,15 @@ static const CGFloat kHeightPercentage = 0.85;
// Container view of the history entries table.
UIView* tabHistoryTableViewContainer_;
base::mac::ObjCPropertyReleaser propertyReleaser_TabHistoryPopupController_;
}
// Determines the width for the popup depending on the device, orientation, and
// CRWSessionEntrys to display.
- (CGFloat)calculatePopupWidth:(NSArray*)entries;
@property(nonatomic, retain)
@property(nonatomic, strong)
TabHistoryViewController* tabHistoryTableViewController;
@property(nonatomic, retain) UIView* tabHistoryTableViewContainer;
@property(nonatomic, strong) UIView* tabHistoryTableViewContainer;
@end
......@@ -69,9 +70,6 @@ static const CGFloat kHeightPercentage = 0.85;
DCHECK(parent);
self = [super initWithParentView:parent];
if (self) {
propertyReleaser_TabHistoryPopupController_.Init(
self, [TabHistoryPopupController class]);
tabHistoryTableViewController_ = [[TabHistoryViewController alloc] init];
[tabHistoryTableViewController_ setSessionEntries:entries];
......@@ -168,7 +166,6 @@ static const CGFloat kHeightPercentage = 0.85;
- (void)dealloc {
[tabHistoryTableViewContainer_ removeFromSuperview];
[super dealloc];
}
@end
......@@ -12,7 +12,7 @@
// TODO(crbug.com/546355): Convert this class to use an array of
// NavigationEntries.
@property(nonatomic, retain) NSArray* sessionEntries;
@property(nonatomic, strong) NSArray* sessionEntries;
// Returns the optimal height needed to display the session entries.
// The height returned is usually less than the |suggestedHeight| unless
......
......@@ -4,11 +4,8 @@
#import "ios/chrome/browser/ui/history/tab_history_view_controller.h"
#import "base/ios/weak_nsobject.h"
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/mac/objc_property_releaser.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
#include "ios/chrome/browser/ui/commands/ios_command_ids.h"
......@@ -20,6 +17,10 @@
#include "ios/web/public/navigation_item.h"
#include "ui/gfx/image/image.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Visible percentage of the last visible row on the Tools menu if the
......@@ -217,16 +218,16 @@ layoutAttributesForSupplementaryViewOfKind:(NSString*)kind
@end
@interface TabHistoryViewController ()<MDCInkTouchControllerDelegate> {
base::scoped_nsobject<MDCInkTouchController> _inkTouchController;
base::scoped_nsobject<NSArray> _partitionedEntries;
base::scoped_nsobject<NSArray> _sessionEntries;
MDCInkTouchController* _inkTouchController;
NSArray* _partitionedEntries;
NSArray* _sessionEntries;
}
@end
@implementation TabHistoryViewController
- (NSArray*)sessionEntries {
return [[_sessionEntries retain] autorelease];
return _sessionEntries;
}
#pragma mark Public Methods
......@@ -235,7 +236,7 @@ layoutAttributesForSupplementaryViewOfKind:(NSString*)kind
DCHECK(suggestedHeight >= kCellHeight);
CGFloat optimalHeight = 0;
for (NSArray* sectionArray in _partitionedEntries.get()) {
for (NSArray* sectionArray in _partitionedEntries) {
NSUInteger sectionItemCount = [sectionArray count];
for (NSUInteger i = 0; i < sectionItemCount; ++i) {
CGFloat proposedHeight = optimalHeight + kCellHeight;
......@@ -263,8 +264,8 @@ layoutAttributesForSupplementaryViewOfKind:(NSString*)kind
}
- (instancetype)init {
base::scoped_nsobject<TabHistoryViewControllerLayout> layout(
[[TabHistoryViewControllerLayout alloc] init]);
TabHistoryViewControllerLayout* layout =
[[TabHistoryViewControllerLayout alloc] init];
return [self initWithCollectionViewLayout:layout];
}
......@@ -286,8 +287,8 @@ layoutAttributesForSupplementaryViewOfKind:(NSString*)kind
forSupplementaryViewOfKind:UICollectionElementKindSectionFooter
withReuseIdentifier:footerIdentifier];
_inkTouchController.reset(
[[MDCInkTouchController alloc] initWithView:collectionView]);
_inkTouchController =
[[MDCInkTouchController alloc] initWithView:collectionView];
[_inkTouchController setDelegate:self];
[_inkTouchController addInkView];
}
......@@ -370,7 +371,7 @@ layoutAttributesForSupplementaryViewOfKind:(NSString*)kind
}
- (void)setSessionEntries:(NSArray*)sessionEntries {
_sessionEntries.reset([sessionEntries retain]);
_sessionEntries = sessionEntries;
std::string previousHost;
......@@ -406,7 +407,7 @@ layoutAttributesForSupplementaryViewOfKind:(NSString*)kind
if (![partitionedEntries count])
partitionedEntries = nil;
_partitionedEntries.reset([partitionedEntries retain]);
_partitionedEntries = partitionedEntries;
}
#pragma mark MDCInkTouchControllerDelegate
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment