autofill_dialog_types.h revision ca12bfac764ba476d6cd062bf1dde12cc64c3f40
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_TYPES_H_ 6#define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_TYPES_H_ 7 8#include <map> 9#include <vector> 10 11#include "base/callback_forward.h" 12#include "base/strings/string16.h" 13#include "components/autofill/core/browser/autofill_metrics.h" 14#include "components/autofill/core/browser/field_types.h" 15#include "third_party/skia/include/core/SkColor.h" 16#include "ui/gfx/font.h" 17#include "ui/gfx/image/image.h" 18#include "ui/gfx/text_constants.h" 19 20namespace autofill { 21 22class AutofillField; 23 24// The time (in milliseconds) to show the splash page when the dialog is first 25// started. 26extern int const kSplashDisplayDurationMs; 27// The time (in milliseconds) spend fading out the splash image. 28extern int const kSplashFadeOutDurationMs; 29// The time (in milliseconds) spend fading in the dialog (after the splash image 30// has been faded out). 31extern int const kSplashFadeInDialogDurationMs; 32 33// This struct describes a single input control for the imperative autocomplete 34// dialog. 35struct DetailInput { 36 // Multiple DetailInput structs with the same row_id go on the same row. The 37 // actual order of the rows is determined by their order of appearance in 38 // kBillingInputs. 39 int row_id; 40 AutofillFieldType type; 41 // Placeholder text resource ID. 42 int placeholder_text_rid; 43 // A number between 0 and 1.0 that describes how much of the horizontal space 44 // in the row should be allotted to this input. 0 is equivalent to 1. 45 float expand_weight; 46 // When non-empty, indicates the starting value for this input. This will be 47 // used when the user is editing existing data. 48 string16 initial_value; 49 // Whether the input is able to be edited (e.g. text changed in textfields, 50 // index changed in comboboxes). 51 bool editable; 52}; 53 54// Determines whether |input| and |field| match. 55typedef base::Callback<bool(const DetailInput& input, 56 const AutofillField& field)> 57 InputFieldComparator; 58 59// Sections of the dialog --- all fields that may be shown to the user fit under 60// one of these sections. 61enum DialogSection { 62 // Lower boundary value for looping over all sections. 63 SECTION_MIN, 64 65 // The Autofill-backed dialog uses separate CC and billing sections. 66 SECTION_CC = SECTION_MIN, 67 SECTION_BILLING, 68 // The wallet-backed dialog uses a combined CC and billing section. 69 SECTION_CC_BILLING, 70 SECTION_SHIPPING, 71 SECTION_EMAIL, 72 73 // Upper boundary value for looping over all sections. 74 SECTION_MAX = SECTION_EMAIL 75}; 76 77// A notification to show in the autofill dialog. Ranges from information to 78// seriously scary security messages, and will give you the color it should be 79// displayed (if you ask it). 80class DialogNotification { 81 public: 82 enum Type { 83 NONE, 84 AUTOCHECKOUT_ERROR, 85 AUTOCHECKOUT_SUCCESS, 86 DEVELOPER_WARNING, 87 EXPLANATORY_MESSAGE, 88 REQUIRED_ACTION, 89 SECURITY_WARNING, 90 VALIDATION_ERROR, 91 WALLET_ERROR, 92 WALLET_USAGE_CONFIRMATION, 93 }; 94 95 DialogNotification(); 96 DialogNotification(Type type, const string16& display_text); 97 98 // Returns the appropriate background or text color for the view's 99 // notification area based on |type_|. 100 SkColor GetBackgroundColor() const; 101 SkColor GetTextColor() const; 102 103 // Whether this notification has an arrow pointing up at the account chooser. 104 bool HasArrow() const; 105 106 // Whether this notifications has the "Save details to wallet" checkbox. 107 bool HasCheckbox() const; 108 109 const string16& display_text() const { return display_text_; } 110 Type type() const { return type_; } 111 112 void set_checked(bool checked) { checked_ = checked; } 113 bool checked() const { return checked_; } 114 115 void set_interactive(bool interactive) { interactive_ = interactive; } 116 bool interactive() const { return interactive_; } 117 118 private: 119 Type type_; 120 string16 display_text_; 121 122 // Whether the dialog notification's checkbox should be checked. Only applies 123 // when |HasCheckbox()| is true. 124 bool checked_; 125 126 // When false, this disables user interaction with the notification. For 127 // example, WALLET_USAGE_CONFIRMATION notifications set this to false after 128 // the submit flow has started. 129 bool interactive_; 130}; 131 132// A notification to show in the autofill dialog. Ranges from information to 133// seriously scary security messages, and will give you the color it should be 134// displayed (if you ask it). 135class DialogAutocheckoutStep { 136 public: 137 DialogAutocheckoutStep(AutocheckoutStepType type, 138 AutocheckoutStepStatus status); 139 140 // Returns the appropriate color for the display text based on |status_|. 141 SkColor GetTextColor() const; 142 143 // Returns the appropriate font for the display text based on |status_|. 144 gfx::Font GetTextFont() const; 145 146 // Returns whether the icon for the view should be visable based on |status_|. 147 bool IsIconVisible() const; 148 149 // Returns the display text based on |type_| and |status_|. 150 string16 GetDisplayText() const; 151 152 AutocheckoutStepStatus status() { return status_; } 153 154 AutocheckoutStepType type() { return type_; } 155 156 private: 157 AutocheckoutStepType type_; 158 AutocheckoutStepStatus status_; 159}; 160 161extern SkColor const kWarningColor; 162 163enum DialogSignedInState { 164 REQUIRES_RESPONSE, 165 REQUIRES_SIGN_IN, 166 REQUIRES_PASSIVE_SIGN_IN, 167 SIGNED_IN, 168 SIGN_IN_DISABLED, 169}; 170 171// Overall state of the Autocheckout flow. 172enum AutocheckoutState { 173 AUTOCHECKOUT_ERROR, // There was an error in the flow. 174 AUTOCHECKOUT_IN_PROGRESS, // The flow is currently in. 175 AUTOCHECKOUT_NOT_STARTED, // The flow has not been initiated by the user yet. 176 AUTOCHECKOUT_SUCCESS, // The flow completed successfully. 177}; 178 179struct SuggestionState { 180 SuggestionState(const string16& text, 181 gfx::Font::FontStyle text_style, 182 const gfx::Image& icon, 183 const string16& extra_text, 184 const gfx::Image& extra_icon); 185 ~SuggestionState(); 186 string16 text; 187 gfx::Font::FontStyle text_style; 188 gfx::Image icon; 189 string16 extra_text; 190 gfx::Image extra_icon; 191}; 192 193// A struct to describe a textual message within a dialog overlay. 194struct DialogOverlayString { 195 DialogOverlayString(); 196 ~DialogOverlayString(); 197 // TODO(estade): need to set a color as well. 198 base::string16 text; 199 SkColor text_color; 200 gfx::Font font; 201 gfx::HorizontalAlignment alignment; 202}; 203 204// A struct to describe a dialog overlay. If |image| is empty, no overlay should 205// be shown. 206struct DialogOverlayState { 207 DialogOverlayState(); 208 ~DialogOverlayState(); 209 // If empty, there should not be an overlay. If non-empty, an image that is 210 // more or less front and center. 211 gfx::Image image; 212 // If non-empty, messages to display. 213 std::vector<DialogOverlayString> strings; 214 // If non-empty, holds text that should go on a button. 215 base::string16 button_text; 216}; 217 218enum ValidationType { 219 VALIDATE_EDIT, // Validate user edits. Allow for empty fields. 220 VALIDATE_FINAL, // Full form validation. Required fields can't be empty. 221}; 222 223typedef std::vector<DetailInput> DetailInputs; 224typedef std::map<const DetailInput*, string16> DetailOutputMap; 225 226typedef std::map<AutofillFieldType, string16> ValidityData; 227 228// Returns the AutofillMetrics::DIALOG_UI_*_EDIT_UI_SHOWN metric corresponding 229// to the |section|. 230AutofillMetrics::DialogUiEvent DialogSectionToUiEditEvent( 231 DialogSection section); 232 233// Returns the AutofillMetrics::DIALOG_UI_*_ITEM_ADDED metric corresponding 234// to the |section|. 235AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( 236 DialogSection section); 237 238// Returns the AutofillMetrics::DIALOG_UI_*_ITEM_ADDED metric corresponding 239// to the |section|. 240AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent( 241 DialogSection section); 242 243} // namespace autofill 244 245#endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_TYPES_H_ 246