Commit 3eaaeefc authored by sczs's avatar sczs Committed by Commit Bot

[ios] Polishes InfobarModal Position and Height.

- Calculates the PasswordsTableView Modal target height based on the
Modal width and not the Window's.
- Uses safeArea bounds to calculate the Modal height, this will prevent
overlapping to the Status bar.

Bug: 981882, 981880
Change-Id: I421ab04420b323400db78899328665c41417b3c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1691035Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#675653}
parent d118d0cb
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
self.modalViewController = nil; self.modalViewController = nil;
} }
- (CGFloat)infobarModalHeight { - (CGFloat)infobarModalHeightForWidth:(CGFloat)width {
// TODO(crbug.com/911864): Implement, this is a temporary value. If // TODO(crbug.com/911864): Implement, this is a temporary value. If
// InfobarConfirmCoordinator ends up having no Modal this should DCHECK or // InfobarConfirmCoordinator ends up having no Modal this should DCHECK or
// NOTREACHED. // NOTREACHED.
......
...@@ -321,8 +321,8 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -321,8 +321,8 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
#pragma mark InfobarModalPositioner #pragma mark InfobarModalPositioner
- (CGFloat)modalHeight { - (CGFloat)modalHeightForWidth:(CGFloat)width {
return [self infobarModalHeight]; return [self infobarModalHeightForWidth:width];
} }
#pragma mark InfobarCoordinatorImplementation #pragma mark InfobarCoordinatorImplementation
...@@ -351,7 +351,7 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -351,7 +351,7 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
NOTREACHED() << "Subclass must implement."; NOTREACHED() << "Subclass must implement.";
} }
- (CGFloat)infobarModalHeight { - (CGFloat)infobarModalHeightForWidth:(CGFloat)width {
NOTREACHED() << "Subclass must implement."; NOTREACHED() << "Subclass must implement.";
return 0; return 0;
} }
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
// The infobar modal height. Used to calculate its presentation container // The infobar modal height. Used to calculate its presentation container
// height. // height.
- (CGFloat)infobarModalHeight; - (CGFloat)infobarModalHeightForWidth:(CGFloat)width;
@end @end
......
...@@ -173,8 +173,10 @@ ...@@ -173,8 +173,10 @@
self.passwordInfoBarDelegate->InfobarDismissed(); self.passwordInfoBarDelegate->InfobarDismissed();
} }
- (CGFloat)infobarModalHeight { - (CGFloat)infobarModalHeightForWidth:(CGFloat)width {
UITableView* tableView = self.modalViewController.tableView; UITableView* tableView = self.modalViewController.tableView;
// Update the tableView frame to then layout its content for |width|.
tableView.frame = CGRectMake(0, 0, width, tableView.frame.size.height);
[tableView setNeedsLayout]; [tableView setNeedsLayout];
[tableView layoutIfNeeded]; [tableView layoutIfNeeded];
......
...@@ -271,6 +271,13 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -271,6 +271,13 @@ typedef NS_ENUM(NSInteger, ItemType) {
return cell; return cell;
} }
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView*)tableView
heightForFooterInSection:(NSInteger)section {
return 0;
}
#pragma mark - UITextFieldDelegate #pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField*)textField { - (BOOL)textFieldShouldReturn:(UITextField*)textField {
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
// InfobarBannerPositioner contains methods used to position the InfobarBanner. // InfobarBannerPositioner contains methods used to position the InfobarBanner.
@protocol InfobarModalPositioner @protocol InfobarModalPositioner
// The target height for the modal view to be presented. // The target height for the modal view to be presented based on |width|.
- (CGFloat)modalHeight; - (CGFloat)modalHeightForWidth:(CGFloat)width;
@end @end
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#endif #endif
namespace { namespace {
// The presented view outer horizontal margins. // The presented view outer margins.
const CGFloat kPresentedViewMargin = 10.0; const CGFloat kPresentedViewMargin = 10.0;
// The presented view maximum width. // The presented view maximum width.
const CGFloat kPresentedViewMaxWidth = 394.0; const CGFloat kPresentedViewMaxWidth = 394.0;
...@@ -48,20 +48,24 @@ const CGFloat kContainerBackgroundColorAlpha = 0.5; ...@@ -48,20 +48,24 @@ const CGFloat kContainerBackgroundColorAlpha = 0.5;
- (CGRect)frameForPresentedView { - (CGRect)frameForPresentedView {
DCHECK(self.modalPositioner); DCHECK(self.modalPositioner);
CGFloat containerWidth = CGRectGetWidth(self.containerView.bounds); CGRect safeAreaBounds = self.containerView.safeAreaLayoutGuide.layoutFrame;
CGFloat containerHeight = CGRectGetHeight(self.containerView.bounds); CGFloat safeAreaWidth = CGRectGetWidth(safeAreaBounds);
CGFloat safeAreaHeight = CGRectGetHeight(safeAreaBounds);
// Calculate the frame width. // Calculate the frame width.
CGFloat maxAvailableWidth = containerWidth - 2 * kPresentedViewMargin; CGFloat maxAvailableWidth = safeAreaWidth - 2 * kPresentedViewMargin;
CGFloat frameWidth = fmin(maxAvailableWidth, kPresentedViewMaxWidth); CGFloat frameWidth = fmin(maxAvailableWidth, kPresentedViewMaxWidth);
// Calculate the frame height needed to fit the content. // Calculate the frame height needed to fit the content.
CGFloat modalTargetHeight = [self.modalPositioner modalHeight]; CGFloat modalTargetHeight =
CGFloat maxAvailableHeight = containerHeight - 2 * kPresentedViewMargin; [self.modalPositioner modalHeightForWidth:frameWidth];
CGFloat maxAvailableHeight = safeAreaHeight - 2 * kPresentedViewMargin;
CGFloat frameHeight = fmin(maxAvailableHeight, modalTargetHeight); CGFloat frameHeight = fmin(maxAvailableHeight, modalTargetHeight);
// Based on the container width calculate the values in order to center the // Based on the container width calculate the values in order to center the
// frame in the X and Y axis. // frame in the X and Y axis.
CGFloat containerWidth = CGRectGetWidth(self.containerView.bounds);
CGFloat containerHeight = CGRectGetHeight(self.containerView.bounds);
CGFloat modalXPosition = (containerWidth / 2) - (frameWidth / 2); CGFloat modalXPosition = (containerWidth / 2) - (frameWidth / 2);
CGFloat modalYPosition = (containerHeight / 2) - (frameHeight / 2); CGFloat modalYPosition = (containerHeight / 2) - (frameHeight / 2);
......
...@@ -57,7 +57,7 @@ NSString* const kInfobarBannerPresentedModalLabel = @"Modal Infobar"; ...@@ -57,7 +57,7 @@ NSString* const kInfobarBannerPresentedModalLabel = @"Modal Infobar";
#pragma mark InfobarBannerPositioner #pragma mark InfobarBannerPositioner
- (CGFloat)modalHeight { - (CGFloat)modalHeightForWidth:(CGFloat)width {
return 200; return 200;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment