| OLD | NEW |
| 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" | 7 #import "base/ios/weak_nsobject.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
| 10 #include "base/mac/objc_property_releaser.h" | 10 #include "base/mac/objc_release_properties.h" |
| 11 #import "ios/chrome/browser/ui/animation_util.h" | 11 #import "ios/chrome/browser/ui/animation_util.h" |
| 12 #import "ios/chrome/browser/ui/popup_menu/popup_menu_view.h" | 12 #import "ios/chrome/browser/ui/popup_menu/popup_menu_view.h" |
| 13 #include "ios/chrome/browser/ui/rtl_geometry.h" | 13 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 14 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 14 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 15 #import "ios/chrome/common/material_timing.h" | 15 #import "ios/chrome/common/material_timing.h" |
| 16 #include "ios/chrome/grit/ios_strings.h" | 16 #include "ios/chrome/grit/ios_strings.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 | 18 |
| 19 using ios::material::TimingFunction; | 19 using ios::material::TimingFunction; |
| 20 | 20 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 48 static CGPoint AnimateInIntermediaryPoint(CGPoint source, CGPoint destination) { | 48 static CGPoint AnimateInIntermediaryPoint(CGPoint source, CGPoint destination) { |
| 49 CGPoint midPoint = CGPointZero; | 49 CGPoint midPoint = CGPointZero; |
| 50 midPoint.x = destination.x; | 50 midPoint.x = destination.x; |
| 51 midPoint.y = source.y - 0.8 * fabs(destination.y - source.y); | 51 midPoint.y = source.y - 0.8 * fabs(destination.y - source.y); |
| 52 return midPoint; | 52 return midPoint; |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // anonymous namespace | 55 } // anonymous namespace |
| 56 | 56 |
| 57 @interface PopupMenuController ()<PopupMenuViewDelegate> { | 57 @interface PopupMenuController ()<PopupMenuViewDelegate> { |
| 58 base::mac::ObjCPropertyReleaser propertyReleaser_PopupMenuController_; | |
| 59 CGPoint sourceAnimationPoint_; | 58 CGPoint sourceAnimationPoint_; |
| 60 } | 59 } |
| 61 @end | 60 @end |
| 62 | 61 |
| 63 @implementation PopupMenuController | 62 @implementation PopupMenuController |
| 64 | 63 |
| 65 @synthesize containerView = containerView_; | 64 @synthesize containerView = containerView_; |
| 66 @synthesize backgroundButton = backgroundButton_; | 65 @synthesize backgroundButton = backgroundButton_; |
| 67 @synthesize popupContainer = popupContainer_; | 66 @synthesize popupContainer = popupContainer_; |
| 68 @synthesize delegate = delegate_; | 67 @synthesize delegate = delegate_; |
| 69 | 68 |
| 70 - (id)initWithParentView:(UIView*)parent { | 69 - (id)initWithParentView:(UIView*)parent { |
| 71 return [self initWithParentView:parent | 70 return [self initWithParentView:parent |
| 72 backgroundButtonParent:nil | 71 backgroundButtonParent:nil |
| 73 backgroundButtonColor:nil | 72 backgroundButtonColor:nil |
| 74 backgroundButtonAlpha:1.0 | 73 backgroundButtonAlpha:1.0 |
| 75 backgroundButtonTag:kBackgroundButtonNoTag | 74 backgroundButtonTag:kBackgroundButtonNoTag |
| 76 backgroundButtonSelector:nil]; | 75 backgroundButtonSelector:nil]; |
| 77 } | 76 } |
| 78 | 77 |
| 79 - (id)initWithParentView:(UIView*)parent | 78 - (id)initWithParentView:(UIView*)parent |
| 80 backgroundButtonParent:(UIView*)backgroundButtonParent | 79 backgroundButtonParent:(UIView*)backgroundButtonParent |
| 81 backgroundButtonColor:(UIColor*)backgroundButtonColor | 80 backgroundButtonColor:(UIColor*)backgroundButtonColor |
| 82 backgroundButtonAlpha:(CGFloat)backgroundButtonAlpha | 81 backgroundButtonAlpha:(CGFloat)backgroundButtonAlpha |
| 83 backgroundButtonTag:(NSInteger)backgroundButtonTag | 82 backgroundButtonTag:(NSInteger)backgroundButtonTag |
| 84 backgroundButtonSelector:(SEL)backgroundButtonSelector { | 83 backgroundButtonSelector:(SEL)backgroundButtonSelector { |
| 85 DCHECK(parent); | 84 DCHECK(parent); |
| 86 self = [super init]; | 85 self = [super init]; |
| 87 if (self) { | 86 if (self) { |
| 88 propertyReleaser_PopupMenuController_.Init(self, | |
| 89 [PopupMenuController class]); | |
| 90 | |
| 91 popupContainer_ = [[PopupMenuView alloc] | 87 popupContainer_ = [[PopupMenuView alloc] |
| 92 initWithFrame:CGRectMake(0, 0, kPopupContainerWidth, | 88 initWithFrame:CGRectMake(0, 0, kPopupContainerWidth, |
| 93 kPopupContainerHeight)]; | 89 kPopupContainerHeight)]; |
| 94 | 90 |
| 95 containerView_ = [[UIView alloc] initWithFrame:[parent bounds]]; | 91 containerView_ = [[UIView alloc] initWithFrame:[parent bounds]]; |
| 96 containerView_.backgroundColor = [UIColor clearColor]; | 92 containerView_.backgroundColor = [UIColor clearColor]; |
| 97 [containerView_ setAccessibilityViewIsModal:YES]; | 93 [containerView_ setAccessibilityViewIsModal:YES]; |
| 98 [popupContainer_ setDelegate:self]; | 94 [popupContainer_ setDelegate:self]; |
| 99 // All views are added to the |containerView_| that in turn is added to the | 95 // 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 | 96 // parent view. The Container View is needed to have a simple alpha |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 animations:^{ | 165 animations:^{ |
| 170 [containerView_ setAlpha:1.0]; | 166 [containerView_ setAlpha:1.0]; |
| 171 } | 167 } |
| 172 completion:completionBlock]; | 168 completion:completionBlock]; |
| 173 } | 169 } |
| 174 | 170 |
| 175 - (void)dealloc { | 171 - (void)dealloc { |
| 176 [popupContainer_ removeFromSuperview]; | 172 [popupContainer_ removeFromSuperview]; |
| 177 [backgroundButton_ removeFromSuperview]; | 173 [backgroundButton_ removeFromSuperview]; |
| 178 [containerView_ removeFromSuperview]; | 174 [containerView_ removeFromSuperview]; |
| 175 base::mac::ReleaseProperties(self); |
| 179 [super dealloc]; | 176 [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 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 } | 275 } |
| 279 | 276 |
| 280 #pragma mark - | 277 #pragma mark - |
| 281 #pragma mark PopupMenuViewDelegate | 278 #pragma mark PopupMenuViewDelegate |
| 282 | 279 |
| 283 - (void)dismissPopupMenu { | 280 - (void)dismissPopupMenu { |
| 284 [delegate_ dismissPopupMenu:self]; | 281 [delegate_ dismissPopupMenu:self]; |
| 285 } | 282 } |
| 286 | 283 |
| 287 @end | 284 @end |
| OLD | NEW |