Commit 68b00bfc authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][MF] Present the icons to the right on iPad

Shows the manual fallback icons to the right on iPads. Changes include:
-Updates FormInputAccessoryView to support a custom view to the right.
-Stops instantiation of ManualFillAccessoryViewController when manual
fallback is disabled.

Bug: 845472
Change-Id: I82b3772bf60af33f3102b520ce3cc647b16310b9
Reviewed-on: https://chromium-review.googlesource.com/c/1329176
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607655}
parent 5e8aa6cf
...@@ -10,18 +10,19 @@ ...@@ -10,18 +10,19 @@
@protocol FormInputAccessoryViewDelegate; @protocol FormInputAccessoryViewDelegate;
// Subview of the accessory view for web forms. Shows a custom view with form // Subview of the accessory view for web forms. Shows a custom view with form
// navigation controls above the keyboard. Subclassed to enable input clicks by // navigation controls above the keyboard. Enables input clicks by way of the
// way of the playInputClick method. // playInputClick method.
@interface FormInputAccessoryView : UIView<UIInputViewAudioFeedback> @interface FormInputAccessoryView : UIView<UIInputViewAudioFeedback>
// Sets up the view with the given |customView|. Navigation controls are shown // Sets up the view with the given |leadingView|. Navigation controls are shown
// and use |delegate| for actions. // on the trailing side and use |delegate| for actions.
- (void)setUpWithNavigationDelegate:(id<FormInputAccessoryViewDelegate>)delegate - (void)setUpWithLeadingView:(UIView*)leadingView
customView:(UIView*)customView; navigationDelegate:(id<FormInputAccessoryViewDelegate>)delegate;
// Sets up the view with the given |customView|. Navigation controls are not // Sets up the view with the given |leadingView|. Navigation controls are
// shown. // replaced with |customTrailingView|.
- (void)setUpWithCustomView:(UIView*)customView; - (void)setUpWithLeadingView:(UIView*)leadingView
customTrailingView:(UIView*)customTrailingView;
@end @end
......
...@@ -86,43 +86,82 @@ constexpr CGFloat ManualFillSeparatorHeight = 0.5; ...@@ -86,43 +86,82 @@ constexpr CGFloat ManualFillSeparatorHeight = 0.5;
@implementation FormInputAccessoryView @implementation FormInputAccessoryView
- (void)setUpWithCustomView:(UIView*)customView { #pragma mark - Public
[self addSubview:customView];
customView.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(self, customView);
[[self class] addBackgroundImageInView:self - (void)setUpWithLeadingView:(UIView*)leadingView
withImageName:@"autofill_keyboard_background"]; customTrailingView:(UIView*)customTrailingView {
[self setUpWithLeadingView:leadingView
customTrailingView:customTrailingView
navigationDelegate:nil];
} }
- (void)setUpWithNavigationDelegate:(id<FormInputAccessoryViewDelegate>)delegate - (void)setUpWithLeadingView:(UIView*)leadingView
customView:(UIView*)customView { navigationDelegate:(id<FormInputAccessoryViewDelegate>)delegate {
self.translatesAutoresizingMaskIntoConstraints = NO; [self setUpWithLeadingView:leadingView
UIView* customViewContainer = [[UIView alloc] init]; customTrailingView:nil
customViewContainer.translatesAutoresizingMaskIntoConstraints = NO; navigationDelegate:delegate];
[self addSubview:customViewContainer]; }
[customViewContainer addSubview:customView]; #pragma mark - UIInputViewAudioFeedback
customView.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(customViewContainer, customView);
UIView* navigationView = - (BOOL)enableInputClicksWhenVisible {
[self viewForNavigationButtonsUsingDelegate:delegate]; return YES;
navigationView.translatesAutoresizingMaskIntoConstraints = NO; }
[self addSubview:navigationView];
#pragma mark - Private Methods
// Sets up the view with the given |leadingView|. If |delegate| is not nil,
// navigation controls are shown on the right and use |delegate| for actions.
// Else navigation controls are replaced with |customTrailingView|. If none of
// |delegate| and |customTrailingView| is set, leadingView will take all the
// space.
- (void)setUpWithLeadingView:(UIView*)leadingView
customTrailingView:(UIView*)customTrailingView
navigationDelegate:(id<FormInputAccessoryViewDelegate>)delegate {
DCHECK(leadingView);
if (!autofill::features::IsPasswordManualFallbackEnabled()) {
[[self class] addBackgroundImageInView:self
withImageName:@"autofill_keyboard_background"];
}
leadingView.translatesAutoresizingMaskIntoConstraints = NO;
UIView* trailingView;
if (delegate) {
trailingView = [self viewForNavigationButtonsUsingDelegate:delegate];
} else {
trailingView = customTrailingView;
}
// If there is no trailing view, set the leading view as the only view and
// return early.
if (!trailingView) {
[self addSubview:leadingView];
AddSameConstraints(self, leadingView);
return;
}
self.translatesAutoresizingMaskIntoConstraints = NO;
UIView* leadingViewContainer = [[UIView alloc] init];
leadingViewContainer.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:leadingViewContainer];
[leadingViewContainer addSubview:leadingView];
AddSameConstraints(leadingViewContainer, leadingView);
trailingView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:trailingView];
id<LayoutGuideProvider> layoutGuide = SafeAreaLayoutGuideForView(self); id<LayoutGuideProvider> layoutGuide = SafeAreaLayoutGuideForView(self);
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[customViewContainer.topAnchor [leadingViewContainer.topAnchor
constraintEqualToAnchor:layoutGuide.topAnchor], constraintEqualToAnchor:layoutGuide.topAnchor],
[customViewContainer.bottomAnchor [leadingViewContainer.bottomAnchor
constraintEqualToAnchor:layoutGuide.bottomAnchor], constraintEqualToAnchor:layoutGuide.bottomAnchor],
[customViewContainer.leadingAnchor [leadingViewContainer.leadingAnchor
constraintEqualToAnchor:layoutGuide.leadingAnchor], constraintEqualToAnchor:layoutGuide.leadingAnchor],
[navigationView.trailingAnchor [trailingView.trailingAnchor
constraintEqualToAnchor:layoutGuide.trailingAnchor], constraintEqualToAnchor:layoutGuide.trailingAnchor],
[navigationView.topAnchor constraintEqualToAnchor:layoutGuide.topAnchor], [trailingView.topAnchor constraintEqualToAnchor:layoutGuide.topAnchor],
[navigationView.bottomAnchor [trailingView.bottomAnchor
constraintEqualToAnchor:layoutGuide.bottomAnchor], constraintEqualToAnchor:layoutGuide.bottomAnchor],
]]; ]];
...@@ -135,7 +174,7 @@ constexpr CGFloat ManualFillSeparatorHeight = 0.5; ...@@ -135,7 +174,7 @@ constexpr CGFloat ManualFillSeparatorHeight = 0.5;
UIImageView* gradientView = UIImageView* gradientView =
[[UIImageView alloc] initWithImage:gradientImage]; [[UIImageView alloc] initWithImage:gradientImage];
gradientView.translatesAutoresizingMaskIntoConstraints = NO; gradientView.translatesAutoresizingMaskIntoConstraints = NO;
[self insertSubview:gradientView belowSubview:navigationView]; [self insertSubview:gradientView belowSubview:trailingView];
UIView* topGrayLine = [[UIView alloc] init]; UIView* topGrayLine = [[UIView alloc] init];
topGrayLine.backgroundColor = UIColor.cr_manualFillSeparatorColor; topGrayLine.backgroundColor = UIColor.cr_manualFillSeparatorColor;
...@@ -161,38 +200,26 @@ constexpr CGFloat ManualFillSeparatorHeight = 0.5; ...@@ -161,38 +200,26 @@ constexpr CGFloat ManualFillSeparatorHeight = 0.5;
[bottomGrayLine.heightAnchor [bottomGrayLine.heightAnchor
constraintEqualToConstant:ManualFillSeparatorHeight], constraintEqualToConstant:ManualFillSeparatorHeight],
[gradientView.topAnchor constraintEqualToAnchor:navigationView.topAnchor], [gradientView.topAnchor constraintEqualToAnchor:trailingView.topAnchor],
[gradientView.bottomAnchor [gradientView.bottomAnchor
constraintEqualToAnchor:navigationView.bottomAnchor], constraintEqualToAnchor:trailingView.bottomAnchor],
[gradientView.widthAnchor [gradientView.widthAnchor
constraintEqualToConstant:ManualFillGradientWidth], constraintEqualToConstant:ManualFillGradientWidth],
[gradientView.trailingAnchor [gradientView.trailingAnchor
constraintEqualToAnchor:navigationView.leadingAnchor constraintEqualToAnchor:trailingView.leadingAnchor
constant:ManualFillGradientMargin], constant:ManualFillGradientMargin],
[customViewContainer.trailingAnchor [leadingViewContainer.trailingAnchor
constraintEqualToAnchor:navigationView.leadingAnchor], constraintEqualToAnchor:trailingView.leadingAnchor],
]]; ]];
} else { } else {
[[self class] addBackgroundImageInView:self [leadingViewContainer.trailingAnchor
withImageName:@"autofill_keyboard_background"]; constraintEqualToAnchor:trailingView.leadingAnchor
[customViewContainer.trailingAnchor
constraintEqualToAnchor:navigationView.leadingAnchor
constant:kNavigationAreaSeparatorShadowWidth] constant:kNavigationAreaSeparatorShadowWidth]
.active = YES; .active = YES;
} }
} }
#pragma mark -
#pragma mark UIInputViewAudioFeedback
- (BOOL)enableInputClicksWhenVisible {
return YES;
}
#pragma mark -
#pragma mark Private Methods
UIImage* ButtonImage(NSString* name) { UIImage* ButtonImage(NSString* name) {
UIImage* rawImage = [UIImage imageNamed:name]; UIImage* rawImage = [UIImage imageNamed:name];
return StretchableImageFromUIImage(rawImage, 1, 0); return StretchableImageFromUIImage(rawImage, 1, 0);
......
...@@ -116,12 +116,6 @@ CGFloat const kInputAccessoryHeight = 44.0f; ...@@ -116,12 +116,6 @@ CGFloat const kInputAccessoryHeight = 44.0f;
client:suggestionClient client:suggestionClient
suggestions:suggestions]; suggestions:suggestions];
// If Manual Fallback is enabled, add its view after the suggestions.
if (autofill::features::IsPasswordManualFallbackEnabled()) {
formSuggestionView.trailingView =
self.manualFillAccessoryViewController.view;
}
if (IsIPadIdiom()) { if (IsIPadIdiom()) {
// On iPad, there's no inputAccessoryView available, so we attach the custom // On iPad, there's no inputAccessoryView available, so we attach the custom
// view directly to the keyboard view instead. // view directly to the keyboard view instead.
...@@ -137,6 +131,8 @@ CGFloat const kInputAccessoryHeight = 44.0f; ...@@ -137,6 +131,8 @@ CGFloat const kInputAccessoryHeight = 44.0f;
} }
if (!autofill::features::IsPasswordManualFallbackEnabled()) { if (!autofill::features::IsPasswordManualFallbackEnabled()) {
// Check that |manualFillAccessoryViewController| was not instantiated.
DCHECK(!self.manualFillAccessoryViewController);
// If this is a form suggestion view and no suggestions have been // If this is a form suggestion view and no suggestions have been
// triggered yet, don't show the custom view. // triggered yet, don't show the custom view.
if (formSuggestionView) { if (formSuggestionView) {
...@@ -149,15 +145,19 @@ CGFloat const kInputAccessoryHeight = 44.0f; ...@@ -149,15 +145,19 @@ CGFloat const kInputAccessoryHeight = 44.0f;
_suggestionsHaveBeenShown = YES; _suggestionsHaveBeenShown = YES;
} }
self.customAccessoryView = [[FormInputAccessoryView alloc] init]; self.customAccessoryView = [[FormInputAccessoryView alloc] init];
[self.customAccessoryView setUpWithCustomView:formSuggestionView]; [self.customAccessoryView
setUpWithLeadingView:formSuggestionView
customTrailingView:self.manualFillAccessoryViewController.view];
[self addCustomAccessoryViewIfNeeded]; [self addCustomAccessoryViewIfNeeded];
} else { } else {
// On iPhone, the custom view replaces the default UI of the // On iPhone, the custom view replaces the default UI of the
// inputAccessoryView. // inputAccessoryView.
[self restoreOriginalInputAccessoryView]; [self restoreOriginalInputAccessoryView];
formSuggestionView.trailingView =
self.manualFillAccessoryViewController.view;
self.customAccessoryView = [[FormInputAccessoryView alloc] init]; self.customAccessoryView = [[FormInputAccessoryView alloc] init];
[self.customAccessoryView setUpWithNavigationDelegate:navigationDelegate [self.customAccessoryView setUpWithLeadingView:formSuggestionView
customView:formSuggestionView]; navigationDelegate:navigationDelegate];
[self addCustomAccessoryViewIfNeeded]; [self addCustomAccessoryViewIfNeeded];
} }
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/autofill/form_input_accessory_coordinator.h" #import "ios/chrome/browser/ui/autofill/form_input_accessory_coordinator.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "components/autofill/core/common/autofill_features.h"
#import "components/autofill/ios/browser/js_suggestion_manager.h" #import "components/autofill/ios/browser/js_suggestion_manager.h"
#import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h"
#import "ios/chrome/browser/ui/autofill/form_input_accessory_mediator.h" #import "ios/chrome/browser/ui/autofill/form_input_accessory_mediator.h"
...@@ -50,14 +51,6 @@ ...@@ -50,14 +51,6 @@
@implementation FormInputAccessoryCoordinator @implementation FormInputAccessoryCoordinator
@synthesize formInputAccessoryMediator = _formInputAccessoryMediator;
@synthesize formInputAccessoryViewController =
_formInputAccessoryViewController;
@synthesize manualFillAccessoryViewController =
_manualFillAccessoryViewController;
@synthesize webStateList = _webStateList;
@synthesize manualFillInjectionHandler = _manualFillInjectionHandler;
- (instancetype)initWithBaseViewController:(UIViewController*)viewController - (instancetype)initWithBaseViewController:(UIViewController*)viewController
browserState: browserState:
(ios::ChromeBrowserState*)browserState (ios::ChromeBrowserState*)browserState
...@@ -75,11 +68,12 @@ ...@@ -75,11 +68,12 @@
_formInputAccessoryViewController = _formInputAccessoryViewController =
[[FormInputAccessoryViewController alloc] init]; [[FormInputAccessoryViewController alloc] init];
_manualFillAccessoryViewController = if (autofill::features::IsPasswordManualFallbackEnabled()) {
[[ManualFillAccessoryViewController alloc] initWithDelegate:self]; _manualFillAccessoryViewController =
[[ManualFillAccessoryViewController alloc] initWithDelegate:self];
_formInputAccessoryViewController.manualFillAccessoryViewController = _formInputAccessoryViewController.manualFillAccessoryViewController =
_manualFillAccessoryViewController; _manualFillAccessoryViewController;
}
_formInputAccessoryMediator = [[FormInputAccessoryMediator alloc] _formInputAccessoryMediator = [[FormInputAccessoryMediator alloc]
initWithConsumer:self.formInputAccessoryViewController initWithConsumer:self.formInputAccessoryViewController
......
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