autofill_dialog_controller.h revision b2df76ea8fec9e32f6f3718986dba0d95315b29c
1// Copyright (c) 2012 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.
4
5#ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_H_
6#define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_H_
7
8#include <vector>
9
10#include "base/string16.h"
11#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
12#include "components/autofill/browser/field_types.h"
13#include "components/autofill/browser/wallet/required_action.h"
14#include "ui/base/range/range.h"
15#include "ui/base/ui_base_types.h"
16#include "ui/gfx/image/image.h"
17#include "ui/gfx/native_widget_types.h"
18
19class Profile;
20
21namespace content {
22class WebContents;
23struct NativeWebKeyboardEvent;
24}
25
26namespace gfx {
27class Rect;
28}
29
30namespace ui {
31class ComboboxModel;
32class MenuModel;
33}
34
35namespace autofill {
36
37// This class defines the interface to the controller that the dialog view sees.
38class AutofillDialogController {
39 public:
40  enum ValidationType {
41    VALIDATE_EDIT,   // validate user edits. Allow for empty fields.
42    VALIDATE_FINAL,  // Full form validation. Mandatory fields can't be empty.
43  };
44
45  // Strings -------------------------------------------------------------------
46
47  virtual string16 DialogTitle() const = 0;
48  virtual string16 AccountChooserText() const = 0;
49  virtual string16 SignInLinkText() const = 0;
50  virtual string16 EditSuggestionText() const = 0;
51  virtual string16 CancelButtonText() const = 0;
52  virtual string16 ConfirmButtonText() const = 0;
53  virtual string16 CancelSignInText() const = 0;
54  virtual string16 SaveLocallyText() const = 0;
55  virtual string16 ProgressBarText() const = 0;
56  virtual string16 LegalDocumentsText() = 0;
57
58  // State ---------------------------------------------------------------------
59
60  // Whether the user is known to be signed in.
61  virtual DialogSignedInState SignedInState() const = 0;
62
63  // Whether the dialog is in a not exactly well-defined state
64  // (while attempting to sign-in or retrieving the wallet data etc).
65  virtual bool ShouldShowSpinner() const = 0;
66
67  // Whether to show the checkbox to save data locally (in Autofill).
68  virtual bool ShouldOfferToSaveInChrome() const = 0;
69
70  // Returns the model for the account chooser. It will return NULL if the
71  // account chooser should not show a menu. In this case, clicking on the
72  // account chooser should initiate sign-in.
73  virtual ui::MenuModel* MenuModelForAccountChooser() = 0;
74
75  // Returns the icon that should be shown in the account chooser.
76  virtual gfx::Image AccountChooserImage() = 0;
77
78  // Whether or not the details container should be showing currently.
79  virtual bool ShouldShowDetailArea() const = 0;
80
81  // Whether or not the progress bar in the button strip should be showing.
82  virtual bool ShouldShowProgressBar() const = 0;
83
84  // Whether or not the |button| should be enabled.
85  virtual bool IsDialogButtonEnabled(ui::DialogButton button) const = 0;
86
87  // Returns ranges to linkify in the text returned by |LegalDocumentsText()|.
88  virtual const std::vector<ui::Range>& LegalDocumentLinks() = 0;
89
90  // Detail inputs -------------------------------------------------------------
91
92  // Whether the section is currently active (i.e. should be shown).
93  virtual bool SectionIsActive(DialogSection section) const = 0;
94
95  // Returns the set of inputs the page has requested which fall under
96  // |section|.
97  virtual const DetailInputs& RequestedFieldsForSection(DialogSection section)
98      const = 0;
99
100  // Returns the combobox model for inputs of type |type|, or NULL if the input
101  // should be a text field.
102  virtual ui::ComboboxModel* ComboboxModelForAutofillType(
103      AutofillFieldType type) = 0;
104
105  // Returns the model for suggestions for fields that fall under |section|.
106  // This may return NULL, in which case no menu should be shown for that
107  // section.
108  virtual ui::MenuModel* MenuModelForSection(DialogSection section) = 0;
109
110#if defined(OS_ANDROID)
111  // As the above, but will never return NULL. TODO(estade): android should
112  // stop relying on this and it should be removed.
113  virtual ui::MenuModel* MenuModelForSectionHack(DialogSection section) = 0;
114#endif
115
116  // Returns the label text used to describe the section (i.e. Billing).
117  virtual string16 LabelForSection(DialogSection section) const = 0;
118
119  // Returns the current state of suggestions for |section|.
120  virtual SuggestionState SuggestionStateForSection(DialogSection section) = 0;
121
122  // Should be called when the user starts editing of the section.
123  virtual void EditClickedForSection(DialogSection section) = 0;
124
125  // Should be called when the user cancels editing of the section.
126  virtual void EditCancelledForSection(DialogSection section) = 0;
127
128  // Returns an icon to be displayed along with the input for the given type.
129  // |user_input| is the current text in the textfield.
130  virtual gfx::Image IconForField(AutofillFieldType type,
131                                  const string16& user_input) const = 0;
132
133  // Decides whether input of |value| is valid for a field of type |type|.
134  virtual bool InputIsValid(AutofillFieldType type,
135                            const string16& value) const = 0;
136
137  // Decides whether the combination of all |inputs| is valid, returns a
138  // map of field types to error strings.
139  virtual ValidityData InputsAreValid(
140      const DetailOutputMap& inputs, ValidationType validation_type) const = 0;
141
142  // Called when the user changes the contents of a text field or activates it
143  // (by focusing and then clicking it). |was_edit| is true when the function
144  // was called in response to the user editing the text field.
145  virtual void UserEditedOrActivatedInput(const DetailInput* input,
146                                          gfx::NativeView parent_view,
147                                          const gfx::Rect& content_bounds,
148                                          const string16& field_contents,
149                                          bool was_edit) = 0;
150
151  // The view forwards keypresses in text inputs. Returns true if there should
152  // be no further processing of the event.
153  virtual bool HandleKeyPressEventInInput(
154      const content::NativeWebKeyboardEvent& event) = 0;
155
156  // Called when focus has changed position within the view.
157  virtual void FocusMoved() = 0;
158
159  // Miscellany ----------------------------------------------------------------
160
161  // Called when the view has been closed.
162  virtual void ViewClosed() = 0;
163
164  // Returns dialog notifications that the view should currently be showing in
165  // order from top to bottom.
166  virtual std::vector<DialogNotification> CurrentNotifications() const = 0;
167
168  // Begins the flow to sign into Wallet.
169  virtual void StartSignInFlow() = 0;
170
171  // Marks the signin flow into Wallet complete.
172  virtual void EndSignInFlow() = 0;
173
174  // Called when a checkbox in the notification area has changed its state.
175  virtual void NotificationCheckboxStateChanged(DialogNotification::Type type,
176                                                bool checked) = 0;
177
178  // A legal document link has been clicked.
179  virtual void LegalDocumentLinkClicked(const ui::Range& range) = 0;
180
181  // Called when the view has been cancelled.
182  virtual void OnCancel() = 0;
183
184  // Called when the view has been accepted. This could be to submit the payment
185  // info or to handle a required action.
186  virtual void OnAccept() = 0;
187
188  // Returns the profile for this dialog.
189  virtual Profile* profile() = 0;
190
191  // The web contents that prompted the dialog.
192  virtual content::WebContents* web_contents() = 0;
193
194 protected:
195  virtual ~AutofillDialogController();
196};
197
198}  // namespace autofill
199
200#endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_H_
201