| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" | 5 #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" |
| 6 | 6 |
| 7 #include "base/ios/block_types.h" | 7 #include "base/ios/block_types.h" |
| 8 #include "base/ios/ios_util.h" | 8 #include "base/ios/ios_util.h" |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/mac/scoped_block.h" | 10 #include "base/mac/scoped_block.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 283 } |
| 284 } | 284 } |
| 285 | 285 |
| 286 - (void)showCustomInputAccessoryView:(UIView*)view { | 286 - (void)showCustomInputAccessoryView:(UIView*)view { |
| 287 DCHECK(view); | 287 DCHECK(view); |
| 288 if (base::ios::IsRunningOnIOS9OrLater() && IsIPadIdiom()) { | 288 if (base::ios::IsRunningOnIOS9OrLater() && IsIPadIdiom()) { |
| 289 // On iPads running iOS 9 or later, there's no inputAccessoryView available | 289 // On iPads running iOS 9 or later, there's no inputAccessoryView available |
| 290 // so we attach the custom view directly to the keyboard view instead. | 290 // so we attach the custom view directly to the keyboard view instead. |
| 291 [_customAccessoryView removeFromSuperview]; | 291 [_customAccessoryView removeFromSuperview]; |
| 292 | 292 |
| 293 // If the keyboard isn't visible or no suggestions have been triggered yet, | 293 // If the keyboard isn't visible don't show the custom view. |
| 294 // don't show the custom view. | |
| 295 int numSuggestions = | |
| 296 [[static_cast<FormSuggestionView*>(view) suggestions] count]; | |
| 297 if (CGRectIntersection([UIScreen mainScreen].bounds, _keyboardFrame) | 294 if (CGRectIntersection([UIScreen mainScreen].bounds, _keyboardFrame) |
| 298 .size.height == 0 || | 295 .size.height == 0 || |
| 299 CGRectEqualToRect(_keyboardFrame, CGRectZero) || | 296 CGRectEqualToRect(_keyboardFrame, CGRectZero)) { |
| 300 (!_suggestionsHaveBeenShown && numSuggestions == 0)) { | |
| 301 _customAccessoryView.reset(); | 297 _customAccessoryView.reset(); |
| 302 return; | 298 return; |
| 303 } | 299 } |
| 300 |
| 301 // If this is a form suggestion view and no suggestions have been triggered |
| 302 // yet, don't show the custom view. |
| 303 FormSuggestionView* formSuggestionView = |
| 304 base::mac::ObjCCastStrict<FormSuggestionView>(view); |
| 305 if (formSuggestionView) { |
| 306 int numSuggestions = [[formSuggestionView suggestions] count]; |
| 307 if (!_suggestionsHaveBeenShown && numSuggestions == 0) { |
| 308 _customAccessoryView.reset(); |
| 309 return; |
| 310 } |
| 311 } |
| 304 _suggestionsHaveBeenShown = YES; | 312 _suggestionsHaveBeenShown = YES; |
| 305 | 313 |
| 306 CGFloat height = autofill::kInputAccessoryHeight; | 314 CGFloat height = autofill::kInputAccessoryHeight; |
| 307 CGRect frame = CGRectMake(_keyboardFrame.origin.x, -height, | 315 CGRect frame = CGRectMake(_keyboardFrame.origin.x, -height, |
| 308 _keyboardFrame.size.width, height); | 316 _keyboardFrame.size.width, height); |
| 309 _customAccessoryView.reset( | 317 _customAccessoryView.reset( |
| 310 [[FormInputAccessoryView alloc] initWithFrame:frame customView:view]); | 318 [[FormInputAccessoryView alloc] initWithFrame:frame customView:view]); |
| 311 UIView* keyboardView = [self getKeyboardView]; | 319 UIView* keyboardView = [self getKeyboardView]; |
| 312 DCHECK(keyboardView); | 320 DCHECK(keyboardView); |
| 313 [keyboardView addSubview:_customAccessoryView]; | 321 [keyboardView addSubview:_customAccessoryView]; |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 // that we don't present our custom view over the keyboard. | 596 // that we don't present our custom view over the keyboard. |
| 589 - (void)textInputDidBeginEditing:(NSNotification*)notification { | 597 - (void)textInputDidBeginEditing:(NSNotification*)notification { |
| 590 [self reset]; | 598 [self reset]; |
| 591 } | 599 } |
| 592 | 600 |
| 593 - (void)keyboardDidHide:(NSNotification*)notification { | 601 - (void)keyboardDidHide:(NSNotification*)notification { |
| 594 _keyboardFrame = CGRectZero; | 602 _keyboardFrame = CGRectZero; |
| 595 } | 603 } |
| 596 | 604 |
| 597 @end | 605 @end |
| OLD | NEW |