autofill_dialog_controller.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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 SaveLocallyText() const = 0;
54  virtual string16 ProgressBarText() const = 0;
55  virtual string16 LegalDocumentsText() = 0;
56
57  // State ---------------------------------------------------------------------
58
59  // Whether the user is known to be signed in.
60  virtual DialogSignedInState SignedInState() const = 0;
61
62  // Whether the dialog is in a not exactly well-defined state
63  // (while attempting to sign-in or retrieving the wallet data etc).
64  virtual bool ShouldShowSpinner() const = 0;
65
66  // Whether to show the checkbox to save data locally (in Autofill).
67  virtual bool ShouldOfferToSaveInChrome() const = 0;
68
69  // Returns the model for the account chooser. It will return NULL if the
70  // account chooser should not show a menu. In this case, clicking on the
71  // account chooser should initiate sign-in.
72  virtual ui::MenuModel* MenuModelForAccountChooser() = 0;
73
74  // Returns the icon that should be shown in the account chooser.
75  virtual gfx::Image AccountChooserImage() = 0;
76
77  // Whether or not the details container should be showing currently.
78  virtual bool ShouldShowDetailArea() const = 0;
79
80  // Whether or not the progress bar in the button strip should be showing.
81  virtual bool ShouldShowProgressBar() const = 0;
82
83  // Which dialog buttons should be visible.
84  virtual int GetDialogButtons() const = 0;
85
86  // Whether or not the |button| should be enabled.
87  virtual bool IsDialogButtonEnabled(ui::DialogButton button) const = 0;
88
89  // Returns ranges to linkify in the text returned by |LegalDocumentsText()|.
90  virtual const std::vector<ui::Range>& LegalDocumentLinks() = 0;
91
92  // Detail inputs -------------------------------------------------------------
93
94  // Whether the section is currently active (i.e. should be shown).
95  virtual bool SectionIsActive(DialogSection section) const = 0;
96
97  // Returns the set of inputs the page has requested which fall under
98  // |section|.
99  virtual const DetailInputs& RequestedFieldsForSection(DialogSection section)
100      const = 0;
101
102  // Returns the combobox model for inputs of type |type|, or NULL if the input
103  // should be a text field.
104  virtual ui::ComboboxModel* ComboboxModelForAutofillType(
105      AutofillFieldType type) = 0;
106
107  // Returns the model for suggestions for fields that fall under |section|.
108  // This may return NULL, in which case no menu should be shown for that
109  // section.
110  virtual ui::MenuModel* MenuModelForSection(DialogSection section) = 0;
111
112#if defined(OS_ANDROID)
113  // As the above, but will never return NULL. TODO(estade): android should
114  // stop relying on this and it should be removed.
115  virtual ui::MenuModel* MenuModelForSectionHack(DialogSection section) = 0;
116#endif
117
118  // Returns the label text used to describe the section (i.e. Billing).
119  virtual string16 LabelForSection(DialogSection section) const = 0;
120
121  // Returns the current state of suggestions for |section|.
122  virtual SuggestionState SuggestionStateForSection(DialogSection section) = 0;
123
124  // Should be called when the user starts editing of the section.
125  virtual void EditClickedForSection(DialogSection section) = 0;
126
127  // Should be called when the user cancels editing of the section.
128  virtual void EditCancelledForSection(DialogSection section) = 0;
129
130  // Returns an icon to be displayed along with the input for the given type.
131  // |user_input| is the current text in the textfield.
132  virtual gfx::Image IconForField(AutofillFieldType type,
133                                  const string16& user_input) const = 0;
134
135  // Decides whether input of |value| is valid for a field of type |type|. If
136  // valid, the returned string will be empty. Otherwise it will contain an
137  // error message.
138  virtual string16 InputValidityMessage(AutofillFieldType type,
139                                        const string16& value) const = 0;
140
141
142  // Decides whether the combination of all |inputs| is valid, returns a
143  // map of field types to error strings.
144  virtual ValidityData InputsAreValid(
145      const DetailOutputMap& inputs, ValidationType validation_type) const = 0;
146
147  // Called when the user changes the contents of a text field or activates it
148  // (by focusing and then clicking it). |was_edit| is true when the function
149  // was called in response to the user editing the text field.
150  virtual void UserEditedOrActivatedInput(const DetailInput* input,
151                                          gfx::NativeView parent_view,
152                                          const gfx::Rect& content_bounds,
153                                          const string16& field_contents,
154                                          bool was_edit) = 0;
155
156  // The view forwards keypresses in text inputs. Returns true if there should
157  // be no further processing of the event.
158  virtual bool HandleKeyPressEventInInput(
159      const content::NativeWebKeyboardEvent& event) = 0;
160
161  // Called when focus has changed position within the view.
162  virtual void FocusMoved() = 0;
163
164  // Miscellany ----------------------------------------------------------------
165
166  // Called when the view has been closed.
167  virtual void ViewClosed() = 0;
168
169  // Returns dialog notifications that the view should currently be showing in
170  // order from top to bottom.
171  virtual std::vector<DialogNotification> CurrentNotifications() const = 0;
172
173  // Begins or aborts the flow to sign into Wallet.
174  virtual void SignInLinkClicked() = 0;
175
176  // Called when a checkbox in the notification area has changed its state.
177  virtual void NotificationCheckboxStateChanged(DialogNotification::Type type,
178                                                bool checked) = 0;
179
180  // A legal document link has been clicked.
181  virtual void LegalDocumentLinkClicked(const ui::Range& range) = 0;
182
183  // Called when the view has been cancelled.
184  virtual void OnCancel() = 0;
185
186  // Called when the view has been accepted. This could be to submit the payment
187  // info or to handle a required action.
188  virtual void OnAccept() = 0;
189
190  // Returns the profile for this dialog.
191  virtual Profile* profile() = 0;
192
193  // The web contents that prompted the dialog.
194  virtual content::WebContents* web_contents() = 0;
195
196 protected:
197  virtual ~AutofillDialogController();
198};
199
200}  // namespace autofill
201
202#endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_H_
203