autofill_dialog_view_delegate.h revision 58537e28ecd584eab876aee8be7156509866d23a
1// Copyright 2013 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_VIEW_DELEGATE_H_
6#define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_VIEW_DELEGATE_H_
7
8#include <vector>
9
10#include "base/strings/string16.h"
11#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
12#include "components/autofill/content/browser/wallet/required_action.h"
13#include "components/autofill/core/browser/field_types.h"
14#include "ui/base/ui_base_types.h"
15#include "ui/gfx/image/image.h"
16#include "ui/gfx/native_widget_types.h"
17#include "ui/gfx/range/range.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 AutofillDialogViewDelegate {
39 public:
40  // Strings -------------------------------------------------------------------
41
42  virtual string16 DialogTitle() const = 0;
43  virtual string16 AccountChooserText() const = 0;
44  virtual string16 SignInLinkText() const = 0;
45  virtual string16 SpinnerText() const = 0;
46  virtual string16 EditSuggestionText() const = 0;
47  virtual string16 CancelButtonText() const = 0;
48  virtual string16 ConfirmButtonText() const = 0;
49  virtual string16 SaveLocallyText() const = 0;
50  virtual string16 SaveLocallyTooltip() const = 0;
51  virtual string16 LegalDocumentsText() = 0;
52
53  // State ---------------------------------------------------------------------
54
55  // Whether the sign-in link should be disabled.
56  virtual bool ShouldDisableSignInLink() const = 0;
57
58  // Whether the dialog is in a not exactly well-defined state
59  // (while attempting to sign-in or retrieving the wallet data etc).
60  virtual bool ShouldShowSpinner() const = 0;
61
62  // Whether to show the checkbox to save data locally (in Autofill).
63  virtual bool ShouldOfferToSaveInChrome() const = 0;
64
65  // Whether the checkbox to save data locally should be checked initially.
66  virtual bool ShouldSaveInChrome() const = 0;
67
68  // Returns the model for the account chooser. It will return NULL if the
69  // account chooser should not show a menu. In this case, clicking on the
70  // account chooser should initiate sign-in.
71  virtual ui::MenuModel* MenuModelForAccountChooser() = 0;
72
73  // Returns the icon that should be shown in the account chooser.
74  virtual gfx::Image AccountChooserImage() = 0;
75
76  // Returns the image that should be shown on the left of the button strip
77  // or an empty image if none should be shown.
78  virtual gfx::Image ButtonStripImage() const = 0;
79
80  // Which dialog buttons should be visible.
81  virtual int GetDialogButtons() const = 0;
82
83  // Whether or not the |button| should be enabled.
84  virtual bool IsDialogButtonEnabled(ui::DialogButton button) const = 0;
85
86  // Returns a struct full of data concerning what overlay, if any, should be
87  // displayed on top of the dialog.
88  virtual DialogOverlayState GetDialogOverlay() = 0;
89
90  // Returns ranges to linkify in the text returned by |LegalDocumentsText()|.
91  virtual const std::vector<gfx::Range>& LegalDocumentLinks() = 0;
92
93  // Detail inputs -------------------------------------------------------------
94
95  // Whether the section is currently active (i.e. should be shown).
96  virtual bool SectionIsActive(DialogSection section) const = 0;
97
98  // Returns the set of inputs the page has requested which fall under
99  // |section|.
100  virtual const DetailInputs& RequestedFieldsForSection(DialogSection section)
101      const = 0;
102
103  // Returns the combobox model for inputs of type |type|, or NULL if the input
104  // should be a text field.
105  virtual ui::ComboboxModel* ComboboxModelForAutofillType(
106      ServerFieldType type) = 0;
107
108  // Returns the model for suggestions for fields that fall under |section|.
109  // This may return NULL, in which case no menu should be shown for that
110  // section.
111  virtual ui::MenuModel* MenuModelForSection(DialogSection section) = 0;
112
113  // Returns the label text used to describe the section (i.e. Billing).
114  virtual string16 LabelForSection(DialogSection section) const = 0;
115
116  // Returns the current state of suggestions for |section|.
117  virtual SuggestionState SuggestionStateForSection(DialogSection section) = 0;
118
119  // Returns an icon to be displayed along with the input for the given type.
120  // |user_input| is the current text in the textfield.
121  virtual gfx::Image IconForField(ServerFieldType type,
122                                  const string16& user_input) const = 0;
123
124  // Decides whether input of |value| is valid for a field of type |type|. If
125  // valid, the returned string will be empty. Otherwise it will contain an
126  // error message.
127  virtual string16 InputValidityMessage(DialogSection section,
128                                        ServerFieldType type,
129                                        const string16& value) = 0;
130
131
132  // Decides whether the combination of all |inputs| is valid, returns a
133  // map of field types to error strings.
134  virtual ValidityData InputsAreValid(
135      DialogSection section,
136      const DetailOutputMap& inputs,
137      ValidationType validation_type) = 0;
138
139  // Called when the user changes the contents of a text field or activates it
140  // (by focusing and then clicking it). |was_edit| is true when the function
141  // was called in response to the user editing the text field.
142  virtual void UserEditedOrActivatedInput(DialogSection section,
143                                          const DetailInput* input,
144                                          gfx::NativeView parent_view,
145                                          const gfx::Rect& content_bounds,
146                                          const string16& field_contents,
147                                          bool was_edit) = 0;
148
149  // The view forwards keypresses in text inputs. Returns true if there should
150  // be no further processing of the event.
151  virtual bool HandleKeyPressEventInInput(
152      const content::NativeWebKeyboardEvent& event) = 0;
153
154  // Called when focus has changed position within the view.
155  virtual void FocusMoved() = 0;
156
157  // Miscellany ----------------------------------------------------------------
158
159  // The image to show in the splash screen when the dialog is first shown. If
160  // no splash screen should be shown, this image will be empty.
161  virtual gfx::Image SplashPageImage() const = 0;
162
163  // Called when the view has been closed.
164  virtual void ViewClosed() = 0;
165
166  // Returns dialog notifications that the view should currently be showing in
167  // order from top to bottom.
168  virtual std::vector<DialogNotification> CurrentNotifications() = 0;
169
170  // Called when a generic link has been clicked in the dialog. Opens the URL
171  // out-of-line.
172  virtual void LinkClicked(const GURL& url) = 0;
173
174  // Begins or aborts the flow to sign into Wallet.
175  virtual void SignInLinkClicked() = 0;
176
177  // Called when a checkbox in the notification area has changed its state.
178  virtual void NotificationCheckboxStateChanged(DialogNotification::Type type,
179                                                bool checked) = 0;
180
181  // A legal document link has been clicked.
182  virtual void LegalDocumentLinkClicked(const gfx::Range& range) = 0;
183
184  // Called when the view has been cancelled. Returns true if the dialog should
185  // now close, or false to keep it open.
186  virtual bool OnCancel() = 0;
187
188  // Called when the view has been accepted. This could be to submit the payment
189  // info or to handle a required action. Returns true if the dialog should now
190  // close, or false to keep it open.
191  virtual bool OnAccept() = 0;
192
193  // Returns the profile for this dialog.
194  virtual Profile* profile() = 0;
195
196  // The web contents that prompted the dialog.
197  virtual content::WebContents* GetWebContents() = 0;
198
199 protected:
200  virtual ~AutofillDialogViewDelegate();
201};
202
203}  // namespace autofill
204
205#endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_VIEW_DELEGATE_H_
206