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/tab/tab_container_view_controller.h" | 9 #import "ios/clean/chrome/browser/ui/tab/tab_container_view_controller.h" |
| 10 | 10 |
| 11 #import "base/mac/foundation_util.h" | |
| 11 #import "ios/clean/chrome/browser/ui/ui_types.h" | 12 #import "ios/clean/chrome/browser/ui/ui_types.h" |
| 12 | 13 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) | 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." | 15 #error "This file requires ARC support." |
| 15 #endif | 16 #endif |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 CGFloat kToolbarHeight = 56.0; | 19 CGFloat kToolbarHeight = 56.0; |
| 19 } | 20 } |
| 20 | 21 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 return self.topmostViewController; | 121 return self.topmostViewController; |
| 121 } | 122 } |
| 122 | 123 |
| 123 - (UIViewController*)childViewControllerForStatusBarStyle { | 124 - (UIViewController*)childViewControllerForStatusBarStyle { |
| 124 return self.topmostViewController; | 125 return self.topmostViewController; |
| 125 } | 126 } |
| 126 | 127 |
| 127 #pragma mark - MenuPresentationDelegate | 128 #pragma mark - MenuPresentationDelegate |
| 128 | 129 |
| 129 - (CGRect)frameForMenuPresentation:(UIPresentationController*)presentation { | 130 - (CGRect)frameForMenuPresentation:(UIPresentationController*)presentation { |
| 130 // Placeholder. | 131 CGSize menuSize = presentation.presentedView.frame.size; |
| 131 return CGRectMake(50, 50, 250, 300); | 132 CGRect menuRect; |
| 133 menuRect.size = menuSize; | |
| 134 | |
| 135 CGRect menuOriginRect = [self rectForZoomWithKey:@"" inView:self.view]; | |
| 136 if (CGRectIsNull(menuOriginRect)) { | |
| 137 menuRect.origin = CGPointMake(50, 50); | |
| 138 return menuRect; | |
| 139 } | |
| 140 // Calculate which corner of the menu the origin rect is in. This is | |
| 141 // deterimined by comparing frames, and thus is RTL-independent. | |
|
lpromero
2017/01/05 14:27:04
*determined
marq (ping after 24h)
2017/01/09 18:05:00
Done.
| |
| 142 if (CGRectGetMinX(menuOriginRect) - CGRectGetMinX(self.view.bounds) < | |
| 143 CGRectGetMaxX(self.view.bounds) - CGRectGetMaxX(menuOriginRect)) { | |
| 144 // Origin rect is closer to the left edge of |self.view| than to the right. | |
| 145 menuRect.origin.x = CGRectGetMinX(menuOriginRect); | |
| 146 } else { | |
| 147 // Origin rect is closer to the right edge of |self.view| than to the left. | |
| 148 menuRect.origin.x = CGRectGetMaxX(menuOriginRect) - menuSize.width; | |
| 149 } | |
| 150 | |
| 151 if (CGRectGetMinY(menuOriginRect) - CGRectGetMinY(self.view.bounds) < | |
| 152 CGRectGetMaxY(self.view.bounds) - CGRectGetMaxY(menuOriginRect)) { | |
| 153 // Origin rect is closer to the top edge of |self.view| than to the bottom. | |
| 154 menuRect.origin.y = CGRectGetMinY(menuOriginRect); | |
| 155 } else { | |
| 156 // Origin rect is closer to the bottom edge of |self.view| than to the top. | |
| 157 menuRect.origin.y = CGRectGetMaxY(menuOriginRect) - menuSize.height; | |
| 158 } | |
| 159 | |
| 160 return menuRect; | |
| 161 } | |
| 162 | |
| 163 #pragma mark - ZoomTransitionDelegate | |
| 164 | |
| 165 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { | |
| 166 UIViewController<ZoomTransitionDelegate>* delegate = | |
| 167 base::mac::ObjCCast<UIViewController<ZoomTransitionDelegate>>( | |
| 168 self.toolbarViewController); | |
| 169 if (delegate) | |
| 170 return [delegate rectForZoomWithKey:key inView:view]; | |
| 171 return CGRectNull; | |
| 132 } | 172 } |
| 133 | 173 |
| 134 #pragma mark - UIResponder | 174 #pragma mark - UIResponder |
| 135 | 175 |
| 136 // Before forwarding actions up the responder chain, give both contained | 176 // Before forwarding actions up the responder chain, give both contained |
| 137 // view controllers a chance to handle them. | 177 // view controllers a chance to handle them. |
| 138 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { | 178 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { |
| 139 self.actionToForward = nullptr; | 179 self.actionToForward = nullptr; |
| 140 self.forwardingTarget = nil; | 180 self.forwardingTarget = nil; |
| 141 for (UIResponder* responder in | 181 for (UIResponder* responder in |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 self.toolbarConstraints = @[ | 315 self.toolbarConstraints = @[ |
| 276 [toolbarView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor], | 316 [toolbarView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor], |
| 277 [toolbarView.heightAnchor constraintEqualToConstant:kToolbarHeight], | 317 [toolbarView.heightAnchor constraintEqualToConstant:kToolbarHeight], |
| 278 [toolbarView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor], | 318 [toolbarView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor], |
| 279 [toolbarView.trailingAnchor | 319 [toolbarView.trailingAnchor |
| 280 constraintEqualToAnchor:self.view.trailingAnchor], | 320 constraintEqualToAnchor:self.view.trailingAnchor], |
| 281 ]; | 321 ]; |
| 282 } | 322 } |
| 283 | 323 |
| 284 @end | 324 @end |
| OLD | NEW |