autofill_dialog_view_delegate.h revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
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
37typedef std::map<ServerFieldType, string16> FieldValueMap;
38typedef std::map<ServerFieldType, gfx::Image> FieldIconMap;
39
40// This class defines the interface to the controller that the dialog view sees.
41class AutofillDialogViewDelegate {
42 public:
43  // Strings -------------------------------------------------------------------
44
45  virtual string16 DialogTitle() const = 0;
46  virtual string16 AccountChooserText() const = 0;
47  virtual string16 SignInLinkText() const = 0;
48  virtual string16 SpinnerText() const = 0;
49  virtual string16 EditSuggestionText() const = 0;
50  virtual string16 CancelButtonText() const = 0;
51  virtual string16 ConfirmButtonText() const = 0;
52  virtual string16 SaveLocallyText() const = 0;
53  virtual string16 SaveLocallyTooltip() const = 0;
54  virtual string16 LegalDocumentsText() = 0;
55
56  // State ---------------------------------------------------------------------
57
58  // Whether the sign-in link should be disabled.
59  virtual bool ShouldDisableSignInLink() const = 0;
60
61  // Whether the dialog is in a not exactly well-defined state
62  // (while attempting to sign-in or retrieving the wallet data etc).
63  virtual bool ShouldShowSpinner() const = 0;
64
65  // Whether to show the checkbox to save data locally (in Autofill).
66  virtual bool ShouldOfferToSaveInChrome() const = 0;
67
68  // Whether the checkbox to save data locally should be checked initially.
69  virtual bool ShouldSaveInChrome() const = 0;
70
71  // Returns the model for the account chooser. It will return NULL if the
72  // account chooser should not show a menu. In this case, clicking on the
73  // account chooser should initiate sign-in.
74  virtual ui::MenuModel* MenuModelForAccountChooser() = 0;
75
76  // Returns the icon that should be shown in the account chooser.
77  virtual gfx::Image AccountChooserImage() = 0;
78
79  // Returns the image that should be shown on the left of the button strip
80  // or an empty image if none should be shown.
81  virtual gfx::Image ButtonStripImage() 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 a struct full of data concerning what overlay, if any, should be
90  // displayed on top of the dialog.
91  virtual DialogOverlayState GetDialogOverlay() = 0;
92
93  // Returns ranges to linkify in the text returned by |LegalDocumentsText()|.
94  virtual const std::vector<gfx::Range>& LegalDocumentLinks() = 0;
95
96  // Detail inputs -------------------------------------------------------------
97
98  // Whether the section is currently active (i.e. should be shown).
99  virtual bool SectionIsActive(DialogSection section) const = 0;
100
101  // Returns the set of inputs the page has requested which fall under
102  // |section|.
103  virtual const DetailInputs& RequestedFieldsForSection(DialogSection section)
104      const = 0;
105
106  // Returns the combobox model for inputs of type |type|, or NULL if the input
107  // should be a text field.
108  virtual ui::ComboboxModel* ComboboxModelForAutofillType(
109      ServerFieldType type) = 0;
110
111  // Returns the model for suggestions for fields that fall under |section|.
112  // This may return NULL, in which case no menu should be shown for that
113  // section.
114  virtual ui::MenuModel* MenuModelForSection(DialogSection section) = 0;
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  // Returns the icons to be displayed along with the given |user_inputs| in a
123  // section.
124  virtual FieldIconMap IconsForFields(
125      const FieldValueMap& user_inputs) const = 0;
126
127  // Returns true if the value of this field |type| controls the icons for the
128  // rest of the fields in a section.
129  virtual bool FieldControlsIcons(ServerFieldType type) const = 0;
130
131  // Returns a tooltip for the given field, or an empty string if none exists.
132  virtual string16 TooltipForField(ServerFieldType type) const = 0;
133
134  // Whether a particular DetailInput in |section| should be edited or not.
135  virtual bool InputIsEditable(const DetailInput& input,
136                               DialogSection section) = 0;
137
138  // Decides whether input of |value| is valid for a field of type |type|. If
139  // valid, the returned string will be empty. Otherwise it will contain an
140  // error message.
141  virtual string16 InputValidityMessage(DialogSection section,
142                                        ServerFieldType type,
143                                        const string16& value) = 0;
144
145
146  // Decides whether the combination of all |inputs| is valid, returns a
147  // map of field types to validity messages.
148  virtual ValidityMessages InputsAreValid(DialogSection section,
149                                          const DetailOutputMap& inputs) = 0;
150
151  // Called when the user changes the contents of a text field or activates it
152  // (by focusing and then clicking it). |was_edit| is true when the function
153  // was called in response to the user editing the text field.
154  virtual void UserEditedOrActivatedInput(DialogSection section,
155                                          const DetailInput* input,
156                                          gfx::NativeView parent_view,
157                                          const gfx::Rect& content_bounds,
158                                          const string16& field_contents,
159                                          bool was_edit) = 0;
160
161  // The view forwards keypresses in text inputs. Returns true if there should
162  // be no further processing of the event.
163  virtual bool HandleKeyPressEventInInput(
164      const content::NativeWebKeyboardEvent& event) = 0;
165
166  // Called when focus has changed position within the view.
167  virtual void FocusMoved() = 0;
168
169  // Whether the view should show a validation error bubble.
170  virtual bool ShouldShowErrorBubble() const = 0;
171
172  // Miscellany ----------------------------------------------------------------
173
174  // Called when the view has been closed.
175  virtual void ViewClosed() = 0;
176
177  // Returns dialog notifications that the view should currently be showing in
178  // order from top to bottom.
179  virtual std::vector<DialogNotification> CurrentNotifications() = 0;
180
181  // Called when a generic link has been clicked in the dialog. Opens the URL
182  // out-of-line.
183  virtual void LinkClicked(const GURL& url) = 0;
184
185  // Begins or aborts the flow to sign into Wallet.
186  virtual void SignInLinkClicked() = 0;
187
188  // Called when a checkbox in the notification area has changed its state.
189  virtual void NotificationCheckboxStateChanged(DialogNotification::Type type,
190                                                bool checked) = 0;
191
192  // A legal document link has been clicked.
193  virtual void LegalDocumentLinkClicked(const gfx::Range& range) = 0;
194
195  // Called when the view has been cancelled. Returns true if the dialog should
196  // now close, or false to keep it open.
197  virtual bool OnCancel() = 0;
198
199  // Called when the view has been accepted. This could be to submit the payment
200  // info or to handle a required action. Returns true if the dialog should now
201  // close, or false to keep it open.
202  virtual bool OnAccept() = 0;
203
204  // Returns the profile for this dialog.
205  virtual Profile* profile() = 0;
206
207  // The web contents that prompted the dialog.
208  virtual content::WebContents* GetWebContents() = 0;
209
210 protected:
211  virtual ~AutofillDialogViewDelegate();
212};
213
214}  // namespace autofill
215
216#endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_VIEW_DELEGATE_H_
217