| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/clean/chrome/browser/ui/presenters/menu_presentation_controller.h" | 5 #import "ios/clean/chrome/browser/ui/presenters/menu_presentation_controller.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include "ios/clean/chrome/browser/ui/commands/toolbar_commands.h" | 9 #include "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h" |
| 10 #include "ios/clean/chrome/browser/ui/presenters/menu_presentation_delegate.h" | 10 #include "ios/clean/chrome/browser/ui/presenters/menu_presentation_delegate.h" |
| 11 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." | 13 #error "This file requires ARC support." |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 @interface MenuPresentationController () | 16 @interface MenuPresentationController () |
| 17 @property(nonatomic, weak) id<MenuPresentationDelegate> presentationDelegate; | 17 @property(nonatomic, weak) id<MenuPresentationDelegate> presentationDelegate; |
| 18 @property(nonatomic, assign) CGRect presentationFrame; | 18 @property(nonatomic, assign) CGRect presentationFrame; |
| 19 @property(nonatomic, strong) UITapGestureRecognizer* dismissRecognizer; | 19 @property(nonatomic, strong) UITapGestureRecognizer* dismissRecognizer; |
| 20 @end | 20 @end |
| 21 | 21 |
| 22 @implementation MenuPresentationController | 22 @implementation MenuPresentationController |
| 23 @synthesize presentationDelegate = _presentationDelegate; | 23 @synthesize presentationDelegate = _presentationDelegate; |
| 24 @synthesize presentationFrame = _presentationFrame; | 24 @synthesize presentationFrame = _presentationFrame; |
| 25 @synthesize toolbarCommandHandler = _toolbarCommandHandler; | 25 @synthesize dispatcher = _dispatcher; |
| 26 @synthesize dismissRecognizer = _dismissRecognizer; | 26 @synthesize dismissRecognizer = _dismissRecognizer; |
| 27 | 27 |
| 28 #pragma mark - UIPresentationDelegate | 28 #pragma mark - UIPresentationDelegate |
| 29 | 29 |
| 30 - (CGRect)frameOfPresentedViewInContainerView { | 30 - (CGRect)frameOfPresentedViewInContainerView { |
| 31 if (CGRectIsEmpty(self.presentationFrame)) { | 31 if (CGRectIsEmpty(self.presentationFrame)) { |
| 32 [self updatePresentationDelegate]; | 32 [self updatePresentationDelegate]; |
| 33 if (self.presentationDelegate) { | 33 if (self.presentationDelegate) { |
| 34 self.presentationFrame = | 34 self.presentationFrame = |
| 35 [self.presentationDelegate frameForMenuPresentation:self]; | 35 [self.presentationDelegate frameForMenuPresentation:self]; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 53 | 53 |
| 54 self.dismissRecognizer = | 54 self.dismissRecognizer = |
| 55 [[UITapGestureRecognizer alloc] initWithTarget:self | 55 [[UITapGestureRecognizer alloc] initWithTarget:self |
| 56 action:@selector(tapToDismiss:)]; | 56 action:@selector(tapToDismiss:)]; |
| 57 [self.containerView addGestureRecognizer:self.dismissRecognizer]; | 57 [self.containerView addGestureRecognizer:self.dismissRecognizer]; |
| 58 } | 58 } |
| 59 | 59 |
| 60 #pragma mark - Private methods. | 60 #pragma mark - Private methods. |
| 61 | 61 |
| 62 - (void)tapToDismiss:(UIGestureRecognizer*)recognizer { | 62 - (void)tapToDismiss:(UIGestureRecognizer*)recognizer { |
| 63 [self.toolbarCommandHandler closeToolsMenu]; | 63 [self.dispatcher closeToolsMenu]; |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Checks if the presenting view controller conforms to | 66 // Checks if the presenting view controller conforms to |
| 67 // MenuPresentationDelegate and, if so, sets that view controller as the | 67 // MenuPresentationDelegate and, if so, sets that view controller as the |
| 68 // presentation delegate. This can't be done at init time, becuase the | 68 // presentation delegate. This can't be done at init time, becuase the |
| 69 // presenting view controller may not have been determined by UIKit yet. | 69 // presenting view controller may not have been determined by UIKit yet. |
| 70 - (void)updatePresentationDelegate { | 70 - (void)updatePresentationDelegate { |
| 71 if ([self.presentingViewController | 71 if ([self.presentingViewController |
| 72 conformsToProtocol:@protocol(MenuPresentationDelegate)]) { | 72 conformsToProtocol:@protocol(MenuPresentationDelegate)]) { |
| 73 self.presentationDelegate = static_cast<id<MenuPresentationDelegate>>( | 73 self.presentationDelegate = static_cast<id<MenuPresentationDelegate>>( |
| 74 self.presentingViewController); | 74 self.presentingViewController); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 @end | 78 @end |
| OLD | NEW |