Commit 9d30c08f authored by stkhapugin's avatar stkhapugin Committed by Commit bot

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

Automatically generated ARCMigrate commit
Notable issues:
* Replaced 2 instances of replaceOldTabModel:(TabModel**)oldTabModel withTabModel:(TabModel*)newTabModel method with an equivalent construct that does not pass pointers to pointers to objc objects. Feel free to suggest a better way that I can implement in a follow-up CL.
* some weak pointer dereferencing replaced with strong pointer dereferencing in blocks
* In tab_model_snapshot.mm, added a bridge cast. I'm not sure if this should be a conversion to std::string, because std::stringstream.operator<<(NSString*) can be both.

BUG=624363
TEST=None

Review-Url: https://codereview.chromium.org/2810193002
Cr-Commit-Position: refs/heads/master@{#468652}
parent be86e8ab
......@@ -50,6 +50,7 @@ bundle_data("resources") {
}
source_set("tab_switcher") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"tab_model_snapshot.h",
"tab_model_snapshot.mm",
......
......@@ -6,6 +6,11 @@
#include "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/tabs/tab.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
TabModelSnapshot::TabModelSnapshot(TabModel* tabModel) {
for (Tab* tab in tabModel) {
......@@ -31,7 +36,7 @@ size_t TabModelSnapshot::hashOfTheVisiblePropertiesOfATab(Tab* tab) {
std::stringstream ss;
// lastVisitedTimestamp is used as an approximation for whether the tab's
// snapshot changed.
ss << tab.tabId << std::endl
ss << base::SysNSStringToUTF8(tab.tabId) << std::endl
<< base::SysNSStringToUTF8(tab.urlDisplayString) << std::endl
<< std::hexfloat << tab.lastVisitedTimestamp << std::endl;
return std::hash<std::string>()(ss.str());
......
......@@ -4,11 +4,14 @@
#include "ios/chrome/browser/ui/tab_switcher/tab_switcher_button.h"
#include "base/mac/scoped_nsobject.h"
#import "ios/third_party/material_components_ios/src/components/Ink/src/MaterialInk.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface TabSwitcherButton () {
base::scoped_nsobject<MDCInkTouchController> _inkTouchController;
MDCInkTouchController* _inkTouchController;
}
@end
......@@ -17,8 +20,7 @@
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
_inkTouchController.reset(
[[MDCInkTouchController alloc] initWithView:self]);
_inkTouchController = [[MDCInkTouchController alloc] initWithView:self];
[_inkTouchController addInkView];
// TODO(crbug.com/606807): Adjust the desired ink color.
[_inkTouchController defaultInkView].inkColor =
......
......@@ -29,7 +29,7 @@ struct PendingSnapshotRequest {
// cached and freed under memory pressure.
@interface TabSwitcherCache : NSObject<TabModelObserver>
@property(nonatomic, readonly) TabModel* mainTabModel;
@property(weak, nonatomic, readonly) TabModel* mainTabModel;
// Request a snapshot for the given |tab| of the given |size|, |completionBlock|
// will be called with the requested snapshot. Must be called from the main
......
......@@ -6,9 +6,7 @@
#include <unordered_map>
#import "base/ios/weak_nsobject.h"
#include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/lock.h"
#import "ios/chrome/browser/tabs/tab.h"
......@@ -17,6 +15,10 @@
#include "ios/chrome/common/ios_app_bundle_id_prefix.h"
#include "ios/web/public/navigation_item.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// The maximum amount of pixels the cache should hold.
NSUInteger kCacheMaxPixelCount = 2048 * 1536 * 4;
......@@ -34,11 +36,11 @@ const CGFloat kMaxFloatDelta = 0.01;
@end
@implementation TabSwitcherCache {
base::scoped_nsobject<NSCache> _cache;
NSCache* _cache;
dispatch_queue_t _cacheQueue;
// The tab models.
TabModel* _mainTabModel; // weak
TabModel* _otrTabModel; // weak
__weak TabModel* _mainTabModel;
__weak TabModel* _otrTabModel;
// Lock protecting the pending requests map.
base::Lock _lock;
......@@ -50,7 +52,7 @@ const CGFloat kMaxFloatDelta = 0.01;
- (instancetype)init {
self = [super init];
if (self) {
_cache.reset([[NSCache alloc] init]);
_cache = [[NSCache alloc] init];
[_cache setTotalCostLimit:kCacheMaxPixelCount];
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
......@@ -71,10 +73,8 @@ const CGFloat kMaxFloatDelta = 0.01;
[nc removeObserver:self
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
dispatch_release(_cacheQueue);
[_mainTabModel removeObserver:self];
[_otrTabModel removeObserver:self];
[super dealloc];
}
- (PendingSnapshotRequest)requestSnapshotForTab:(Tab*)tab
......@@ -231,28 +231,39 @@ const CGFloat kMaxFloatDelta = 0.01;
UIImage* resizedSnapshot =
ResizeImage(image, pixelSize, ProjectionMode::kAspectFillNoClipping, YES);
// Creates a new image with the correct |scale| attribute.
return [[[UIImage alloc] initWithCGImage:resizedSnapshot.CGImage
scale:screenScale
orientation:UIImageOrientationUp] autorelease];
return [[UIImage alloc] initWithCGImage:resizedSnapshot.CGImage
scale:screenScale
orientation:UIImageOrientationUp];
}
- (void)lowMemoryWarningReceived {
[_cache removeAllObjects];
}
- (void)setMainTabModel:(TabModel*)mainTabModel
otrTabModel:(TabModel*)otrTabModel {
if (mainTabModel != _mainTabModel)
[self replaceOldTabModel:&_mainTabModel withTabModel:mainTabModel];
if (otrTabModel != _otrTabModel)
[self replaceOldTabModel:&_otrTabModel withTabModel:otrTabModel];
- (void)setMainTabModel:(TabModel*)mainTabModel {
if (mainTabModel == _mainTabModel) {
return;
}
[_mainTabModel removeObserver:self];
_mainTabModel = mainTabModel;
[_mainTabModel addObserver:self];
}
- (void)replaceOldTabModel:(TabModel**)oldTabModel
withTabModel:(TabModel*)newTabModel {
[*oldTabModel removeObserver:self];
*oldTabModel = newTabModel;
[newTabModel addObserver:self];
- (void)setOTRTabModel:(TabModel*)otrTabModel {
if (_otrTabModel == otrTabModel) {
return;
}
[_otrTabModel removeObserver:self];
_otrTabModel = otrTabModel;
[_otrTabModel addObserver:self];
}
- (void)setMainTabModel:(TabModel*)mainTabModel
otrTabModel:(TabModel*)otrTabModel {
[self setMainTabModel:mainTabModel];
[self setOTRTabModel:otrTabModel];
}
#pragma mark - TabModelObserver
......
......@@ -5,12 +5,15 @@
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_header_cell.h"
#include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_session_cell_data.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// View alpha value used when the header cell is not selected.
const CGFloat kInactiveAlpha = 0.54;
......@@ -18,8 +21,8 @@ const CGFloat kImageViewWidth = 24;
}
@interface TabSwitcherHeaderCell () {
base::scoped_nsobject<UIImageView> _imageView;
base::scoped_nsobject<UILabel> _label;
UIImageView* _imageView;
UILabel* _label;
}
@end
......@@ -59,11 +62,11 @@ const CGFloat kImageViewWidth = 24;
#pragma mark - Private
- (void)loadSubviews {
_imageView.reset([[UIImageView alloc] initWithFrame:CGRectZero]);
_imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
[_imageView setContentMode:UIViewContentModeCenter];
[_imageView setTranslatesAutoresizingMaskIntoConstraints:NO];
[_imageView setTintColor:[UIColor whiteColor]];
_label.reset([[UILabel alloc] initWithFrame:CGRectZero]);
_label = [[UILabel alloc] initWithFrame:CGRectZero];
[_label setBackgroundColor:[UIColor clearColor]];
[_label setTranslatesAutoresizingMaskIntoConstraints:NO];
[_label setTextColor:[UIColor whiteColor]];
......@@ -72,8 +75,8 @@ const CGFloat kImageViewWidth = 24;
// Configure layout.
// The icon and the title are centered within |contentView|, have a spacing of
// one-third of icon width and the icon is on the leading side of title.
base::scoped_nsobject<UIStackView> stackView(
[[UIStackView alloc] initWithArrangedSubviews:@[ _imageView, _label ]]);
UIStackView* stackView =
[[UIStackView alloc] initWithArrangedSubviews:@[ _imageView, _label ]];
[stackView setSpacing:kImageViewWidth / 3];
[self.contentView addSubview:stackView];
......
......@@ -31,9 +31,9 @@
@interface TabSwitcherHeaderView : UIView
@property(nonatomic, assign) id<TabSwitcherHeaderViewDelegate> delegate;
@property(nonatomic, assign) id<TabSwitcherHeaderViewDataSource> dataSource;
@property(nonatomic, readonly) UIView* dismissButton;
@property(nonatomic, weak) id<TabSwitcherHeaderViewDelegate> delegate;
@property(nonatomic, weak) id<TabSwitcherHeaderViewDataSource> dataSource;
@property(weak, nonatomic, readonly) UIView* dismissButton;
// Selects the item at the specified index.
// The delegate is not called.
......
......@@ -4,9 +4,7 @@
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_header_view.h"
#import "base/ios/weak_nsobject.h"
#include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
#include "base/metrics/user_metrics_action.h"
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
......@@ -17,6 +15,10 @@
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const CGFloat kCollectionViewTopMargin = 39.0;
const CGFloat kCollectionViewHeight = 56.0;
......@@ -41,7 +43,7 @@ enum PanelSelectionChangeDirection { RIGHT, LEFT };
// we want the accessibilityFrame to resize itself using autoresizing masks.
@interface AccessiblePanelSelectorView : UIView {
// The delegate which receives actions.
base::WeakNSProtocol<id<AccessiblePanelSelectorDelegate>> _delegate;
__weak id<AccessiblePanelSelectorDelegate> _delegate;
}
- (void)setDelegate:(id<AccessiblePanelSelectorDelegate>)delegate;
@end
......@@ -49,7 +51,7 @@ enum PanelSelectionChangeDirection { RIGHT, LEFT };
@implementation AccessiblePanelSelectorView
- (void)setDelegate:(id<AccessiblePanelSelectorDelegate>)delegate {
_delegate.reset(delegate);
_delegate = delegate;
}
- (UIAccessibilityTraits)accessibilityTraits {
......@@ -74,11 +76,11 @@ enum PanelSelectionChangeDirection { RIGHT, LEFT };
@interface TabSwitcherHeaderView ()<UICollectionViewDataSource,
UICollectionViewDelegate,
AccessiblePanelSelectorDelegate> {
base::scoped_nsobject<UICollectionViewFlowLayout> _flowLayout;
base::scoped_nsobject<UICollectionView> _collectionView;
base::scoped_nsobject<AccessiblePanelSelectorView> _accessibilityView;
base::scoped_nsobject<UIButton> _dismissButton;
base::scoped_nsobject<UIView> _activeSpaceIndicatorView;
UICollectionViewFlowLayout* _flowLayout;
UICollectionView* _collectionView;
AccessiblePanelSelectorView* _accessibilityView;
UIButton* _dismissButton;
UIView* _activeSpaceIndicatorView;
BOOL _performingUpdate;
}
......@@ -133,13 +135,14 @@ enum PanelSelectionChangeDirection { RIGHT, LEFT };
completion:(ProceduralBlock)completion {
DCHECK(updateBlock);
__block TabSwitcherHeaderView* weakSelf = self;
__weak TabSwitcherHeaderView* weakSelf = self;
[_collectionView performBatchUpdates:^{
if (!weakSelf)
TabSwitcherHeaderView* strongSelf = weakSelf;
if (!strongSelf)
return;
weakSelf->_performingUpdate = YES;
updateBlock(weakSelf);
weakSelf->_performingUpdate = NO;
strongSelf->_performingUpdate = YES;
updateBlock(strongSelf);
strongSelf->_performingUpdate = NO;
}
completion:^(BOOL finished) {
// Reestablish selection after the update.
......@@ -165,7 +168,7 @@ enum PanelSelectionChangeDirection { RIGHT, LEFT };
}
- (UIView*)dismissButton {
return _dismissButton.get();
return _dismissButton;
}
#pragma mark - Private
......@@ -202,7 +205,7 @@ enum PanelSelectionChangeDirection { RIGHT, LEFT };
- (NSArray*)indexPathArrayWithIndexes:(NSArray*)indexes {
NSMutableArray* array =
[[[NSMutableArray alloc] initWithCapacity:indexes.count] autorelease];
[[NSMutableArray alloc] initWithCapacity:indexes.count];
for (NSNumber* index in indexes) {
[array
addObject:[NSIndexPath indexPathForItem:[index intValue] inSection:0]];
......@@ -211,8 +214,8 @@ enum PanelSelectionChangeDirection { RIGHT, LEFT };
}
- (void)loadSubviews {
base::scoped_nsobject<UICollectionViewFlowLayout> flowLayout(
[[UICollectionViewFlowLayout alloc] init]);
UICollectionViewFlowLayout* flowLayout =
[[UICollectionViewFlowLayout alloc] init];
[flowLayout setMinimumLineSpacing:0];
[flowLayout setMinimumInteritemSpacing:0];
const CGSize cellSize =
......@@ -221,9 +224,9 @@ enum PanelSelectionChangeDirection { RIGHT, LEFT };
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
_flowLayout = flowLayout;
_collectionView.reset([[UICollectionView alloc]
initWithFrame:[self collectionViewFrame]
collectionViewLayout:flowLayout]);
_collectionView =
[[UICollectionView alloc] initWithFrame:[self collectionViewFrame]
collectionViewLayout:flowLayout];
[_collectionView setDelegate:self];
[_collectionView setDataSource:self];
[_collectionView registerClass:[TabSwitcherHeaderCell class]
......@@ -237,8 +240,8 @@ enum PanelSelectionChangeDirection { RIGHT, LEFT };
[_collectionView setAccessibilityElementsHidden:YES];
[self addSubview:_collectionView];
_accessibilityView.reset([[AccessiblePanelSelectorView alloc]
initWithFrame:[self collectionViewFrame]]);
_accessibilityView = [[AccessiblePanelSelectorView alloc]
initWithFrame:[self collectionViewFrame]];
[_accessibilityView
setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleWidth];
......@@ -246,7 +249,7 @@ enum PanelSelectionChangeDirection { RIGHT, LEFT };
[_accessibilityView setUserInteractionEnabled:NO];
[self addSubview:_accessibilityView];
_dismissButton.reset([[UIButton alloc] initWithFrame:CGRectZero]);
_dismissButton = [[UIButton alloc] initWithFrame:CGRectZero];
UIImage* dismissImage =
[UIImage imageNamed:@"tabswitcher_tab_switcher_button"];
dismissImage =
......@@ -270,7 +273,7 @@ enum PanelSelectionChangeDirection { RIGHT, LEFT };
@"H:[dismissButton(==buttonWidth)]-0-|",
];
NSDictionary* viewsDictionary = @{
@"dismissButton" : _dismissButton.get(),
@"dismissButton" : _dismissButton,
};
NSDictionary* metrics = @{
@"buttonHeight" : @(kDismissButtonHeight),
......@@ -279,8 +282,7 @@ enum PanelSelectionChangeDirection { RIGHT, LEFT };
ApplyVisualConstraintsWithMetricsAndOptions(
constraints, viewsDictionary, metrics, LayoutOptionForRTLSupport(), self);
base::scoped_nsobject<UIView> activeSpaceIndicatorView(
[[UIView alloc] initWithFrame:CGRectZero]);
UIView* activeSpaceIndicatorView = [[UIView alloc] initWithFrame:CGRectZero];
[activeSpaceIndicatorView
setBackgroundColor:[[MDCPalette cr_bluePalette] tint500]];
[activeSpaceIndicatorView
......
......@@ -23,6 +23,10 @@
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_model_private.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
bool TabSwitcherSessionTypeIsLocalSession(TabSwitcherSessionType sessionType) {
return sessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION ||
sessionType == TabSwitcherSessionType::REGULAR_SESSION;
......@@ -54,10 +58,10 @@ void FillSetUsingSessions(synced_sessions::SyncedSessions const& sessions,
// The browser state.
ios::ChromeBrowserState* _browserState; // weak
// The tab models.
TabModel* _mainTabModel; // weak
TabModel* _otrTabModel; // weak
__weak TabModel* _mainTabModel;
__weak TabModel* _otrTabModel;
// The delegate for event callbacks.
id<TabSwitcherModelDelegate> _delegate; // weak, owns us.
__weak id<TabSwitcherModelDelegate> _delegate;
// The synced sessions. Must never be null.
std::unique_ptr<synced_sessions::SyncedSessions> _syncedSessions;
// The synced sessions change observer.
......@@ -67,7 +71,7 @@ void FillSetUsingSessions(synced_sessions::SyncedSessions const& sessions,
std::unique_ptr<TabModelSnapshot> _mainTabModelSnapshot;
std::unique_ptr<TabModelSnapshot> _otrTabModelSnapshot;
// The cache holding resized tabs snapshots.
base::scoped_nsobject<TabSwitcherCache> _cache;
TabSwitcherCache* _cache;
}
// Returns the type of the local session corresponding to the given |tabModel|.
......@@ -101,23 +105,36 @@ void FillSetUsingSessions(synced_sessions::SyncedSessions const& sessions,
_otrTabModelSnapshot.reset(new TabModelSnapshot(otrTabModel));
[_mainTabModel addObserver:self];
[_otrTabModel addObserver:self];
_cache.reset([cache retain]);
_cache = cache;
}
return self;
}
- (void)setMainTabModel:(TabModel*)mainTabModel
otrTabModel:(TabModel*)otrTabModel {
[self replaceOldTabModel:&_mainTabModel withTabModel:mainTabModel];
[self replaceOldTabModel:&_otrTabModel withTabModel:otrTabModel];
[self replaceMainTabModelWithTabModel:mainTabModel];
[self replaceOTRTabModelWithTabModel:otrTabModel];
}
- (void)replaceOldTabModel:(TabModel**)oldTabModel
withTabModel:(TabModel*)newTabModel {
if (*oldTabModel == newTabModel)
- (void)replaceMainTabModelWithTabModel:(TabModel*)newTabModel {
if (_mainTabModel == newTabModel)
return;
[*oldTabModel removeObserver:self];
*oldTabModel = newTabModel;
[_mainTabModel removeObserver:self];
_mainTabModel = newTabModel;
[newTabModel addObserver:self];
// Calling |tabModelChanged:| may trigger an animated refresh of the
// Tab Switcher's collection view.
// Here in |replaceOldTabModel:withTabModel:| the animation is undesirable.
[UIView performWithoutAnimation:^{
[self tabModelChanged:newTabModel];
}];
}
- (void)replaceOTRTabModelWithTabModel:(TabModel*)newTabModel {
if (_otrTabModel == newTabModel)
return;
[_otrTabModel removeObserver:self];
_otrTabModel = newTabModel;
[newTabModel addObserver:self];
// Calling |tabModelChanged:| may trigger an animated refresh of the
// Tab Switcher's collection view.
......@@ -130,7 +147,6 @@ void FillSetUsingSessions(synced_sessions::SyncedSessions const& sessions,
- (void)dealloc {
[_mainTabModel removeObserver:self];
[_otrTabModel removeObserver:self];
[super dealloc];
}
- (NSInteger)sessionCount {
......
......@@ -32,7 +32,7 @@ CGFloat tabSwitcherLocalSessionCellTopBarHeight();
+ (NSString*)identifier;
// The cell delegate.
@property(nonatomic, assign) id<SessionCellDelegate> delegate;
@property(nonatomic, unsafe_unretained) id<SessionCellDelegate> delegate;
@end
......@@ -41,7 +41,7 @@ CGFloat tabSwitcherLocalSessionCellTopBarHeight();
// Returns the top bar of the cell. The top bar holds the favicon and the tab
// title.
@property(nonatomic, readonly) UIView* topBar;
@property(unsafe_unretained, nonatomic, readonly) UIView* topBar;
// Sets the cell's appearance using information in |tab|.
// The delegate needs to be set before calling this method.
......
......@@ -7,7 +7,10 @@
#include <algorithm>
#include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const CGFloat minWidthOfTab = 200;
......@@ -20,8 +23,8 @@ const CGFloat kMaxCellHeightWidthRatio = 1.8;
@implementation TabSwitcherPanelCollectionViewLayout {
// Keeps track of the inserted and deleted index paths.
base::scoped_nsobject<NSMutableArray> _deletedIndexPaths;
base::scoped_nsobject<NSMutableArray> _insertedIndexPaths;
NSMutableArray* _deletedIndexPaths;
NSMutableArray* _insertedIndexPaths;
}
- (int)maxRowCountWithColumnCount:(int)columnCount inBounds:(CGSize)boundsSize {
......
......@@ -50,8 +50,9 @@ class ChromeBrowserState;
@interface TabSwitcherPanelController : NSObject
@property(nonatomic, readonly) TabSwitcherPanelView* view;
@property(nonatomic, assign) id<TabSwitcherPanelControllerDelegate> delegate;
@property(unsafe_unretained, nonatomic, readonly) TabSwitcherPanelView* view;
@property(nonatomic, unsafe_unretained) id<TabSwitcherPanelControllerDelegate>
delegate;
@property(nonatomic, readonly) TabSwitcherSessionType sessionType;
// Initializes a controller for a view showing local tabs. |offTheRecord|
......
......@@ -6,7 +6,6 @@
#include "base/logging.h"
#import "base/mac/foundation_util.h"
#import "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/tabs/tab.h"
#include "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h"
......@@ -16,6 +15,10 @@
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_view.h"
#include "ios/chrome/browser/ui/tab_switcher/tab_switcher_session_changes.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
void FillVectorWithHashesUsingDistantSession(
......@@ -34,12 +37,12 @@ void FillVectorWithHashesUsingDistantSession(
UICollectionViewDelegate,
SessionCellDelegate> {
ios::ChromeBrowserState* _browserState; // Weak.
base::scoped_nsobject<TabSwitcherPanelView> _panelView;
base::scoped_nsobject<TabSwitcherModel> _model;
TabSwitcherPanelView* _panelView;
TabSwitcherModel* _model;
std::string _sessionTag;
TabSwitcherSessionType _sessionType;
base::scoped_nsobject<TabSwitcherCache> _cache;
base::scoped_nsobject<TabSwitcherPanelOverlayView> _overlayView;
TabSwitcherCache* _cache;
TabSwitcherPanelOverlayView* _overlayView;
std::unique_ptr<const synced_sessions::DistantSession> _distantSession;
std::unique_ptr<const TabModelSnapshot> _localSession;
}
......@@ -61,7 +64,7 @@ void FillVectorWithHashesUsingDistantSession(
if (self) {
DCHECK(model);
_sessionType = TabSwitcherSessionType::DISTANT_SESSION;
_model.reset([model retain]);
_model = model;
_distantSession = [model distantSessionForTag:sessionTag];
_sessionTag = sessionTag;
_browserState = browserState;
......@@ -78,9 +81,9 @@ void FillVectorWithHashesUsingDistantSession(
if (self) {
DCHECK(model);
_sessionType = sessionType;
_model.reset([model retain]);
_model = model;
_localSession = [model tabModelSnapshotForLocalSession:sessionType];
_cache.reset([cache retain]);
_cache = cache;
_browserState = browserState;
[self loadView];
}
......@@ -311,9 +314,9 @@ void FillVectorWithHashesUsingDistantSession(
DCHECK(TabSwitcherSessionTypeIsLocalSession(_sessionType));
if (!_overlayView) {
_overlayView.reset([[TabSwitcherPanelOverlayView alloc]
initWithFrame:[_panelView bounds]
browserState:_browserState]);
_overlayView =
[[TabSwitcherPanelOverlayView alloc] initWithFrame:[_panelView bounds]
browserState:_browserState];
[_overlayView
setOverlayType:
(_sessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION)
......@@ -339,10 +342,9 @@ void FillVectorWithHashesUsingDistantSession(
}
- (void)loadView {
_panelView.reset(
[[TabSwitcherPanelView alloc] initWithSessionType:_sessionType]);
_panelView.get().collectionView.dataSource = self;
_panelView.get().collectionView.delegate = self;
_panelView = [[TabSwitcherPanelView alloc] initWithSessionType:_sessionType];
_panelView.collectionView.dataSource = self;
_panelView.collectionView.delegate = self;
}
- (synced_sessions::DistantSession const*)distantSession {
......
......@@ -4,14 +4,16 @@
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_view.h"
#import "base/mac/scoped_nsobject.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_collection_view_layout.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface TabSwitcherPanelView () {
base::scoped_nsobject<UICollectionView> _collectionView;
base::scoped_nsobject<TabSwitcherPanelCollectionViewLayout>
_collectionViewLayout;
UICollectionView* _collectionView;
TabSwitcherPanelCollectionViewLayout* _collectionViewLayout;
TabSwitcherSessionType _sessionType;
}
......@@ -57,11 +59,10 @@
#pragma mark - Private
- (void)loadSubviews {
_collectionViewLayout.reset(
[[TabSwitcherPanelCollectionViewLayout alloc] init]);
_collectionView.reset([[UICollectionView alloc]
initWithFrame:self.bounds
collectionViewLayout:_collectionViewLayout.get()]);
_collectionViewLayout = [[TabSwitcherPanelCollectionViewLayout alloc] init];
_collectionView =
[[UICollectionView alloc] initWithFrame:self.bounds
collectionViewLayout:_collectionViewLayout];
if (_sessionType == TabSwitcherSessionType::DISTANT_SESSION) {
[_collectionView registerClass:[TabSwitcherDistantSessionCell class]
forCellWithReuseIdentifier:[TabSwitcherDistantSessionCell identifier]];
......
......@@ -6,6 +6,10 @@
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation TabSwitcherSessionCellData
@synthesize type = _type;
......
......@@ -6,6 +6,10 @@
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_utils.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
TabSwitcherSessionChanges::TabSwitcherSessionChanges(
std::vector<size_t> const& tabHashesInInitialState,
std::vector<size_t> const& tabHashesInFinalState) {
......
......@@ -8,11 +8,13 @@
#import <QuartzCore/QuartzCore.h>
#import "base/ios/weak_nsobject.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// Returns the animation drag coefficient set by the iPhone simulator.
// This is useful when debugging with the simulator because when
// "slow animation" mode is toggled, it only impacts UIKit animations not
......@@ -106,16 +108,15 @@ const CGFloat kTabFoldAnimationDuration = 0.15;
_animatingFold = YES;
[self setUserInteractionEnabled:NO];
[CATransaction begin];
base::WeakNSObject<TabSwitcherTabStripPlaceholderView> weakSelf(self);
__weak TabSwitcherTabStripPlaceholderView* weakSelf = self;
[CATransaction setCompletionBlock:^{
base::scoped_nsobject<TabSwitcherTabStripPlaceholderView> strongSelf(
[weakSelf retain]);
TabSwitcherTabStripPlaceholderView* strongSelf = weakSelf;
if (!strongSelf) {
if (completion)
completion();
return;
}
strongSelf.get()->_animatingFold = NO;
strongSelf->_animatingFold = NO;
[strongSelf setUserInteractionEnabled:YES];
if (completion)
completion();
......
......@@ -4,7 +4,6 @@
#include "ios/chrome/browser/ui/tab_switcher/tab_switcher_transition_context.h"
#include "base/mac/objc_property_releaser.h"
#import "ios/chrome/browser/tabs/tab.h"
#import "ios/chrome/browser/ui/browser_view_controller.h"
#include "ios/chrome/browser/ui/tab_switcher/tab_switcher_transition_context.h"
......@@ -12,25 +11,26 @@
#import "ios/chrome/browser/ui/tabs/tab_strip_controller.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
@class BrowserViewController;
@interface TabSwitcherTransitionContextContent () {
base::scoped_nsobject<TabSwitcherTabStripPlaceholderView>
_tabStripPlaceholderView;
base::WeakNSObject<BrowserViewController> _bvc;
TabSwitcherTabStripPlaceholderView* _tabStripPlaceholderView;
__weak BrowserViewController* _bvc;
}
@end
@implementation TabSwitcherTransitionContextContent {
base::mac::ObjCPropertyReleaser
_propertyReleaser_tabSwitcherTransitionContextContent;
}
+ (instancetype)tabSwitcherTransitionContextContentFromBVC:
(BrowserViewController*)bvc {
TabSwitcherTransitionContextContent* transitionContextContent =
[[[TabSwitcherTransitionContextContent alloc] init] autorelease];
[[TabSwitcherTransitionContextContent alloc] init];
transitionContextContent.initialTabID = bvc.tabModel.currentTab.tabId;
......@@ -40,17 +40,16 @@
}
UIView* toolbarView = [[bvc toolbarController] view];
base::scoped_nsobject<UIView> toolbarSnapshotView;
UIView* toolbarSnapshotView;
if ([toolbarView window]) {
toolbarSnapshotView.reset(
[[toolbarView snapshotViewAfterScreenUpdates:NO] retain]);
toolbarSnapshotView = [toolbarView snapshotViewAfterScreenUpdates:NO];
} else {
toolbarSnapshotView.reset([[UIView alloc] initWithFrame:toolbarView.frame]);
toolbarSnapshotView = [[UIView alloc] initWithFrame:toolbarView.frame];
[toolbarSnapshotView layer].contents = static_cast<id>(
CaptureViewWithOption(toolbarView, 1, kClientSideRendering).CGImage);
}
transitionContextContent.toolbarSnapshotView = toolbarSnapshotView;
transitionContextContent->_bvc.reset(bvc);
transitionContextContent->_bvc = bvc;
return transitionContextContent;
}
......@@ -65,8 +64,6 @@
- (instancetype)init {
self = [super init];
if (self) {
_propertyReleaser_tabSwitcherTransitionContextContent.Init(
self, [TabSwitcherTransitionContextContent class]);
}
return self;
}
......@@ -74,8 +71,6 @@
@end
@implementation TabSwitcherTransitionContext {
base::mac::ObjCPropertyReleaser
_propertyReleaser_tabSwitcherTransitionContext;
}
+ (instancetype)
......@@ -83,7 +78,7 @@ tabSwitcherTransitionContextWithCurrent:(BrowserViewController*)currentBVC
mainBVC:(BrowserViewController*)mainBVC
otrBVC:(BrowserViewController*)otrBVC {
TabSwitcherTransitionContext* transitionContext =
[[[TabSwitcherTransitionContext alloc] init] autorelease];
[[TabSwitcherTransitionContext alloc] init];
Tab* currentTab = [[currentBVC tabModel] currentTab];
UIImage* tabSnapshotImage =
[currentTab generateSnapshotWithOverlay:YES visibleFrameOnly:YES];
......@@ -108,8 +103,6 @@ tabSwitcherTransitionContextWithCurrent:(BrowserViewController*)currentBVC
- (instancetype)init {
self = [super init];
if (self) {
_propertyReleaser_tabSwitcherTransitionContext.Init(
self, [TabSwitcherTransitionContext class]);
}
return self;
}
......
......@@ -28,10 +28,11 @@ enum NewTabButtonStyle { UNINITIALIZED, BLUE, GRAY, HIDDEN };
@interface TabSwitcherView : UIView<UIScrollViewDelegate>
@property(nonatomic, readonly) TabSwitcherHeaderView* headerView;
@property(nonatomic, readonly) UIScrollView* scrollView;
@property(unsafe_unretained, nonatomic, readonly)
TabSwitcherHeaderView* headerView;
@property(unsafe_unretained, nonatomic, readonly) UIScrollView* scrollView;
@property(nonatomic, assign) id<TabSwitcherViewDelegate> delegate;
@property(nonatomic, unsafe_unretained) id<TabSwitcherViewDelegate> delegate;
// Select the panel at the given index, updating both the header and content.
// The panel selection will be animated if VoiceOver is disabled.
......
......@@ -6,7 +6,6 @@
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.h"
#include "base/metrics/user_metrics.h"
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
......@@ -19,6 +18,10 @@
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const CGFloat kHeaderHeight = 95;
const CGFloat kNewTabButtonMarginFromEdges = 48;
......@@ -26,10 +29,10 @@ const CGFloat kNewTabButtonWidth = 48;
}
@interface TabSwitcherView ()<UIScrollViewDelegate> {
base::scoped_nsobject<TabSwitcherHeaderView> _headerView;
base::scoped_nsobject<UIScrollView> _scrollView;
base::scoped_nsobject<MDCButton> _openNewTabButton;
base::scoped_nsobject<NSMutableArray> _panels;
TabSwitcherHeaderView* _headerView;
UIScrollView* _scrollView;
MDCButton* _openNewTabButton;
NSMutableArray* _panels;
ios_internal::NewTabButtonStyle _openNewTabButtonStyle;
NSInteger _previousPanelIndex;
}
......@@ -61,7 +64,7 @@ const CGFloat kNewTabButtonWidth = 48;
if (self) {
_openNewTabButtonStyle = ios_internal::NewTabButtonStyle::UNINITIALIZED;
[self loadSubviews];
_panels.reset([[NSMutableArray alloc] init]);
_panels = [[NSMutableArray alloc] init];
_previousPanelIndex = -1;
}
return self;
......@@ -104,7 +107,7 @@ const CGFloat kNewTabButtonWidth = 48;
}
- (void)removePanelViewAtIndex:(NSUInteger)index updateScrollView:(BOOL)update {
DCHECK_EQ([[_panels objectAtIndex:index] superview], _scrollView.get());
DCHECK_EQ([[_panels objectAtIndex:index] superview], _scrollView);
[[_panels objectAtIndex:index] removeFromSuperview];
[_panels removeObjectAtIndex:index];
if (update)
......@@ -171,14 +174,14 @@ const CGFloat kNewTabButtonWidth = 48;
- (void)loadSubviews {
// Creates and add the header view showing the list of panels.
base::scoped_nsobject<TabSwitcherHeaderView> headerView(
[[TabSwitcherHeaderView alloc] initWithFrame:[self headerViewFrame]]);
TabSwitcherHeaderView* headerView =
[[TabSwitcherHeaderView alloc] initWithFrame:[self headerViewFrame]];
[self addSubview:headerView];
_headerView = headerView;
// Creates and add the scrollview containing the panels.
base::scoped_nsobject<UIScrollView> scrollView(
[[UIScrollView alloc] initWithFrame:[self scrollViewFrame]]);
UIScrollView* scrollView =
[[UIScrollView alloc] initWithFrame:[self scrollViewFrame]];
[scrollView setBackgroundColor:[[MDCPalette greyPalette] tint900]];
[scrollView setAlwaysBounceHorizontal:YES];
[scrollView setDelegate:self];
......@@ -190,7 +193,7 @@ const CGFloat kNewTabButtonWidth = 48;
_scrollView = scrollView;
// Creates and add the floating new tab button.
_openNewTabButton.reset([[MDCFloatingButton alloc] init]);
_openNewTabButton = [[MDCFloatingButton alloc] init];
UIImage* openNewTabButtonImage =
[[UIImage imageNamed:@"tabswitcher_new_tab_fab"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
......
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