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 @@
self.modalViewController = nil;
}
- (CGFloat)infobarModalHeight {
- (CGFloat)infobarModalHeightForWidth:(CGFloat)width {
// TODO(crbug.com/911864): Implement, this is a temporary value. If
// InfobarConfirmCoordinator ends up having no Modal this should DCHECK or
// NOTREACHED.
......
......@@ -321,8 +321,8 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
#pragma mark InfobarModalPositioner
- (CGFloat)modalHeight {
return [self infobarModalHeight];
- (CGFloat)modalHeightForWidth:(CGFloat)width {
return [self infobarModalHeightForWidth:width];
}
#pragma mark InfobarCoordinatorImplementation
......@@ -351,7 +351,7 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
NOTREACHED() << "Subclass must implement.";
}
- (CGFloat)infobarModalHeight {
- (CGFloat)infobarModalHeightForWidth:(CGFloat)width {
NOTREACHED() << "Subclass must implement.";
return 0;
}
......
......@@ -35,7 +35,7 @@
// The infobar modal height. Used to calculate its presentation container
// height.
- (CGFloat)infobarModalHeight;
- (CGFloat)infobarModalHeightForWidth:(CGFloat)width;
@end
......
......@@ -173,8 +173,10 @@
self.passwordInfoBarDelegate->InfobarDismissed();
}
- (CGFloat)infobarModalHeight {
- (CGFloat)infobarModalHeightForWidth:(CGFloat)width {
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 layoutIfNeeded];
......
......@@ -271,6 +271,13 @@ typedef NS_ENUM(NSInteger, ItemType) {
return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView*)tableView
heightForFooterInSection:(NSInteger)section {
return 0;
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField*)textField {
......
......@@ -10,8 +10,8 @@
// InfobarBannerPositioner contains methods used to position the InfobarBanner.
@protocol InfobarModalPositioner
// The target height for the modal view to be presented.
- (CGFloat)modalHeight;
// The target height for the modal view to be presented based on |width|.
- (CGFloat)modalHeightForWidth:(CGFloat)width;
@end
......
......@@ -13,7 +13,7 @@
#endif
namespace {
// The presented view outer horizontal margins.
// The presented view outer margins.
const CGFloat kPresentedViewMargin = 10.0;
// The presented view maximum width.
const CGFloat kPresentedViewMaxWidth = 394.0;
......@@ -48,20 +48,24 @@ const CGFloat kContainerBackgroundColorAlpha = 0.5;
- (CGRect)frameForPresentedView {
DCHECK(self.modalPositioner);
CGFloat containerWidth = CGRectGetWidth(self.containerView.bounds);
CGFloat containerHeight = CGRectGetHeight(self.containerView.bounds);
CGRect safeAreaBounds = self.containerView.safeAreaLayoutGuide.layoutFrame;
CGFloat safeAreaWidth = CGRectGetWidth(safeAreaBounds);
CGFloat safeAreaHeight = CGRectGetHeight(safeAreaBounds);
// Calculate the frame width.
CGFloat maxAvailableWidth = containerWidth - 2 * kPresentedViewMargin;
CGFloat maxAvailableWidth = safeAreaWidth - 2 * kPresentedViewMargin;
CGFloat frameWidth = fmin(maxAvailableWidth, kPresentedViewMaxWidth);
// Calculate the frame height needed to fit the content.
CGFloat modalTargetHeight = [self.modalPositioner modalHeight];
CGFloat maxAvailableHeight = containerHeight - 2 * kPresentedViewMargin;
CGFloat modalTargetHeight =
[self.modalPositioner modalHeightForWidth:frameWidth];
CGFloat maxAvailableHeight = safeAreaHeight - 2 * kPresentedViewMargin;
CGFloat frameHeight = fmin(maxAvailableHeight, modalTargetHeight);
// Based on the container width calculate the values in order to center the
// 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 modalYPosition = (containerHeight / 2) - (frameHeight / 2);
......
......@@ -57,7 +57,7 @@ NSString* const kInfobarBannerPresentedModalLabel = @"Modal Infobar";
#pragma mark InfobarBannerPositioner
- (CGFloat)modalHeight {
- (CGFloat)modalHeightForWidth:(CGFloat)width {
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