Commit 50ac3f62 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] add manual fallback address cell

Will merge the cell_utils with card_cell after crrev/c/1303730 is merged.

Bug: 845472
Change-Id: Iead98637aeaa8b7e3b0252057b8592ef4fff0529
Reviewed-on: https://chromium-review.googlesource.com/c/1317853
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarEric Noyau <noyau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606423}
parent 19ab1de3
...@@ -46,6 +46,7 @@ source_set("manual_fill_ui") { ...@@ -46,6 +46,7 @@ source_set("manual_fill_ui") {
sources = [ sources = [
"action_cell.h", "action_cell.h",
"action_cell.mm", "action_cell.mm",
"address_list_delegate.h",
"card_list_delegate.h", "card_list_delegate.h",
"credential.h", "credential.h",
"credential.mm", "credential.mm",
...@@ -53,8 +54,12 @@ source_set("manual_fill_ui") { ...@@ -53,8 +54,12 @@ source_set("manual_fill_ui") {
"keyboard_observer_helper.mm", "keyboard_observer_helper.mm",
"manual_fill_accessory_view_controller.h", "manual_fill_accessory_view_controller.h",
"manual_fill_accessory_view_controller.mm", "manual_fill_accessory_view_controller.mm",
"manual_fill_address_cell.h",
"manual_fill_address_cell.mm",
"manual_fill_card_cell.h", "manual_fill_card_cell.h",
"manual_fill_card_cell.mm", "manual_fill_card_cell.mm",
"manual_fill_cell_utils.h",
"manual_fill_cell_utils.mm",
"manual_fill_content_delegate.h", "manual_fill_content_delegate.h",
"manual_fill_password_cell.h", "manual_fill_password_cell.h",
"manual_fill_password_cell.mm", "manual_fill_password_cell.mm",
......
// Copyright 2018 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_AUTOFILL_MANUAL_FILL_ADDRESS_LIST_DELEGATE_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_ADDRESS_LIST_DELEGATE_H_
// Delegate for actions in manual fallback's addresses list.
@protocol AddressListDelegate
// Dismisses the presented view controller and continues as pop over on iPads
// or above the keyboard elsewhere.
- (void)dismissPresentedViewController;
// Opens addresses settings.
- (void)openAddressSettings;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_ADDRESS_LIST_DELEGATE_H_
...@@ -13,7 +13,7 @@ class CreditCard; ...@@ -13,7 +13,7 @@ class CreditCard;
@protocol CardListDelegate @protocol CardListDelegate
// Dismisses the presented view controller and continues as pop over on iPads // Dismisses the presented view controller and continues as pop over on iPads
// or above the keyboard else. // or above the keyboard elsewhere.
- (void)dismissPresentedViewController; - (void)dismissPresentedViewController;
// Opens cards settings. // Opens cards settings.
......
// Copyright 2018 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_AUTOFILL_MANUAL_FILL_MANUAL_FILL_ADDRESS_CELL_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_MANUAL_FILL_ADDRESS_CELL_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/table_view/cells/table_view_item.h"
namespace autofill {
class AutofillProfile;
} // namespace autofill
// TODO(crbug.com/845472): rename, see
// https://crrev.com/c/1317853/7/ios/chrome/browser/ui/autofill/manual_fill/manual_fill_address_cell.h#17.
@protocol ManualFillContentDelegate;
// Wrapper to show address cells in a ChromeTableViewController.
@interface ManualFillAddressItem : TableViewItem
// Inits an address with a |profile| and the |delegate| for user selection.
- (instancetype)initWithAutofillProfile:
(const autofill::AutofillProfile&)profile
delegate:(id<ManualFillContentDelegate>)delegate
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithType:(NSInteger)type NS_UNAVAILABLE;
@end
// Cell to display an Address into parts that are interactable
// and sendable the data to the delegate.
@interface ManualFillAddressCell : UITableViewCell
// Updates the cell with address and the |delegate| to be notified.
- (void)setUpWithAutofillProfile:(const autofill::AutofillProfile&)profile
delegate:(id<ManualFillContentDelegate>)delegate;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_MANUAL_FILL_ADDRESS_CELL_H_
// Copyright 2018 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_AUTOFILL_MANUAL_FILL_MANUAL_FILL_CELL_UTILS_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_MANUAL_FILL_CELL_UTILS_H_
#import <UIKit/UIKit.h>
// Creates a blank button in fallback style, for the given |action| and
// |target|.
UIButton* CreateButtonWithSelectorAndTarget(SEL action, id target);
// Creates horizontal constraints for given |button| based on given |width| on
// both sides.
void HorizontalConstraintsMarginForButtonWithWidth(UIButton* button,
CGFloat width);
// Sets vertical constraints on firstBaselineAnchor for the button or label rows
// in |views| inside |container| starting at its topAnchor. Returns the applied
// constrainst to allow caller to deactivate them later.
NSArray<NSLayoutConstraint*>* VerticalConstraintsSpacingForViewsInContainer(
NSArray<UIView*>* views,
UIView* container);
// Sets constraints for the given |views|, so as to lay them out horizontally,
// parallel to the given |guide| view, and applying the given constant |shift|
// to the whole row. Returns the applied constraints to allow caller to
// deactivate them later.
NSArray<NSLayoutConstraint*>* HorizontalConstraintsForViewsOnGuideWithShift(
NSArray<UIView*>* views,
UIView* guide,
CGFloat shift);
// Sets all baseline anchors for the gievn |views| to match the one on |onView|.
// Returns the applied constrainst to allow caller to deactivate them later.
NSArray<NSLayoutConstraint*>* SyncBaselinesForViewsOnView(
NSArray<UIView*>* views,
UIView* onView);
// Creates a blank label with autoresize mask off and adjustable font size.
UILabel* CreateLabel();
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_MANUAL_FILL_CELL_UTILS_H_
// Copyright 2018 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/autofill/manual_fill/manual_fill_cell_utils.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/uicolor_manualfill.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// The multiplier for the base system spacing at the top margin.
static const CGFloat TopSystemSpacingMultiplier = 1.58;
// The multiplier for the base system spacing between elements (vertical).
static const CGFloat MiddleSystemSpacingMultiplier = 1.83;
// The multiplier for the base system spacing at the bottom margin.
static const CGFloat BottomSystemSpacingMultiplier = 2.26;
} // namespace
UIButton* CreateButtonWithSelectorAndTarget(SEL action, id target) {
UIButton* button = [UIButton buttonWithType:UIButtonTypeSystem];
[button setTitleColor:UIColor.cr_manualFillTintColor
forState:UIControlStateNormal];
button.translatesAutoresizingMaskIntoConstraints = NO;
button.titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleBody];
button.titleLabel.adjustsFontForContentSizeCategory = YES;
[button addTarget:target
action:action
forControlEvents:UIControlEventTouchUpInside];
return button;
}
void HorizontalConstraintsMarginForButtonWithWidth(UIButton* button,
CGFloat width) {
[NSLayoutConstraint activateConstraints:@[
[button.leadingAnchor
constraintEqualToAnchor:button.titleLabel.leadingAnchor
constant:-width],
[button.trailingAnchor
constraintEqualToAnchor:button.titleLabel.trailingAnchor
constant:width],
]];
}
NSArray<NSLayoutConstraint*>* VerticalConstraintsSpacingForViewsInContainer(
NSArray<UIView*>* views,
UIView* container) {
NSMutableArray* verticalConstraints = [[NSMutableArray alloc] init];
// Multipliers of these constraints are calculated based on a 24 base
// system spacing.
NSLayoutYAxisAnchor* previousAnchor = container.topAnchor;
CGFloat multiplier = TopSystemSpacingMultiplier;
for (UIView* view in views) {
[verticalConstraints
addObject:[view.firstBaselineAnchor
constraintEqualToSystemSpacingBelowAnchor:previousAnchor
multiplier:multiplier]];
multiplier = MiddleSystemSpacingMultiplier;
previousAnchor = view.lastBaselineAnchor;
}
multiplier = BottomSystemSpacingMultiplier;
[verticalConstraints
addObject:[container.bottomAnchor
constraintEqualToSystemSpacingBelowAnchor:previousAnchor
multiplier:multiplier]];
[NSLayoutConstraint activateConstraints:verticalConstraints];
return verticalConstraints;
}
NSArray<NSLayoutConstraint*>* HorizontalConstraintsForViewsOnGuideWithShift(
NSArray<UIView*>* views,
UIView* guide,
CGFloat shift) {
NSMutableArray* horizontalConstraints = [[NSMutableArray alloc] init];
NSLayoutXAxisAnchor* previousAnchor = guide.leadingAnchor;
for (UIView* view in views) {
[horizontalConstraints
addObject:[view.leadingAnchor constraintEqualToAnchor:previousAnchor
constant:shift]];
previousAnchor = view.trailingAnchor;
shift = 0;
}
if (views.count > 0) {
[horizontalConstraints
addObject:[views.lastObject.trailingAnchor
constraintLessThanOrEqualToAnchor:guide.trailingAnchor
constant:shift]];
}
[NSLayoutConstraint activateConstraints:horizontalConstraints];
return horizontalConstraints;
}
NSArray<NSLayoutConstraint*>* SyncBaselinesForViewsOnView(
NSArray<UIView*>* views,
UIView* onView) {
NSMutableArray* baselinesConstraints = [[NSMutableArray alloc] init];
for (UIView* view in views) {
[baselinesConstraints
addObject:[view.firstBaselineAnchor
constraintEqualToAnchor:onView.firstBaselineAnchor]];
}
[NSLayoutConstraint activateConstraints:baselinesConstraints];
return baselinesConstraints;
}
UILabel* CreateLabel() {
UILabel* label = [[UILabel alloc] init];
label.translatesAutoresizingMaskIntoConstraints = NO;
label.adjustsFontForContentSizeCategory = YES;
return label;
}
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
@protocol PasswordListDelegate @protocol PasswordListDelegate
// Dismisses the presented view controller and continues as pop over on iPads // Dismisses the presented view controller and continues as pop over on iPads
// or above the keyboard else. // or above the keyboard elsewhere.
- (void)dismissPresentedViewController; - (void)dismissPresentedViewController;
// Requests to open the list of all passwords. // Requests to open the list of all passwords.
......
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