Chromium Code Reviews| 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 // ====== New Architecture ===== | 5 // ====== New Architecture ===== |
| 6 // = This code is only used in the new iOS Chrome architecture. = | 6 // = This code is only used in the new iOS Chrome architecture. = |
| 7 // ============================================================================ | 7 // ============================================================================ |
| 8 | 8 |
| 9 #import "ios/clean/chrome/browser/ui/presenters/menu_presentation_controller.h" | 9 #import "ios/clean/chrome/browser/ui/presenters/menu_presentation_controller.h" |
| 10 | 10 |
| 11 #import <QuartzCore/QuartzCore.h> | 11 #import <QuartzCore/QuartzCore.h> |
| 12 | 12 |
| 13 #include "ios/clean/chrome/browser/ui/commands/toolbar_commands.h" | |
| 13 #include "ios/clean/chrome/browser/ui/presenters/menu_presentation_delegate.h" | 14 #include "ios/clean/chrome/browser/ui/presenters/menu_presentation_delegate.h" |
| 14 | 15 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
| 17 #endif | 18 #endif |
| 18 | 19 |
| 19 @interface MenuPresentationController () | 20 @interface MenuPresentationController () |
| 20 @property(nonatomic, weak) id<MenuPresentationDelegate> presentationDelegate; | 21 @property(nonatomic, weak) id<MenuPresentationDelegate> presentationDelegate; |
| 21 @property(nonatomic, assign) CGRect presentationFrame; | 22 @property(nonatomic, assign) CGRect presentationFrame; |
| 23 @property(nonatomic) UITapGestureRecognizer* dismissRecognizer; | |
|
lpromero
2017/01/05 14:27:04
I'd explicitly annotate "strong".
marq (ping after 24h)
2017/01/09 18:05:00
Done.
| |
| 22 @end | 24 @end |
| 23 | 25 |
| 24 @implementation MenuPresentationController | 26 @implementation MenuPresentationController |
| 25 @synthesize presentationDelegate = _presentationDelegate; | 27 @synthesize presentationDelegate = _presentationDelegate; |
| 26 @synthesize presentationFrame = _presentationFrame; | 28 @synthesize presentationFrame = _presentationFrame; |
| 29 @synthesize toolbarCommandHandler = _toolbarCommandHandler; | |
| 30 @synthesize dismissRecognizer = _dismissRecognizer; | |
| 27 | 31 |
| 28 #pragma mark - UIPresentationDelegate | 32 #pragma mark - UIPresentationDelegate |
| 29 | 33 |
| 30 - (CGRect)frameOfPresentedViewInContainerView { | 34 - (CGRect)frameOfPresentedViewInContainerView { |
| 31 if (CGRectIsEmpty(self.presentationFrame)) { | 35 if (CGRectIsEmpty(self.presentationFrame)) { |
| 32 [self updatePresentationDelegate]; | 36 [self updatePresentationDelegate]; |
| 33 if (self.presentationDelegate) { | 37 if (self.presentationDelegate) { |
| 34 self.presentationFrame = | 38 self.presentationFrame = |
| 35 [self.presentationDelegate frameForMenuPresentation:self]; | 39 [self.presentationDelegate frameForMenuPresentation:self]; |
| 36 } else { | 40 } else { |
| 37 // Placeholder default frame: something rectangular, 50 points in and | 41 // Placeholder default frame: centered in the presenting view. |
| 38 // down. | 42 CGSize menuSize = self.presentedView.frame.size; |
| 39 self.presentationFrame = CGRectMake(50, 50, 250, 300); | 43 self.presentationFrame.size = menuSize; |
| 44 self.presentationFrame.origin = CGPointMake( | |
| 45 self.containerView.bounds.size.width - menuSize.width / 2.0, | |
| 46 self.containerView.bounds.size.height - menuSize.height / 2.0); | |
|
lpromero
2017/01/05 14:27:04
Shouldn’t it be (a - b)/2 instead of a - b/2?
marq (ping after 24h)
2017/01/09 18:05:00
Yes, I am mostly innumerate.
| |
| 40 } | 47 } |
| 41 } | 48 } |
| 42 return self.presentationFrame; | 49 return self.presentationFrame; |
| 43 } | 50 } |
| 44 | 51 |
| 45 - (void)presentationTransitionWillBegin { | 52 - (void)presentationTransitionWillBegin { |
| 46 self.presentedView.layer.borderWidth = 1.0; | 53 self.presentedView.layer.borderWidth = 1.0; |
| 47 self.presentedView.layer.shadowRadius = 1.0; | 54 self.presentedView.layer.shadowRadius = 1.0; |
| 48 self.presentedView.layer.borderColor = [UIColor blackColor].CGColor; | 55 self.presentedView.layer.borderColor = [UIColor blackColor].CGColor; |
| 56 | |
| 57 self.dismissRecognizer = | |
| 58 [[UITapGestureRecognizer alloc] initWithTarget:self | |
| 59 action:@selector(tapToDismiss:)]; | |
| 60 [self.containerView addGestureRecognizer:self.dismissRecognizer]; | |
| 49 } | 61 } |
| 50 | 62 |
| 51 #pragma mark - Private methods. | 63 #pragma mark - Private methods. |
| 52 | 64 |
| 65 - (void)tapToDismiss:(UIGestureRecognizer*)recognizer { | |
| 66 [self.toolbarCommandHandler closeToolsMenu]; | |
| 67 } | |
| 68 | |
| 53 // Checks if the presenting view controller conforms to | 69 // Checks if the presenting view controller conforms to |
| 54 // MenuPresentationDelegate and, if so, sets that view controller as the | 70 // MenuPresentationDelegate and, if so, sets that view controller as the |
| 55 // presentation delegate. This can't be done at init time, becuase the | 71 // presentation delegate. This can't be done at init time, becuase the |
| 56 // presenting view controller may not have been determined by UIKit yet. | 72 // presenting view controller may not have been determined by UIKit yet. |
| 57 - (void)updatePresentationDelegate { | 73 - (void)updatePresentationDelegate { |
| 58 if ([self.presentingViewController | 74 if ([self.presentingViewController |
| 59 conformsToProtocol:@protocol(MenuPresentationDelegate)]) { | 75 conformsToProtocol:@protocol(MenuPresentationDelegate)]) { |
| 60 self.presentationDelegate = static_cast<id<MenuPresentationDelegate>>( | 76 self.presentationDelegate = static_cast<id<MenuPresentationDelegate>>( |
| 61 self.presentingViewController); | 77 self.presentingViewController); |
| 62 } | 78 } |
| 63 } | 79 } |
| 64 | 80 |
| 65 @end | 81 @end |
| OLD | NEW |