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_list.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, // Shares a line with other short inputs, like display: inline. 32 SHORT_EOL, // Like SHORT but starts a new line directly afterward. Used to 33 // separate groups of short inputs into different lines. 34 LONG, // Will be given its own full line, like display: block. 35 NONE, // Input will not be shown. 36 }; 37 38 // Returns whether this input can spread across multiple lines. 39 bool IsMultiline() const; 40 41 // Used to determine which inputs share lines when laying out. 42 Length length; 43 44 ServerFieldType type; 45 46 // Text shown when the input is at its default state (e.g. empty). 47 base::string16 placeholder_text; 48 49 // A number between 0 and 1.0 that describes how much of the horizontal space 50 // in the row should be allotted to this input. 0 is equivalent to 1. 51 float expand_weight; 52 53 // When non-empty, indicates the starting value for this input. This will be 54 // used when the user is editing existing data. 55 base::string16 initial_value; 56 }; 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 105 Type type() const { return type_; } 106 const base::string16& display_text() const { return display_text_; } 107 108 void set_link_url(const GURL& link_url) { link_url_ = link_url; } 109 const GURL& link_url() const { return link_url_; } 110 111 const gfx::Range& link_range() const { return link_range_; } 112 113 void set_tooltip_text(const base::string16& tooltip_text) { 114 tooltip_text_ = tooltip_text; 115 } 116 const base::string16& tooltip_text() const { return tooltip_text_; } 117 118 void set_checked(bool 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 // Font list to render the message's text in. 175 gfx::FontList font_list; 176 }; 177 178 // A struct to describe a dialog overlay. If |image| is empty, no overlay should 179 // be shown. 180 struct 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 192 enum 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 197 typedef std::vector<DetailInput> DetailInputs; 198 typedef std::map<ServerFieldType, base::string16> FieldValueMap; 199 200 // A validity message for a single input field. 201 struct 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. 215 class ValidityMessages { 216 public: 217 ValidityMessages(); 218 ~ValidityMessages(); 219 220 // Sets the message for |field|, but will not overwrite a previous, invalid 221 // message. 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