Commit 0d7cba3f authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Commit Bot

[AF][IOS] Removes the tooltip on the credit card unmask prompt

Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ib286e9a2bb2e3f4d06e0bc1ddb7ee3c5854f333f
Reviewed-on: https://chromium-review.googlesource.com/1125290Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572553}
parent 69fc00a5
......@@ -32,7 +32,5 @@
</if>
<if expr="is_ios">
<structure type="chrome_scaled_image" name="IDR_AUTOFILL_GOOGLE_PAY_WITH_DIVIDER" file="autofill/infobar_autofill_googlepay_with_divider.png" />
<structure type="chrome_scaled_image" name="IDR_AUTOFILL_TOOLTIP_ICON" file="autofill/autofill_tooltip_icon.png" />
<structure type="chrome_scaled_image" name="IDR_AUTOFILL_TOOLTIP_ICON_H" file="autofill/autofill_tooltip_icon_hover.png" />
</if>
</grit-part>
......@@ -11,8 +11,6 @@ source_set("autofill") {
"card_unmask_prompt_view_bridge.mm",
"chrome_autofill_client_ios.h",
"chrome_autofill_client_ios.mm",
"storage_switch_tooltip.h",
"storage_switch_tooltip.mm",
]
deps = [
":autofill_ui",
......
......@@ -14,16 +14,16 @@
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/autofill/cells/cvc_item.h"
#import "ios/chrome/browser/ui/autofill/cells/status_item.h"
#import "ios/chrome/browser/ui/autofill/cells/storage_switch_item.h"
#import "ios/chrome/browser/ui/autofill/storage_switch_tooltip.h"
#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
#import "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/third_party/material_components_ios/src/components/AppBar/src/MaterialAppBar.h"
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -126,12 +126,7 @@ void CardUnmaskPromptViewBridge::DeleteSelf() {
UIBarButtonItem* _verifyButton;
CVCItem* _CVCItem;
StatusItem* _statusItem;
StorageSwitchItem* _storageSwitchItem;
// The tooltip is added as a child of the collection view rather than the
// StorageSwitchContentView to allow it to overflow the bounds of the switch
// view.
StorageSwitchTooltip* _storageSwitchTooltip;
CollectionViewSwitchItem* _storageSwitchItem;
// Owns |self|.
autofill::CardUnmaskPromptViewBridge* _bridge; // weak
......@@ -222,14 +217,12 @@ void CardUnmaskPromptViewBridge::DeleteSelf() {
if (controller->CanStoreLocally()) {
_storageSwitchItem =
[[StorageSwitchItem alloc] initWithType:ItemTypeStorageSwitch];
[[CollectionViewSwitchItem alloc] initWithType:ItemTypeStorageSwitch];
_storageSwitchItem.text = l10n_util::GetNSString(
IDS_AUTOFILL_CARD_UNMASK_PROMPT_STORAGE_CHECKBOX);
_storageSwitchItem.on = controller->GetStoreLocallyStartState();
[model addItem:_storageSwitchItem
toSectionWithIdentifier:SectionIdentifierMain];
_storageSwitchTooltip = [[StorageSwitchTooltip alloc] init];
[_storageSwitchTooltip setHidden:YES];
[self.collectionView addSubview:_storageSwitchTooltip];
} else {
_storageSwitchItem = nil;
}
......@@ -268,7 +261,6 @@ void CardUnmaskPromptViewBridge::DeleteSelf() {
- (void)showSpinner {
[_verifyButton setEnabled:NO];
[_storageSwitchTooltip setHidden:YES];
[self
updateWithStatus:StatusItemState::VERIFYING
......@@ -335,31 +327,6 @@ void CardUnmaskPromptViewBridge::DeleteSelf() {
preferredHeightForStatus);
}
- (void)layoutTooltipFromButton:(UIButton*)button {
const CGRect buttonFrameInCollectionView =
[self.collectionView convertRect:button.bounds fromView:button];
CGRect tooltipFrame = _storageSwitchTooltip.frame;
// First, set the width and use sizeToFit to have the label flow the text and
// set the height appropriately.
const CGFloat kTooltipMargin = 8;
CGFloat availableWidth =
CGRectGetMinX(buttonFrameInCollectionView) - 2 * kTooltipMargin;
const CGFloat kMaxTooltipWidth = 210;
tooltipFrame.size.width = MIN(availableWidth, kMaxTooltipWidth);
_storageSwitchTooltip.frame = tooltipFrame;
[_storageSwitchTooltip sizeToFit];
// Then use the size to position the tooltip appropriately, based on the
// button position.
tooltipFrame = _storageSwitchTooltip.frame;
tooltipFrame.origin.x = CGRectGetMinX(buttonFrameInCollectionView) -
kTooltipMargin - CGRectGetWidth(tooltipFrame);
tooltipFrame.origin.y = CGRectGetMaxY(buttonFrameInCollectionView) -
CGRectGetHeight(tooltipFrame);
_storageSwitchTooltip.frame = tooltipFrame;
}
- (BOOL)inputCVCIsValid:(CVCItem*)item {
return _bridge->GetController()->InputCvcIsValid(
base::SysNSStringToUTF16(item.CVCText));
......@@ -453,19 +420,6 @@ void CardUnmaskPromptViewBridge::DeleteSelf() {
_bridge->PerformClose();
}
- (void)onTooltipButtonTapped:(UIButton*)button {
BOOL shouldShowTooltip = !button.selected;
button.highlighted = shouldShowTooltip;
if (shouldShowTooltip) {
button.selected = YES;
[self layoutTooltipFromButton:button];
[_storageSwitchTooltip setHidden:NO];
} else {
button.selected = NO;
[_storageSwitchTooltip setHidden:YES];
}
}
- (void)onStorageSwitchChanged:(UISwitch*)switchView {
// Update the item.
_storageSwitchItem.on = switchView.on;
......@@ -565,12 +519,11 @@ void CardUnmaskPromptViewBridge::DeleteSelf() {
break;
}
case ItemTypeStorageSwitch: {
StorageSwitchCell* storageSwitchCell =
base::mac::ObjCCastStrict<StorageSwitchCell>(cell);
[storageSwitchCell.tooltipButton
addTarget:self
action:@selector(onTooltipButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
CollectionViewSwitchCell* storageSwitchCell =
base::mac::ObjCCastStrict<CollectionViewSwitchCell>(cell);
storageSwitchCell.textLabel.font = [MDCTypography body2Font];
storageSwitchCell.textLabel.textColor =
[[MDCPalette greyPalette] tint500];
[storageSwitchCell.switchView addTarget:self
action:@selector(onStorageSwitchChanged:)
forControlEvents:UIControlEventValueChanged];
......
......@@ -10,8 +10,6 @@ source_set("cells") {
"cvc_item.mm",
"status_item.h",
"status_item.mm",
"storage_switch_item.h",
"storage_switch_item.mm",
]
deps = [
......@@ -39,7 +37,6 @@ source_set("unit_tests") {
"autofill_edit_item_unittest.mm",
"cvc_item_unittest.mm",
"status_item_unittest.mm",
"storage_switch_item_unittest.mm",
]
deps = [
......
// Copyright 2016 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_CELLS_STORAGE_SWITCH_ITEM_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_CELLS_STORAGE_SWITCH_ITEM_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h"
// StorageSwitchItem is the model class corresponding to StorageSwitchCell.
@interface StorageSwitchItem : CollectionViewItem
// The current state of the switch.
@property(nonatomic, assign, getter=isOn) BOOL on;
@end
// StorageSwitchCell implements a UICollectionViewCell subclass containing a
// text label, a switch and a tooltip button.
@interface StorageSwitchCell : MDCCollectionViewCell
// Label displaying a standard text.
@property(nonatomic, readonly, strong) UILabel* textLabel;
// The tooltip button. Clients own and manage the tooltip they present and can
// use the button frame as the anchor point. Otherwise, this button is a no-op.
@property(nonatomic, readonly, strong) UIButton* tooltipButton;
// The switch view.
@property(nonatomic, readonly, strong) UISwitch* switchView;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_CELLS_STORAGE_SWITCH_ITEM_H_
// Copyright 2016 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/cells/storage_switch_item.h"
#include "components/grit/components_scaled_resources.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.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 {
// Padding used on the leading and trailing edges of the cell.
const CGFloat kHorizontalPadding = 16;
// Padding used on the top and bottom edges of the cell.
const CGFloat kVerticalPadding = 16;
// Space at the leading side of the tooltip button.
const CGFloat kTooltipButtonLeadingSpacing = 8;
// Space at the trailing side of the tooltip button.
const CGFloat kTooltipButtonTrailingSpacing = 30;
}
@implementation StorageSwitchItem
@synthesize on = _on;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
if (self) {
self.cellClass = [StorageSwitchCell class];
}
return self;
}
#pragma mark CollectionViewItem
- (void)configureCell:(StorageSwitchCell*)cell {
[super configureCell:cell];
cell.switchView.on = self.on;
}
@end
@implementation StorageSwitchCell
@synthesize textLabel = _textLabel;
@synthesize tooltipButton = _tooltipButton;
@synthesize switchView = _switchView;
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
UIView* contentView = self.contentView;
_textLabel = [[UILabel alloc] init];
_textLabel.translatesAutoresizingMaskIntoConstraints = NO;
[contentView addSubview:_textLabel];
_switchView = [[UISwitch alloc] init];
_switchView.translatesAutoresizingMaskIntoConstraints = NO;
[contentView addSubview:_switchView];
_tooltipButton = [UIButton buttonWithType:UIButtonTypeCustom];
_tooltipButton.translatesAutoresizingMaskIntoConstraints = NO;
[contentView addSubview:_tooltipButton];
_textLabel.text = l10n_util::GetNSString(
IDS_AUTOFILL_CARD_UNMASK_PROMPT_STORAGE_CHECKBOX);
_textLabel.font = [[MDCTypography fontLoader] mediumFontOfSize:14];
_textLabel.textColor = [[MDCPalette greyPalette] tint500];
_textLabel.numberOfLines = 0;
[_textLabel
setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
forAxis:
UILayoutConstraintAxisHorizontal];
_switchView.onTintColor = [[MDCPalette cr_bluePalette] tint500];
[_tooltipButton setImage:NativeImage(IDR_AUTOFILL_TOOLTIP_ICON_H)
forState:UIControlStateSelected];
[_tooltipButton setImage:NativeImage(IDR_AUTOFILL_TOOLTIP_ICON)
forState:UIControlStateNormal];
// Set up the constraints.
[NSLayoutConstraint activateConstraints:@[
[_textLabel.topAnchor constraintEqualToAnchor:contentView.topAnchor
constant:kVerticalPadding],
[_textLabel.bottomAnchor constraintEqualToAnchor:contentView.bottomAnchor
constant:-kVerticalPadding],
[_textLabel.leadingAnchor
constraintEqualToAnchor:contentView.leadingAnchor
constant:kHorizontalPadding],
[_textLabel.trailingAnchor
constraintLessThanOrEqualToAnchor:_tooltipButton.leadingAnchor
constant:-kTooltipButtonLeadingSpacing],
[_tooltipButton.centerYAnchor
constraintEqualToAnchor:contentView.centerYAnchor],
[_tooltipButton.trailingAnchor
constraintEqualToAnchor:_switchView.leadingAnchor
constant:-kTooltipButtonTrailingSpacing],
[_switchView.centerYAnchor
constraintEqualToAnchor:contentView.centerYAnchor],
[_switchView.trailingAnchor
constraintEqualToAnchor:contentView.trailingAnchor
constant:-kHorizontalPadding],
]];
}
return self;
}
// Implement -layoutSubviews as per instructions in documentation for
// +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:].
- (void)layoutSubviews {
[super layoutSubviews];
// Adjust the text label preferredMaxLayoutWidth when the parent's width
// changes, for instance on screen rotation.
self.textLabel.preferredMaxLayoutWidth =
CGRectGetWidth(self.contentView.frame) - 2 * kHorizontalPadding -
kTooltipButtonLeadingSpacing - CGRectGetWidth(self.tooltipButton.frame) -
kTooltipButtonTrailingSpacing - CGRectGetWidth(self.switchView.frame);
// Re-layout with the new preferred width to allow the label to adjust its
// height.
[super layoutSubviews];
}
- (void)prepareForReuse {
[super prepareForReuse];
[self.tooltipButton removeTarget:nil
action:nil
forControlEvents:self.tooltipButton.allControlEvents];
[self.switchView removeTarget:nil
action:nil
forControlEvents:self.switchView.allControlEvents];
}
@end
// Copyright 2016 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/cells/storage_switch_item.h"
#include "base/mac/foundation_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
using StorageSwitchItemTest = PlatformTest;
// Tests that the label and switch values are set properly after a call to
// |configureCell:|.
TEST_F(StorageSwitchItemTest, ConfigureCell) {
StorageSwitchItem* item = [[StorageSwitchItem alloc] initWithType:0];
item.on = YES;
id cell = [[[item cellClass] alloc] init];
ASSERT_TRUE([cell isMemberOfClass:[StorageSwitchCell class]]);
StorageSwitchCell* switchCell =
base::mac::ObjCCastStrict<StorageSwitchCell>(cell);
EXPECT_TRUE(switchCell.textLabel.text);
EXPECT_FALSE(switchCell.switchView.on);
[item configureCell:cell];
EXPECT_TRUE(switchCell.switchView.on);
}
TEST_F(StorageSwitchItemTest, PrepareForReuseClearsActions) {
StorageSwitchCell* cell = [[StorageSwitchCell alloc] init];
UIButton* tooltipButton = cell.tooltipButton;
UISwitch* switchView = cell.switchView;
NSArray* target = [NSArray array];
EXPECT_EQ(0U, [[tooltipButton allTargets] count]);
EXPECT_EQ(0U, [[switchView allTargets] count]);
[tooltipButton addTarget:target
action:@selector(count)
forControlEvents:UIControlEventTouchUpInside];
[switchView addTarget:target
action:@selector(count)
forControlEvents:UIControlEventValueChanged];
EXPECT_EQ(1U, [[tooltipButton allTargets] count]);
EXPECT_EQ(1U, [[switchView allTargets] count]);
[cell prepareForReuse];
EXPECT_EQ(0U, [[tooltipButton allTargets] count]);
EXPECT_EQ(0U, [[switchView allTargets] count]);
}
} // namespace
// Copyright 2015 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_STORAGE_SWITCH_TOOLTIP_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_STORAGE_SWITCH_TOOLTIP_H_
#import <UIKit/UIKit.h>
// A label that displays the storage setting tooltip text with appropriate
// layout and styling.
@interface StorageSwitchTooltip : UILabel
- (instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER;
- (instancetype)init;
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_STORAGE_SWITCH_TOOLTIP_H_
// Copyright 2015 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/storage_switch_tooltip.h"
#include "base/logging.h"
#include "components/strings/grit/components_strings.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const CGFloat kCornerRadius = 2.0f;
const CGFloat kFontSize = 12.0f;
const CGFloat kInset = 8.0f;
} // namespace
@implementation StorageSwitchTooltip
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
NSString* tooltipText =
l10n_util::GetNSString(IDS_AUTOFILL_CARD_UNMASK_PROMPT_STORAGE_TOOLTIP);
[self setText:tooltipText];
[self setTextColor:[UIColor whiteColor]];
[self setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.9]];
[[self layer] setCornerRadius:kCornerRadius];
[[self layer] setMasksToBounds:YES];
[self setFont:[[MDCTypography fontLoader] regularFontOfSize:kFontSize]];
[self setNumberOfLines:0]; // Allows multi-line layout.
}
return self;
}
- (instancetype)init {
return [self initWithFrame:CGRectZero];
}
- (instancetype)initWithCoder:(NSCoder*)aDecoder {
NOTREACHED();
return nil;
}
// The logic in textRectForBounds:limitedToNumberOfLines: and drawTextInRect:
// adds an inset. Based on
// http://stackoverflow.com/questions/21167226/resizing-a-uilabel-to-accomodate-insets/21267507#21267507
- (CGRect)textRectForBounds:(CGRect)bounds
limitedToNumberOfLines:(NSInteger)numberOfLines {
UIEdgeInsets insets = {kInset, kInset, kInset, kInset};
CGRect rect = [super textRectForBounds:UIEdgeInsetsInsetRect(bounds, insets)
limitedToNumberOfLines:numberOfLines];
rect.origin.x -= insets.left;
rect.origin.y -= insets.top;
rect.size.width += (insets.left + insets.right);
rect.size.height += (insets.top + insets.bottom);
return rect;
}
- (void)drawTextInRect:(CGRect)rect {
UIEdgeInsets insets = {kInset, kInset, kInset, kInset};
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
}
@end
......@@ -18,7 +18,6 @@
#import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h"
#import "ios/chrome/browser/ui/autofill/cells/cvc_item.h"
#import "ios/chrome/browser/ui/autofill/cells/status_item.h"
#import "ios/chrome/browser/ui/autofill/cells/storage_switch_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_account_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item.h"
......@@ -90,7 +89,6 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeAutofillDynamicHeight,
ItemTypeAutofillCVC,
ItemTypeAutofillStatus,
ItemTypeAutofillStorageSwitch,
ItemTypeAccountControlDynamicHeight,
ItemTypeFooter,
ItemTypeContentSuggestions,
......@@ -245,8 +243,6 @@ const CGFloat kCardIssuerNetworkIconDimension = 25.0;
toSectionWithIdentifier:SectionIdentifierAutofill];
[model addItem:[self statusItemError]
toSectionWithIdentifier:SectionIdentifierAutofill];
[model addItem:[self storageSwitchItem]
toSectionWithIdentifier:SectionIdentifierAutofill];
// Payments cells.
[model addSectionWithIdentifier:SectionIdentifierPayments];
......@@ -367,7 +363,6 @@ const CGFloat kCardIssuerNetworkIconDimension = 25.0;
case ItemTypeTextError:
case ItemTypeAutofillCVC:
case ItemTypeAutofillStatus:
case ItemTypeAutofillStorageSwitch:
case ItemTypePaymentsDynamicHeight:
case ItemTypeAutofillDynamicHeight:
case ItemTypeColdStateSigninPromo:
......@@ -427,7 +422,6 @@ const CGFloat kCardIssuerNetworkIconDimension = 25.0;
[self.collectionViewModel itemAtIndexPath:indexPath];
switch (item.type) {
case ItemTypeApp:
case ItemTypeAutofillStorageSwitch:
case ItemTypeColdStateSigninPromo:
case ItemTypeSwitchBasic:
case ItemTypeSwitchDynamicHeight:
......@@ -695,13 +689,6 @@ const CGFloat kCardIssuerNetworkIconDimension = 25.0;
return item;
}
- (CollectionViewItem*)storageSwitchItem {
StorageSwitchItem* item =
[[StorageSwitchItem alloc] initWithType:ItemTypeAutofillStorageSwitch];
item.on = YES;
return item;
}
- (CollectionViewFooterItem*)shortFooterItem {
CollectionViewFooterItem* footerItem =
[[CollectionViewFooterItem alloc] initWithType:ItemTypeFooter];
......
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