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

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

Issue 2952213003: [ios clean] Refactors ToolsMenu and Tabs presentation (Closed)
Patch Set: Created 3 years, 6 months 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/clean/chrome/browser/ui/presenters/menu_presentation_controller.mm
diff --git a/ios/clean/chrome/browser/ui/presenters/menu_presentation_controller.mm b/ios/clean/chrome/browser/ui/presenters/menu_presentation_controller.mm
index 79a0295a3081d8ef1079efdcf8bf9113928739e1..40fbaaac2fb395680a367100ed8478f4ce272ec1 100644
--- a/ios/clean/chrome/browser/ui/presenters/menu_presentation_controller.mm
+++ b/ios/clean/chrome/browser/ui/presenters/menu_presentation_controller.mm
@@ -31,8 +31,12 @@
if (CGRectIsEmpty(self.presentationFrame)) {
[self updatePresentationDelegate];
if (self.presentationDelegate) {
- self.presentationFrame =
- [self.presentationDelegate frameForMenuPresentation:self];
+ self.presentationFrame = [self
+ frameForPresentationWithSize:self.presentedView.frame.size
+ origin:[self.presentationDelegate
+ originForMenuPresentation]
+ bounds:[self.presentationDelegate
+ boundsForMenuPresentation]];
} else {
// Placeholder default frame: centered in the presenting view.
CGSize menuSize = self.presentedView.frame.size;
@@ -75,4 +79,37 @@
}
}
+- (CGRect)frameForPresentationWithSize:(CGSize)menuSize
+ origin:(CGRect)menuOriginRect
+ bounds:(CGRect)presentationBounds {
+ CGRect menuRect;
+ menuRect.size = menuSize;
+
+ if (CGRectIsNull(menuOriginRect)) {
+ menuRect.origin = CGPointMake(50, 50);
+ return menuRect;
+ }
+ // Calculate which corner of the menu the origin rect is in. This is
+ // determined by comparing frames, and thus is RTL-independent.
+ if (CGRectGetMinX(menuOriginRect) - CGRectGetMinX(presentationBounds) <
+ CGRectGetMaxX(presentationBounds) - CGRectGetMaxX(menuOriginRect)) {
+ // Origin rect is closer to the left edge of |self.view| than to the right.
+ menuRect.origin.x = CGRectGetMinX(menuOriginRect);
+ } else {
+ // Origin rect is closer to the right edge of |self.view| than to the left.
+ menuRect.origin.x = CGRectGetMaxX(menuOriginRect) - menuSize.width;
+ }
+
+ if (CGRectGetMinY(menuOriginRect) - CGRectGetMinY(presentationBounds) <
+ CGRectGetMaxY(presentationBounds) - CGRectGetMaxY(menuOriginRect)) {
+ // Origin rect is closer to the top edge of |self.view| than to the bottom.
+ menuRect.origin.y = CGRectGetMinY(menuOriginRect);
+ } else {
+ // Origin rect is closer to the bottom edge of |self.view| than to the top.
+ menuRect.origin.y = CGRectGetMaxY(menuOriginRect) - menuSize.height;
+ }
+
+ return menuRect;
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698