autofill_dialog_types.cc revision ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16
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#include "grit/generated_resources.h"
9#include "ui/base/l10n/l10n_util.h"
10#include "ui/base/resource/resource_bundle.h"
11
12namespace autofill {
13
14int const kSplashDisplayDurationMs = 1200;
15int const kSplashFadeOutDurationMs = 200;
16int const kSplashFadeInDialogDurationMs = 150;
17
18DialogNotification::DialogNotification() : type_(NONE) {}
19
20DialogNotification::DialogNotification(Type type, const string16& display_text)
21    : type_(type),
22      display_text_(display_text),
23      checked_(false),
24      interactive_(true) {}
25
26SkColor DialogNotification::GetBackgroundColor() const {
27  switch (type_) {
28    case DialogNotification::AUTOCHECKOUT_SUCCESS:
29    case DialogNotification::EXPLANATORY_MESSAGE:
30    case DialogNotification::WALLET_USAGE_CONFIRMATION:
31      return SkColorSetRGB(0xf5, 0xf5, 0xf5);
32    case DialogNotification::REQUIRED_ACTION:
33    case DialogNotification::WALLET_ERROR:
34    case DialogNotification::AUTOCHECKOUT_ERROR:
35      return SkColorSetRGB(0xfc, 0xf3, 0xbf);
36    case DialogNotification::DEVELOPER_WARNING:
37    case DialogNotification::SECURITY_WARNING:
38    case DialogNotification::VALIDATION_ERROR:
39      return kWarningColor;
40    case DialogNotification::NONE:
41      return SK_ColorTRANSPARENT;
42  }
43
44  NOTREACHED();
45  return SK_ColorTRANSPARENT;
46}
47
48SkColor DialogNotification::GetBorderColor() const {
49  switch (type_) {
50    case DialogNotification::AUTOCHECKOUT_SUCCESS:
51    case DialogNotification::EXPLANATORY_MESSAGE:
52    case DialogNotification::WALLET_USAGE_CONFIRMATION:
53      return SkColorSetRGB(0xe5, 0xe5, 0xe5);
54    case DialogNotification::REQUIRED_ACTION:
55    case DialogNotification::WALLET_ERROR:
56    case DialogNotification::AUTOCHECKOUT_ERROR:
57    case DialogNotification::DEVELOPER_WARNING:
58    case DialogNotification::SECURITY_WARNING:
59    case DialogNotification::VALIDATION_ERROR:
60    case DialogNotification::NONE:
61      return GetBackgroundColor();
62  }
63
64  NOTREACHED();
65  return SK_ColorTRANSPARENT;
66}
67
68SkColor DialogNotification::GetTextColor() const {
69  switch (type_) {
70    case DialogNotification::REQUIRED_ACTION:
71    case DialogNotification::WALLET_ERROR:
72    case DialogNotification::AUTOCHECKOUT_ERROR:
73    case DialogNotification::AUTOCHECKOUT_SUCCESS:
74    case DialogNotification::EXPLANATORY_MESSAGE:
75    case DialogNotification::WALLET_USAGE_CONFIRMATION:
76      return SkColorSetRGB(102, 102, 102);
77    case DialogNotification::DEVELOPER_WARNING:
78    case DialogNotification::SECURITY_WARNING:
79    case DialogNotification::VALIDATION_ERROR:
80      return SK_ColorWHITE;
81    case DialogNotification::NONE:
82      return SK_ColorTRANSPARENT;
83  }
84
85  NOTREACHED();
86  return SK_ColorTRANSPARENT;
87}
88
89bool DialogNotification::HasArrow() const {
90  return type_ == DialogNotification::EXPLANATORY_MESSAGE ||
91         type_ == DialogNotification::WALLET_ERROR ||
92         type_ == DialogNotification::WALLET_USAGE_CONFIRMATION;
93}
94
95bool DialogNotification::HasCheckbox() const {
96  return type_ == DialogNotification::WALLET_USAGE_CONFIRMATION;
97}
98
99DialogAutocheckoutStep::DialogAutocheckoutStep(AutocheckoutStepType type,
100                                               AutocheckoutStepStatus status)
101    : type_(type),
102      status_(status) {}
103
104SkColor DialogAutocheckoutStep::GetTextColor() const {
105  switch (status_) {
106    case AUTOCHECKOUT_STEP_UNSTARTED:
107      return SK_ColorGRAY;
108
109    case AUTOCHECKOUT_STEP_STARTED:
110    case AUTOCHECKOUT_STEP_COMPLETED:
111      return SK_ColorBLACK;
112
113    case AUTOCHECKOUT_STEP_FAILED:
114      return SK_ColorRED;
115  }
116
117  NOTREACHED();
118  return SK_ColorTRANSPARENT;
119}
120
121gfx::Font DialogAutocheckoutStep::GetTextFont() const {
122  gfx::Font::FontStyle font_style = gfx::Font::NORMAL;
123  switch (status_) {
124    case AUTOCHECKOUT_STEP_UNSTARTED:
125    case AUTOCHECKOUT_STEP_STARTED:
126      font_style = gfx::Font::NORMAL;
127      break;
128
129    case AUTOCHECKOUT_STEP_COMPLETED:
130    case AUTOCHECKOUT_STEP_FAILED:
131      font_style = gfx::Font::BOLD;
132      break;
133  }
134
135  return ui::ResourceBundle::GetSharedInstance().GetFont(
136      ui::ResourceBundle::BaseFont).DeriveFont(0, font_style);
137}
138
139bool DialogAutocheckoutStep::IsIconVisible() const {
140  return status_ == AUTOCHECKOUT_STEP_COMPLETED;
141}
142
143string16 DialogAutocheckoutStep::GetDisplayText() const {
144  int description_id = -1;
145  switch (status_) {
146    case AUTOCHECKOUT_STEP_UNSTARTED:
147      switch (type_) {
148        case AUTOCHECKOUT_STEP_SHIPPING:
149          description_id = IDS_AUTOFILL_STEP_SHIPPING_DETAILS_UNSTARTED;
150          break;
151
152        case AUTOCHECKOUT_STEP_DELIVERY:
153          description_id = IDS_AUTOFILL_STEP_DELIVERY_DETAILS_UNSTARTED;
154          break;
155
156        case AUTOCHECKOUT_STEP_BILLING:
157          description_id = IDS_AUTOFILL_STEP_BILLING_DETAILS_UNSTARTED;
158          break;
159
160        case AUTOCHECKOUT_STEP_PROXY_CARD:
161          description_id = IDS_AUTOFILL_STEP_PROXY_CARD_UNSTARTED;
162          break;
163      }
164      break;
165
166    case AUTOCHECKOUT_STEP_STARTED:
167      switch (type_) {
168        case AUTOCHECKOUT_STEP_SHIPPING:
169          description_id = IDS_AUTOFILL_STEP_SHIPPING_DETAILS_STARTED;
170          break;
171
172        case AUTOCHECKOUT_STEP_DELIVERY:
173          description_id = IDS_AUTOFILL_STEP_DELIVERY_DETAILS_STARTED;
174          break;
175
176        case AUTOCHECKOUT_STEP_BILLING:
177          description_id = IDS_AUTOFILL_STEP_BILLING_DETAILS_STARTED;
178          break;
179
180        case AUTOCHECKOUT_STEP_PROXY_CARD:
181          description_id = IDS_AUTOFILL_STEP_PROXY_CARD_STARTED;
182          break;
183      }
184      break;
185
186    case AUTOCHECKOUT_STEP_COMPLETED:
187      switch (type_) {
188        case AUTOCHECKOUT_STEP_SHIPPING:
189          description_id = IDS_AUTOFILL_STEP_SHIPPING_DETAILS_COMPLETE;
190          break;
191
192        case AUTOCHECKOUT_STEP_DELIVERY:
193          description_id = IDS_AUTOFILL_STEP_DELIVERY_DETAILS_COMPLETE;
194          break;
195
196        case AUTOCHECKOUT_STEP_BILLING:
197          description_id = IDS_AUTOFILL_STEP_BILLING_DETAILS_COMPLETE;
198          break;
199
200        case AUTOCHECKOUT_STEP_PROXY_CARD:
201          description_id = IDS_AUTOFILL_STEP_PROXY_CARD_COMPLETE;
202          break;
203      }
204      break;
205
206    case AUTOCHECKOUT_STEP_FAILED:
207      switch (type_) {
208        case AUTOCHECKOUT_STEP_SHIPPING:
209          description_id = IDS_AUTOFILL_STEP_SHIPPING_DETAILS_FAILED;
210          break;
211
212        case AUTOCHECKOUT_STEP_DELIVERY:
213          description_id = IDS_AUTOFILL_STEP_DELIVERY_DETAILS_FAILED;
214          break;
215
216        case AUTOCHECKOUT_STEP_BILLING:
217          description_id = IDS_AUTOFILL_STEP_BILLING_DETAILS_FAILED;
218          break;
219
220        case AUTOCHECKOUT_STEP_PROXY_CARD:
221          description_id = IDS_AUTOFILL_STEP_PROXY_CARD_FAILED;
222          break;
223      }
224      break;
225  }
226
227  return l10n_util::GetStringUTF16(description_id);
228}
229
230SkColor const kWarningColor = SkColorSetRGB(0xde, 0x49, 0x32);
231
232SuggestionState::SuggestionState(const string16& text,
233                                 gfx::Font::FontStyle text_style,
234                                 const gfx::Image& icon,
235                                 const string16& extra_text,
236                                 const gfx::Image& extra_icon)
237    : text(text),
238      text_style(text_style),
239      icon(icon),
240      extra_text(extra_text),
241      extra_icon(extra_icon) {}
242SuggestionState::~SuggestionState() {}
243
244DialogOverlayString::DialogOverlayString() : alignment(gfx::ALIGN_LEFT) {}
245DialogOverlayString::~DialogOverlayString() {}
246
247DialogOverlayState::DialogOverlayState() {}
248DialogOverlayState::~DialogOverlayState() {}
249
250}  // namespace autofill
251