Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Unified Diff: ios/chrome/browser/ui/toolbar/toolbar_controller.mm

Issue 2852713002: Revert of [ObjC ARC] Converts ios/chrome/browser/ui/toolbar:toolbar to ARC. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/toolbar/toolbar_controller.mm
diff --git a/ios/chrome/browser/ui/toolbar/toolbar_controller.mm b/ios/chrome/browser/ui/toolbar/toolbar_controller.mm
index 7dd27ef31e01929f573355fa5d96ff80b22d4021..3eb51c61eca69a187f4aed516de3ddd5dea89ae4 100644
--- a/ios/chrome/browser/ui/toolbar/toolbar_controller.mm
+++ b/ios/chrome/browser/ui/toolbar/toolbar_controller.mm
@@ -76,10 +76,6 @@
// Makes a two-element C array of CGRects as described above, one for each
// device idiom.
#define FRAME_PAIR(H) { IPHONE_FRAME(H), IPAD_FRAME(H) }
-
-#if !defined(__has_feature) || !__has_feature(objc_arc)
-#error "This file requires ARC support."
-#endif
// clang-format on
const CGRect kToolbarFrame[INTERFACE_IDIOM_COUNT] = FRAME_PAIR(56);
@@ -204,21 +200,26 @@
@end
@interface ToolbarController () {
- // The shadow view. Only used on iPhone.
- UIImageView* fullBleedShadowView_;
+ // The top-level toolbar view.
+ base::scoped_nsobject<ToolbarView> view_;
+ // The view for the toolbar background image.
+ base::scoped_nsobject<UIImageView> backgroundView_;
+ base::scoped_nsobject<UIImageView> shadowView_;
+ base::scoped_nsobject<UIImageView> fullBleedShadowView_;
// The backing object for |self.transitionLayers|.
- NSMutableArray* transitionLayers_;
-
- ToolbarToolsMenuButton* toolsMenuButton_;
- UIButton* stackButton_;
- UIButton* shareButton_;
- NSArray* standardButtons_;
- ToolsMenuButtonObserverBridge* toolsMenuButtonObserverBridge_;
+ base::scoped_nsobject<NSMutableArray> transitionLayers_;
+
+ base::scoped_nsobject<ToolbarToolsMenuButton> toolsMenuButton_;
+ base::scoped_nsobject<UIButton> stackButton_;
+ base::scoped_nsobject<UIButton> shareButton_;
+ base::scoped_nsobject<NSArray> standardButtons_;
+ base::scoped_nsobject<ToolsMenuButtonObserverBridge>
+ toolsMenuButtonObserverBridge_;
ToolbarControllerStyle style_;
// The following is nil if not visible.
- ToolsPopupController* toolsPopupController_;
+ base::scoped_nsobject<ToolsPopupController> toolsPopupController_;
}
// Returns the background image that should be used for |style|.
@@ -244,18 +245,15 @@
@implementation ToolbarController
@synthesize readingListModel = readingListModel_;
-@synthesize view = view_;
-@synthesize backgroundView = backgroundView_;
-@synthesize shadowView = shadowView_;
-@synthesize toolsPopupController = toolsPopupController_;
+
@synthesize style = style_;
- (void)setReadingListModel:(ReadingListModel*)readingListModel {
readingListModel_ = readingListModel;
if (readingListModel_) {
- toolsMenuButtonObserverBridge_ =
- [[ToolsMenuButtonObserverBridge alloc] initWithModel:readingListModel_
- toolbarButton:toolsMenuButton_];
+ toolsMenuButtonObserverBridge_.reset([[ToolsMenuButtonObserverBridge alloc]
+ initWithModel:readingListModel_
+ toolbarButton:toolsMenuButton_]);
}
}
@@ -280,11 +278,11 @@
toolsMenuButtonFrame.origin.y += statusBarOffset;
}
- view_ = [[ToolbarView alloc] initWithFrame:viewFrame];
- backgroundView_ = [[UIImageView alloc] initWithFrame:backgroundFrame];
- toolsMenuButton_ =
- [[ToolbarToolsMenuButton alloc] initWithFrame:toolsMenuButtonFrame
- style:style_];
+ view_.reset([[ToolbarView alloc] initWithFrame:viewFrame]);
+ backgroundView_.reset([[UIImageView alloc] initWithFrame:backgroundFrame]);
+ toolsMenuButton_.reset([[ToolbarToolsMenuButton alloc]
+ initWithFrame:toolsMenuButtonFrame
+ style:style_]);
[toolsMenuButton_ setTag:IDC_SHOW_TOOLS_MENU];
[toolsMenuButton_
setAutoresizingMask:UIViewAutoresizingFlexibleLeadingMargin() |
@@ -298,7 +296,7 @@
if (idiom == IPAD_IDIOM) {
CGRect shareButtonFrame = LayoutRectGetRect(kShareMenuButtonFrame);
- shareButton_ = [[UIButton alloc] initWithFrame:shareButtonFrame];
+ shareButton_.reset([[UIButton alloc] initWithFrame:shareButtonFrame]);
[shareButton_ setTag:IDC_SHARE_PAGE];
[shareButton_
setAutoresizingMask:UIViewAutoresizingFlexibleLeadingMargin() |
@@ -315,7 +313,7 @@
CGRect shadowFrame = kShadowViewFrame[idiom];
shadowFrame.origin.y = CGRectGetMaxY(backgroundFrame);
- shadowView_ = [[UIImageView alloc] initWithFrame:shadowFrame];
+ shadowView_.reset([[UIImageView alloc] initWithFrame:shadowFrame]);
[shadowView_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[shadowView_ setUserInteractionEnabled:NO];
[view_ addSubview:shadowView_];
@@ -325,8 +323,8 @@
// iPad omnibox does not expand to full bleed.
CGRect fullBleedShadowFrame = kFullBleedShadowViewFrame;
fullBleedShadowFrame.origin.y = shadowFrame.origin.y;
- fullBleedShadowView_ =
- [[UIImageView alloc] initWithFrame:fullBleedShadowFrame];
+ fullBleedShadowView_.reset(
+ [[UIImageView alloc] initWithFrame:fullBleedShadowFrame]);
[fullBleedShadowView_
setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[fullBleedShadowView_ setUserInteractionEnabled:NO];
@@ -336,8 +334,8 @@
setImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW_FULL_BLEED)];
}
- transitionLayers_ =
- [[NSMutableArray alloc] initWithCapacity:kTransitionLayerCapacity];
+ transitionLayers_.reset(
+ [[NSMutableArray alloc] initWithCapacity:kTransitionLayerCapacity]);
// UIImageViews do not default to userInteractionEnabled:YES.
[view_ setUserInteractionEnabled:YES];
@@ -348,8 +346,8 @@
setImage:StretchableImageFromUIImage(tile, 0.0, 3.0)];
if (idiom == IPHONE_IDIOM) {
- stackButton_ =
- [[ToolbarCenteredButton alloc] initWithFrame:stackButtonFrame];
+ stackButton_.reset(
+ [[ToolbarCenteredButton alloc] initWithFrame:stackButtonFrame]);
[stackButton_ setTag:IDC_TOGGLE_TAB_SWITCHER];
[[stackButton_ titleLabel]
setFont:[self fontForSize:kFontSizeFewerThanTenTabs]];
@@ -409,14 +407,27 @@
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[toolsPopupController_ setDelegate:nil];
+ [super dealloc];
+}
+
+- (UIImageView*)view {
+ return view_.get();
+}
+
+- (UIImageView*)backgroundView {
+ return backgroundView_.get();
}
- (CGFloat)statusBarOffset {
return StatusBarHeight();
}
+- (UIImageView*)shadowView {
+ return shadowView_.get();
+}
+
- (NSMutableArray*)transitionLayers {
- return transitionLayers_;
+ return transitionLayers_.get();
}
- (BOOL)imageShouldFlipForRightToLeftLayoutDirection:(int)imageEnum {
@@ -433,18 +444,22 @@
[standardButtons addObject:stackButton_];
if (shareButtonShouldBeVisible)
[standardButtons addObject:shareButton_];
- standardButtons_ = standardButtons;
+ standardButtons_.reset([standardButtons retain]);
}
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[self updateStandardButtons];
}
+- (ToolsPopupController*)toolsPopupController {
+ return toolsPopupController_.get();
+}
+
- (void)applicationDidEnterBackground:(NSNotification*)notify {
- if (toolsPopupController_) {
+ if (toolsPopupController_.get()) {
// Dismiss the tools popup menu without animation.
[toolsMenuButton_ setToolsMenuIsVisible:NO];
- toolsPopupController_ = nil;
+ toolsPopupController_.reset(nil);
[[NSNotificationCenter defaultCenter]
postNotificationName:kMenuWillHideNotification
object:nil];
@@ -475,7 +490,7 @@
}
- (int)imageEnumForButton:(UIButton*)button {
- if (button == stackButton_)
+ if (button == stackButton_.get())
return ToolbarButtonNameStack;
return NumberOfToolbarButtonNames;
}
@@ -548,7 +563,7 @@
}
- (void)registerEventsForButton:(UIButton*)button {
- if (button != toolsMenuButton_) {
+ if (button != toolsMenuButton_.get()) {
// |target| must be |self| (as opposed to |nil|) because |self| isn't in the
// responder chain.
[button addTarget:self
@@ -570,7 +585,7 @@
}
- (UIView*)shareButtonView {
- return shareButton_;
+ return shareButton_.get();
}
- (void)showToolsMenuPopupWithConfiguration:
@@ -587,8 +602,8 @@
[toolsMenuButton_ setToolsMenuIsVisible:YES];
[configuration setToolsMenuButton:toolsMenuButton_];
- toolsPopupController_ =
- [[ToolsPopupController alloc] initWithConfiguration:configuration];
+ toolsPopupController_.reset(
+ [[ToolsPopupController alloc] initWithConfiguration:configuration]);
[toolsPopupController_ setDelegate:self];
@@ -598,9 +613,9 @@
}
- (void)dismissToolsMenuPopup {
- if (!toolsPopupController_)
+ if (!toolsPopupController_.get())
return;
- ToolsPopupController* tempTPC = toolsPopupController_;
+ ToolsPopupController* tempTPC = toolsPopupController_.get();
[tempTPC containerView].userInteractionEnabled = NO;
[tempTPC dismissAnimatedWithCompletion:^{
// Unpress the tools menu button by restoring the normal and
@@ -611,7 +626,7 @@
}];
// reset tabHistoryPopupController_ to prevent -applicationDidEnterBackground
// from posting another kMenuWillHideNotification.
- toolsPopupController_ = nil;
+ toolsPopupController_.reset();
[[NSNotificationCenter defaultCenter]
postNotificationName:kMenuWillHideNotification
@@ -670,7 +685,7 @@
fadeButtons.fromValue = @1;
fadeButtons.toValue = @0;
- for (UIButton* button in standardButtons_) {
+ for (UIButton* button in standardButtons_.get()) {
if (![button isHidden]) {
[button layer].opacity = 0;
[[button layer] addAnimation:fadeButtons forKey:@"fade"];
@@ -684,7 +699,7 @@
[CATransaction
setAnimationTimingFunction:TimingFunction(ios::material::CurveEaseIn)];
- for (UIButton* button in standardButtons_) {
+ for (UIButton* button in standardButtons_.get()) {
CABasicAnimation* shiftButton =
[CABasicAnimation animationWithKeyPath:@"position"];
CGPoint startPosition = [button layer].position;
@@ -706,7 +721,7 @@
}
- (void)fadeInStandardControls {
- for (UIButton* button in standardButtons_) {
+ for (UIButton* button in standardButtons_.get()) {
[self fadeInView:button
fromLeadingOffset:10
withDuration:ios::material::kDuration2
@@ -724,7 +739,7 @@
- (void)animationDidStart:(CAAnimation*)anim {
// Once the buttons start fading in, set their opacity to 1 so there's no
// flicker at the end of the animation.
- for (UIButton* button in standardButtons_) {
+ for (UIButton* button in standardButtons_.get()) {
if (anim == [[button layer] animationForKey:@"fadeIn"]) {
[button layer].opacity = 1;
return;
@@ -918,18 +933,18 @@
- (void)setStandardControlsVisible:(BOOL)visible {
if (visible) {
- for (UIButton* button in standardButtons_) {
+ for (UIButton* button in standardButtons_.get()) {
[button setAlpha:1.0];
}
} else {
- for (UIButton* button in standardButtons_) {
+ for (UIButton* button in standardButtons_.get()) {
[button setAlpha:0.0];
}
}
}
- (void)setStandardControlsAlpha:(CGFloat)alpha {
- for (UIButton* button in standardButtons_) {
+ for (UIButton* button in standardButtons_.get()) {
if (![button isHidden])
[button setAlpha:alpha];
}
@@ -941,7 +956,7 @@
}
- (void)setStandardControlsTransform:(CGAffineTransform)transform {
- for (UIButton* button in standardButtons_) {
+ for (UIButton* button in standardButtons_.get()) {
[button setTransform:transform];
}
}
@@ -999,11 +1014,11 @@
}
- (IBAction)recordUserMetrics:(id)sender {
- if (sender == toolsMenuButton_)
+ if (sender == toolsMenuButton_.get())
base::RecordAction(UserMetricsAction("MobileToolbarShowMenu"));
- else if (sender == stackButton_)
+ else if (sender == stackButton_.get())
base::RecordAction(UserMetricsAction("MobileToolbarShowStackView"));
- else if (sender == shareButton_)
+ else if (sender == shareButton_.get())
base::RecordAction(UserMetricsAction("MobileToolbarShareMenu"));
else
NOTREACHED();
« no previous file with comments | « ios/chrome/browser/ui/toolbar/toolbar_controller.h ('k') | ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698