Commit e676b7b4 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] use view controller base class for manual fill passwords

Bug: 845472
Change-Id: I012839e8ee5dee6ae54d66327f1de5f38ff96d71
Reviewed-on: https://chromium-review.googlesource.com/c/1335599
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608376}
parent e409d21b
...@@ -7,32 +7,24 @@ ...@@ -7,32 +7,24 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/autofill/manual_fill/fallback_view_controller.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/password_consumer.h" #import "ios/chrome/browser/ui/autofill/manual_fill/password_consumer.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
namespace manual_fill { namespace manual_fill {
extern NSString* const PasswordSearchBarAccessibilityIdentifier; extern NSString* const PasswordSearchBarAccessibilityIdentifier;
extern NSString* const PasswordTableViewAccessibilityIdentifier; extern NSString* const PasswordTableViewAccessibilityIdentifier;
extern NSString* const PasswordDoneButtonAccessibilityIdentifier;
} // namespace manual_fill } // namespace manual_fill
// This class presents a list of usernames and passwords in a table view. // This class presents a list of usernames and passwords in a table view.
@interface PasswordViewController @interface PasswordViewController
: ChromeTableViewController<ManualFillPasswordConsumer> : FallbackViewController<ManualFillPasswordConsumer>
- (instancetype)initWithSearchController:(UISearchController*)searchController - (instancetype)initWithSearchController:(UISearchController*)searchController
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithTableViewStyle:(UITableViewStyle)style - (instancetype)init NS_UNAVAILABLE;
appBarStyle:
(ChromeTableViewControllerStyle)appBarStyle
NS_UNAVAILABLE;
// If set to YES, the controller will add negative content insets inverse to the
// ones added by UITableViewController to accommodate for the keyboard.
@property(nonatomic, assign) BOOL contentInsetsAlwaysEqualToSafeArea;
@end @end
......
...@@ -27,21 +27,6 @@ NSString* const PasswordTableViewAccessibilityIdentifier = ...@@ -27,21 +27,6 @@ NSString* const PasswordTableViewAccessibilityIdentifier =
} // namespace manual_fill } // namespace manual_fill
namespace {
typedef NS_ENUM(NSInteger, SectionIdentifier) {
CredentialsSectionIdentifier = kSectionIdentifierEnumZero,
ActionsSectionIdentifier,
};
// This is the width used for |self.preferredContentSize|.
constexpr float PopoverPreferredWidth = 320;
// This is the maximum height used for |self.preferredContentSize|.
constexpr float PopoverMaxHeight = 250;
} // namespace
@interface PasswordViewController () @interface PasswordViewController ()
// Search controller if any. // Search controller if any.
...@@ -51,40 +36,17 @@ constexpr float PopoverMaxHeight = 250; ...@@ -51,40 +36,17 @@ constexpr float PopoverMaxHeight = 250;
@implementation PasswordViewController @implementation PasswordViewController
@synthesize searchController = _searchController;
- (instancetype)initWithSearchController:(UISearchController*)searchController { - (instancetype)initWithSearchController:(UISearchController*)searchController {
self = [super initWithTableViewStyle:UITableViewStylePlain self = [super init];
appBarStyle:ChromeTableViewControllerStyleNoAppBar];
if (self) { if (self) {
_searchController = searchController; _searchController = searchController;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(handleKeyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(handleKeyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
} }
return self; return self;
} }
- (void)viewDidLoad { - (void)viewDidLoad {
// Super's |viewDidLoad| uses |styler.tableViewBackgroundColor| so it needs to
// be set before.
self.styler.tableViewBackgroundColor = [UIColor whiteColor];
[super viewDidLoad]; [super viewDidLoad];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.sectionHeaderHeight = 0;
self.tableView.sectionFooterHeight = 20.0;
self.tableView.estimatedRowHeight = 200;
self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
self.tableView.accessibilityIdentifier = self.tableView.accessibilityIdentifier =
manual_fill::PasswordTableViewAccessibilityIdentifier; manual_fill::PasswordTableViewAccessibilityIdentifier;
...@@ -110,79 +72,11 @@ constexpr float PopoverMaxHeight = 250; ...@@ -110,79 +72,11 @@ constexpr float PopoverMaxHeight = 250;
UMA_HISTOGRAM_COUNTS_100("ManualFallback.PresentedOptions.Passwords", UMA_HISTOGRAM_COUNTS_100("ManualFallback.PresentedOptions.Passwords",
credentials.count); credentials.count);
} }
[self presentItems:credentials inSection:CredentialsSectionIdentifier]; [self presentDataItems:(NSArray<TableViewItem*>*)credentials];
} }
- (void)presentActions:(NSArray<ManualFillActionItem*>*)actions { - (void)presentActions:(NSArray<ManualFillActionItem*>*)actions {
[self presentItems:actions inSection:ActionsSectionIdentifier]; [self presentActionItems:actions];
}
#pragma mark - Private
- (void)handleKeyboardDidHide:(NSNotification*)notification {
if (self.contentInsetsAlwaysEqualToSafeArea && !IsIPadIdiom()) {
// Resets the table view content inssets to be equal to the safe area
// insets.
self.tableView.contentInset = self.view.safeAreaInsets;
}
}
- (void)handleKeyboardWillShow:(NSNotification*)notification {
if (self.contentInsetsAlwaysEqualToSafeArea && !IsIPadIdiom()) {
// Sets the bottom inset to be equal to the height of the keyboard to
// override the behaviour in UITableViewController. Which adjust the scroll
// view insets to accommodate for the keyboard.
CGRect keyboardFrame =
[notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardHeight = keyboardFrame.size.height;
UIEdgeInsets safeInsets = self.view.safeAreaInsets;
self.tableView.contentInset =
UIEdgeInsetsMake(safeInsets.top, safeInsets.left,
safeInsets.bottom - keyboardHeight, safeInsets.right);
}
}
// Presents |items| in the respective section. Handles creating or deleting the
// section accordingly.
- (void)presentItems:(NSArray<TableViewItem*>*)items
inSection:(SectionIdentifier)sectionIdentifier {
if (!self.tableViewModel) {
[self loadModel];
}
BOOL doesSectionExist =
[self.tableViewModel hasSectionForSectionIdentifier:sectionIdentifier];
// If there are no passed credentials, remove section if exist.
if (!items.count) {
if (doesSectionExist) {
[self.tableViewModel removeSectionWithIdentifier:sectionIdentifier];
}
} else {
if (!doesSectionExist) {
if (sectionIdentifier == CredentialsSectionIdentifier) {
[self.tableViewModel
insertSectionWithIdentifier:CredentialsSectionIdentifier
atIndex:0];
} else {
[self.tableViewModel addSectionWithIdentifier:sectionIdentifier];
}
}
[self.tableViewModel
deleteAllItemsFromSectionWithIdentifier:sectionIdentifier];
for (TableViewItem* item in items) {
[self.tableViewModel addItem:item
toSectionWithIdentifier:sectionIdentifier];
}
}
[self.tableView reloadData];
if (IsIPadIdiom()) {
// Update the preffered content size on iPad so the popover shows the right
// size.
[self.tableView layoutIfNeeded];
CGSize systemLayoutSize = self.tableView.contentSize;
CGFloat preferredHeight = MIN(systemLayoutSize.height, PopoverMaxHeight);
self.preferredContentSize =
CGSizeMake(PopoverPreferredWidth, preferredHeight);
}
} }
@end @end
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