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
3 // found in the LICENSE file.
5 #ifndef IOS_CHROME_BROWSER_AUTOFILL_FORM_INPUT_ACCESSORY_VIEW_CONTROLLER_H_
6 #define IOS_CHROME_BROWSER_AUTOFILL_FORM_INPUT_ACCESSORY_VIEW_CONTROLLER_H_
8 #import <UIKit/UIKit.h>
10 #import "ios/chrome/browser/autofill/form_input_accessory_view_delegate.h"
11 #import "ios/web/public/web_state/web_state_observer_bridge.h"
13 @protocol CRWWebViewProxy
;
15 namespace ios_internal
{
17 extern NSString
* const kFormSuggestionAssistButtonPreviousElement
;
18 extern NSString
* const kFormSuggestionAssistButtonNextElement
;
19 extern NSString
* const kFormSuggestionAssistButtonDone
;
20 } // namespace autofill
21 } // namespace ios_internal
23 @protocol FormInputAccessoryViewProvider
;
24 @
class FormInputAccessoryViewController
;
26 // Block type to indicate that a FormInputAccessoryViewProvider has an accessory
28 typedef void (^AccessoryViewAvailableCompletion
)(
29 BOOL inputAccessoryViewAvailable
);
31 // Block type to provide an accessory view asynchronously.
32 typedef void (^AccessoryViewReadyCompletion
)(
34 id
<FormInputAccessoryViewProvider
> provider
);
36 // Represents an object that can provide a custom keyboard input accessory view.
37 @protocol FormInputAccessoryViewProvider
<NSObject
>
39 // A delegate for form navigation.
40 @
property(nonatomic
, assign
)
41 id
<FormInputAccessoryViewDelegate
> accessoryViewDelegate
;
43 // Determines asynchronously if this provider has a view available for the
44 // specified form/field and invokes |completionHandler| with the answer.
46 checkIfAccessoryViewIsAvailableForFormNamed
:(const std::string
&)formName
47 fieldName
:(const std::string
&)fieldName
48 webState
:(web::WebState
*)webState
50 (AccessoryViewAvailableCompletion
)
53 // Asynchronously retrieves an accessory view from this provider for the
54 // specified form/field and returns it via |accessoryViewUpdateBlock|.
55 - (void)retrieveAccessoryViewForFormNamed
:(const std::string
&)formName
56 fieldName
:(const std::string
&)fieldName
57 value
:(const std::string
&)value
58 type
:(const std::string
&)type
59 webState
:(web::WebState
*)webState
60 accessoryViewUpdateBlock
:
61 (AccessoryViewReadyCompletion
)accessoryViewUpdateBlock
;
63 // Notifies this provider that the accessory view is going away.
64 - (void)inputAccessoryViewControllerDidReset
:
65 (FormInputAccessoryViewController
*)controller
;
67 // Notifies this provider that the accessory view frame is changing. If the
68 // view provided by this provider needs to change, the updated view should be
69 // set using |accessoryViewUpdateBlock|.
70 - (void)resizeAccessoryView
;
74 // Creates and manages a custom input accessory view while the user is
75 // interacting with a form. Also handles hiding and showing the default
76 // accessory view elements.
77 @interface FormInputAccessoryViewController
78 : NSObject
<CRWWebStateObserver
, FormInputAccessoryViewDelegate
>
80 // Initializes a new controller with the specified |providers| of input
82 - (instancetype
)initWithWebState
:(web::WebState
*)webState
83 providers
:(NSArray
*)providers
;
85 // Hides the default input accessory view and replaces it with one that shows
86 // |customView| and form navigation controls.
87 - (void)showCustomInputAccessoryView
:(UIView
*)customView
;
89 // Restores the default input accessory view, removing (if necessary) any
90 // previously-added custom view.
91 - (void)restoreDefaultInputAccessoryView
;
95 #endif // IOS_CHROME_BROWSER_AUTOFILL_FORM_INPUT_ACCESSORY_VIEW_CONTROLLER_H_