Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Unified Diff: ios/chrome/browser/autofill/form_input_accessory_view_controller.mm

Issue 1305433003: Make Autofill work again on iPads running iOS 9. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/autofill/form_input_accessory_view_controller.mm
diff --git a/ios/chrome/browser/autofill/form_input_accessory_view_controller.mm b/ios/chrome/browser/autofill/form_input_accessory_view_controller.mm
index cbcbe2684685215c8b97b6cf1ac084d11566113e..355081d15f60b72b687e4a9a3e1e7708b318721d 100644
--- a/ios/chrome/browser/autofill/form_input_accessory_view_controller.mm
+++ b/ios/chrome/browser/autofill/form_input_accessory_view_controller.mm
@@ -5,15 +5,15 @@
#import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h"
#include "base/ios/block_types.h"
+#include "base/ios/ios_util.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_block.h"
#include "base/mac/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
-#include "base/strings/sys_string_conversions.h"
-#include "base/strings/utf_string_conversions.h"
#import "components/autofill/ios/browser/js_suggestion_manager.h"
#import "ios/chrome/browser/autofill/form_input_accessory_view.h"
#import "ios/chrome/browser/passwords/password_generation_utils.h"
+#include "ios/chrome/browser/ui/ui_util.h"
#include "ios/web/public/test/crw_test_js_injection_receiver.h"
#include "ios/web/public/url_scheme_util.h"
#import "ios/web/public/web_state/crw_web_view_proxy.h"
@@ -25,6 +25,7 @@ namespace autofill {
NSString* const kFormSuggestionAssistButtonPreviousElement = @"previousTap";
NSString* const kFormSuggestionAssistButtonNextElement = @"nextTap";
NSString* const kFormSuggestionAssistButtonDone = @"done";
+CGFloat const kInputAccessoryHeight = 44.0f;
} // namespace autofill
namespace {
@@ -93,7 +94,7 @@ NSArray* FindDescendantToolbarItemsForActionName(UIView* root,
// If there is only one part, the frame is returned in |leftFrame| and
// |rightFrame| has size zero.
//
-// Heuristics are used to compute this information. It returns true if the
+// Heuristics are used to compute this information. It returns false if the
// number of |inputAccessoryView.subviews| is not 2.
bool ComputeFramesOfKeyboardParts(UIView* inputAccessoryView,
CGRect* leftFrame,
@@ -130,8 +131,8 @@ bool ComputeFramesOfKeyboardParts(UIView* inputAccessoryView,
JSSuggestionManager:(JsSuggestionManager*)JSSuggestionManager
providers:(NSArray*)providers;
-// Called when the keyboard did change frame.
-- (void)keyboardDidChangeFrame:(NSNotification*)notification;
+// Called when the keyboard will or did change frame.
+- (void)keyboardWillOrDidChangeFrame:(NSNotification*)notification;
// Called when the keyboard is dismissed.
- (void)keyboardDidHide:(NSNotification*)notification;
@@ -215,9 +216,16 @@ bool ComputeFramesOfKeyboardParts(UIView* inputAccessoryView,
// There is no defined relation on the timing of JavaScript events and
// keyboard showing up. So it is necessary to listen to the keyboard
// notification to make sure the keyboard is updated.
+ if (base::ios::IsRunningOnIOS9OrLater() && IsIPadIdiom()) {
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(keyboardWillOrDidChangeFrame:)
+ name:UIKeyboardWillChangeFrameNotification
+ object:nil];
+ }
[[NSNotificationCenter defaultCenter]
addObserver:self
- selector:@selector(keyboardDidChangeFrame:)
+ selector:@selector(keyboardWillOrDidChangeFrame:)
name:UIKeyboardDidChangeFrameNotification
object:nil];
[[NSNotificationCenter defaultCenter]
@@ -253,20 +261,48 @@ bool ComputeFramesOfKeyboardParts(UIView* inputAccessoryView,
}
- (void)showCustomInputAccessoryView:(UIView*)view {
- [self restoreDefaultInputAccessoryView];
- CGRect leftFrame;
- CGRect rightFrame;
- UIView* inputAccessoryView = [self.webViewProxy getKeyboardAccessory];
- if (ComputeFramesOfKeyboardParts(inputAccessoryView, &leftFrame,
- &rightFrame)) {
- [self hideSubviewsInOriginalAccessoryView:inputAccessoryView];
+ if (base::ios::IsRunningOnIOS9OrLater() && IsIPadIdiom()) {
+ // On iPads running iOS 9 or later, there's no inputAccessoryView available
+ // so we attach the custom view directly to the keyboard view instead.
+ [_customAccessoryView removeFromSuperview];
+ UIViewController* rootViewController =
+ [UIApplication sharedApplication].keyWindow.rootViewController;
+
+ // If the keyboard isn't visible or another controller has been presented
+ // over the webview (as in the case of the credit card unmask dialog), don't
+ // show the custom view.
+ if (CGRectIntersection([UIScreen mainScreen].bounds, _keyboardFrame)
+ .size.height == 0 ||
+ CGRectEqualToRect(_keyboardFrame, CGRectZero) ||
+ [rootViewController presentedViewController]) {
+ _customAccessoryView.reset();
+ return;
+ }
+
+ CGFloat height = autofill::kInputAccessoryHeight;
+ CGRect frame = CGRectMake(_keyboardFrame.origin.x, -height,
+ _keyboardFrame.size.width, height);
_customAccessoryView.reset(
- [[FormInputAccessoryView alloc] initWithFrame:inputAccessoryView.frame
- delegate:self
- customView:view
- leftFrame:leftFrame
- rightFrame:rightFrame]);
- [inputAccessoryView addSubview:_customAccessoryView];
+ [[FormInputAccessoryView alloc] initWithFrame:frame customView:view]);
+ [[self getKeyboardView] addSubview:_customAccessoryView];
justincohen 2015/08/19 20:34:19 Is there a way we can DCHECK if something changes
Justin Donnelly 2015/08/20 16:38:01 Done.
+ } else {
+ // On all other versions, the custom view replaces the default UI of the
+ // inputAccessoryView.
+ [self restoreDefaultInputAccessoryView];
+ CGRect leftFrame;
+ CGRect rightFrame;
+ UIView* inputAccessoryView = [self.webViewProxy getKeyboardAccessory];
+ if (ComputeFramesOfKeyboardParts(inputAccessoryView, &leftFrame,
+ &rightFrame)) {
+ [self hideSubviewsInOriginalAccessoryView:inputAccessoryView];
+ _customAccessoryView.reset([[FormInputAccessoryView alloc]
+ initWithFrame:inputAccessoryView.frame
+ delegate:self
+ customView:view
+ leftFrame:leftFrame
+ rightFrame:rightFrame]);
+ [inputAccessoryView addSubview:_customAccessoryView];
+ }
}
}
@@ -481,7 +517,32 @@ bool ComputeFramesOfKeyboardParts(UIView* inputAccessoryView,
passwords::RunSearchPipeline(findProviderBlocks, onProviderFound);
}
-- (void)keyboardDidChangeFrame:(NSNotification*)notification {
+- (UIView*)getKeyboardView {
+ NSArray* windows = [UIApplication sharedApplication].windows;
+ if (windows.count < 2)
+ return nil;
+
+ UIWindow* window = windows[1];
+ for (UIView* subview in window.subviews) {
+ if ([NSStringFromClass([subview class])
+ isEqualToString:@"UIPeripheralHost"]) {
+ return subview;
+ }
+ if ([NSStringFromClass([subview class])
+ isEqualToString:@"UIInputSetContainerView"]) {
+ for (UIView* subsubview in subview.subviews) {
+ if ([NSStringFromClass([subsubview class])
+ isEqualToString:@"UIInputSetHostView"]) {
+ return subsubview;
+ }
+ }
+ }
+ }
+
+ return nil;
+}
+
+- (void)keyboardWillOrDidChangeFrame:(NSNotification*)notification {
if (!self.webState || !_currentProvider)
return;
CGRect keyboardFrame =

Powered by Google App Engine
This is Rietveld 408576698