Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_VIEW_DELEGATE_H_ |
| 6 | #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_VIEW_DELEGATE_H_ |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 7 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 10 | #include "base/strings/string16.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 11 | #include "chrome/browser/ui/autofill/autofill_dialog_types.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 12 | #include "components/autofill/content/browser/wallet/required_action.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 13 | #include "components/autofill/core/browser/field_types.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 14 | #include "ui/base/range/range.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 15 | #include "ui/base/ui_base_types.h" |
| 16 | #include "ui/gfx/image/image.h" |
| 17 | #include "ui/gfx/native_widget_types.h" |
| 18 | |
| 19 | class Profile; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 20 | |
| 21 | namespace content { |
| 22 | class WebContents; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 23 | struct NativeWebKeyboardEvent; |
| 24 | } |
| 25 | |
| 26 | namespace gfx { |
| 27 | class Rect; |
| 28 | } |
| 29 | |
| 30 | namespace ui { |
| 31 | class ComboboxModel; |
| 32 | class MenuModel; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | namespace autofill { |
| 36 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 37 | // This class defines the interface to the controller that the dialog view sees. |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 38 | class AutofillDialogViewDelegate { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 39 | public: |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 40 | // Strings ------------------------------------------------------------------- |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 41 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 42 | virtual string16 DialogTitle() const = 0; |
| 43 | virtual string16 AccountChooserText() const = 0; |
| 44 | virtual string16 SignInLinkText() const = 0; |
| 45 | virtual string16 EditSuggestionText() const = 0; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 46 | virtual string16 CancelButtonText() const = 0; |
| 47 | virtual string16 ConfirmButtonText() const = 0; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 48 | virtual string16 SaveLocallyText() const = 0; |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 49 | virtual string16 SaveLocallyTooltip() const = 0; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 50 | virtual string16 LegalDocumentsText() = 0; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 51 | |
| 52 | // State --------------------------------------------------------------------- |
| 53 | |
| 54 | // Whether the user is known to be signed in. |
| 55 | virtual DialogSignedInState SignedInState() const = 0; |
| 56 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 57 | // Whether the dialog is in a not exactly well-defined state |
| 58 | // (while attempting to sign-in or retrieving the wallet data etc). |
| 59 | virtual bool ShouldShowSpinner() const = 0; |
| 60 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 61 | // Whether to show the checkbox to save data locally (in Autofill). |
| 62 | virtual bool ShouldOfferToSaveInChrome() const = 0; |
| 63 | |
| 64 | // Returns the model for the account chooser. It will return NULL if the |
| 65 | // account chooser should not show a menu. In this case, clicking on the |
| 66 | // account chooser should initiate sign-in. |
| 67 | virtual ui::MenuModel* MenuModelForAccountChooser() = 0; |
| 68 | |
| 69 | // Returns the icon that should be shown in the account chooser. |
| 70 | virtual gfx::Image AccountChooserImage() = 0; |
| 71 | |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 72 | // Whether or not the details container should be showing currently. |
| 73 | virtual bool ShouldShowDetailArea() const = 0; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 74 | |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 75 | // Whether or not the progress bar in the button strip should be showing. |
| 76 | virtual bool ShouldShowProgressBar() const = 0; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 77 | |
Ben Murdoch | 2385ea3 | 2013-08-06 11:01:04 +0100 | [diff] [blame] | 78 | // Returns the image that should be shown on the left of the button strip |
| 79 | // or an empty image if none should be shown. |
| 80 | virtual gfx::Image ButtonStripImage() const = 0; |
| 81 | |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 82 | // Which dialog buttons should be visible. |
| 83 | virtual int GetDialogButtons() const = 0; |
| 84 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 85 | // Whether or not the |button| should be enabled. |
| 86 | virtual bool IsDialogButtonEnabled(ui::DialogButton button) const = 0; |
| 87 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 88 | // Returns a struct full of data concerning what overlay, if any, should be |
| 89 | // displayed on top of the dialog. |
| 90 | virtual DialogOverlayState GetDialogOverlay() const = 0; |
| 91 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 92 | // Returns ranges to linkify in the text returned by |LegalDocumentsText()|. |
| 93 | virtual const std::vector<ui::Range>& LegalDocumentLinks() = 0; |
| 94 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 95 | // Detail inputs ------------------------------------------------------------- |
| 96 | |
| 97 | // Whether the section is currently active (i.e. should be shown). |
| 98 | virtual bool SectionIsActive(DialogSection section) const = 0; |
| 99 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 100 | // Returns the set of inputs the page has requested which fall under |
| 101 | // |section|. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 102 | virtual const DetailInputs& RequestedFieldsForSection(DialogSection section) |
| 103 | const = 0; |
| 104 | |
| 105 | // Returns the combobox model for inputs of type |type|, or NULL if the input |
| 106 | // should be a text field. |
| 107 | virtual ui::ComboboxModel* ComboboxModelForAutofillType( |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 108 | ServerFieldType type) = 0; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 109 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 110 | // Returns the model for suggestions for fields that fall under |section|. |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 111 | // This may return NULL, in which case no menu should be shown for that |
| 112 | // section. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 113 | virtual ui::MenuModel* MenuModelForSection(DialogSection section) = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 114 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 115 | // Returns the label text used to describe the section (i.e. Billing). |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 116 | virtual string16 LabelForSection(DialogSection section) const = 0; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 117 | |
| 118 | // Returns the current state of suggestions for |section|. |
| 119 | virtual SuggestionState SuggestionStateForSection(DialogSection section) = 0; |
| 120 | |
| 121 | // Should be called when the user starts editing of the section. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 122 | virtual void EditClickedForSection(DialogSection section) = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 123 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 124 | // Should be called when the user cancels editing of the section. |
| 125 | virtual void EditCancelledForSection(DialogSection section) = 0; |
| 126 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 127 | // Returns an icon to be displayed along with the input for the given type. |
| 128 | // |user_input| is the current text in the textfield. |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 129 | virtual gfx::Image IconForField(ServerFieldType type, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 130 | const string16& user_input) const = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 131 | |
Torne (Richard Coles) | a93a17c | 2013-05-15 11:34:50 +0100 | [diff] [blame] | 132 | // Decides whether input of |value| is valid for a field of type |type|. If |
| 133 | // valid, the returned string will be empty. Otherwise it will contain an |
| 134 | // error message. |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 135 | virtual string16 InputValidityMessage(DialogSection section, |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 136 | ServerFieldType type, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 137 | const string16& value) = 0; |
Torne (Richard Coles) | a93a17c | 2013-05-15 11:34:50 +0100 | [diff] [blame] | 138 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 139 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 140 | // Decides whether the combination of all |inputs| is valid, returns a |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 141 | // map of field types to error strings. |
| 142 | virtual ValidityData InputsAreValid( |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 143 | DialogSection section, |
| 144 | const DetailOutputMap& inputs, |
| 145 | ValidationType validation_type) = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 146 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 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. |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 150 | virtual void UserEditedOrActivatedInput(DialogSection section, |
| 151 | const DetailInput* input, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 152 | gfx::NativeView parent_view, |
| 153 | const gfx::Rect& content_bounds, |
| 154 | const string16& field_contents, |
| 155 | bool was_edit) = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 156 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 157 | // The view forwards keypresses in text inputs. Returns true if there should |
| 158 | // be no further processing of the event. |
| 159 | virtual bool HandleKeyPressEventInInput( |
| 160 | const content::NativeWebKeyboardEvent& event) = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 161 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 162 | // Called when focus has changed position within the view. |
| 163 | virtual void FocusMoved() = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 164 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 165 | // Miscellany ---------------------------------------------------------------- |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 166 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 167 | // The image to show in the splash screen when the dialog is first shown. If |
| 168 | // no splash screen should be shown, this image will be empty. |
| 169 | virtual gfx::Image SplashPageImage() const = 0; |
| 170 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 171 | // Called when the view has been closed. |
| 172 | virtual void ViewClosed() = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 173 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 174 | // Returns dialog notifications that the view should currently be showing in |
| 175 | // order from top to bottom. |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 176 | virtual std::vector<DialogNotification> CurrentNotifications() = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 177 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 178 | // Returns Autocheckout steps that the view should currently be showing in |
| 179 | // order from first to last. |
| 180 | virtual std::vector<DialogAutocheckoutStep> CurrentAutocheckoutSteps() |
| 181 | const = 0; |
| 182 | |
Torne (Richard Coles) | a93a17c | 2013-05-15 11:34:50 +0100 | [diff] [blame] | 183 | // Begins or aborts the flow to sign into Wallet. |
| 184 | virtual void SignInLinkClicked() = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 185 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 186 | // Called when a checkbox in the notification area has changed its state. |
| 187 | virtual void NotificationCheckboxStateChanged(DialogNotification::Type type, |
| 188 | bool checked) = 0; |
| 189 | |
| 190 | // A legal document link has been clicked. |
| 191 | virtual void LegalDocumentLinkClicked(const ui::Range& range) = 0; |
| 192 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 193 | // A button in the dialog's overlay has been pressed. |
| 194 | virtual void OverlayButtonPressed() = 0; |
| 195 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 196 | // Called when the view has been cancelled. Returns true if the dialog should |
| 197 | // now close, or false to keep it open. |
| 198 | virtual bool OnCancel() = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 199 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 200 | // Called when the view has been accepted. This could be to submit the payment |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 201 | // info or to handle a required action. Returns true if the dialog should now |
| 202 | // close, or false to keep it open. |
| 203 | virtual bool OnAccept() = 0; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 204 | |
| 205 | // Returns the profile for this dialog. |
| 206 | virtual Profile* profile() = 0; |
| 207 | |
| 208 | // The web contents that prompted the dialog. |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 209 | virtual content::WebContents* GetWebContents() = 0; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 210 | |
| 211 | protected: |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 212 | virtual ~AutofillDialogViewDelegate(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | } // namespace autofill |
| 216 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 217 | #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_VIEW_DELEGATE_H_ |