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

Side by Side Diff: ios/chrome/browser/ui/popup_menu/popup_menu_controller.mm

Issue 2935743002: [ObjC ARC] Converts ios/chrome/browser/ui/popup_menu:popup_menu to ARC. (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/ui/popup_menu/popup_menu_controller.h" 5 #import "ios/chrome/browser/ui/popup_menu/popup_menu_controller.h"
6 6
7 #import "base/ios/weak_nsobject.h"
8 #include "base/logging.h" 7 #include "base/logging.h"
9 #include "base/mac/bundle_locations.h" 8 #include "base/mac/bundle_locations.h"
10 #include "base/mac/objc_property_releaser.h"
11 #import "ios/chrome/browser/ui/animation_util.h" 9 #import "ios/chrome/browser/ui/animation_util.h"
12 #import "ios/chrome/browser/ui/popup_menu/popup_menu_view.h" 10 #import "ios/chrome/browser/ui/popup_menu/popup_menu_view.h"
13 #include "ios/chrome/browser/ui/rtl_geometry.h" 11 #include "ios/chrome/browser/ui/rtl_geometry.h"
14 #import "ios/chrome/browser/ui/uikit_ui_util.h" 12 #import "ios/chrome/browser/ui/uikit_ui_util.h"
15 #import "ios/chrome/common/material_timing.h" 13 #import "ios/chrome/common/material_timing.h"
16 #include "ios/chrome/grit/ios_strings.h" 14 #include "ios/chrome/grit/ios_strings.h"
17 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
18 16
17 #if !defined(__has_feature) || !__has_feature(objc_arc)
18 #error "This file requires ARC support."
19 #endif
20
19 using ios::material::TimingFunction; 21 using ios::material::TimingFunction;
20 22
21 namespace { 23 namespace {
22 // Inset for the shadows of the contained views. 24 // Inset for the shadows of the contained views.
23 static const CGFloat kPopupMenuVerticalInset = 11.0; 25 static const CGFloat kPopupMenuVerticalInset = 11.0;
24 // Duration for the Popup Menu Fade In animation 26 // Duration for the Popup Menu Fade In animation
25 static const CGFloat kFadeInAnimationDuration = 0.2; 27 static const CGFloat kFadeInAnimationDuration = 0.2;
26 // Value to pass in for backgroundButtonTag to not set a tag value for 28 // Value to pass in for backgroundButtonTag to not set a tag value for
27 // |backgroundButton_|. 29 // |backgroundButton_|.
28 static const NSInteger kBackgroundButtonNoTag = -1; 30 static const NSInteger kBackgroundButtonNoTag = -1;
(...skipping 19 matching lines...) Expand all
48 static CGPoint AnimateInIntermediaryPoint(CGPoint source, CGPoint destination) { 50 static CGPoint AnimateInIntermediaryPoint(CGPoint source, CGPoint destination) {
49 CGPoint midPoint = CGPointZero; 51 CGPoint midPoint = CGPointZero;
50 midPoint.x = destination.x; 52 midPoint.x = destination.x;
51 midPoint.y = source.y - 0.8 * fabs(destination.y - source.y); 53 midPoint.y = source.y - 0.8 * fabs(destination.y - source.y);
52 return midPoint; 54 return midPoint;
53 } 55 }
54 56
55 } // anonymous namespace 57 } // anonymous namespace
56 58
57 @interface PopupMenuController ()<PopupMenuViewDelegate> { 59 @interface PopupMenuController ()<PopupMenuViewDelegate> {
58 base::mac::ObjCPropertyReleaser propertyReleaser_PopupMenuController_;
59 CGPoint sourceAnimationPoint_; 60 CGPoint sourceAnimationPoint_;
60 } 61 }
61 @end 62 @end
62 63
63 @implementation PopupMenuController 64 @implementation PopupMenuController
64 65
65 @synthesize containerView = containerView_; 66 @synthesize containerView = containerView_;
66 @synthesize backgroundButton = backgroundButton_; 67 @synthesize backgroundButton = backgroundButton_;
67 @synthesize popupContainer = popupContainer_; 68 @synthesize popupContainer = popupContainer_;
68 @synthesize delegate = delegate_; 69 @synthesize delegate = delegate_;
69 70
70 - (id)initWithParentView:(UIView*)parent { 71 - (id)initWithParentView:(UIView*)parent {
71 return [self initWithParentView:parent 72 return [self initWithParentView:parent
72 backgroundButtonParent:nil 73 backgroundButtonParent:nil
73 backgroundButtonColor:nil 74 backgroundButtonColor:nil
74 backgroundButtonAlpha:1.0 75 backgroundButtonAlpha:1.0
75 backgroundButtonTag:kBackgroundButtonNoTag 76 backgroundButtonTag:kBackgroundButtonNoTag
76 backgroundButtonSelector:nil]; 77 backgroundButtonSelector:nil];
77 } 78 }
78 79
79 - (id)initWithParentView:(UIView*)parent 80 - (id)initWithParentView:(UIView*)parent
80 backgroundButtonParent:(UIView*)backgroundButtonParent 81 backgroundButtonParent:(UIView*)backgroundButtonParent
81 backgroundButtonColor:(UIColor*)backgroundButtonColor 82 backgroundButtonColor:(UIColor*)backgroundButtonColor
82 backgroundButtonAlpha:(CGFloat)backgroundButtonAlpha 83 backgroundButtonAlpha:(CGFloat)backgroundButtonAlpha
83 backgroundButtonTag:(NSInteger)backgroundButtonTag 84 backgroundButtonTag:(NSInteger)backgroundButtonTag
84 backgroundButtonSelector:(SEL)backgroundButtonSelector { 85 backgroundButtonSelector:(SEL)backgroundButtonSelector {
85 DCHECK(parent); 86 DCHECK(parent);
86 self = [super init]; 87 self = [super init];
87 if (self) { 88 if (self) {
88 propertyReleaser_PopupMenuController_.Init(self,
89 [PopupMenuController class]);
90
91 popupContainer_ = [[PopupMenuView alloc] 89 popupContainer_ = [[PopupMenuView alloc]
92 initWithFrame:CGRectMake(0, 0, kPopupContainerWidth, 90 initWithFrame:CGRectMake(0, 0, kPopupContainerWidth,
93 kPopupContainerHeight)]; 91 kPopupContainerHeight)];
94 92
95 containerView_ = [[UIView alloc] initWithFrame:[parent bounds]]; 93 containerView_ = [[UIView alloc] initWithFrame:[parent bounds]];
96 containerView_.backgroundColor = [UIColor clearColor]; 94 containerView_.backgroundColor = [UIColor clearColor];
97 [containerView_ setAccessibilityViewIsModal:YES]; 95 [containerView_ setAccessibilityViewIsModal:YES];
98 [popupContainer_ setDelegate:self]; 96 [popupContainer_ setDelegate:self];
99 // All views are added to the |containerView_| that in turn is added to the 97 // All views are added to the |containerView_| that in turn is added to the
100 // parent view. The Container View is needed to have a simple alpha 98 // parent view. The Container View is needed to have a simple alpha
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 animations:^{ 167 animations:^{
170 [containerView_ setAlpha:1.0]; 168 [containerView_ setAlpha:1.0];
171 } 169 }
172 completion:completionBlock]; 170 completion:completionBlock];
173 } 171 }
174 172
175 - (void)dealloc { 173 - (void)dealloc {
176 [popupContainer_ removeFromSuperview]; 174 [popupContainer_ removeFromSuperview];
177 [backgroundButton_ removeFromSuperview]; 175 [backgroundButton_ removeFromSuperview];
178 [containerView_ removeFromSuperview]; 176 [containerView_ removeFromSuperview];
179 [super dealloc];
180 } 177 }
181 178
182 - (void)tappedBehindPopup:(id)sender { 179 - (void)tappedBehindPopup:(id)sender {
183 [self dismissPopupMenu]; 180 [self dismissPopupMenu];
184 } 181 }
185 182
186 - (void)animateInFromPoint:(CGPoint)source toPoint:(CGPoint)destination { 183 - (void)animateInFromPoint:(CGPoint)source toPoint:(CGPoint)destination {
187 sourceAnimationPoint_ = source; 184 sourceAnimationPoint_ = source;
188 185
189 // Set anchor to top right for top right destinations. 186 // Set anchor to top right for top right destinations.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 midPoint.x = destination.x; 234 midPoint.x = destination.x;
238 midPoint.y = source.y - 0.8 * fabs(destination.x - source.x); 235 midPoint.y = source.y - 0.8 * fabs(destination.x - source.x);
239 236
240 CATransform3D scaleTransform = 237 CATransform3D scaleTransform =
241 CATransform3DMakeScale(kPopoverScaleFactor, kPopoverScaleFactor, 1); 238 CATransform3DMakeScale(kPopoverScaleFactor, kPopoverScaleFactor, 1);
242 239
243 CAMediaTimingFunction* easeIn = TimingFunction(ios::material::CurveEaseIn); 240 CAMediaTimingFunction* easeIn = TimingFunction(ios::material::CurveEaseIn);
244 [CATransaction begin]; 241 [CATransaction begin];
245 [CATransaction setAnimationTimingFunction:easeIn]; 242 [CATransaction setAnimationTimingFunction:easeIn];
246 [CATransaction setAnimationDuration:ios::material::kDuration2]; 243 [CATransaction setAnimationDuration:ios::material::kDuration2];
247
248 base::WeakNSObject<PopupMenuController> weakSelf(self);
249 [CATransaction setCompletionBlock:^{ 244 [CATransaction setCompletionBlock:^{
250 if (completion) 245 if (completion)
251 completion(); 246 completion();
252 }]; 247 }];
253 248
254 NSValue* sourceScaleValue = 249 NSValue* sourceScaleValue =
255 [NSValue valueWithCATransform3D:CATransform3DIdentity]; 250 [NSValue valueWithCATransform3D:CATransform3DIdentity];
256 251
257 CABasicAnimation* scaleAnimation = 252 CABasicAnimation* scaleAnimation =
258 [CABasicAnimation animationWithKeyPath:@"transform"]; 253 [CABasicAnimation animationWithKeyPath:@"transform"];
(...skipping 19 matching lines...) Expand all
278 } 273 }
279 274
280 #pragma mark - 275 #pragma mark -
281 #pragma mark PopupMenuViewDelegate 276 #pragma mark PopupMenuViewDelegate
282 277
283 - (void)dismissPopupMenu { 278 - (void)dismissPopupMenu {
284 [delegate_ dismissPopupMenu:self]; 279 [delegate_ dismissPopupMenu:self];
285 } 280 }
286 281
287 @end 282 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/popup_menu/popup_menu_controller.h ('k') | ios/chrome/browser/ui/popup_menu/popup_menu_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698