Commit 3aa33b80 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] Fixed manual fallback when using hardware keyboard

Bug: 905657
Change-Id: I4c535ba13c2a8e97fbaf217aebafd222b791cd3c
Reviewed-on: https://chromium-review.googlesource.com/c/1344055Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Commit-Queue: David Jean <djean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610561}
parent ef64951d
...@@ -30,10 +30,12 @@ ...@@ -30,10 +30,12 @@
// Replace the keyboard accessory view with one showing the passed suggestions. // Replace the keyboard accessory view with one showing the passed suggestions.
// And form navigation buttons if not an iPad (which already includes those). // And form navigation buttons if not an iPad (which already includes those).
// |isHardwareKeyboard| is true if a hardware keyboard is in use.
- (void)showAccessorySuggestions:(NSArray<FormSuggestion*>*)suggestions - (void)showAccessorySuggestions:(NSArray<FormSuggestion*>*)suggestions
suggestionClient:(id<FormSuggestionClient>)suggestionClient suggestionClient:(id<FormSuggestionClient>)suggestionClient
navigationDelegate: navigationDelegate:
(id<FormInputAccessoryViewDelegate>)navigationDelegate; (id<FormInputAccessoryViewDelegate>)navigationDelegate
isHardwareKeyboard:(BOOL)hardwareKeyboard;
@end @end
......
...@@ -152,17 +152,15 @@ constexpr CGFloat ManualFillSeparatorHeight = 0.5; ...@@ -152,17 +152,15 @@ constexpr CGFloat ManualFillSeparatorHeight = 0.5;
id<LayoutGuideProvider> layoutGuide = self.safeAreaLayoutGuide; id<LayoutGuideProvider> layoutGuide = self.safeAreaLayoutGuide;
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[leadingViewContainer.topAnchor [leadingViewContainer.topAnchor constraintEqualToAnchor:self.topAnchor],
constraintEqualToAnchor:layoutGuide.topAnchor],
[leadingViewContainer.bottomAnchor [leadingViewContainer.bottomAnchor
constraintEqualToAnchor:layoutGuide.bottomAnchor], constraintEqualToAnchor:self.bottomAnchor],
[leadingViewContainer.leadingAnchor [leadingViewContainer.leadingAnchor
constraintEqualToAnchor:layoutGuide.leadingAnchor], constraintEqualToAnchor:layoutGuide.leadingAnchor],
[trailingView.trailingAnchor [trailingView.trailingAnchor
constraintEqualToAnchor:layoutGuide.trailingAnchor], constraintEqualToAnchor:layoutGuide.trailingAnchor],
[trailingView.topAnchor constraintEqualToAnchor:layoutGuide.topAnchor], [trailingView.topAnchor constraintEqualToAnchor:self.topAnchor],
[trailingView.bottomAnchor [trailingView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
constraintEqualToAnchor:layoutGuide.bottomAnchor],
]]; ]];
if (autofill::features::IsPasswordManualFallbackEnabled()) { if (autofill::features::IsPasswordManualFallbackEnabled()) {
......
...@@ -111,7 +111,8 @@ CGFloat const kInputAccessoryHeight = 44.0f; ...@@ -111,7 +111,8 @@ CGFloat const kInputAccessoryHeight = 44.0f;
- (void)showAccessorySuggestions:(NSArray<FormSuggestion*>*)suggestions - (void)showAccessorySuggestions:(NSArray<FormSuggestion*>*)suggestions
suggestionClient:(id<FormSuggestionClient>)suggestionClient suggestionClient:(id<FormSuggestionClient>)suggestionClient
navigationDelegate: navigationDelegate:
(id<FormInputAccessoryViewDelegate>)navigationDelegate { (id<FormInputAccessoryViewDelegate>)navigationDelegate
isHardwareKeyboard:(BOOL)hardwareKeyboard {
FormSuggestionView* formSuggestionView = FormSuggestionView* formSuggestionView =
[[FormSuggestionView alloc] initWithFrame:CGRectZero [[FormSuggestionView alloc] initWithFrame:CGRectZero
client:suggestionClient client:suggestionClient
...@@ -150,6 +151,14 @@ CGFloat const kInputAccessoryHeight = 44.0f; ...@@ -150,6 +151,14 @@ CGFloat const kInputAccessoryHeight = 44.0f;
setUpWithLeadingView:formSuggestionView setUpWithLeadingView:formSuggestionView
customTrailingView:self.manualFillAccessoryViewController.view]; customTrailingView:self.manualFillAccessoryViewController.view];
[self addCustomAccessoryViewIfNeeded]; [self addCustomAccessoryViewIfNeeded];
} else if (hardwareKeyboard) {
// On iPhones, when using a hardware keyboard, for most models, there's no
// space to show suggestions because of the on-screen menu button.
[self restoreOriginalInputAccessoryView];
self.customAccessoryView = [[FormInputAccessoryView alloc] init];
[self.customAccessoryView setUpWithLeadingView:[[UIView alloc] init]
navigationDelegate:navigationDelegate];
[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.
......
...@@ -186,7 +186,8 @@ class FormSuggestionControllerTest : public PlatformTest { ...@@ -186,7 +186,8 @@ class FormSuggestionControllerTest : public PlatformTest {
[[[mock_consumer_ stub] andDo:mockShow] [[[mock_consumer_ stub] andDo:mockShow]
showAccessorySuggestions:[OCMArg any] showAccessorySuggestions:[OCMArg any]
suggestionClient:[OCMArg any] suggestionClient:[OCMArg any]
navigationDelegate:[OCMArg any]]; navigationDelegate:[OCMArg any]
isHardwareKeyboard:NO];
// Mock restore keyboard to verify cleanup. // Mock restore keyboard to verify cleanup.
void (^mockRestore)(NSInvocation*) = ^(NSInvocation* invocation) { void (^mockRestore)(NSInvocation*) = ^(NSInvocation* invocation) {
......
...@@ -70,6 +70,10 @@ ...@@ -70,6 +70,10 @@
// The WebState this instance is observing. Can be null. // The WebState this instance is observing. Can be null.
@property(nonatomic, assign) web::WebState* webState; @property(nonatomic, assign) web::WebState* webState;
// Track the use of hardware keyboard, when there's a notification of keyboard
// use but no keyboard on the screen.
@property(nonatomic, assign) BOOL hardwareKeyboard;
@end @end
@implementation FormInputAccessoryMediator { @implementation FormInputAccessoryMediator {
...@@ -404,7 +408,8 @@ queryViewBlockForProvider:(id<FormInputSuggestionsProvider>)provider ...@@ -404,7 +408,8 @@ queryViewBlockForProvider:(id<FormInputSuggestionsProvider>)provider
if (self.suggestionsDisabled) { if (self.suggestionsDisabled) {
[self.consumer showAccessorySuggestions:@[] [self.consumer showAccessorySuggestions:@[]
suggestionClient:provider suggestionClient:provider
navigationDelegate:self.formInputAccessoryHandler]; navigationDelegate:self.formInputAccessoryHandler
isHardwareKeyboard:self.hardwareKeyboard];
} else { } else {
// If suggestions are enabled update |currentProvider|. // If suggestions are enabled update |currentProvider|.
self.currentProvider = provider; self.currentProvider = provider;
...@@ -412,13 +417,20 @@ queryViewBlockForProvider:(id<FormInputSuggestionsProvider>)provider ...@@ -412,13 +417,20 @@ queryViewBlockForProvider:(id<FormInputSuggestionsProvider>)provider
// Post it to the consumer. // Post it to the consumer.
[self.consumer showAccessorySuggestions:suggestions [self.consumer showAccessorySuggestions:suggestions
suggestionClient:provider suggestionClient:provider
navigationDelegate:self.formInputAccessoryHandler]; navigationDelegate:self.formInputAccessoryHandler
isHardwareKeyboard:self.hardwareKeyboard];
} }
#pragma mark - Keyboard Notifications #pragma mark - Keyboard Notifications
// When the keyboard is shown, send the last suggestions to the consumer. // When the keyboard is shown, send the last suggestions to the consumer.
- (void)handleKeyboardWillShow:(NSNotification*)notification { - (void)handleKeyboardWillShow:(NSNotification*)notification {
NSDictionary* userInfo = [notification userInfo];
CGRect keyboardFrame =
[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
self.hardwareKeyboard =
!CGRectContainsRect([UIScreen mainScreen].bounds, keyboardFrame);
if (self.lastSuggestions) { if (self.lastSuggestions) {
[self updateWithProvider:self.lastProvider [self updateWithProvider:self.lastProvider
suggestions:self.lastSuggestions]; suggestions:self.lastSuggestions];
......
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