autofill_dialog_types.h revision f2477e01787aa58f445919b809d89e252beef54f
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  base::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    REQUIRED_ACTION,
81    SECURITY_WARNING,
82    WALLET_ERROR,
83    WALLET_USAGE_CONFIRMATION,
84  };
85
86  DialogNotification();
87  DialogNotification(Type type, const base::string16& display_text);
88  ~DialogNotification();
89
90  // Returns the appropriate background, border, or text color for the view's
91  // notification area based on |type_|.
92  SkColor GetBackgroundColor() const;
93  SkColor GetBorderColor() const;
94  SkColor GetTextColor() const;
95
96  // Whether this notification has an arrow pointing up at the account chooser.
97  bool HasArrow() const;
98
99  // Whether this notifications has the "Save details to wallet" checkbox.
100  bool HasCheckbox() const;
101
102  Type type() const { return type_; }
103  const base::string16& display_text() const { return display_text_; }
104
105  void set_link_url(const GURL& link_url) { link_url_ = link_url; }
106  const GURL& link_url() const { return link_url_; }
107
108  const gfx::Range& link_range() const { return link_range_; }
109
110  void set_tooltip_text(const base::string16& tooltip_text) {
111    tooltip_text_ = tooltip_text;
112  }
113  const base::string16& tooltip_text() const { return tooltip_text_; }
114
115  void set_checked(bool checked) { checked_ = checked; }
116  bool checked() const { return checked_; }
117
118 private:
119  Type type_;
120  base::string16 display_text_;
121
122  // If the notification includes a link, these describe the destination and
123  // which part of |display_text_| is the anchor text.
124  GURL link_url_;
125  gfx::Range link_range_;
126
127  // When non-empty, indicates that a tooltip should be shown on the end of
128  // the notification.
129  base::string16 tooltip_text_;
130
131  // Whether the dialog notification's checkbox should be checked. Only applies
132  // when |HasCheckbox()| is true.
133  bool checked_;
134};
135
136extern SkColor const kWarningColor;
137
138struct SuggestionState {
139  SuggestionState();
140  SuggestionState(bool visible,
141                  const base::string16& vertically_compact_text,
142                  const base::string16& horizontally_compact_text,
143                  const gfx::Image& icon,
144                  const base::string16& extra_text,
145                  const gfx::Image& extra_icon);
146  ~SuggestionState();
147
148  // Whether a suggestion should be shown.
149  bool visible;
150
151  // Text to be shown for the suggestion. This should be preferred over
152  // |horizontally_compact_text| when there's enough horizontal space available
153  // to display it. When there's not enough space, fall back to
154  // |horizontally_compact_text|.
155  base::string16 vertically_compact_text;
156  base::string16 horizontally_compact_text;
157
158  gfx::Image icon;
159  base::string16 extra_text;
160  gfx::Image extra_icon;
161};
162
163// A struct to describe a textual message within a dialog overlay.
164struct DialogOverlayString {
165  DialogOverlayString();
166  ~DialogOverlayString();
167
168  // Text content of the message.
169  base::string16 text;
170
171  // Color of the message's text.
172  SkColor text_color;
173
174  // Font to render the message's text in.
175  gfx::Font font;
176};
177
178// A struct to describe a dialog overlay. If |image| is empty, no overlay should
179// be shown.
180struct DialogOverlayState {
181  DialogOverlayState();
182  ~DialogOverlayState();
183
184  // If empty, there should not be an overlay. If non-empty, an image that is
185  // more or less front and center.
186  gfx::Image image;
187
188  // Message to display.
189  DialogOverlayString string;
190};
191
192enum ValidationType {
193  VALIDATE_EDIT,   // Validate user edits. Allow for empty fields.
194  VALIDATE_FINAL,  // Full form validation. Required fields can't be empty.
195};
196
197typedef std::vector<DetailInput> DetailInputs;
198typedef std::map<ServerFieldType, base::string16> FieldValueMap;
199
200// A validity message for a single input field.
201struct ValidityMessage {
202  ValidityMessage(const base::string16& text, bool sure);
203  ~ValidityMessage();
204
205  // Message text. If not empty, error text. If empty, indicates valid field.
206  base::string16 text;
207
208  // If |sure| is true, always display message. If it is false,
209  // only display on final validation (i.e. after the user has attempted to
210  // submit).
211  bool sure;
212};
213
214// A mapping of field types to their corresponding ValidityMessage results.
215class ValidityMessages {
216 public:
217  ValidityMessages();
218  ~ValidityMessages();
219
220  void Set(ServerFieldType field, const ValidityMessage& message);
221  const ValidityMessage& GetMessageOrDefault(ServerFieldType field) const;
222
223  bool HasSureError(ServerFieldType field) const;
224  bool HasErrors() const;
225  bool HasSureErrors() const;
226
227 private:
228  typedef std::map<ServerFieldType, ValidityMessage> MessageMap;
229  MessageMap messages_;
230  ValidityMessage default_message_;
231};
232
233}  // namespace autofill
234
235#endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_TYPES_H_
236