autofill_dialog_types.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
6
7#include "base/logging.h"
8
9namespace autofill {
10
11DialogNotification::DialogNotification() : type_(NONE) {}
12
13DialogNotification::DialogNotification(Type type, const string16& display_text)
14    : type_(type),
15      display_text_(display_text),
16      checked_(false),
17      interactive_(true) {}
18
19SkColor DialogNotification::GetBackgroundColor() const {
20  switch (type_) {
21    case DialogNotification::EXPLANATORY_MESSAGE:
22    case DialogNotification::WALLET_SIGNIN_PROMO:
23    case DialogNotification::WALLET_USAGE_CONFIRMATION:
24      return SkColorSetRGB(0x47, 0x89, 0xfa);
25    case DialogNotification::REQUIRED_ACTION:
26    case DialogNotification::WALLET_ERROR:
27    case DialogNotification::AUTOCHECKOUT_ERROR:
28      return SkColorSetRGB(0xfc, 0xf3, 0xbf);
29    case DialogNotification::SECURITY_WARNING:
30    case DialogNotification::VALIDATION_ERROR:
31      return SkColorSetRGB(0xde, 0x49, 0x32);
32    case DialogNotification::NONE:
33      return SK_ColorTRANSPARENT;
34  }
35
36  NOTREACHED();
37  return SK_ColorTRANSPARENT;
38}
39
40SkColor DialogNotification::GetTextColor() const {
41  switch (type_) {
42    case DialogNotification::REQUIRED_ACTION:
43    case DialogNotification::WALLET_ERROR:
44    case DialogNotification::AUTOCHECKOUT_ERROR:
45      return SK_ColorBLACK;
46    case DialogNotification::EXPLANATORY_MESSAGE:
47    case DialogNotification::WALLET_SIGNIN_PROMO:
48    case DialogNotification::WALLET_USAGE_CONFIRMATION:
49    case DialogNotification::SECURITY_WARNING:
50    case DialogNotification::VALIDATION_ERROR:
51      return SK_ColorWHITE;
52    case DialogNotification::NONE:
53      return SK_ColorTRANSPARENT;
54  }
55
56  NOTREACHED();
57  return SK_ColorTRANSPARENT;
58}
59
60bool DialogNotification::HasArrow() const {
61  return type_ == DialogNotification::EXPLANATORY_MESSAGE ||
62         type_ == DialogNotification::WALLET_ERROR ||
63         type_ == DialogNotification::WALLET_SIGNIN_PROMO ||
64         type_ == DialogNotification::WALLET_USAGE_CONFIRMATION;
65}
66
67bool DialogNotification::HasCheckbox() const {
68  return type_ == DialogNotification::WALLET_USAGE_CONFIRMATION;
69}
70
71SuggestionState::SuggestionState(const string16& text,
72                                 gfx::Font::FontStyle text_style,
73                                 const gfx::Image& icon,
74                                 const string16& extra_text,
75                                 const gfx::Image& extra_icon,
76                                 bool editable)
77    : text(text),
78      text_style(text_style),
79      icon(icon),
80      extra_text(extra_text),
81      extra_icon(extra_icon),
82      editable(editable) {}
83SuggestionState::~SuggestionState() {}
84
85AutofillMetrics::DialogUiEvent DialogSectionToUiEditEvent(
86    DialogSection section) {
87  switch (section) {
88    case SECTION_EMAIL:
89      return AutofillMetrics::DIALOG_UI_EMAIL_EDIT_UI_SHOWN;
90
91    case SECTION_BILLING:
92      return AutofillMetrics::DIALOG_UI_BILLING_EDIT_UI_SHOWN;
93
94    case SECTION_CC_BILLING:
95      return AutofillMetrics::DIALOG_UI_CC_BILLING_EDIT_UI_SHOWN;
96
97    case SECTION_SHIPPING:
98      return AutofillMetrics::DIALOG_UI_SHIPPING_EDIT_UI_SHOWN;
99
100    case SECTION_CC:
101      return AutofillMetrics::DIALOG_UI_CC_EDIT_UI_SHOWN;
102  }
103
104  NOTREACHED();
105  return AutofillMetrics::NUM_DIALOG_UI_EVENTS;
106}
107
108AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent(
109    DialogSection section) {
110  switch (section) {
111    case SECTION_EMAIL:
112      return AutofillMetrics::DIALOG_UI_EMAIL_ITEM_ADDED;
113
114    case SECTION_BILLING:
115      return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED;
116
117    case SECTION_CC_BILLING:
118      return AutofillMetrics::DIALOG_UI_CC_BILLING_ITEM_ADDED;
119
120    case SECTION_SHIPPING:
121      return AutofillMetrics::DIALOG_UI_SHIPPING_ITEM_ADDED;
122
123    case SECTION_CC:
124      return AutofillMetrics::DIALOG_UI_CC_ITEM_ADDED;
125  }
126
127  NOTREACHED();
128  return AutofillMetrics::NUM_DIALOG_UI_EVENTS;
129}
130
131AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent(
132    DialogSection section) {
133  switch (section) {
134    case SECTION_EMAIL:
135      return AutofillMetrics::DIALOG_UI_EMAIL_SELECTED_SUGGESTION_CHANGED;
136
137    case SECTION_BILLING:
138      return AutofillMetrics::DIALOG_UI_BILLING_SELECTED_SUGGESTION_CHANGED;
139
140    case SECTION_CC_BILLING:
141      return AutofillMetrics::DIALOG_UI_CC_BILLING_SELECTED_SUGGESTION_CHANGED;
142
143    case SECTION_SHIPPING:
144      return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED;
145
146    case SECTION_CC:
147      return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED;
148  }
149
150  NOTREACHED();
151  return AutofillMetrics::NUM_DIALOG_UI_EVENTS;
152}
153
154}  // namespace autofill
155