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