autofill_dialog_types.h revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
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 "base/time/time.h"
14#include "components/autofill/core/browser/autofill_metrics.h"
15#include "components/autofill/core/browser/field_types.h"
16#include "third_party/skia/include/core/SkColor.h"
17#include "ui/gfx/font.h"
18#include "ui/gfx/image/image.h"
19#include "ui/gfx/range/range.h"
20#include "ui/gfx/text_constants.h"
21#include "url/gurl.h"
22
23namespace autofill {
24
25class AutofillField;
26
27// This struct describes a single input control for the imperative autocomplete
28// dialog.
29struct DetailInput {
30  // Multiple DetailInput structs with the same row_id go on the same row. The
31  // actual order of the rows is determined by their order of appearance in
32  // kBillingInputs. If negative, don't show the input at all (leave it hidden
33  // at all times).
34  int row_id;
35
36  ServerFieldType type;
37
38  // Placeholder text resource ID.
39  int placeholder_text_rid;
40
41  // A number between 0 and 1.0 that describes how much of the horizontal space
42  // in the row should be allotted to this input. 0 is equivalent to 1.
43  float expand_weight;
44
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};
49
50// Determines whether |input| and |field| match.
51typedef base::Callback<bool(const DetailInput& input,
52                            const AutofillField& field)>
53    InputFieldComparator;
54
55// Sections of the dialog --- all fields that may be shown to the user fit under
56// one of these sections.
57enum DialogSection {
58  // Lower boundary value for looping over all sections.
59  SECTION_MIN,
60
61  // The Autofill-backed dialog uses separate CC and billing sections.
62  SECTION_CC = SECTION_MIN,
63  SECTION_BILLING,
64  // The wallet-backed dialog uses a combined CC and billing section.
65  SECTION_CC_BILLING,
66  SECTION_SHIPPING,
67
68  // Upper boundary value for looping over all sections.
69  SECTION_MAX = SECTION_SHIPPING
70};
71
72// A notification to show in the autofill dialog. Ranges from information to
73// seriously scary security messages, and will give you the color it should be
74// displayed (if you ask it).
75class DialogNotification {
76 public:
77  enum Type {
78    NONE,
79    DEVELOPER_WARNING,
80    EXPLANATORY_MESSAGE,
81    REQUIRED_ACTION,
82    SECURITY_WARNING,
83    VALIDATION_ERROR,
84    WALLET_ERROR,
85    WALLET_USAGE_CONFIRMATION,
86  };
87
88  DialogNotification();
89  DialogNotification(Type type, const string16& display_text);
90  ~DialogNotification();
91
92  // Returns the appropriate background, border, or text color for the view's
93  // notification area based on |type_|.
94  SkColor GetBackgroundColor() const;
95  SkColor GetBorderColor() const;
96  SkColor GetTextColor() const;
97
98  // Whether this notification has an arrow pointing up at the account chooser.
99  bool HasArrow() const;
100
101  // Whether this notifications has the "Save details to wallet" checkbox.
102  bool HasCheckbox() const;
103
104  Type type() const { return type_; }
105  const string16& display_text() const { return display_text_; }
106
107  void set_link_url(const GURL& link_url) { link_url_ = link_url; }
108  const GURL& link_url() const { return link_url_; }
109
110  const gfx::Range& link_range() const { return link_range_; }
111
112  void set_tooltip_text(const string16& tooltip_text) {
113    tooltip_text_ = tooltip_text;
114  }
115  const string16& tooltip_text() const { return tooltip_text_; }
116
117  void set_checked(bool checked) { checked_ = checked; }
118  bool checked() const { return checked_; }
119
120 private:
121  Type type_;
122  string16 display_text_;
123
124  // If the notification includes a link, these describe the destination and
125  // which part of |display_text_| is the anchor text.
126  GURL link_url_;
127  gfx::Range link_range_;
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
138extern SkColor const kWarningColor;
139
140struct SuggestionState {
141  SuggestionState();
142  SuggestionState(bool visible,
143                  const string16& vertically_compact_text,
144                  const string16& horizontally_compact_text,
145                  const gfx::Image& icon,
146                  const string16& extra_text,
147                  const gfx::Image& extra_icon);
148  ~SuggestionState();
149
150  // Whether a suggestion should be shown.
151  bool visible;
152
153  // Text to be shown for the suggestion. This should be preferred over
154  // |horizontally_compact_text| when there's enough horizontal space available
155  // to display it. When there's not enough space, fall back to
156  // |horizontally_compact_text|.
157  base::string16 vertically_compact_text;
158  base::string16 horizontally_compact_text;
159
160  gfx::Image icon;
161  string16 extra_text;
162  gfx::Image extra_icon;
163};
164
165// A struct to describe a textual message within a dialog overlay.
166struct DialogOverlayString {
167  DialogOverlayString();
168  ~DialogOverlayString();
169
170  // Text content of the message.
171  base::string16 text;
172
173  // Color of the message's text.
174  SkColor text_color;
175
176  // Font to render the message's text in.
177  gfx::Font font;
178};
179
180// A struct to describe a dialog overlay. If |image| is empty, no overlay should
181// be shown.
182struct DialogOverlayState {
183  DialogOverlayState();
184  ~DialogOverlayState();
185
186  // If empty, there should not be an overlay. If non-empty, an image that is
187  // more or less front and center.
188  gfx::Image image;
189
190  // Message to display.
191  DialogOverlayString string;
192};
193
194enum ValidationType {
195  VALIDATE_EDIT,   // Validate user edits. Allow for empty fields.
196  VALIDATE_FINAL,  // Full form validation. Required fields can't be empty.
197};
198
199typedef std::vector<DetailInput> DetailInputs;
200typedef std::map<const DetailInput*, string16> DetailOutputMap;
201
202// A validity message for a single input field.
203struct ValidityMessage {
204  ValidityMessage(const base::string16& text, bool sure);
205  ~ValidityMessage();
206
207  // Message text. If not empty, error text. If empty, indicates valid field.
208  base::string16 text;
209
210  // If |sure| is true, always display message. If it is false,
211  // only display on final validation (i.e. after the user has attempted to
212  // submit).
213  bool sure;
214};
215
216// A mapping of field types to their corresponding ValidityMessage results.
217class ValidityMessages {
218 public:
219  ValidityMessages();
220  ~ValidityMessages();
221
222  void Set(ServerFieldType field, const ValidityMessage& message);
223  const ValidityMessage& GetMessageOrDefault(ServerFieldType field) const;
224
225  bool HasSureError(ServerFieldType field) const;
226  bool HasErrors() const;
227  bool HasSureErrors() const;
228
229 private:
230  typedef std::map<ServerFieldType, ValidityMessage> MessageMap;
231  MessageMap messages_;
232  ValidityMessage default_message_;
233};
234
235}  // namespace autofill
236
237#endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_TYPES_H_
238