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

Unified Diff: ios/chrome/browser/ui/presenters/menu_presentation_controller.mm

Issue 2589803002: Upstream Chrome on iOS source code [6/11]. (Closed)
Patch Set: Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/presenters/menu_presentation_controller.mm
diff --git a/ios/chrome/browser/ui/presenters/menu_presentation_controller.mm b/ios/chrome/browser/ui/presenters/menu_presentation_controller.mm
new file mode 100644
index 0000000000000000000000000000000000000000..8c87a8b8ccdc33911764adb98533ea22ef5ef6bf
--- /dev/null
+++ b/ios/chrome/browser/ui/presenters/menu_presentation_controller.mm
@@ -0,0 +1,65 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// ====== New Architecture =====
+// = This code is only used in the new iOS Chrome architecture. =
+// ============================================================================
+
+#import "ios/chrome/browser/ui/presenters/menu_presentation_controller.h"
+
+#import <QuartzCore/QuartzCore.h>
+
+#include "ios/chrome/browser/ui/presenters/menu_presentation_delegate.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+@interface MenuPresentationController ()
+@property(nonatomic, weak) id<MenuPresentationDelegate> presentationDelegate;
+@property(nonatomic, assign) CGRect presentationFrame;
+@end
+
+@implementation MenuPresentationController
+@synthesize presentationDelegate = _presentationDelegate;
+@synthesize presentationFrame = _presentationFrame;
+
+#pragma mark - UIPresentationDelegate
+
+- (CGRect)frameOfPresentedViewInContainerView {
+ if (CGRectIsEmpty(self.presentationFrame)) {
+ [self updatePresentationDelegate];
+ if (self.presentationDelegate) {
+ self.presentationFrame =
+ [self.presentationDelegate frameForMenuPresentation:self];
+ } else {
+ // Placeholder default frame: something rectangular, 50 points in and
+ // down.
+ self.presentationFrame = CGRectMake(50, 50, 250, 300);
+ }
+ }
+ return self.presentationFrame;
+}
+
+- (void)presentationTransitionWillBegin {
+ self.presentedView.layer.borderWidth = 1.0;
+ self.presentedView.layer.shadowRadius = 1.0;
+ self.presentedView.layer.borderColor = [UIColor blackColor].CGColor;
+}
+
+#pragma mark - Private methods.
+
+// Checks if the presenting view controller conforms to
+// MenuPresentationDelegate and, if so, sets that view controller as the
+// presentation delegate. This can't be done at init time, becuase the
+// presenting view controller may not have been determined by UIKit yet.
+- (void)updatePresentationDelegate {
+ if ([self.presentingViewController
+ conformsToProtocol:@protocol(MenuPresentationDelegate)]) {
+ self.presentationDelegate = static_cast<id<MenuPresentationDelegate>>(
+ self.presentingViewController);
+ }
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698