| 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_suggestion_controller.h" | 5 #import "ios/chrome/browser/autofill/form_suggestion_controller.h" |
| 6 | 6 |
| 7 #include "base/ios/ios_util.h" |
| 7 #include "base/ios/weak_nsobject.h" | 8 #include "base/ios/weak_nsobject.h" |
| 8 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 9 #include "base/mac/scoped_block.h" | 10 #include "base/mac/scoped_block.h" |
| 10 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "components/autofill/core/browser/autofill_popup_delegate.h" | 15 #include "components/autofill/core/browser/autofill_popup_delegate.h" |
| 15 #include "components/autofill/ios/browser/autofill_field_trial_ios.h" | 16 #include "components/autofill/ios/browser/autofill_field_trial_ios.h" |
| 16 #import "components/autofill/ios/browser/form_suggestion.h" | 17 #import "components/autofill/ios/browser/form_suggestion.h" |
| 17 #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" | 18 #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" |
| 18 #import "ios/chrome/browser/autofill/form_suggestion_provider.h" | 19 #import "ios/chrome/browser/autofill/form_suggestion_provider.h" |
| 19 #import "ios/chrome/browser/autofill/form_suggestion_view.h" | 20 #import "ios/chrome/browser/autofill/form_suggestion_view.h" |
| 20 #import "ios/chrome/browser/passwords/password_generation_utils.h" | 21 #import "ios/chrome/browser/passwords/password_generation_utils.h" |
| 22 #include "ios/chrome/browser/ui/ui_util.h" |
| 21 #include "ios/web/public/url_scheme_util.h" | 23 #include "ios/web/public/url_scheme_util.h" |
| 22 #import "ios/web/public/web_state/crw_web_view_proxy.h" | 24 #import "ios/web/public/web_state/crw_web_view_proxy.h" |
| 23 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 25 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
| 24 #import "ios/web/public/web_state/web_state.h" | 26 #import "ios/web/public/web_state/web_state.h" |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 // Struct that describes suggestion state. | 30 // Struct that describes suggestion state. |
| 29 struct AutofillSuggestionState { | 31 struct AutofillSuggestionState { |
| 30 AutofillSuggestionState(const std::string& form_name, | 32 AutofillSuggestionState(const std::string& form_name, |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 257 |
| 256 - (void)clearSuggestions { | 258 - (void)clearSuggestions { |
| 257 // Note that other parts of the suggestionsState are not reset. | 259 // Note that other parts of the suggestionsState are not reset. |
| 258 if (!_suggestionState.get()) | 260 if (!_suggestionState.get()) |
| 259 return; | 261 return; |
| 260 _suggestionState->suggestions.reset([[NSArray alloc] init]); | 262 _suggestionState->suggestions.reset([[NSArray alloc] init]); |
| 261 [self updateKeyboard:_suggestionState.get()]; | 263 [self updateKeyboard:_suggestionState.get()]; |
| 262 } | 264 } |
| 263 | 265 |
| 264 - (void)updateKeyboard:(AutofillSuggestionState*)suggestionState { | 266 - (void)updateKeyboard:(AutofillSuggestionState*)suggestionState { |
| 265 if (!_suggestionState) { | 267 if (!suggestionState) { |
| 266 if (accessoryViewUpdateBlock_) | 268 if (accessoryViewUpdateBlock_) |
| 267 accessoryViewUpdateBlock_.get()(nil, self); | 269 accessoryViewUpdateBlock_.get()(nil, self); |
| 268 } else { | 270 } else { |
| 269 [self updateKeyboardWithSuggestions:_suggestionState->suggestions]; | 271 [self updateKeyboardWithSuggestions:suggestionState->suggestions]; |
| 270 } | 272 } |
| 271 } | 273 } |
| 272 | 274 |
| 273 - (void)updateKeyboardWithSuggestions:(NSArray*)suggestions { | 275 - (void)updateKeyboardWithSuggestions:(NSArray*)suggestions { |
| 274 if (accessoryViewUpdateBlock_) { | 276 if (accessoryViewUpdateBlock_) { |
| 275 accessoryViewUpdateBlock_.get()( | 277 accessoryViewUpdateBlock_.get()( |
| 276 [self suggestionViewWithSuggestions:suggestions], self); | 278 [self suggestionViewWithSuggestions:suggestions], self); |
| 277 } | 279 } |
| 278 } | 280 } |
| 279 | 281 |
| 280 - (UIView*)suggestionViewWithSuggestions:(NSArray*)suggestions { | 282 - (UIView*)suggestionViewWithSuggestions:(NSArray*)suggestions { |
| 283 CGRect frame = [_webViewProxy getKeyboardAccessory].frame; |
| 284 // Force the desired height on iPads running iOS 9 or later where the height |
| 285 // of the inputAccessoryView is 0. |
| 286 if (base::ios::IsRunningOnIOS9OrLater() && IsIPadIdiom()) { |
| 287 frame.size.height = autofill::kInputAccessoryHeight; |
| 288 } |
| 281 base::scoped_nsobject<FormSuggestionView> view([[FormSuggestionView alloc] | 289 base::scoped_nsobject<FormSuggestionView> view([[FormSuggestionView alloc] |
| 282 initWithFrame:[_webViewProxy getKeyboardAccessory].frame | 290 initWithFrame:frame |
| 283 client:self | 291 client:self |
| 284 suggestions:suggestions]); | 292 suggestions:suggestions]); |
| 285 return view.autorelease(); | 293 return view.autorelease(); |
| 286 } | 294 } |
| 287 | 295 |
| 288 - (void)didSelectSuggestion:(FormSuggestion*)suggestion { | 296 - (void)didSelectSuggestion:(FormSuggestion*)suggestion { |
| 289 if (!_suggestionState) | 297 if (!_suggestionState) |
| 290 return; | 298 return; |
| 291 | 299 |
| 292 // Send the suggestion to the provider. Upon completion advance the cursor | 300 // Send the suggestion to the provider. Upon completion advance the cursor |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 (FormInputAccessoryViewController*)controller { | 359 (FormInputAccessoryViewController*)controller { |
| 352 accessoryViewUpdateBlock_.reset(); | 360 accessoryViewUpdateBlock_.reset(); |
| 353 [self resetSuggestionState]; | 361 [self resetSuggestionState]; |
| 354 } | 362 } |
| 355 | 363 |
| 356 - (void)resizeAccessoryView { | 364 - (void)resizeAccessoryView { |
| 357 [self updateKeyboard:_suggestionState.get()]; | 365 [self updateKeyboard:_suggestionState.get()]; |
| 358 } | 366 } |
| 359 | 367 |
| 360 @end | 368 @end |
| OLD | NEW |