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