| 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/tools_menu/tools_popup_controller.h" | 5 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/scoped_nsobject.h" | |
| 11 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
| 12 #include "base/metrics/user_metrics_action.h" | 11 #include "base/metrics/user_metrics_action.h" |
| 13 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 12 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 13 #import "ios/chrome/browser/ui/popup_menu/popup_menu_view.h" |
| 14 #include "ios/chrome/browser/ui/rtl_geometry.h" | 14 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 15 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h" | 15 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h" |
| 16 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 16 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 17 #import "ios/shared/chrome/browser/ui/tools_menu/tools_menu_configuration.h" | 17 #import "ios/shared/chrome/browser/ui/tools_menu/tools_menu_configuration.h" |
| 18 | 18 |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 20 #error "This file requires ARC support." |
| 21 #endif |
| 22 |
| 19 using base::UserMetricsAction; | 23 using base::UserMetricsAction; |
| 20 | 24 |
| 21 NSString* const kToolsMenuTableViewId = @"kToolsMenuTableViewId"; | 25 NSString* const kToolsMenuTableViewId = @"kToolsMenuTableViewId"; |
| 22 | 26 |
| 23 namespace { | 27 namespace { |
| 24 | 28 |
| 25 const CGFloat kToolsPopupMenuWidth = 280.0; | 29 const CGFloat kToolsPopupMenuWidth = 280.0; |
| 26 const CGFloat kToolsPopupMenuTrailingOffset = 4; | 30 const CGFloat kToolsPopupMenuTrailingOffset = 4; |
| 27 | 31 |
| 28 // Inset for the shadows of the contained views. | 32 // Inset for the shadows of the contained views. |
| 29 NS_INLINE UIEdgeInsets TabHistoryPopupMenuInsets() { | 33 NS_INLINE UIEdgeInsets TabHistoryPopupMenuInsets() { |
| 30 return UIEdgeInsetsMake(9, 11, 12, 11); | 34 return UIEdgeInsetsMake(9, 11, 12, 11); |
| 31 } | 35 } |
| 32 | 36 |
| 33 } // namespace | 37 } // namespace |
| 34 | 38 |
| 35 @interface ToolsPopupController ()<ToolsPopupTableDelegate> { | 39 @interface ToolsPopupController ()<ToolsPopupTableDelegate> { |
| 36 base::scoped_nsobject<ToolsMenuViewController> _toolsMenuViewController; | 40 ToolsMenuViewController* _toolsMenuViewController; |
| 37 // Container view of the menu items table. | 41 // Container view of the menu items table. |
| 38 base::scoped_nsobject<UIView> _toolsTableViewContainer; | 42 UIView* _toolsTableViewContainer; |
| 39 } | 43 } |
| 40 @end | 44 @end |
| 41 | 45 |
| 42 @implementation ToolsPopupController | 46 @implementation ToolsPopupController |
| 43 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; | 47 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; |
| 44 | 48 |
| 45 - (instancetype)initWithConfiguration:(ToolsMenuConfiguration*)configuration { | 49 - (instancetype)initWithConfiguration:(ToolsMenuConfiguration*)configuration { |
| 46 DCHECK(configuration.displayView); | 50 DCHECK(configuration.displayView); |
| 47 self = [super initWithParentView:configuration.displayView]; | 51 self = [super initWithParentView:configuration.displayView]; |
| 48 if (self) { | 52 if (self) { |
| 49 _toolsMenuViewController.reset([[ToolsMenuViewController alloc] init]); | 53 _toolsMenuViewController = [[ToolsMenuViewController alloc] init]; |
| 50 _toolsTableViewContainer.reset([[_toolsMenuViewController view] retain]); | 54 _toolsTableViewContainer = [_toolsMenuViewController view]; |
| 51 [_toolsTableViewContainer layer].cornerRadius = 2; | 55 [_toolsTableViewContainer layer].cornerRadius = 2; |
| 52 [_toolsTableViewContainer layer].masksToBounds = YES; | 56 [_toolsTableViewContainer layer].masksToBounds = YES; |
| 53 [_toolsMenuViewController initializeMenuWithConfiguration:configuration]; | 57 [_toolsMenuViewController initializeMenuWithConfiguration:configuration]; |
| 54 | 58 |
| 55 UIEdgeInsets popupInsets = TabHistoryPopupMenuInsets(); | 59 UIEdgeInsets popupInsets = TabHistoryPopupMenuInsets(); |
| 56 CGFloat popupWidth = kToolsPopupMenuWidth; | 60 CGFloat popupWidth = kToolsPopupMenuWidth; |
| 57 | 61 |
| 58 CGPoint origin = CGPointMake(CGRectGetMidX(configuration.sourceRect), | 62 CGPoint origin = CGPointMake(CGRectGetMidX(configuration.sourceRect), |
| 59 CGRectGetMidY(configuration.sourceRect)); | 63 CGRectGetMidY(configuration.sourceRect)); |
| 60 | 64 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 [toolsButton setImageEdgeInsets:configuration.toolsButtonInsets]; | 111 [toolsButton setImageEdgeInsets:configuration.toolsButtonInsets]; |
| 108 [outsideAnimationView addSubview:toolsButton]; | 112 [outsideAnimationView addSubview:toolsButton]; |
| 109 } | 113 } |
| 110 } | 114 } |
| 111 return self; | 115 return self; |
| 112 } | 116 } |
| 113 | 117 |
| 114 - (void)dealloc { | 118 - (void)dealloc { |
| 115 [_toolsTableViewContainer removeFromSuperview]; | 119 [_toolsTableViewContainer removeFromSuperview]; |
| 116 [_toolsMenuViewController setDelegate:nil]; | 120 [_toolsMenuViewController setDelegate:nil]; |
| 117 [super dealloc]; | |
| 118 } | 121 } |
| 119 | 122 |
| 120 - (void)fadeInPopupFromSource:(CGPoint)source | 123 - (void)fadeInPopupFromSource:(CGPoint)source |
| 121 toDestination:(CGPoint)destination { | 124 toDestination:(CGPoint)destination { |
| 122 [_toolsMenuViewController animateContentIn]; | 125 [_toolsMenuViewController animateContentIn]; |
| 123 [super fadeInPopupFromSource:source toDestination:destination]; | 126 [super fadeInPopupFromSource:source toDestination:destination]; |
| 124 } | 127 } |
| 125 | 128 |
| 126 - (void)dismissAnimatedWithCompletion:(void (^)(void))completion { | 129 - (void)dismissAnimatedWithCompletion:(void (^)(void))completion { |
| 127 [_toolsMenuViewController hideContent]; | 130 [_toolsMenuViewController hideContent]; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 default: | 233 default: |
| 231 NOTREACHED(); | 234 NOTREACHED(); |
| 232 break; | 235 break; |
| 233 } | 236 } |
| 234 | 237 |
| 235 // Close the menu. | 238 // Close the menu. |
| 236 [self.delegate dismissPopupMenu:self]; | 239 [self.delegate dismissPopupMenu:self]; |
| 237 } | 240 } |
| 238 | 241 |
| 239 @end | 242 @end |
| OLD | NEW |