• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 namespace autofill {
24 
25 class AutofillField;
26 
27 // This struct describes a single input control for the imperative autocomplete
28 // dialog.
29 struct DetailInput {
30   enum Length {
31     SHORT,  // Short inputs share a line with other short inputs. [ CVC ][ Zip ]
32     LONG,   // Long inputs will be given their own full line.     [ City       ]
33     NONE,   // Input will not be shown.
34   };
35 
36   // Used to determine which inputs share lines when laying out.
37   Length length;
38 
39   ServerFieldType type;
40 
41   // Placeholder text resource ID.
42   int placeholder_text_rid;
43 
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 
48   // When non-empty, indicates the starting value for this input. This will be
49   // used when the user is editing existing data.
50   base::string16 initial_value;
51 };
52 
53 // Determines whether |input| and |field| match.
54 typedef 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.
60 enum 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 
71   // Upper boundary value for looping over all sections.
72   SECTION_MAX = SECTION_SHIPPING
73 };
74 
75 // A notification to show in the autofill dialog. Ranges from information to
76 // seriously scary security messages, and will give you the color it should be
77 // displayed (if you ask it).
78 class DialogNotification {
79  public:
80   enum Type {
81     NONE,
82     DEVELOPER_WARNING,
83     REQUIRED_ACTION,
84     SECURITY_WARNING,
85     WALLET_ERROR,
86     WALLET_USAGE_CONFIRMATION,
87   };
88 
89   DialogNotification();
90   DialogNotification(Type type, const base::string16& display_text);
91   ~DialogNotification();
92 
93   // Returns the appropriate background, border, or text color for the view's
94   // notification area based on |type_|.
95   SkColor GetBackgroundColor() const;
96   SkColor GetBorderColor() const;
97   SkColor GetTextColor() const;
98 
99   // Whether this notification has an arrow pointing up at the account chooser.
100   bool HasArrow() const;
101 
102   // Whether this notifications has the "Save details to wallet" checkbox.
103   bool HasCheckbox() const;
104 
type()105   Type type() const { return type_; }
display_text()106   const base::string16& display_text() const { return display_text_; }
107 
set_link_url(const GURL & link_url)108   void set_link_url(const GURL& link_url) { link_url_ = link_url; }
link_url()109   const GURL& link_url() const { return link_url_; }
110 
link_range()111   const gfx::Range& link_range() const { return link_range_; }
112 
set_tooltip_text(const base::string16 & tooltip_text)113   void set_tooltip_text(const base::string16& tooltip_text) {
114     tooltip_text_ = tooltip_text;
115   }
tooltip_text()116   const base::string16& tooltip_text() const { return tooltip_text_; }
117 
set_checked(bool checked)118   void set_checked(bool checked) { checked_ = checked; }
checked()119   bool checked() const { return checked_; }
120 
121  private:
122   Type type_;
123   base::string16 display_text_;
124 
125   // If the notification includes a link, these describe the destination and
126   // which part of |display_text_| is the anchor text.
127   GURL link_url_;
128   gfx::Range link_range_;
129 
130   // When non-empty, indicates that a tooltip should be shown on the end of
131   // the notification.
132   base::string16 tooltip_text_;
133 
134   // Whether the dialog notification's checkbox should be checked. Only applies
135   // when |HasCheckbox()| is true.
136   bool checked_;
137 };
138 
139 extern SkColor const kWarningColor;
140 
141 struct SuggestionState {
142   SuggestionState();
143   SuggestionState(bool visible,
144                   const base::string16& vertically_compact_text,
145                   const base::string16& horizontally_compact_text,
146                   const gfx::Image& icon,
147                   const base::string16& extra_text,
148                   const gfx::Image& extra_icon);
149   ~SuggestionState();
150 
151   // Whether a suggestion should be shown.
152   bool visible;
153 
154   // Text to be shown for the suggestion. This should be preferred over
155   // |horizontally_compact_text| when there's enough horizontal space available
156   // to display it. When there's not enough space, fall back to
157   // |horizontally_compact_text|.
158   base::string16 vertically_compact_text;
159   base::string16 horizontally_compact_text;
160 
161   gfx::Image icon;
162   base::string16 extra_text;
163   gfx::Image extra_icon;
164 };
165 
166 // A struct to describe a textual message within a dialog overlay.
167 struct DialogOverlayString {
168   DialogOverlayString();
169   ~DialogOverlayString();
170 
171   // Text content of the message.
172   base::string16 text;
173 
174   // Color of the message's text.
175   SkColor text_color;
176 
177   // Font to render the message's text in.
178   gfx::Font font;
179 };
180 
181 // A struct to describe a dialog overlay. If |image| is empty, no overlay should
182 // be shown.
183 struct DialogOverlayState {
184   DialogOverlayState();
185   ~DialogOverlayState();
186 
187   // If empty, there should not be an overlay. If non-empty, an image that is
188   // more or less front and center.
189   gfx::Image image;
190 
191   // Message to display.
192   DialogOverlayString string;
193 };
194 
195 enum ValidationType {
196   VALIDATE_EDIT,   // Validate user edits. Allow for empty fields.
197   VALIDATE_FINAL,  // Full form validation. Required fields can't be empty.
198 };
199 
200 typedef std::vector<DetailInput> DetailInputs;
201 typedef std::map<ServerFieldType, base::string16> FieldValueMap;
202 
203 // A validity message for a single input field.
204 struct ValidityMessage {
205   ValidityMessage(const base::string16& text, bool sure);
206   ~ValidityMessage();
207 
208   // Message text. If not empty, error text. If empty, indicates valid field.
209   base::string16 text;
210 
211   // If |sure| is true, always display message. If it is false,
212   // only display on final validation (i.e. after the user has attempted to
213   // submit).
214   bool sure;
215 };
216 
217 // A mapping of field types to their corresponding ValidityMessage results.
218 class ValidityMessages {
219  public:
220   ValidityMessages();
221   ~ValidityMessages();
222 
223   void Set(ServerFieldType field, const ValidityMessage& message);
224   const ValidityMessage& GetMessageOrDefault(ServerFieldType field) const;
225 
226   bool HasSureError(ServerFieldType field) const;
227   bool HasErrors() const;
228   bool HasSureErrors() const;
229 
230  private:
231   typedef std::map<ServerFieldType, ValidityMessage> MessageMap;
232   MessageMap messages_;
233   ValidityMessage default_message_;
234 };
235 
236 }  // namespace autofill
237 
238 #endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_TYPES_H_
239