Commit 9474c785 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Creates InfobarSaveCardTableVC.

- Create InfobarSaveCardTableVC class and configures it on its Coordinator.
- Implements InfobarSaveCardTableVC Cancel button.
- Implements infobarModalHeightForWidth on InfobarSaveCardCoordinator,
this is using the same code as InfobarPasswordCoordinator for now. It might
be worth creating a util file that all subclassed Coordinators can use but
I want to make sure its really needed first.

Screenshot:
https://drive.google.com/open?id=1sNsb5OhfsgNOvom4OqvumJt7ChNwVVDG

Bug: 1014652
Change-Id: I704ee0c047b8bb12e58dfd0a45fdd8f6348131e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872769Reviewed-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@{#708653}
parent 0c8c54d7
......@@ -11,6 +11,7 @@
#import "ios/chrome/browser/ui/infobars/banners/infobar_banner_view_controller.h"
#import "ios/chrome/browser/ui/infobars/coordinators/infobar_coordinator_implementation.h"
#import "ios/chrome/browser/ui/infobars/infobar_container.h"
#import "ios/chrome/browser/ui/infobars/modals/infobar_save_card_table_view_controller.h"
#include "ui/gfx/image/image.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -21,9 +22,9 @@
// InfobarBannerViewController owned by this Coordinator.
@property(nonatomic, strong) InfobarBannerViewController* bannerViewController;
// ModalViewController owned by this Coordinator.
// TODO(crbug.com/1014652): Replace with CustomVC later on.
@property(nonatomic, strong) UIViewController* modalViewController;
// InfobarSaveCardTableViewController owned by this Coordinator.
@property(nonatomic, strong)
InfobarSaveCardTableViewController* modalViewController;
// Delegate that holds the Infobar information and actions.
@property(nonatomic, readonly)
autofill::AutofillSaveCardInfoBarDelegateMobile* saveCardInfoBarDelegate;
......@@ -133,17 +134,41 @@
#pragma mark Modal
- (BOOL)configureModalViewController {
// TODO(crbug.com/1014652): Continue implementation.
return NO;
// Return early if there's no delegate. e.g. A Modal presentation has been
// triggered after the Infobar was destroyed, but before the badge/banner
// were dismissed.
if (!self.saveCardInfoBarDelegate)
return NO;
self.modalViewController =
[[InfobarSaveCardTableViewController alloc] initWithModalDelegate:self];
// TODO(crbug.com/1014652): Replace with Modal specific text.
self.modalViewController.title =
base::SysUTF16ToNSString(self.saveCardInfoBarDelegate->GetMessageText());
return YES;
}
- (void)infobarModalPresentedFromBanner:(BOOL)presentedFromBanner {
// TODO(crbug.com/1014652): Continue implementation.
// TODO(crbug.com/1014652): Check if there's a metric that should be recorded
// here, or if there's a need to keep track of the presented state of the
// Infobar for recording metrics on de-alloc. (See equivalent method on
// InfobarPasswordCoordinator).
}
- (CGFloat)infobarModalHeightForWidth:(CGFloat)width {
// TODO(crbug.com/1014652): Continue implementation.
return 0.0;
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];
// Since the TableView is contained in a NavigationController get the
// navigation bar height.
CGFloat navigationBarHeight = self.modalViewController.navigationController
.navigationBar.frame.size.height;
return tableView.contentSize.height + navigationBarHeight;
}
@end
......@@ -11,6 +11,8 @@ source_set("modals") {
"infobar_password_modal_delegate.h",
"infobar_password_table_view_controller.h",
"infobar_password_table_view_controller.mm",
"infobar_save_card_table_view_controller.h",
"infobar_save_card_table_view_controller.mm",
]
deps = [
":public",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_INFOBARS_MODALS_INFOBAR_SAVE_CARD_TABLE_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_INFOBARS_MODALS_INFOBAR_SAVE_CARD_TABLE_VIEW_CONTROLLER_H_
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
@protocol InfobarModalDelegate;
// InfobarSaveCardTableViewController represents the content for the Save Card
// InfobarModal.
@interface InfobarSaveCardTableViewController : ChromeTableViewController
- (instancetype)initWithModalDelegate:(id<InfobarModalDelegate>)modalDelegate
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithTableViewStyle:(UITableViewStyle)style
appBarStyle:
(ChromeTableViewControllerStyle)appBarStyle
NS_UNAVAILABLE;
@end
#endif // IOS_CHROME_BROWSER_UI_INFOBARS_MODALS_INFOBAR_SAVE_CARD_TABLE_VIEW_CONTROLLER_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/infobars/modals/infobar_save_card_table_view_controller.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "ios/chrome/browser/infobars/infobar_metrics_recorder.h"
#import "ios/chrome/browser/ui/infobars/modals/infobar_modal_constants.h"
#import "ios/chrome/browser/ui/infobars/modals/infobar_modal_delegate.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#import "ios/chrome/common/colors/semantic_color_names.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface InfobarSaveCardTableViewController ()
// InfobarPasswordModalDelegate for this ViewController.
@property(nonatomic, strong) id<InfobarModalDelegate> infobarModalDelegate;
// Used to build and record metrics.
@property(nonatomic, strong) InfobarMetricsRecorder* metricsRecorder;
@end
@implementation InfobarSaveCardTableViewController
- (instancetype)initWithModalDelegate:(id<InfobarModalDelegate>)modalDelegate {
self = [super initWithTableViewStyle:UITableViewStylePlain
appBarStyle:ChromeTableViewControllerStyleNoAppBar];
if (self) {
_infobarModalDelegate = modalDelegate;
_metricsRecorder = [[InfobarMetricsRecorder alloc]
initWithType:InfobarType::kInfobarTypeSaveCard];
}
return self;
}
#pragma mark - ViewController Lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorNamed:kBackgroundColor];
self.styler.cellBackgroundColor = [UIColor colorNamed:kBackgroundColor];
self.tableView.sectionHeaderHeight = 0;
[self.tableView
setSeparatorInset:UIEdgeInsetsMake(0, kTableViewHorizontalSpacing, 0, 0)];
// Configure the NavigationBar.
UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:@selector(dismissInfobarModal:)];
cancelButton.accessibilityIdentifier = kInfobarModalCancelButton;
self.navigationItem.leftBarButtonItem = cancelButton;
self.navigationController.navigationBar.prefersLargeTitles = NO;
}
#pragma mark - Private Methods
- (void)dismissInfobarModal:(UIButton*)sender {
base::RecordAction(
base::UserMetricsAction("MobileMessagesModalCancelledTapped"));
[self.metricsRecorder recordModalEvent:MobileMessagesModalEvent::Canceled];
[self.infobarModalDelegate dismissInfobarModal:sender
animated:YES
completion:nil];
}
@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