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