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