OLD | NEW |
| (Empty) |
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/field_types.h" | |
15 #include "third_party/skia/include/core/SkColor.h" | |
16 #include "ui/gfx/font_list.h" | |
17 #include "ui/gfx/image/image.h" | |
18 #include "ui/gfx/range/range.h" | |
19 #include "ui/gfx/text_constants.h" | |
20 #include "url/gurl.h" | |
21 | |
22 namespace autofill { | |
23 | |
24 class AutofillField; | |
25 | |
26 // A notification to show in the autofill dialog. Ranges from information to | |
27 // seriously scary security messages, and will give you the color it should be | |
28 // displayed (if you ask it). | |
29 class DialogNotification { | |
30 public: | |
31 enum Type { | |
32 NONE, | |
33 DEVELOPER_WARNING, | |
34 REQUIRED_ACTION, | |
35 SECURITY_WARNING, | |
36 WALLET_ERROR, | |
37 WALLET_USAGE_CONFIRMATION, | |
38 }; | |
39 | |
40 DialogNotification(); | |
41 DialogNotification(Type type, const base::string16& display_text); | |
42 DialogNotification(const DialogNotification& other); | |
43 ~DialogNotification(); | |
44 | |
45 // Returns the appropriate background, border, or text color for the view's | |
46 // notification area based on |type_|. | |
47 SkColor GetBackgroundColor() const; | |
48 SkColor GetBorderColor() const; | |
49 SkColor GetTextColor() const; | |
50 | |
51 // Whether this notification has an arrow pointing up at the account chooser. | |
52 bool HasArrow() const; | |
53 | |
54 // Whether this notifications has the "Save details to wallet" checkbox. | |
55 bool HasCheckbox() const; | |
56 | |
57 Type type() const { return type_; } | |
58 const base::string16& display_text() const { return display_text_; } | |
59 | |
60 void set_link_url(const GURL& link_url) { link_url_ = link_url; } | |
61 const GURL& link_url() const { return link_url_; } | |
62 | |
63 const gfx::Range& link_range() const { return link_range_; } | |
64 | |
65 void set_tooltip_text(const base::string16& tooltip_text) { | |
66 tooltip_text_ = tooltip_text; | |
67 } | |
68 const base::string16& tooltip_text() const { return tooltip_text_; } | |
69 | |
70 void set_checked(bool checked) { checked_ = checked; } | |
71 bool checked() const { return checked_; } | |
72 | |
73 private: | |
74 Type type_; | |
75 base::string16 display_text_; | |
76 | |
77 // If the notification includes a link, these describe the destination and | |
78 // which part of |display_text_| is the anchor text. | |
79 GURL link_url_; | |
80 gfx::Range link_range_; | |
81 | |
82 // When non-empty, indicates that a tooltip should be shown on the end of | |
83 // the notification. | |
84 base::string16 tooltip_text_; | |
85 | |
86 // Whether the dialog notification's checkbox should be checked. Only applies | |
87 // when |HasCheckbox()| is true. | |
88 bool checked_; | |
89 }; | |
90 | |
91 extern SkColor const kWarningColor; | |
92 extern SkColor const kLightShadingColor; | |
93 extern SkColor const kSubtleBorderColor; | |
94 | |
95 struct SuggestionState { | |
96 SuggestionState(); | |
97 SuggestionState(bool visible, | |
98 const base::string16& vertically_compact_text, | |
99 const base::string16& horizontally_compact_text, | |
100 const gfx::Image& icon, | |
101 const base::string16& extra_text, | |
102 const gfx::Image& extra_icon); | |
103 SuggestionState(const SuggestionState& other); | |
104 ~SuggestionState(); | |
105 | |
106 // Whether a suggestion should be shown. | |
107 bool visible; | |
108 | |
109 // Text to be shown for the suggestion. This should be preferred over | |
110 // |horizontally_compact_text| when there's enough horizontal space available | |
111 // to display it. When there's not enough space, fall back to | |
112 // |horizontally_compact_text|. | |
113 base::string16 vertically_compact_text; | |
114 base::string16 horizontally_compact_text; | |
115 | |
116 gfx::Image icon; | |
117 base::string16 extra_text; | |
118 gfx::Image extra_icon; | |
119 }; | |
120 | |
121 // A struct to describe a textual message within a dialog overlay. | |
122 struct DialogOverlayString { | |
123 DialogOverlayString(); | |
124 ~DialogOverlayString(); | |
125 | |
126 // Text content of the message. | |
127 base::string16 text; | |
128 | |
129 // Font list to render the message's text in. | |
130 gfx::FontList font_list; | |
131 }; | |
132 | |
133 // A struct to describe a dialog overlay. If |image| is empty, no overlay should | |
134 // be shown. | |
135 struct DialogOverlayState { | |
136 DialogOverlayState(); | |
137 ~DialogOverlayState(); | |
138 | |
139 // If empty, there should not be an overlay. If non-empty, an image that is | |
140 // more or less front and center. | |
141 gfx::Image image; | |
142 | |
143 // Message to display. | |
144 DialogOverlayString string; | |
145 }; | |
146 | |
147 enum ValidationType { | |
148 VALIDATE_EDIT, // Validate user edits. Allow for empty fields. | |
149 VALIDATE_FINAL, // Full form validation. Required fields can't be empty. | |
150 }; | |
151 | |
152 typedef std::map<ServerFieldType, base::string16> FieldValueMap; | |
153 | |
154 // A validity message for a single input field. | |
155 struct ValidityMessage { | |
156 ValidityMessage(const base::string16& text, bool sure); | |
157 ~ValidityMessage(); | |
158 | |
159 // Message text. If not empty, error text. If empty, indicates valid field. | |
160 base::string16 text; | |
161 | |
162 // If |sure| is true, always display message. If it is false, | |
163 // only display on final validation (i.e. after the user has attempted to | |
164 // submit). | |
165 bool sure; | |
166 }; | |
167 | |
168 // A mapping of field types to their corresponding ValidityMessage results. | |
169 class ValidityMessages { | |
170 public: | |
171 ValidityMessages(); | |
172 ValidityMessages(const ValidityMessages& other); | |
173 ~ValidityMessages(); | |
174 | |
175 // Sets the message for |field|, but will not overwrite a previous, invalid | |
176 // message. | |
177 void Set(ServerFieldType field, const ValidityMessage& message); | |
178 const ValidityMessage& GetMessageOrDefault(ServerFieldType field) const; | |
179 | |
180 bool HasSureError(ServerFieldType field) const; | |
181 bool HasErrors() const; | |
182 bool HasSureErrors() const; | |
183 | |
184 private: | |
185 typedef std::map<ServerFieldType, ValidityMessage> MessageMap; | |
186 MessageMap messages_; | |
187 ValidityMessage default_message_; | |
188 }; | |
189 | |
190 } // namespace autofill | |
191 | |
192 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_TYPES_H_ | |
OLD | NEW |