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

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

Automatically generated ARCMigrate commit
Notable issues:None
BUG=624363
TEST=None

Review-Url: https://codereview.chromium.org/2737603007
Cr-Commit-Position: refs/heads/master@{#456064}
parent 317e6094
...@@ -5,6 +5,28 @@ ...@@ -5,6 +5,28 @@
source_set("bookmarks_arc") { source_set("bookmarks_arc") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"bookmark_collection_cells.h",
"bookmark_collection_cells.mm",
"bookmark_collection_view.h",
"bookmark_collection_view.mm",
"bookmark_collection_view_background.h",
"bookmark_collection_view_background.mm",
"bookmark_controller_factory.h",
"bookmark_controller_factory.mm",
"bookmark_edit_view_controller.h",
"bookmark_edit_view_controller.mm",
"bookmark_elevated_toolbar.h",
"bookmark_elevated_toolbar.mm",
"bookmark_extended_button.h",
"bookmark_extended_button.mm",
"bookmark_folder_collection_view.h",
"bookmark_folder_collection_view.mm",
"bookmark_folder_editor_view_controller.h",
"bookmark_folder_editor_view_controller.mm",
"bookmark_folder_table_view_cell.h",
"bookmark_folder_table_view_cell.mm",
"bookmark_folder_view_controller.h",
"bookmark_folder_view_controller.mm",
"bookmark_home_handset_view_controller.h", "bookmark_home_handset_view_controller.h",
"bookmark_home_handset_view_controller.mm", "bookmark_home_handset_view_controller.mm",
"bookmark_home_tablet_ntp_controller.h", "bookmark_home_tablet_ntp_controller.h",
...@@ -73,28 +95,6 @@ source_set("bookmarks_arc") { ...@@ -73,28 +95,6 @@ source_set("bookmarks_arc") {
source_set("bookmarks") { source_set("bookmarks") {
sources = [ sources = [
"bookmark_collection_cells.h",
"bookmark_collection_cells.mm",
"bookmark_collection_view.h",
"bookmark_collection_view.mm",
"bookmark_collection_view_background.h",
"bookmark_collection_view_background.mm",
"bookmark_controller_factory.h",
"bookmark_controller_factory.mm",
"bookmark_edit_view_controller.h",
"bookmark_edit_view_controller.mm",
"bookmark_elevated_toolbar.h",
"bookmark_elevated_toolbar.mm",
"bookmark_extended_button.h",
"bookmark_extended_button.mm",
"bookmark_folder_collection_view.h",
"bookmark_folder_collection_view.mm",
"bookmark_folder_editor_view_controller.h",
"bookmark_folder_editor_view_controller.mm",
"bookmark_folder_table_view_cell.h",
"bookmark_folder_table_view_cell.mm",
"bookmark_folder_view_controller.h",
"bookmark_folder_view_controller.mm",
"bookmark_home_primary_view.h", "bookmark_home_primary_view.h",
"bookmark_home_view_controller.h", "bookmark_home_view_controller.h",
"bookmark_home_view_controller.mm", "bookmark_home_view_controller.mm",
......
...@@ -43,7 +43,7 @@ typedef enum { ...@@ -43,7 +43,7 @@ typedef enum {
// There is also an image and an optional menu button. // There is also an image and an optional menu button.
@interface BookmarkCell : UICollectionViewCell<BookmarkImageableView> @interface BookmarkCell : UICollectionViewCell<BookmarkImageableView>
@property(nonatomic, retain, readonly) UILabel* titleLabel; @property(nonatomic, strong, readonly) UILabel* titleLabel;
+ (NSString*)reuseIdentifier; + (NSString*)reuseIdentifier;
......
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/objc_property_releaser.h"
#include "base/mac/scoped_nsobject.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_extended_button.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_extended_button.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
...@@ -22,38 +21,37 @@ ...@@ -22,38 +21,37 @@
#import "ui/gfx/ios/NSString+CrStringDrawing.h" #import "ui/gfx/ios/NSString+CrStringDrawing.h"
#include "url/gurl.h" #include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace { namespace {
const CGFloat kBookmarkItemCellDefaultImageSize = 40.0; const CGFloat kBookmarkItemCellDefaultImageSize = 40.0;
const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
} // namespace } // namespace
@interface BookmarkCell () { @interface BookmarkCell ()
@protected
// Subclasses should set these in the constructor with the wanted values.
CGFloat _imageSize;
@private
base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkCell;
}
// Redefined to be read-write. // Redefined to be read-write.
@property(nonatomic, retain) UILabel* titleLabel; @property(nonatomic, strong) UILabel* titleLabel;
// Redefined to readwrite. // Redefined to readwrite.
@property(nonatomic, retain) UIImageView* imageView; @property(nonatomic, strong) UIImageView* imageView;
// Label to show placeholder text when there is no image displayed. // Label to show placeholder text when there is no image displayed.
@property(nonatomic, retain) UILabel* placeholderLabel; @property(nonatomic, strong) UILabel* placeholderLabel;
// When the cell is selected for editing, a cover is shown with a blue color. // When the cell is selected for editing, a cover is shown with a blue color.
// Subclasses should insert new views below this view. // Subclasses should insert new views below this view.
@property(nonatomic, retain) UIView* highlightCover; @property(nonatomic, strong) UIView* highlightCover;
// Lists the accessibility elements that are to be seen by UIAccessibility. // Lists the accessibility elements that are to be seen by UIAccessibility.
@property(nonatomic, readonly) NSMutableArray* accessibilityElements; @property(nonatomic, readonly) NSMutableArray* accessibilityElements;
// Location of the last touch on the cell. // Location of the last touch on the cell.
@property(nonatomic, assign) CGPoint touchLocation; @property(nonatomic, assign) CGPoint touchLocation;
// The view doing the highlight animation. Only set while the cell is // The view doing the highlight animation. Only set while the cell is
// highlighted. // highlighted.
@property(nonatomic, retain) MDCInkView* touchFeedbackView; @property(nonatomic, strong) MDCInkView* touchFeedbackView;
@property(nonatomic, retain) BookmarkExtendedButton* button; @property(nonatomic, strong) BookmarkExtendedButton* button;
@property(nonatomic, assign) SEL buttonAction; @property(nonatomic, assign) SEL buttonAction;
@property(nonatomic, assign) id buttonTarget; @property(nonatomic, weak) id buttonTarget;
// Side of a square image. Subclasses should set this to desired size.
@property(nonatomic, assign) CGFloat imageSize;
@end @end
@implementation BookmarkCell @implementation BookmarkCell
...@@ -68,6 +66,7 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -68,6 +66,7 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
@synthesize buttonAction = _buttonAction; @synthesize buttonAction = _buttonAction;
@synthesize buttonTarget = _buttonTarget; @synthesize buttonTarget = _buttonTarget;
@synthesize placeholderLabel = _placeholderLabel; @synthesize placeholderLabel = _placeholderLabel;
@synthesize imageSize = _imageSize;
+ (NSString*)reuseIdentifier { + (NSString*)reuseIdentifier {
NOTREACHED(); NOTREACHED();
...@@ -77,7 +76,6 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -77,7 +76,6 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
- (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
_propertyReleaser_BookmarkCell.Init(self, [BookmarkCell class]);
self.exclusiveTouch = YES; self.exclusiveTouch = YES;
self.backgroundColor = [UIColor whiteColor]; self.backgroundColor = [UIColor whiteColor];
...@@ -102,8 +100,7 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -102,8 +100,7 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
_highlightCover.translatesAutoresizingMaskIntoConstraints = NO; _highlightCover.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_highlightCover]; [self.contentView addSubview:_highlightCover];
self.button = base::scoped_nsobject<BookmarkExtendedButton>( self.button = [[BookmarkExtendedButton alloc] init];
[[BookmarkExtendedButton alloc] init]);
self.button.contentMode = UIViewContentModeCenter; self.button.contentMode = UIViewContentModeCenter;
self.button.backgroundColor = [UIColor clearColor]; self.button.backgroundColor = [UIColor clearColor];
[self.button addTarget:self [self.button addTarget:self
...@@ -127,7 +124,7 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -127,7 +124,7 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
} }
- (void)updateConstraints { - (void)updateConstraints {
if (_imageSize) { if (self.imageSize) {
// Create constraints. // Create constraints.
// Align all the views on the same horizontal line. // Align all the views on the same horizontal line.
...@@ -152,10 +149,10 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -152,10 +149,10 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
@"highlight" : self.highlightCover @"highlight" : self.highlightCover
}, },
@{ @{
@"buttonSize" : [NSNumber numberWithFloat:32.0], @"buttonSize" :@32.0,
@"leadingImageMargin" : [NSNumber numberWithFloat:16.0], @"leadingImageMargin" : @16.0,
@"leadingMargin" : [NSNumber numberWithFloat:64.0], @"leadingMargin" : @64.0,
@"imageSize" : [NSNumber numberWithFloat:_imageSize], @"imageSize" : @(self.imageSize),
}, },
self.contentView); self.contentView);
// clang-format on // clang-format on
...@@ -247,8 +244,8 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -247,8 +244,8 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
if (highlighted) { if (highlighted) {
// Creates an ink feedback and animates it. // Creates an ink feedback and animates it.
base::scoped_nsobject<MDCInkView> touchFeedbackView( MDCInkView* touchFeedbackView =
[[MDCInkView alloc] initWithFrame:self.bounds]); [[MDCInkView alloc] initWithFrame:self.bounds];
[self addSubview:touchFeedbackView]; [self addSubview:touchFeedbackView];
self.touchFeedbackView = touchFeedbackView; self.touchFeedbackView = touchFeedbackView;
[self.touchFeedbackView startTouchBeganAnimationAtPoint:self.touchLocation [self.touchFeedbackView startTouchBeganAnimationAtPoint:self.touchLocation
...@@ -272,9 +269,12 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -272,9 +269,12 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
} }
- (void)buttonTapped:(id)target { - (void)buttonTapped:(id)target {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self.buttonTarget performSelector:self.buttonAction [self.buttonTarget performSelector:self.buttonAction
withObject:self withObject:self
withObject:target]; withObject:target];
#pragma clang diagnostic pop
} }
- (void)showButtonOfType:(bookmark_cell::ButtonType)buttonType - (void)showButtonOfType:(bookmark_cell::ButtonType)buttonType
...@@ -355,11 +355,6 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -355,11 +355,6 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
#pragma mark - BookmarkItemCell #pragma mark - BookmarkItemCell
@interface BookmarkItemCell () {
base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkItemCell;
}
@end
@implementation BookmarkItemCell @implementation BookmarkItemCell
+ (NSString*)reuseIdentifier { + (NSString*)reuseIdentifier {
...@@ -373,15 +368,13 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -373,15 +368,13 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
- (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
_propertyReleaser_BookmarkItemCell.Init(self, [BookmarkItemCell class]);
// Set the non-layout properties of the titles. // Set the non-layout properties of the titles.
UIFont* font = [MDCTypography subheadFont]; UIFont* font = [MDCTypography subheadFont];
self.titleLabel.font = font; self.titleLabel.font = font;
self.titleLabel.backgroundColor = [UIColor clearColor]; self.titleLabel.backgroundColor = [UIColor clearColor];
self.titleLabel.numberOfLines = 1; self.titleLabel.numberOfLines = 1;
_imageSize = kBookmarkItemCellDefaultImageSize; self.imageSize = kBookmarkItemCellDefaultImageSize;
} }
return self; return self;
} }
...@@ -406,13 +399,6 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -406,13 +399,6 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
@end @end
#pragma mark - BookmarkFolderCell #pragma mark - BookmarkFolderCell
@interface BookmarkFolderCell () {
base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkFolderCell;
}
@end
@implementation BookmarkFolderCell @implementation BookmarkFolderCell
+ (NSString*)reuseIdentifier { + (NSString*)reuseIdentifier {
...@@ -422,12 +408,10 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -422,12 +408,10 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
- (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
_propertyReleaser_BookmarkFolderCell.Init(self, [BookmarkFolderCell class]);
self.imageView.image = [UIImage imageNamed:@"bookmark_gray_folder"]; self.imageView.image = [UIImage imageNamed:@"bookmark_gray_folder"];
self.titleLabel.font = [MDCTypography subheadFont]; self.titleLabel.font = [MDCTypography subheadFont];
_imageSize = kBookmarkFolderCellDefaultImageSize; self.imageSize = kBookmarkFolderCellDefaultImageSize;
} }
return self; return self;
} }
...@@ -448,14 +432,13 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -448,14 +432,13 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
#pragma mark - BookmarkHeaderView #pragma mark - BookmarkHeaderView
@interface BookmarkHeaderView () { @interface BookmarkHeaderView ()
base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkHeaderView; @property(nonatomic, strong) UILabel* titleLabel;
}
@property(nonatomic, retain) UILabel* titleLabel;
@end @end
@implementation BookmarkHeaderView @implementation BookmarkHeaderView
@synthesize titleLabel = _titleLabel; @synthesize titleLabel = _titleLabel;
+ (NSString*)reuseIdentifier { + (NSString*)reuseIdentifier {
return @"BookmarkHeaderView"; return @"BookmarkHeaderView";
} }
...@@ -467,9 +450,7 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -467,9 +450,7 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
- (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
_propertyReleaser_BookmarkHeaderView.Init(self, [BookmarkHeaderView class]); UILabel* titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
base::scoped_nsobject<UILabel> titleLabel(
[[UILabel alloc] initWithFrame:CGRectZero]);
self.titleLabel = titleLabel; self.titleLabel = titleLabel;
UIFont* font = [MDCTypography body2Font]; UIFont* font = [MDCTypography body2Font];
self.titleLabel.font = font; self.titleLabel.font = font;
...@@ -507,11 +488,9 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -507,11 +488,9 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
#pragma mark - BookmarkHeaderSeparatorView #pragma mark - BookmarkHeaderSeparatorView
@interface BookmarkHeaderSeparatorView () { @interface BookmarkHeaderSeparatorView ()
base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkHeaderSeparatorView;
}
// The bottom separator line. // The bottom separator line.
@property(nonatomic, retain) UIView* lineView; @property(nonatomic, strong) UIView* lineView;
@end @end
@implementation BookmarkHeaderSeparatorView @implementation BookmarkHeaderSeparatorView
...@@ -529,8 +508,6 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; ...@@ -529,8 +508,6 @@ const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0;
- (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
_propertyReleaser_BookmarkHeaderSeparatorView.Init(
self, [BookmarkHeaderSeparatorView class]);
_lineView = [[UIView alloc] init]; _lineView = [[UIView alloc] init];
_lineView.backgroundColor = bookmark_utils_ios::separatorColor(); _lineView.backgroundColor = bookmark_utils_ios::separatorColor();
[self addSubview:_lineView]; [self addSubview:_lineView];
......
...@@ -213,7 +213,7 @@ class ChromeBrowserState; ...@@ -213,7 +213,7 @@ class ChromeBrowserState;
#pragma mark - Commonly used properties #pragma mark - Commonly used properties
@property(nonatomic, assign, readonly) bookmarks::BookmarkModel* bookmarkModel; @property(nonatomic, assign, readonly) bookmarks::BookmarkModel* bookmarkModel;
@property(nonatomic, assign, readonly) id<UrlLoader> loader; @property(nonatomic, weak, readonly) id<UrlLoader> loader;
@property(nonatomic, assign, readonly) ios::ChromeBrowserState* browserState; @property(nonatomic, assign, readonly) ios::ChromeBrowserState* browserState;
#pragma mark - Editing #pragma mark - Editing
......
...@@ -9,11 +9,8 @@ ...@@ -9,11 +9,8 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include "base/ios/weak_nsobject.h"
#include "base/mac/bind_objc_block.h" #include "base/mac/bind_objc_block.h"
#include "base/mac/foundation_util.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" #include "base/strings/sys_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_model_observer.h" #include "components/bookmarks/browser/bookmark_model_observer.h"
...@@ -34,6 +31,10 @@ ...@@ -34,6 +31,10 @@
#include "skia/ext/skia_utils_ios.h" #include "skia/ext/skia_utils_ios.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using bookmarks::BookmarkNode; using bookmarks::BookmarkNode;
namespace { namespace {
...@@ -62,8 +63,6 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; ...@@ -62,8 +63,6 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0;
std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge; std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge;
ios::ChromeBrowserState* _browserState; ios::ChromeBrowserState* _browserState;
base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkCollectionView;
// Map of favicon load tasks for each index path. Used to keep track of // Map of favicon load tasks for each index path. Used to keep track of
// pending favicon load operations so that they can be cancelled upon cell // pending favicon load operations so that they can be cancelled upon cell
// reuse. Keys are (section, item) pairs of cell index paths. // reuse. Keys are (section, item) pairs of cell index paths.
...@@ -75,16 +74,16 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; ...@@ -75,16 +74,16 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0;
// Redefined to be readwrite. // Redefined to be readwrite.
@property(nonatomic, assign) bookmarks::BookmarkModel* bookmarkModel; @property(nonatomic, assign) bookmarks::BookmarkModel* bookmarkModel;
// Redefined to be readwrite. // Redefined to be readwrite.
@property(nonatomic, retain) UICollectionView* collectionView; @property(nonatomic, strong) UICollectionView* collectionView;
// Redefined to be readwrite. // Redefined to be readwrite.
@property(nonatomic, assign) BOOL editing; @property(nonatomic, assign) BOOL editing;
// Detects a long press on a cell. // Detects a long press on a cell.
@property(nonatomic, retain) UILongPressGestureRecognizer* longPressRecognizer; @property(nonatomic, strong) UILongPressGestureRecognizer* longPressRecognizer;
// Background view of the collection view shown when there is no items. // Background view of the collection view shown when there is no items.
@property(nonatomic, retain) @property(nonatomic, strong)
BookmarkCollectionViewBackground* emptyCollectionBackgroundView; BookmarkCollectionViewBackground* emptyCollectionBackgroundView;
// Shadow to display over the content. // Shadow to display over the content.
@property(nonatomic, retain) UIView* shadow; @property(nonatomic, strong) UIView* shadow;
// Updates the editing state for the cell. // Updates the editing state for the cell.
- (void)updateEditingStateOfCell:(BookmarkCell*)cell - (void)updateEditingStateOfCell:(BookmarkCell*)cell
...@@ -137,9 +136,6 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; ...@@ -137,9 +136,6 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0;
frame:(CGRect)frame { frame:(CGRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
_propertyReleaser_BookmarkCollectionView.Init(
self, [BookmarkCollectionView class]);
_browserState = browserState; _browserState = browserState;
// Set up connection to the BookmarkModel. // Set up connection to the BookmarkModel.
...@@ -170,17 +166,16 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; ...@@ -170,17 +166,16 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0;
[moi self]; [moi self];
}); });
_faviconTaskTracker.TryCancelAll(); _faviconTaskTracker.TryCancelAll();
[super dealloc];
} }
- (void)setupViews { - (void)setupViews {
self.backgroundColor = bookmark_utils_ios::mainBackgroundColor(); self.backgroundColor = bookmark_utils_ios::mainBackgroundColor();
base::scoped_nsobject<UICollectionViewFlowLayout> layout( UICollectionViewFlowLayout* layout =
[[UICollectionViewFlowLayout alloc] init]); [[UICollectionViewFlowLayout alloc] init];
base::scoped_nsobject<UICollectionView> collectionView( UICollectionView* collectionView =
[[UICollectionView alloc] initWithFrame:self.bounds [[UICollectionView alloc] initWithFrame:self.bounds
collectionViewLayout:layout]); collectionViewLayout:layout];
self.collectionView = collectionView; self.collectionView = collectionView;
self.collectionView.backgroundColor = [UIColor clearColor]; self.collectionView.backgroundColor = [UIColor clearColor];
self.collectionView.autoresizingMask = self.collectionView.autoresizingMask =
...@@ -205,9 +200,8 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; ...@@ -205,9 +200,8 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0;
[self addSubview:self.collectionView]; [self addSubview:self.collectionView];
// Set up the background view shown when the collection is empty. // Set up the background view shown when the collection is empty.
base::scoped_nsobject<BookmarkCollectionViewBackground> BookmarkCollectionViewBackground* emptyCollectionBackgroundView =
emptyCollectionBackgroundView( [[BookmarkCollectionViewBackground alloc] initWithFrame:CGRectZero];
[[BookmarkCollectionViewBackground alloc] initWithFrame:CGRectZero]);
self.emptyCollectionBackgroundView = emptyCollectionBackgroundView; self.emptyCollectionBackgroundView = emptyCollectionBackgroundView;
self.emptyCollectionBackgroundView.autoresizingMask = self.emptyCollectionBackgroundView.autoresizingMask =
UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
...@@ -219,11 +213,9 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; ...@@ -219,11 +213,9 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0;
[self updateShadow]; [self updateShadow];
self.longPressRecognizer = self.longPressRecognizer = [[UILongPressGestureRecognizer alloc]
base::scoped_nsobject<UILongPressGestureRecognizer>( initWithTarget:self
[[UILongPressGestureRecognizer alloc] action:@selector(longPress:)];
initWithTarget:self
action:@selector(longPress:)]);
self.longPressRecognizer.delegate = self; self.longPressRecognizer.delegate = self;
[self.collectionView addGestureRecognizer:self.longPressRecognizer]; [self.collectionView addGestureRecognizer:self.longPressRecognizer];
} }
...@@ -240,10 +232,9 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; ...@@ -240,10 +232,9 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0;
self.shadow = self.shadow =
bookmark_utils_ios::dropShadowWithWidth(CGRectGetWidth(self.bounds)); bookmark_utils_ios::dropShadowWithWidth(CGRectGetWidth(self.bounds));
} else { } else {
self.shadow = [[[UIView alloc] self.shadow = [[UIView alloc]
initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds),
1 / [[UIScreen mainScreen] scale])] 1 / [[UIScreen mainScreen] scale])];
autorelease];
self.shadow.backgroundColor = [UIColor colorWithWhite:0.0 alpha:.12]; self.shadow.backgroundColor = [UIColor colorWithWhite:0.0 alpha:.12];
} }
...@@ -486,12 +477,12 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; ...@@ -486,12 +477,12 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0;
[self cancelLoadingFaviconAtIndexPath:indexPath]; [self cancelLoadingFaviconAtIndexPath:indexPath];
// Start loading a favicon. // Start loading a favicon.
base::WeakNSObject<BookmarkCollectionView> weakSelf(self); __weak BookmarkCollectionView* weakSelf = self;
const bookmarks::BookmarkNode* node = [self nodeAtIndexPath:indexPath]; const bookmarks::BookmarkNode* node = [self nodeAtIndexPath:indexPath];
GURL blockURL(node->url()); GURL blockURL(node->url());
void (^faviconBlock)(const favicon_base::LargeIconResult&) = ^( void (^faviconBlock)(const favicon_base::LargeIconResult&) = ^(
const favicon_base::LargeIconResult& result) { const favicon_base::LargeIconResult& result) {
base::scoped_nsobject<BookmarkCollectionView> strongSelf([weakSelf retain]); BookmarkCollectionView* strongSelf = weakSelf;
if (!strongSelf) if (!strongSelf)
return; return;
UIImage* favIcon = nil; UIImage* favIcon = nil;
...@@ -499,8 +490,7 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; ...@@ -499,8 +490,7 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0;
UIColor* textColor = nil; UIColor* textColor = nil;
NSString* fallbackText = nil; NSString* fallbackText = nil;
if (result.bitmap.is_valid()) { if (result.bitmap.is_valid()) {
scoped_refptr<base::RefCountedMemory> data = scoped_refptr<base::RefCountedMemory> data = result.bitmap.bitmap_data;
result.bitmap.bitmap_data.get();
favIcon = [UIImage imageWithData:[NSData dataWithBytes:data->front() favIcon = [UIImage imageWithData:[NSData dataWithBytes:data->front()
length:data->size()]]; length:data->size()]];
} else if (result.fallback_icon_style) { } else if (result.fallback_icon_style) {
...@@ -527,7 +517,7 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; ...@@ -527,7 +517,7 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0;
base::CancelableTaskTracker::TaskId taskId = base::CancelableTaskTracker::TaskId taskId =
IOSChromeLargeIconServiceFactory::GetForBrowserState(self.browserState) IOSChromeLargeIconServiceFactory::GetForBrowserState(self.browserState)
->GetLargeIconOrFallbackStyle(node->url(), minSize, preferredSize, ->GetLargeIconOrFallbackStyle(node->url(), minSize, preferredSize,
base::BindBlock(faviconBlock), base::BindBlockArc(faviconBlock),
&_faviconTaskTracker); &_faviconTaskTracker);
_faviconLoadTasks[IntegerPair(indexPath.section, indexPath.item)] = taskId; _faviconLoadTasks[IntegerPair(indexPath.section, indexPath.item)] = taskId;
} }
...@@ -701,8 +691,7 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; ...@@ -701,8 +691,7 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0;
UICollectionViewCell* cell = UICollectionViewCell* cell =
[self.collectionView cellForItemAtIndexPath:indexPath]; [self.collectionView cellForItemAtIndexPath:indexPath];
if (!cell) { if (!cell) {
cell = [[[BookmarkPromoCell alloc] initWithFrame:estimatedFrame] cell = [[BookmarkPromoCell alloc] initWithFrame:estimatedFrame];
autorelease];
} }
cell.frame = estimatedFrame; cell.frame = estimatedFrame;
[cell layoutIfNeeded]; [cell layoutIfNeeded];
......
...@@ -4,9 +4,12 @@ ...@@ -4,9 +4,12 @@
#include "ios/chrome/browser/ui/bookmarks/bookmark_collection_view_background.h" #include "ios/chrome/browser/ui/bookmarks/bookmark_collection_view_background.h"
#include "base/mac/objc_property_releaser.h"
#import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoFontLoader.h" #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoFontLoader.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace { namespace {
NSString* const kBookmarkGrayStar = @"bookmark_gray_star_large"; NSString* const kBookmarkGrayStar = @"bookmark_gray_star_large";
const CGFloat kEmptyBookmarkTextSize = 16.0; const CGFloat kEmptyBookmarkTextSize = 16.0;
...@@ -14,10 +17,7 @@ const CGFloat kEmptyBookmarkTextSize = 16.0; ...@@ -14,10 +17,7 @@ const CGFloat kEmptyBookmarkTextSize = 16.0;
const CGFloat kImageViewOffsetFromText = 5.0; const CGFloat kImageViewOffsetFromText = 5.0;
} // namespace } // namespace
@interface BookmarkCollectionViewBackground () { @interface BookmarkCollectionViewBackground ()
base::mac::ObjCPropertyReleaser
_propertyReleaser_BookmarkBookmarkCollectionViewBackground;
}
// Star image view shown on top of the label. // Star image view shown on top of the label.
@property(nonatomic, retain) UIImageView* emptyBookmarksImageView; @property(nonatomic, retain) UIImageView* emptyBookmarksImageView;
...@@ -34,8 +34,6 @@ const CGFloat kImageViewOffsetFromText = 5.0; ...@@ -34,8 +34,6 @@ const CGFloat kImageViewOffsetFromText = 5.0;
- (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
_propertyReleaser_BookmarkBookmarkCollectionViewBackground.Init(
self, [BookmarkCollectionViewBackground class]);
_emptyBookmarksImageView = [self newBookmarkImageView]; _emptyBookmarksImageView = [self newBookmarkImageView];
[self addSubview:_emptyBookmarksImageView]; [self addSubview:_emptyBookmarksImageView];
_emptyBookmarksLabel = [self newEmptyBookmarkLabel]; _emptyBookmarksLabel = [self newEmptyBookmarkLabel];
......
...@@ -8,23 +8,26 @@ ...@@ -8,23 +8,26 @@
#import "ios/chrome/browser/ui/bookmarks/bookmark_home_handset_view_controller.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_home_handset_view_controller.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_home_tablet_ntp_controller.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_home_tablet_ntp_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation BookmarkControllerFactory @implementation BookmarkControllerFactory
- (BookmarkHomeViewController*) - (BookmarkHomeViewController*)
bookmarkControllerWithBrowserState:(ios::ChromeBrowserState*)browserState bookmarkControllerWithBrowserState:(ios::ChromeBrowserState*)browserState
loader:(id<UrlLoader>)loader { loader:(id<UrlLoader>)loader {
return [[[BookmarkHomeHandsetViewController alloc] return
initWithLoader:loader [[BookmarkHomeHandsetViewController alloc] initWithLoader:loader
browserState:browserState] autorelease]; browserState:browserState];
} }
- (id<NewTabPagePanelProtocol>) - (id<NewTabPagePanelProtocol>)
bookmarkPanelControllerForBrowserState:(ios::ChromeBrowserState*)browserState bookmarkPanelControllerForBrowserState:(ios::ChromeBrowserState*)browserState
loader:(id<UrlLoader>)loader loader:(id<UrlLoader>)loader
colorCache:(NSMutableDictionary*)cache { colorCache:(NSMutableDictionary*)cache {
return [[[BookmarkHomeTabletNTPController alloc] initWithLoader:loader return [[BookmarkHomeTabletNTPController alloc] initWithLoader:loader
browserState:browserState] browserState:browserState];
autorelease];
} }
@end @end
...@@ -43,7 +43,7 @@ class ChromeBrowserState; ...@@ -43,7 +43,7 @@ class ChromeBrowserState;
// changes underneath it. // changes underneath it.
@interface BookmarkEditViewController : CollectionViewController @interface BookmarkEditViewController : CollectionViewController
@property(nonatomic, assign) id<BookmarkEditViewControllerDelegate> delegate; @property(nonatomic, weak) id<BookmarkEditViewControllerDelegate> delegate;
// Designated initializer. // Designated initializer.
// |bookmark|: mustn't be NULL at initialization time. It also mustn't be a // |bookmark|: mustn't be NULL at initialization time. It also mustn't be a
......
...@@ -9,13 +9,11 @@ ...@@ -9,13 +9,11 @@
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/ios/block_types.h" #include "base/ios/block_types.h"
#include "base/ios/weak_nsobject.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/bind_objc_block.h" #include "base/mac/bind_objc_block.h"
#import "base/mac/foundation_util.h" #import "base/mac/foundation_util.h"
#include "base/mac/objc_property_releaser.h"
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/url_formatter/url_fixer.h" #include "components/url_formatter/url_fixer.h"
...@@ -45,6 +43,10 @@ ...@@ -45,6 +43,10 @@
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "url/gurl.h" #include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using bookmarks::BookmarkModel; using bookmarks::BookmarkModel;
using bookmarks::BookmarkNode; using bookmarks::BookmarkNode;
...@@ -78,8 +80,6 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -78,8 +80,6 @@ typedef NS_ENUM(NSInteger, ItemType) {
BOOL _ignoresBookmarkModelChanges; BOOL _ignoresBookmarkModelChanges;
std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge; std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge;
base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkEditViewController;
} }
// The bookmark this controller displays or edits. // The bookmark this controller displays or edits.
...@@ -97,20 +97,20 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -97,20 +97,20 @@ typedef NS_ENUM(NSInteger, ItemType) {
// The folder picker view controller. // The folder picker view controller.
// Redefined to be readwrite. // Redefined to be readwrite.
@property(nonatomic, retain) BookmarkFolderViewController* folderViewController; @property(nonatomic, strong) BookmarkFolderViewController* folderViewController;
@property(nonatomic, assign) ios::ChromeBrowserState* browserState; @property(nonatomic, assign) ios::ChromeBrowserState* browserState;
// Cancel button item in navigation bar. // Cancel button item in navigation bar.
@property(nonatomic, retain) UIBarButtonItem* cancelItem; @property(nonatomic, strong) UIBarButtonItem* cancelItem;
// Done button item in navigation bar. // Done button item in navigation bar.
@property(nonatomic, retain) UIBarButtonItem* doneItem; @property(nonatomic, strong) UIBarButtonItem* doneItem;
// CollectionViewItem-s from the collection. // CollectionViewItem-s from the collection.
@property(nonatomic, retain) BookmarkTextFieldItem* nameItem; @property(nonatomic, strong) BookmarkTextFieldItem* nameItem;
@property(nonatomic, retain) BookmarkParentFolderItem* folderItem; @property(nonatomic, strong) BookmarkParentFolderItem* folderItem;
@property(nonatomic, retain) BookmarkTextFieldItem* URLItem; @property(nonatomic, strong) BookmarkTextFieldItem* URLItem;
// Reports the changes to the delegate, that has the responsibility to save the // Reports the changes to the delegate, that has the responsibility to save the
// bookmark. // bookmark.
...@@ -168,8 +168,6 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -168,8 +168,6 @@ typedef NS_ENUM(NSInteger, ItemType) {
DCHECK(browserState); DCHECK(browserState);
self = [super initWithStyle:CollectionViewControllerStyleAppBar]; self = [super initWithStyle:CollectionViewControllerStyleAppBar];
if (self) { if (self) {
_propertyReleaser_BookmarkEditViewController.Init(
self, [BookmarkEditViewController class]);
DCHECK(!bookmark->is_folder()); DCHECK(!bookmark->is_folder());
DCHECK(!browserState->IsOffTheRecord()); DCHECK(!browserState->IsOffTheRecord());
_bookmark = bookmark; _bookmark = bookmark;
...@@ -189,7 +187,6 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -189,7 +187,6 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)dealloc { - (void)dealloc {
_folderViewController.delegate = nil; _folderViewController.delegate = nil;
[super dealloc];
} }
#pragma mark View lifecycle #pragma mark View lifecycle
...@@ -211,36 +208,34 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -211,36 +208,34 @@ typedef NS_ENUM(NSInteger, ItemType) {
self.navigationItem.leftBarButtonItem = cancelItem; self.navigationItem.leftBarButtonItem = cancelItem;
self.cancelItem = cancelItem; self.cancelItem = cancelItem;
base::scoped_nsobject<UIBarButtonItem> doneItem([[UIBarButtonItem alloc] UIBarButtonItem* doneItem = [[UIBarButtonItem alloc]
initWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_DONE_BUTTON) initWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_DONE_BUTTON)
style:UIBarButtonItemStylePlain style:UIBarButtonItemStylePlain
target:self target:self
action:@selector(save)]); action:@selector(save)];
doneItem.get().accessibilityIdentifier = @"Done"; doneItem.accessibilityIdentifier = @"Done";
self.navigationItem.rightBarButtonItem = doneItem; self.navigationItem.rightBarButtonItem = doneItem;
self.doneItem = doneItem; self.doneItem = doneItem;
base::scoped_nsobject<BookmarksElevatedToolbar> buttonBar( BookmarksElevatedToolbar* buttonBar = [[BookmarksElevatedToolbar alloc] init];
[[BookmarksElevatedToolbar alloc] init]); UIBarButtonItem* deleteItem = [[UIBarButtonItem alloc]
base::scoped_nsobject<UIBarButtonItem> deleteItem([[UIBarButtonItem alloc]
initWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_DELETE) initWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_DELETE)
style:UIBarButtonItemStylePlain style:UIBarButtonItemStylePlain
target:self target:self
action:@selector(deleteBookmark)]); action:@selector(deleteBookmark)];
deleteItem.get().accessibilityIdentifier = @"Delete_action"; deleteItem.accessibilityIdentifier = @"Delete_action";
[deleteItem setTitleTextAttributes:@{ [deleteItem setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor blackColor] NSForegroundColorAttributeName : [UIColor blackColor]
} }
forState:UIControlStateNormal]; forState:UIControlStateNormal];
[buttonBar.get().layer [buttonBar.layer addSublayer:[[MDCShadowLayer alloc] init]];
addSublayer:[[[MDCShadowLayer alloc] init] autorelease]]; buttonBar.shadowElevation = MDCShadowElevationSearchBarResting;
buttonBar.get().shadowElevation = MDCShadowElevationSearchBarResting; buttonBar.backgroundColor = [UIColor whiteColor];
buttonBar.get().backgroundColor = [UIColor whiteColor]; buttonBar.items = @[ deleteItem ];
buttonBar.get().items = @[ deleteItem ];
[self.view addSubview:buttonBar]; [self.view addSubview:buttonBar];
// Constraint |buttonBar| to be in bottom // Constraint |buttonBar| to be in bottom
buttonBar.get().translatesAutoresizingMaskIntoConstraints = NO; buttonBar.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addConstraints: [self.view addConstraints:
[NSLayoutConstraint [NSLayoutConstraint
constraintsWithVisualFormat:@"H:|[buttonBar]|" constraintsWithVisualFormat:@"H:|[buttonBar]|"
...@@ -348,8 +343,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -348,8 +343,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
[model addSectionWithIdentifier:SectionIdentifierInfo]; [model addSectionWithIdentifier:SectionIdentifierInfo];
self.nameItem = self.nameItem = [[BookmarkTextFieldItem alloc] initWithType:ItemTypeName];
[[[BookmarkTextFieldItem alloc] initWithType:ItemTypeName] autorelease];
self.nameItem.accessibilityIdentifier = @"Title Field"; self.nameItem.accessibilityIdentifier = @"Title Field";
self.nameItem.placeholder = self.nameItem.placeholder =
l10n_util::GetNSString(IDS_IOS_BOOKMARK_NAME_FIELD_HEADER); l10n_util::GetNSString(IDS_IOS_BOOKMARK_NAME_FIELD_HEADER);
...@@ -357,13 +351,12 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -357,13 +351,12 @@ typedef NS_ENUM(NSInteger, ItemType) {
self.nameItem.delegate = self; self.nameItem.delegate = self;
[model addItem:self.nameItem toSectionWithIdentifier:SectionIdentifierInfo]; [model addItem:self.nameItem toSectionWithIdentifier:SectionIdentifierInfo];
self.folderItem = [[[BookmarkParentFolderItem alloc] self.folderItem =
initWithType:ItemTypeFolder] autorelease]; [[BookmarkParentFolderItem alloc] initWithType:ItemTypeFolder];
self.folderItem.title = bookmark_utils_ios::TitleForBookmarkNode(self.folder); self.folderItem.title = bookmark_utils_ios::TitleForBookmarkNode(self.folder);
[model addItem:self.folderItem toSectionWithIdentifier:SectionIdentifierInfo]; [model addItem:self.folderItem toSectionWithIdentifier:SectionIdentifierInfo];
self.URLItem = self.URLItem = [[BookmarkTextFieldItem alloc] initWithType:ItemTypeURL];
[[[BookmarkTextFieldItem alloc] initWithType:ItemTypeURL] autorelease];
self.URLItem.accessibilityIdentifier = @"URL Field"; self.URLItem.accessibilityIdentifier = @"URL Field";
self.URLItem.placeholder = self.URLItem.placeholder =
l10n_util::GetNSString(IDS_IOS_BOOKMARK_URL_FIELD_HEADER); l10n_util::GetNSString(IDS_IOS_BOOKMARK_URL_FIELD_HEADER);
...@@ -410,14 +403,14 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -410,14 +403,14 @@ typedef NS_ENUM(NSInteger, ItemType) {
std::set<const BookmarkNode*> editedNodes; std::set<const BookmarkNode*> editedNodes;
editedNodes.insert(self.bookmark); editedNodes.insert(self.bookmark);
base::scoped_nsobject<BookmarkFolderViewController> folderViewController( BookmarkFolderViewController* folderViewController =
[[BookmarkFolderViewController alloc] [[BookmarkFolderViewController alloc]
initWithBookmarkModel:self.bookmarkModel initWithBookmarkModel:self.bookmarkModel
allowsNewFolders:YES allowsNewFolders:YES
editedNodes:editedNodes editedNodes:editedNodes
allowsCancel:NO allowsCancel:NO
selectedFolder:self.folder]); selectedFolder:self.folder];
folderViewController.get().delegate = self; folderViewController.delegate = self;
self.folderViewController = folderViewController; self.folderViewController = folderViewController;
[self.navigationController pushViewController:self.folderViewController [self.navigationController pushViewController:self.folderViewController
...@@ -583,7 +576,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -583,7 +576,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
#pragma mark - UIResponder #pragma mark - UIResponder
- (NSArray*)keyCommands { - (NSArray*)keyCommands {
base::WeakNSObject<BookmarkEditViewController> weakSelf(self); __weak BookmarkEditViewController* weakSelf = self;
return @[ [UIKeyCommand cr_keyCommandWithInput:UIKeyInputEscape return @[ [UIKeyCommand cr_keyCommandWithInput:UIKeyInputEscape
modifierFlags:Cr_UIKeyModifierNone modifierFlags:Cr_UIKeyModifierNone
title:nil title:nil
......
...@@ -4,27 +4,16 @@ ...@@ -4,27 +4,16 @@
#import "ios/chrome/browser/ui/bookmarks/bookmark_elevated_toolbar.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_elevated_toolbar.h"
#include "base/mac/objc_property_releaser.h"
#import "ios/third_party/material_components_ios/src/components/ShadowElevations/src/MaterialShadowElevations.h" #import "ios/third_party/material_components_ios/src/components/ShadowElevations/src/MaterialShadowElevations.h"
#import "ios/third_party/material_components_ios/src/components/ShadowLayer/src/MaterialShadowLayer.h" #import "ios/third_party/material_components_ios/src/components/ShadowLayer/src/MaterialShadowLayer.h"
@implementation BookmarksElevatedToolbar { #if !defined(__has_feature) || !__has_feature(objc_arc)
base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarksElevatedToolbar; #error "This file requires ARC support."
} #endif
@implementation BookmarksElevatedToolbar
@synthesize shadowLayer = _shadowLayer; @synthesize shadowLayer = _shadowLayer;
#pragma mark - Lifecycle
- (instancetype)init {
self = [super init];
if (self) {
_propertyReleaser_BookmarksElevatedToolbar.Init(
self, [BookmarksElevatedToolbar class]);
}
return self;
}
#pragma mark - Properties #pragma mark - Properties
- (MDCShadowLayer*)shadowLayer { - (MDCShadowLayer*)shadowLayer {
......
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
#include "base/logging.h" #include "base/logging.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace { namespace {
// Apple's guidelines indicate that buttons should have a minimum touch area of // Apple's guidelines indicate that buttons should have a minimum touch area of
// 44pt x 44pt. // 44pt x 44pt.
......
...@@ -31,7 +31,7 @@ class BookmarkNode; ...@@ -31,7 +31,7 @@ class BookmarkNode;
// Called when something outside the view causes the promo state to change. // Called when something outside the view causes the promo state to change.
- (void)promoStateChangedAnimated:(BOOL)animate; - (void)promoStateChangedAnimated:(BOOL)animate;
@property(nonatomic, assign) id<BookmarkFolderCollectionViewDelegate> delegate; @property(nonatomic, weak) id<BookmarkFolderCollectionViewDelegate> delegate;
@property(nonatomic, assign, readonly) const bookmarks::BookmarkNode* folder; @property(nonatomic, assign, readonly) const bookmarks::BookmarkNode* folder;
@end @end
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#import "ios/chrome/browser/ui/bookmarks/bookmark_folder_collection_view.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_collection_view.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/objc_property_releaser.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "ios/chrome/browser/bookmarks/bookmarks_utils.h" #include "ios/chrome/browser/bookmarks/bookmarks_utils.h"
...@@ -14,11 +13,13 @@ ...@@ -14,11 +13,13 @@
#import "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using bookmarks::BookmarkNode; using bookmarks::BookmarkNode;
@interface BookmarkFolderCollectionView ()<BookmarkPromoCellDelegate> { @interface BookmarkFolderCollectionView ()<BookmarkPromoCellDelegate> {
base::mac::ObjCPropertyReleaser
_propertyReleaser_BookmarkFolderCollectionView;
// A vector of folders to display in the collection view. // A vector of folders to display in the collection view.
std::vector<const BookmarkNode*> _subFolders; std::vector<const BookmarkNode*> _subFolders;
// A vector of bookmark urls to display in the collection view. // A vector of bookmark urls to display in the collection view.
...@@ -36,7 +37,7 @@ using bookmarks::BookmarkNode; ...@@ -36,7 +37,7 @@ using bookmarks::BookmarkNode;
@property(nonatomic, readonly, assign) NSInteger sectionCount; @property(nonatomic, readonly, assign) NSInteger sectionCount;
// Keep a reference to the promo cell to deregister as delegate. // Keep a reference to the promo cell to deregister as delegate.
@property(nonatomic, retain) BookmarkPromoCell* promoCell; @property(nonatomic, strong) BookmarkPromoCell* promoCell;
@end @end
...@@ -49,9 +50,6 @@ using bookmarks::BookmarkNode; ...@@ -49,9 +50,6 @@ using bookmarks::BookmarkNode;
frame:(CGRect)frame { frame:(CGRect)frame {
self = [super initWithBrowserState:browserState frame:frame]; self = [super initWithBrowserState:browserState frame:frame];
if (self) { if (self) {
_propertyReleaser_BookmarkFolderCollectionView.Init(
self, [BookmarkFolderCollectionView class]);
[self updateCollectionView]; [self updateCollectionView];
} }
return self; return self;
...@@ -59,7 +57,6 @@ using bookmarks::BookmarkNode; ...@@ -59,7 +57,6 @@ using bookmarks::BookmarkNode;
- (void)dealloc { - (void)dealloc {
_promoCell.delegate = nil; _promoCell.delegate = nil;
[super dealloc];
} }
- (void)setDelegate:(id<BookmarkFolderCollectionViewDelegate>)delegate { - (void)setDelegate:(id<BookmarkFolderCollectionViewDelegate>)delegate {
......
...@@ -39,7 +39,7 @@ class ChromeBrowserState; ...@@ -39,7 +39,7 @@ class ChromeBrowserState;
// bookmark model can affect this controller's state. // bookmark model can affect this controller's state.
@interface BookmarkFolderEditorViewController : CollectionViewController @interface BookmarkFolderEditorViewController : CollectionViewController
@property(nonatomic, assign) id<BookmarkFolderEditorViewControllerDelegate> @property(nonatomic, weak) id<BookmarkFolderEditorViewControllerDelegate>
delegate; delegate;
// Designated factory methods. // Designated factory methods.
......
...@@ -8,11 +8,9 @@ ...@@ -8,11 +8,9 @@
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#import "base/ios/weak_nsobject.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/foundation_util.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" #include "base/strings/sys_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_node.h" #include "components/bookmarks/browser/bookmark_node.h"
...@@ -35,6 +33,10 @@ ...@@ -35,6 +33,10 @@
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h" #import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using bookmarks::BookmarkNode; using bookmarks::BookmarkNode;
namespace { namespace {
...@@ -55,8 +57,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -55,8 +57,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
BookmarkModelBridgeObserver, BookmarkModelBridgeObserver,
BookmarkTextFieldItemDelegate> { BookmarkTextFieldItemDelegate> {
std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge; std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge;
base::mac::ObjCPropertyReleaser
_propertyReleaser_BookmarkFolderEditorViewController;
// Flag to ignore bookmark model Move notifications when the move is performed // Flag to ignore bookmark model Move notifications when the move is performed
// by this class. // by this class.
BOOL _ignoresOwnMove; BOOL _ignoresOwnMove;
...@@ -65,14 +66,14 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -65,14 +66,14 @@ typedef NS_ENUM(NSInteger, ItemType) {
@property(nonatomic, assign) bookmarks::BookmarkModel* bookmarkModel; @property(nonatomic, assign) bookmarks::BookmarkModel* bookmarkModel;
@property(nonatomic, assign) ios::ChromeBrowserState* browserState; @property(nonatomic, assign) ios::ChromeBrowserState* browserState;
@property(nonatomic, assign) const BookmarkNode* folder; @property(nonatomic, assign) const BookmarkNode* folder;
@property(nonatomic, retain) BookmarkFolderViewController* folderViewController; @property(nonatomic, strong) BookmarkFolderViewController* folderViewController;
@property(nonatomic, assign) const BookmarkNode* parentFolder; @property(nonatomic, assign) const BookmarkNode* parentFolder;
@property(nonatomic, assign) UIBarButtonItem* doneItem; @property(nonatomic, weak) UIBarButtonItem* doneItem;
@property(nonatomic, retain) BookmarkTextFieldItem* titleItem; @property(nonatomic, strong) BookmarkTextFieldItem* titleItem;
@property(nonatomic, retain) BookmarkParentFolderItem* parentFolderItem; @property(nonatomic, strong) BookmarkParentFolderItem* parentFolderItem;
// Bottom toolbar with DELETE button that only appears when the edited folder // Bottom toolbar with DELETE button that only appears when the edited folder
// allows deletion. // allows deletion.
@property(nonatomic, assign) BookmarksElevatedToolbar* toolbar; @property(nonatomic, weak) BookmarksElevatedToolbar* toolbar;
// |bookmarkModel| must not be NULL and must be loaded. // |bookmarkModel| must not be NULL and must be loaded.
- (instancetype)initWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel - (instancetype)initWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel
...@@ -113,12 +114,12 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -113,12 +114,12 @@ typedef NS_ENUM(NSInteger, ItemType) {
+ (instancetype) + (instancetype)
folderCreatorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel folderCreatorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel
parentFolder:(const BookmarkNode*)parentFolder { parentFolder:(const BookmarkNode*)parentFolder {
base::scoped_nsobject<BookmarkFolderEditorViewController> folderCreator( BookmarkFolderEditorViewController* folderCreator =
[[self alloc] initWithBookmarkModel:bookmarkModel]); [[self alloc] initWithBookmarkModel:bookmarkModel];
folderCreator.get().parentFolder = parentFolder; folderCreator.parentFolder = parentFolder;
folderCreator.get().folder = NULL; folderCreator.folder = NULL;
folderCreator.get().editingExistingFolder = NO; folderCreator.editingExistingFolder = NO;
return folderCreator.autorelease(); return folderCreator = nil;
} }
+ (instancetype) + (instancetype)
...@@ -128,13 +129,13 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel ...@@ -128,13 +129,13 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel
DCHECK(folder); DCHECK(folder);
DCHECK(!bookmarkModel->is_permanent_node(folder)); DCHECK(!bookmarkModel->is_permanent_node(folder));
DCHECK(browserState); DCHECK(browserState);
base::scoped_nsobject<BookmarkFolderEditorViewController> folderEditor( BookmarkFolderEditorViewController* folderEditor =
[[self alloc] initWithBookmarkModel:bookmarkModel]); [[self alloc] initWithBookmarkModel:bookmarkModel];
folderEditor.get().parentFolder = folder->parent(); folderEditor.parentFolder = folder->parent();
folderEditor.get().folder = folder; folderEditor.folder = folder;
folderEditor.get().browserState = browserState; folderEditor.browserState = browserState;
folderEditor.get().editingExistingFolder = YES; folderEditor.editingExistingFolder = YES;
return folderEditor.autorelease(); return folderEditor = nil;
} }
#pragma mark - Initialization #pragma mark - Initialization
...@@ -144,8 +145,6 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel ...@@ -144,8 +145,6 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel
DCHECK(bookmarkModel->loaded()); DCHECK(bookmarkModel->loaded());
self = [super initWithStyle:CollectionViewControllerStyleAppBar]; self = [super initWithStyle:CollectionViewControllerStyleAppBar];
if (self) { if (self) {
_propertyReleaser_BookmarkFolderEditorViewController.Init(
self, [BookmarkFolderEditorViewController class]);
_bookmarkModel = bookmarkModel; _bookmarkModel = bookmarkModel;
// Set up the bookmark model oberver. // Set up the bookmark model oberver.
...@@ -163,7 +162,6 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel ...@@ -163,7 +162,6 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel
- (void)dealloc { - (void)dealloc {
_titleItem.delegate = nil; _titleItem.delegate = nil;
_folderViewController.delegate = nil; _folderViewController.delegate = nil;
[super dealloc];
} }
#pragma mark - UIViewController #pragma mark - UIViewController
...@@ -173,13 +171,13 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel ...@@ -173,13 +171,13 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel
self.collectionView.backgroundColor = [UIColor whiteColor]; self.collectionView.backgroundColor = [UIColor whiteColor];
// Add Done button. // Add Done button.
base::scoped_nsobject<UIBarButtonItem> doneItem([[UIBarButtonItem alloc] UIBarButtonItem* doneItem = [[UIBarButtonItem alloc]
initWithTitle:l10n_util::GetNSString( initWithTitle:l10n_util::GetNSString(
IDS_IOS_BOOKMARK_EDIT_MODE_EXIT_MOBILE) IDS_IOS_BOOKMARK_EDIT_MODE_EXIT_MOBILE)
style:UIBarButtonItemStylePlain style:UIBarButtonItemStylePlain
target:self target:self
action:@selector(saveFolder)]); action:@selector(saveFolder)];
doneItem.get().accessibilityIdentifier = @"Save"; doneItem.accessibilityIdentifier = @"Save";
self.navigationItem.rightBarButtonItem = doneItem; self.navigationItem.rightBarButtonItem = doneItem;
self.doneItem = doneItem; self.doneItem = doneItem;
...@@ -273,14 +271,14 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel ...@@ -273,14 +271,14 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel
std::set<const BookmarkNode*> editedNodes; std::set<const BookmarkNode*> editedNodes;
if (self.folder) if (self.folder)
editedNodes.insert(self.folder); editedNodes.insert(self.folder);
base::scoped_nsobject<BookmarkFolderViewController> folderViewController( BookmarkFolderViewController* folderViewController =
[[BookmarkFolderViewController alloc] [[BookmarkFolderViewController alloc]
initWithBookmarkModel:self.bookmarkModel initWithBookmarkModel:self.bookmarkModel
allowsNewFolders:NO allowsNewFolders:NO
editedNodes:editedNodes editedNodes:editedNodes
allowsCancel:NO allowsCancel:NO
selectedFolder:self.parentFolder]); selectedFolder:self.parentFolder];
folderViewController.get().delegate = self; folderViewController.delegate = self;
self.folderViewController = folderViewController; self.folderViewController = folderViewController;
[self.navigationController pushViewController:folderViewController [self.navigationController pushViewController:folderViewController
...@@ -442,23 +440,23 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel ...@@ -442,23 +440,23 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel
[self.collectionViewModel addSectionWithIdentifier:SectionIdentifierInfo]; [self.collectionViewModel addSectionWithIdentifier:SectionIdentifierInfo];
base::scoped_nsobject<BookmarkTextFieldItem> titleItem( BookmarkTextFieldItem* titleItem =
[[BookmarkTextFieldItem alloc] initWithType:ItemTypeFolderTitle]); [[BookmarkTextFieldItem alloc] initWithType:ItemTypeFolderTitle];
titleItem.get().text = titleItem.text =
(self.folder) (self.folder)
? bookmark_utils_ios::TitleForBookmarkNode(self.folder) ? bookmark_utils_ios::TitleForBookmarkNode(self.folder)
: l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_GROUP_DEFAULT_NAME); : l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_GROUP_DEFAULT_NAME);
titleItem.get().placeholder = titleItem.placeholder =
l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_EDITOR_NAME_LABEL); l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_EDITOR_NAME_LABEL);
titleItem.get().accessibilityIdentifier = @"Title"; titleItem.accessibilityIdentifier = @"Title";
[self.collectionViewModel addItem:titleItem [self.collectionViewModel addItem:titleItem
toSectionWithIdentifier:SectionIdentifierInfo]; toSectionWithIdentifier:SectionIdentifierInfo];
titleItem.get().delegate = self; titleItem.delegate = self;
self.titleItem = titleItem; self.titleItem = titleItem;
base::scoped_nsobject<BookmarkParentFolderItem> parentFolderItem( BookmarkParentFolderItem* parentFolderItem =
[[BookmarkParentFolderItem alloc] initWithType:ItemTypeParentFolder]); [[BookmarkParentFolderItem alloc] initWithType:ItemTypeParentFolder];
parentFolderItem.get().title = parentFolderItem.title =
bookmark_utils_ios::TitleForBookmarkNode(self.parentFolder); bookmark_utils_ios::TitleForBookmarkNode(self.parentFolder);
[self.collectionViewModel addItem:parentFolderItem [self.collectionViewModel addItem:parentFolderItem
toSectionWithIdentifier:SectionIdentifierInfo]; toSectionWithIdentifier:SectionIdentifierInfo];
...@@ -467,26 +465,24 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel ...@@ -467,26 +465,24 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel
- (void)addToolbar { - (void)addToolbar {
// Add bottom toolbar with Delete button. // Add bottom toolbar with Delete button.
base::scoped_nsobject<BookmarksElevatedToolbar> buttonBar( BookmarksElevatedToolbar* buttonBar = [[BookmarksElevatedToolbar alloc] init];
[[BookmarksElevatedToolbar alloc] init]); UIBarButtonItem* deleteItem = [[UIBarButtonItem alloc]
base::scoped_nsobject<UIBarButtonItem> deleteItem([[UIBarButtonItem alloc]
initWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_GROUP_DELETE) initWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_GROUP_DELETE)
style:UIBarButtonItemStylePlain style:UIBarButtonItemStylePlain
target:self target:self
action:@selector(deleteFolder)]); action:@selector(deleteFolder)];
deleteItem.get().accessibilityIdentifier = @"Delete Folder"; deleteItem.accessibilityIdentifier = @"Delete Folder";
[deleteItem setTitleTextAttributes:@{ [deleteItem setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor blackColor] NSForegroundColorAttributeName : [UIColor blackColor]
} }
forState:UIControlStateNormal]; forState:UIControlStateNormal];
[buttonBar.get().layer [buttonBar.layer addSublayer:[[MDCShadowLayer alloc] init]];
addSublayer:[[[MDCShadowLayer alloc] init] autorelease]]; buttonBar.shadowElevation = MDCShadowElevationSearchBarResting;
buttonBar.get().shadowElevation = MDCShadowElevationSearchBarResting; buttonBar.items = @[ deleteItem ];
buttonBar.get().items = @[ deleteItem ];
[self.view addSubview:buttonBar]; [self.view addSubview:buttonBar];
// Constraint |buttonBar| to be in bottom. // Constraint |buttonBar| to be in bottom.
buttonBar.get().translatesAutoresizingMaskIntoConstraints = NO; buttonBar.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addConstraints: [self.view addConstraints:
[NSLayoutConstraint [NSLayoutConstraint
constraintsWithVisualFormat:@"H:|[buttonBar]|" constraintsWithVisualFormat:@"H:|[buttonBar]|"
......
...@@ -4,13 +4,16 @@ ...@@ -4,13 +4,16 @@
#import "ios/chrome/browser/ui/bookmarks/bookmark_folder_table_view_cell.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_table_view_cell.h"
#include "base/mac/scoped_nsobject.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
#import "ios/chrome/browser/ui/rtl_geometry.h" #import "ios/chrome/browser/ui/rtl_geometry.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h" #import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util_mac.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 { namespace {
// The amount in points by which to offset horizontally the text label. // The amount in points by which to offset horizontally the text label.
const CGFloat kTitleLabelLeadingOffset = 18.0; const CGFloat kTitleLabelLeadingOffset = 18.0;
...@@ -35,26 +38,24 @@ const CGFloat kFolderCellIndentationWidth = 32.0; ...@@ -35,26 +38,24 @@ const CGFloat kFolderCellIndentationWidth = 32.0;
} }
+ (instancetype)folderCell { + (instancetype)folderCell {
base::scoped_nsobject<BookmarkFolderTableViewCell> folderCell( BookmarkFolderTableViewCell* folderCell =
[[[self class] alloc] initWithStyle:UITableViewCellStyleDefault [[[self class] alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:[self folderCellReuseIdentifier]]); reuseIdentifier:[self folderCellReuseIdentifier]];
folderCell.get().indentationWidth = kFolderCellIndentationWidth; folderCell.indentationWidth = kFolderCellIndentationWidth;
folderCell.get().imageView.image = folderCell.imageView.image = [UIImage imageNamed:@"bookmark_gray_folder"];
[UIImage imageNamed:@"bookmark_gray_folder"]; return folderCell = nil;
return folderCell.autorelease();
} }
+ (instancetype)folderCreationCell { + (instancetype)folderCreationCell {
base::scoped_nsobject<BookmarkFolderTableViewCell> newFolderCell( BookmarkFolderTableViewCell* newFolderCell = [[[self class] alloc]
[[[self class] alloc] initWithStyle:UITableViewCellStyleDefault
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[self folderCreationCellReuseIdentifier]];
reuseIdentifier:[self folderCreationCellReuseIdentifier]]); newFolderCell.textLabel.text =
newFolderCell.get().textLabel.text =
l10n_util::GetNSString(IDS_IOS_BOOKMARK_CREATE_GROUP); l10n_util::GetNSString(IDS_IOS_BOOKMARK_CREATE_GROUP);
newFolderCell.get().imageView.image = newFolderCell.imageView.image =
[UIImage imageNamed:@"bookmark_gray_new_folder"]; [UIImage imageNamed:@"bookmark_gray_new_folder"];
newFolderCell.get().accessibilityIdentifier = @"Create New Folder"; newFolderCell.accessibilityIdentifier = @"Create New Folder";
return newFolderCell.autorelease(); return newFolderCell = nil;
} }
- (instancetype)initWithStyle:(UITableViewCellStyle)style - (instancetype)initWithStyle:(UITableViewCellStyle)style
...@@ -74,10 +75,10 @@ const CGFloat kFolderCellIndentationWidth = 32.0; ...@@ -74,10 +75,10 @@ const CGFloat kFolderCellIndentationWidth = 32.0;
- (void)setChecked:(BOOL)checked { - (void)setChecked:(BOOL)checked {
if (checked != _checked) { if (checked != _checked) {
_checked = checked; _checked = checked;
base::scoped_nsobject<UIImageView> checkImageView( UIImageView* checkImageView =
checked ? [[UIImageView alloc] checked ? [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"bookmark_blue_check"]] initWithImage:[UIImage imageNamed:@"bookmark_blue_check"]]
: nil); : nil;
self.accessoryView = checkImageView; self.accessoryView = checkImageView;
} }
} }
......
...@@ -31,7 +31,7 @@ class BookmarkNode; ...@@ -31,7 +31,7 @@ class BookmarkNode;
// The bookmark model is assumed to be loaded, thus also not to be NULL. // The bookmark model is assumed to be loaded, thus also not to be NULL.
@interface BookmarkFolderViewController : UIViewController @interface BookmarkFolderViewController : UIViewController
@property(nonatomic, assign) id<BookmarkFolderViewControllerDelegate> delegate; @property(nonatomic, weak) id<BookmarkFolderViewControllerDelegate> delegate;
// The current nodes (bookmarks or folders) that are considered for a move. // The current nodes (bookmarks or folders) that are considered for a move.
@property(nonatomic, assign, readonly) @property(nonatomic, assign, readonly)
......
...@@ -7,10 +7,7 @@ ...@@ -7,10 +7,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#import "base/ios/weak_nsobject.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/objc_property_releaser.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_folder_editor_view_controller.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_editor_view_controller.h"
...@@ -24,6 +21,10 @@ ...@@ -24,6 +21,10 @@
#import "ios/third_party/material_components_ios/src/components/AppBar/src/MaterialAppBar.h" #import "ios/third_party/material_components_ios/src/components/AppBar/src/MaterialAppBar.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using bookmarks::BookmarkNode; using bookmarks::BookmarkNode;
namespace { namespace {
...@@ -54,9 +55,7 @@ const NSInteger BookmarkFolderSectionCount = 2; ...@@ -54,9 +55,7 @@ const NSInteger BookmarkFolderSectionCount = 2;
std::set<const BookmarkNode*> _editedNodes; std::set<const BookmarkNode*> _editedNodes;
std::vector<const BookmarkNode*> _folders; std::vector<const BookmarkNode*> _folders;
std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge; std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge;
base::scoped_nsobject<MDCAppBar> _appBar; MDCAppBar* _appBar;
base::mac::ObjCPropertyReleaser
_propertyReleaser_BookmarkFolderViewController;
} }
// Should the controller setup Cancel and Done buttons instead of a back button. // Should the controller setup Cancel and Done buttons instead of a back button.
...@@ -72,7 +71,7 @@ const NSInteger BookmarkFolderSectionCount = 2; ...@@ -72,7 +71,7 @@ const NSInteger BookmarkFolderSectionCount = 2;
@property(nonatomic, readonly) const BookmarkNode* selectedFolder; @property(nonatomic, readonly) const BookmarkNode* selectedFolder;
// The view controller to present when creating a new folder. // The view controller to present when creating a new folder.
@property(nonatomic, retain) @property(nonatomic, strong)
BookmarkFolderEditorViewController* folderAddController; BookmarkFolderEditorViewController* folderAddController;
// A linear list of folders. // A linear list of folders.
...@@ -80,7 +79,7 @@ const NSInteger BookmarkFolderSectionCount = 2; ...@@ -80,7 +79,7 @@ const NSInteger BookmarkFolderSectionCount = 2;
const std::vector<const BookmarkNode*>& folders; const std::vector<const BookmarkNode*>& folders;
// The table view that displays the options and folders. // The table view that displays the options and folders.
@property(nonatomic, retain) UITableView* tableView; @property(nonatomic, strong) UITableView* tableView;
// Returns the cell for the default section and the given |row|. // Returns the cell for the default section and the given |row|.
- (BookmarkFolderTableViewCell*)defaultSectionCellForRow:(NSInteger)row; - (BookmarkFolderTableViewCell*)defaultSectionCellForRow:(NSInteger)row;
...@@ -126,8 +125,6 @@ const NSInteger BookmarkFolderSectionCount = 2; ...@@ -126,8 +125,6 @@ const NSInteger BookmarkFolderSectionCount = 2;
DCHECK(selectedFolder == NULL || selectedFolder->is_folder()); DCHECK(selectedFolder == NULL || selectedFolder->is_folder());
self = [super initWithNibName:nil bundle:nil]; self = [super initWithNibName:nil bundle:nil];
if (self) { if (self) {
_propertyReleaser_BookmarkFolderViewController.Init(
self, [BookmarkFolderViewController class]);
_allowsCancel = allowsCancel; _allowsCancel = allowsCancel;
_allowsNewFolders = allowsNewFolders; _allowsNewFolders = allowsNewFolders;
_bookmarkModel = bookmarkModel; _bookmarkModel = bookmarkModel;
...@@ -138,7 +135,7 @@ const NSInteger BookmarkFolderSectionCount = 2; ...@@ -138,7 +135,7 @@ const NSInteger BookmarkFolderSectionCount = 2;
_modelBridge.reset( _modelBridge.reset(
new bookmarks::BookmarkModelBridge(self, _bookmarkModel)); new bookmarks::BookmarkModelBridge(self, _bookmarkModel));
_appBar.reset([[MDCAppBar alloc] init]); _appBar = [[MDCAppBar alloc] init];
[self addChildViewController:[_appBar headerViewController]]; [self addChildViewController:[_appBar headerViewController]];
} }
return self; return self;
...@@ -155,7 +152,6 @@ const NSInteger BookmarkFolderSectionCount = 2; ...@@ -155,7 +152,6 @@ const NSInteger BookmarkFolderSectionCount = 2;
_tableView.dataSource = nil; _tableView.dataSource = nil;
_tableView.delegate = nil; _tableView.delegate = nil;
_folderAddController.delegate = nil; _folderAddController.delegate = nil;
[super dealloc];
} }
- (UIStatusBarStyle)preferredStatusBarStyle { - (UIStatusBarStyle)preferredStatusBarStyle {
...@@ -174,13 +170,13 @@ const NSInteger BookmarkFolderSectionCount = 2; ...@@ -174,13 +170,13 @@ const NSInteger BookmarkFolderSectionCount = 2;
self.title = l10n_util::GetNSString(IDS_IOS_BOOKMARK_CHOOSE_GROUP_BUTTON); self.title = l10n_util::GetNSString(IDS_IOS_BOOKMARK_CHOOSE_GROUP_BUTTON);
base::scoped_nsobject<UIBarButtonItem> doneItem([[UIBarButtonItem alloc] UIBarButtonItem* doneItem = [[UIBarButtonItem alloc]
initWithTitle:l10n_util::GetNSString( initWithTitle:l10n_util::GetNSString(
IDS_IOS_BOOKMARK_EDIT_MODE_EXIT_MOBILE) IDS_IOS_BOOKMARK_EDIT_MODE_EXIT_MOBILE)
style:UIBarButtonItemStylePlain style:UIBarButtonItemStylePlain
target:self target:self
action:@selector(done:)]); action:@selector(done:)];
doneItem.get().accessibilityIdentifier = @"Done"; doneItem.accessibilityIdentifier = @"Done";
self.navigationItem.rightBarButtonItem = doneItem; self.navigationItem.rightBarButtonItem = doneItem;
if (self.allowsCancel) { if (self.allowsCancel) {
...@@ -204,14 +200,14 @@ const NSInteger BookmarkFolderSectionCount = 2; ...@@ -204,14 +200,14 @@ const NSInteger BookmarkFolderSectionCount = 2;
} }
// The table view. // The table view.
base::scoped_nsobject<UITableView> tableView([[UITableView alloc] UITableView* tableView =
initWithFrame:self.view.bounds [[UITableView alloc] initWithFrame:self.view.bounds
style:UITableViewStylePlain]); style:UITableViewStylePlain];
tableView.get().dataSource = self; tableView.dataSource = self;
tableView.get().delegate = self; tableView.delegate = self;
tableView.get().autoresizingMask = tableView.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
tableView.get().separatorStyle = UITableViewCellSeparatorStyleNone; tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:tableView]; [self.view addSubview:tableView];
[self.view sendSubviewToBack:tableView]; [self.view sendSubviewToBack:tableView];
self.tableView = tableView; self.tableView = tableView;
...@@ -337,18 +333,16 @@ const NSInteger BookmarkFolderSectionCount = 2; ...@@ -337,18 +333,16 @@ const NSInteger BookmarkFolderSectionCount = 2;
CGRect headerViewFrame = CGRect headerViewFrame =
CGRectMake(0, 0, CGRectGetWidth(tableView.frame), CGRectMake(0, 0, CGRectGetWidth(tableView.frame),
[self tableView:tableView heightForHeaderInSection:section]); [self tableView:tableView heightForHeaderInSection:section]);
UIView* headerView = UIView* headerView = [[UIView alloc] initWithFrame:headerViewFrame];
[[[UIView alloc] initWithFrame:headerViewFrame] autorelease];
if (section == BookmarkFolderSectionFolders && if (section == BookmarkFolderSectionFolders &&
[self shouldShowDefaultSection]) { [self shouldShowDefaultSection]) {
CGRect separatorFrame = CGRect separatorFrame =
CGRectMake(0, 0, CGRectGetWidth(headerView.bounds), CGRectMake(0, 0, CGRectGetWidth(headerView.bounds),
1.0 / [[UIScreen mainScreen] scale]); // 1-pixel divider. 1.0 / [[UIScreen mainScreen] scale]); // 1-pixel divider.
base::scoped_nsobject<UIView> separator( UIView* separator = [[UIView alloc] initWithFrame:separatorFrame];
[[UIView alloc] initWithFrame:separatorFrame]); separator.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin |
separator.get().autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
UIViewAutoresizingFlexibleWidth; separator.backgroundColor = bookmark_utils_ios::separatorColor();
separator.get().backgroundColor = bookmark_utils_ios::separatorColor();
[headerView addSubview:separator]; [headerView addSubview:separator];
} }
return headerView; return headerView;
...@@ -369,7 +363,7 @@ const NSInteger BookmarkFolderSectionCount = 2; ...@@ -369,7 +363,7 @@ const NSInteger BookmarkFolderSectionCount = 2;
- (UIView*)tableView:(UITableView*)tableView - (UIView*)tableView:(UITableView*)tableView
viewForFooterInSection:(NSInteger)section { viewForFooterInSection:(NSInteger)section {
return [[[UIView alloc] init] autorelease]; return [[UIView alloc] init];
} }
- (void)tableView:(UITableView*)tableView - (void)tableView:(UITableView*)tableView
...@@ -538,16 +532,15 @@ const NSInteger BookmarkFolderSectionCount = 2; ...@@ -538,16 +532,15 @@ const NSInteger BookmarkFolderSectionCount = 2;
- (void)delayedNotifyDelegateOfSelection { - (void)delayedNotifyDelegateOfSelection {
self.view.userInteractionEnabled = NO; self.view.userInteractionEnabled = NO;
base::WeakNSObject<BookmarkFolderViewController> weakSelf(self); __weak BookmarkFolderViewController* weakSelf = self;
dispatch_after( dispatch_after(
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{ dispatch_get_main_queue(), ^{
base::scoped_nsobject<BookmarkFolderViewController> strongSelf( BookmarkFolderViewController* strongSelf = weakSelf;
[weakSelf retain]);
// Early return if the controller has been deallocated. // Early return if the controller has been deallocated.
if (!strongSelf) if (!strongSelf)
return; return;
strongSelf.get().view.userInteractionEnabled = YES; strongSelf.view.userInteractionEnabled = YES;
[strongSelf done:nil]; [strongSelf done:nil];
}); });
} }
......
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