autofill_dialog_controller.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 "ui/base/ui_base_types.h" 14#include "ui/gfx/image/image.h" 15#include "ui/gfx/native_widget_types.h" 16 17class Profile; 18 19namespace content { 20class WebContents; 21struct NativeWebKeyboardEvent; 22} 23 24namespace gfx { 25class Rect; 26} 27 28namespace ui { 29class ComboboxModel; 30class MenuModel; 31} 32 33namespace autofill { 34 35// This class defines the interface to the controller that the dialog view sees. 36class AutofillDialogController { 37 public: 38 39 // Strings ------------------------------------------------------------------- 40 41 virtual string16 DialogTitle() const = 0; 42 virtual string16 AccountChooserText() const = 0; 43 virtual string16 SignInLinkText() const = 0; 44 virtual string16 EditSuggestionText() const = 0; 45 virtual string16 UseBillingForShippingText() const = 0; 46 virtual string16 CancelButtonText() const = 0; 47 virtual string16 ConfirmButtonText() const = 0; 48 virtual string16 CancelSignInText() const = 0; 49 virtual string16 SaveLocallyText() const = 0; 50 virtual string16 ProgressBarText() const = 0; 51 52 // State --------------------------------------------------------------------- 53 54 // Whether the user is known to be signed in. 55 virtual DialogSignedInState SignedInState() const = 0; 56 57 // Whether to show the checkbox to save data locally (in Autofill). 58 virtual bool ShouldOfferToSaveInChrome() const = 0; 59 60 // Returns the model for the account chooser. It will return NULL if the 61 // account chooser should not show a menu. In this case, clicking on the 62 // account chooser should initiate sign-in. 63 virtual ui::MenuModel* MenuModelForAccountChooser() = 0; 64 65 // Returns the icon that should be shown in the account chooser. 66 virtual gfx::Image AccountChooserImage() = 0; 67 68 // Whether or not an Autocheckout flow is running. 69 virtual bool AutocheckoutIsRunning() const = 0; 70 71 // Whether or not there was an error in an Autocheckout flow. 72 virtual bool HadAutocheckoutError() const = 0; 73 74 // Whether or not the |button| should be enabled. 75 virtual bool IsDialogButtonEnabled(ui::DialogButton button) const = 0; 76 77 // Detail inputs ------------------------------------------------------------- 78 79 // Whether the section is currently active (i.e. should be shown). 80 virtual bool SectionIsActive(DialogSection section) const = 0; 81 82 // Returns the set of inputs the page has requested which fall under 83 // |section|. 84 virtual const DetailInputs& RequestedFieldsForSection(DialogSection section) 85 const = 0; 86 87 // Returns the combobox model for inputs of type |type|, or NULL if the input 88 // should be a text field. 89 virtual ui::ComboboxModel* ComboboxModelForAutofillType( 90 AutofillFieldType type) = 0; 91 92 // Returns the model for suggestions for fields that fall under |section|. 93 virtual ui::MenuModel* MenuModelForSection(DialogSection section) = 0; 94 95 virtual string16 LabelForSection(DialogSection section) const = 0; 96 virtual string16 SuggestionTextForSection(DialogSection section) = 0; 97 virtual gfx::Image SuggestionIconForSection(DialogSection section) = 0; 98 virtual void EditClickedForSection(DialogSection section) = 0; 99 100 // Returns an icon to be displayed along with the input for the given type. 101 // |user_input| is the current text in the textfield. 102 virtual gfx::Image IconForField(AutofillFieldType type, 103 const string16& user_input) const = 0; 104 105 // Decides whether input of |value| is valid for a field of type |type|. 106 virtual bool InputIsValid(AutofillFieldType type, 107 const string16& value) = 0; 108 109 // Decides whether the combination of all |inputs| is valid, returns a 110 // vector of all invalid fields. 111 virtual std::vector<AutofillFieldType> InputsAreValid( 112 const DetailOutputMap& inputs) = 0; 113 114 // Called when the user changes the contents of a text field or activates it 115 // (by focusing and then clicking it). |was_edit| is true when the function 116 // was called in response to the user editing the text field. 117 virtual void UserEditedOrActivatedInput(const DetailInput* input, 118 DialogSection section, 119 gfx::NativeView parent_view, 120 const gfx::Rect& content_bounds, 121 const string16& field_contents, 122 bool was_edit) = 0; 123 124 // The view forwards keypresses in text inputs. Returns true if there should 125 // be no further processing of the event. 126 virtual bool HandleKeyPressEventInInput( 127 const content::NativeWebKeyboardEvent& event) = 0; 128 129 // Called when focus has changed position within the view. 130 virtual void FocusMoved() = 0; 131 132 // Miscellany ---------------------------------------------------------------- 133 134 // Called when the view has been closed. 135 virtual void ViewClosed() = 0; 136 137 // Returns dialog notifications that the view should currently be showing in 138 // order from top to bottom. 139 virtual std::vector<DialogNotification> CurrentNotifications() const = 0; 140 141 // Begins the flow to sign into Wallet. 142 virtual void StartSignInFlow() = 0; 143 144 // Marks the signin flow into Wallet complete. 145 virtual void EndSignInFlow() = 0; 146 147 // Called when the view has been cancelled. 148 virtual void OnCancel() = 0; 149 150 // Called when the view has been accepted. 151 virtual void OnSubmit() = 0; 152 153 // Returns the profile for this dialog. 154 virtual Profile* profile() = 0; 155 156 // The web contents that prompted the dialog. 157 virtual content::WebContents* web_contents() = 0; 158 159 protected: 160 virtual ~AutofillDialogController(); 161}; 162 163} // namespace autofill 164 165#endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_H_ 166