Home | History | Annotate | Download | only in autofill
      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 "components/autofill/core/browser/autofill_metrics.h"
     14 #include "components/autofill/core/browser/field_types.h"
     15 #include "third_party/skia/include/core/SkColor.h"
     16 #include "ui/gfx/font.h"
     17 #include "ui/gfx/image/image.h"
     18 #include "ui/gfx/text_constants.h"
     19 
     20 namespace autofill {
     21 
     22 class AutofillField;
     23 
     24 // The time (in milliseconds) to show the splash page when the dialog is first
     25 // started.
     26 extern int const kSplashDisplayDurationMs;
     27 // The time (in milliseconds) spend fading out the splash image.
     28 extern int const kSplashFadeOutDurationMs;
     29 // The time (in milliseconds) spend fading in the dialog (after the splash image
     30 // has been faded out).
     31 extern int const kSplashFadeInDialogDurationMs;
     32 
     33 // This struct describes a single input control for the imperative autocomplete
     34 // dialog.
     35 struct DetailInput {
     36   // Multiple DetailInput structs with the same row_id go on the same row. The
     37   // actual order of the rows is determined by their order of appearance in
     38   // kBillingInputs. If negative, don't show the input at all (leave it hidden
     39   // at all times).
     40   int row_id;
     41   ServerFieldType type;
     42   // Placeholder text resource ID.
     43   int placeholder_text_rid;
     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   // When non-empty, indicates the starting value for this input. This will be
     48   // used when the user is editing existing data.
     49   string16 initial_value;
     50   // Whether the input is able to be edited (e.g. text changed in textfields,
     51   // index changed in comboboxes).
     52   bool editable;
     53 };
     54 
     55 // Determines whether |input| and |field| match.
     56 typedef base::Callback<bool(const DetailInput& input,
     57                             const AutofillField& field)>
     58     InputFieldComparator;
     59 
     60 // Sections of the dialog --- all fields that may be shown to the user fit under
     61 // one of these sections.
     62 enum DialogSection {
     63   // Lower boundary value for looping over all sections.
     64   SECTION_MIN,
     65 
     66   // The Autofill-backed dialog uses separate CC and billing sections.
     67   SECTION_CC = SECTION_MIN,
     68   SECTION_BILLING,
     69   // The wallet-backed dialog uses a combined CC and billing section.
     70   SECTION_CC_BILLING,
     71   SECTION_SHIPPING,
     72   SECTION_EMAIL,
     73 
     74   // Upper boundary value for looping over all sections.
     75   SECTION_MAX = SECTION_EMAIL
     76 };
     77 
     78 // A notification to show in the autofill dialog. Ranges from information to
     79 // seriously scary security messages, and will give you the color it should be
     80 // displayed (if you ask it).
     81 class DialogNotification {
     82  public:
     83   enum Type {
     84     NONE,
     85     AUTOCHECKOUT_ERROR,
     86     AUTOCHECKOUT_SUCCESS,
     87     DEVELOPER_WARNING,
     88     EXPLANATORY_MESSAGE,
     89     REQUIRED_ACTION,
     90     SECURITY_WARNING,
     91     VALIDATION_ERROR,
     92     WALLET_ERROR,
     93     WALLET_USAGE_CONFIRMATION,
     94   };
     95 
     96   DialogNotification();
     97   DialogNotification(Type type, const string16& display_text);
     98 
     99   // Returns the appropriate background, border, or text color for the view's
    100   // notification area based on |type_|.
    101   SkColor GetBackgroundColor() const;
    102   SkColor GetBorderColor() const;
    103   SkColor GetTextColor() const;
    104 
    105   // Whether this notification has an arrow pointing up at the account chooser.
    106   bool HasArrow() const;
    107 
    108   // Whether this notifications has the "Save details to wallet" checkbox.
    109   bool HasCheckbox() const;
    110 
    111   Type type() const { return type_; }
    112   const string16& display_text() const { return display_text_; }
    113 
    114   void set_tooltip_text(const string16& tooltip_text) {
    115     tooltip_text_ = tooltip_text;
    116   }
    117   const string16& tooltip_text() const { return tooltip_text_; }
    118 
    119   void set_checked(bool checked) { checked_ = checked; }
    120   bool checked() const { return checked_; }
    121 
    122   void set_interactive(bool interactive) { interactive_ = interactive; }
    123   bool interactive() const { return interactive_; }
    124 
    125  private:
    126   Type type_;
    127   string16 display_text_;
    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   // When false, this disables user interaction with the notification. For
    138   // example, WALLET_USAGE_CONFIRMATION notifications set this to false after
    139   // the submit flow has started.
    140   bool interactive_;
    141 };
    142 
    143 // A notification to show in the autofill dialog. Ranges from information to
    144 // seriously scary security messages, and will give you the color it should be
    145 // displayed (if you ask it).
    146 class DialogAutocheckoutStep {
    147  public:
    148   DialogAutocheckoutStep(AutocheckoutStepType type,
    149                          AutocheckoutStepStatus status);
    150 
    151   // Returns the appropriate color for the display text based on |status_|.
    152   SkColor GetTextColor() const;
    153 
    154   // Returns the appropriate font for the display text based on |status_|.
    155   gfx::Font GetTextFont() const;
    156 
    157   // Returns whether the icon for the view should be visable based on |status_|.
    158   bool IsIconVisible() const;
    159 
    160   // Returns the display text based on |type_| and |status_|.
    161   string16 GetDisplayText() const;
    162 
    163   AutocheckoutStepStatus status() { return status_; }
    164 
    165   AutocheckoutStepType type() { return type_; }
    166 
    167  private:
    168   AutocheckoutStepType type_;
    169   AutocheckoutStepStatus status_;
    170 };
    171 
    172 extern SkColor const kWarningColor;
    173 
    174 enum DialogSignedInState {
    175   REQUIRES_RESPONSE,
    176   REQUIRES_SIGN_IN,
    177   REQUIRES_PASSIVE_SIGN_IN,
    178   SIGNED_IN,
    179   SIGN_IN_DISABLED,
    180 };
    181 
    182 // Overall state of the Autocheckout flow.
    183 enum AutocheckoutState {
    184   AUTOCHECKOUT_ERROR,        // There was an error in the flow.
    185   AUTOCHECKOUT_IN_PROGRESS,  // The flow is currently in.
    186   AUTOCHECKOUT_NOT_STARTED,  // The flow has not been initiated by the user yet.
    187   AUTOCHECKOUT_SUCCESS,      // The flow completed successfully.
    188 };
    189 
    190 struct SuggestionState {
    191   SuggestionState();
    192   SuggestionState(bool visible,
    193                   const string16& vertically_compact_text,
    194                   const string16& horizontally_compact_text,
    195                   const gfx::Image& icon,
    196                   const string16& extra_text,
    197                   const gfx::Image& extra_icon);
    198   ~SuggestionState();
    199   // Whether a suggestion should be shown.
    200   bool visible;
    201   // Text to be shown for the suggestion. This should be preferred over
    202   // |horizontally_compact_text| when there's enough horizontal space available
    203   // to display it. When there's not enough space, fall back to
    204   // |horizontally_compact_text|.
    205   base::string16 vertically_compact_text;
    206   base::string16 horizontally_compact_text;
    207   gfx::Image icon;
    208   string16 extra_text;
    209   gfx::Image extra_icon;
    210 };
    211 
    212 // A struct to describe a textual message within a dialog overlay.
    213 struct DialogOverlayString {
    214   DialogOverlayString();
    215   ~DialogOverlayString();
    216   // TODO(estade): need to set a color as well.
    217   base::string16 text;
    218   SkColor text_color;
    219   gfx::Font font;
    220   gfx::HorizontalAlignment alignment;
    221 };
    222 
    223 // A struct to describe a dialog overlay. If |image| is empty, no overlay should
    224 // be shown.
    225 struct DialogOverlayState {
    226   DialogOverlayState();
    227   ~DialogOverlayState();
    228   // If empty, there should not be an overlay. If non-empty, an image that is
    229   // more or less front and center.
    230   gfx::Image image;
    231   // If non-empty, messages to display.
    232   std::vector<DialogOverlayString> strings;
    233   // If non-empty, holds text that should go on a button.
    234   base::string16 button_text;
    235 };
    236 
    237 enum ValidationType {
    238   VALIDATE_EDIT,   // Validate user edits. Allow for empty fields.
    239   VALIDATE_FINAL,  // Full form validation. Required fields can't be empty.
    240 };
    241 
    242 typedef std::vector<DetailInput> DetailInputs;
    243 typedef std::map<const DetailInput*, string16> DetailOutputMap;
    244 
    245 typedef std::map<ServerFieldType, string16> ValidityData;
    246 
    247 }  // namespace autofill
    248 
    249 #endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_TYPES_H_
    250