autofill_dialog_types.cc revision a36e5920737c6adbddd3e43b760e5de8431db6e0
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com// Use of this source code is governed by a BSD-style license that can be 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com// found in the LICENSE file. 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com#include "chrome/browser/ui/autofill/autofill_dialog_types.h" 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com#include "base/logging.h" 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "grit/generated_resources.h" 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "ui/base/l10n/l10n_util.h" 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "ui/base/resource/resource_bundle.h" 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comnamespace autofill { 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comint const kSplashDisplayDurationMs = 1200; 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comint const kSplashFadeOutDurationMs = 200; 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comint const kSplashFadeInDialogDurationMs = 150; 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comDialogNotification::DialogNotification() : type_(NONE) {} 19961ddb04a0a7aba843032d829ab867518e52559ereed@google.com 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comDialogNotification::DialogNotification(Type type, const string16& display_text) 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : type_(type), 22ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com display_text_(display_text), 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com checked_(false), 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com interactive_(true) {} 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 26961ddb04a0a7aba843032d829ab867518e52559ereed@google.comSkColor DialogNotification::GetBackgroundColor() const { 27961ddb04a0a7aba843032d829ab867518e52559ereed@google.com switch (type_) { 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::AUTOCHECKOUT_SUCCESS: 29ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com case DialogNotification::EXPLANATORY_MESSAGE: 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::WALLET_USAGE_CONFIRMATION: 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkColorSetRGB(0xf5, 0xf5, 0xf5); 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::REQUIRED_ACTION: 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::WALLET_ERROR: 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::AUTOCHECKOUT_ERROR: 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkColorSetRGB(0xfc, 0xf3, 0xbf); 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::DEVELOPER_WARNING: 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::SECURITY_WARNING: 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::VALIDATION_ERROR: 39ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com return kWarningColor; 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::NONE: 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_ColorTRANSPARENT; 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com NOTREACHED(); 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_ColorTRANSPARENT; 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkColor DialogNotification::GetBorderColor() const { 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (type_) { 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::AUTOCHECKOUT_SUCCESS: 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::EXPLANATORY_MESSAGE: 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::WALLET_USAGE_CONFIRMATION: 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkColorSetRGB(0xe5, 0xe5, 0xe5); 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::REQUIRED_ACTION: 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::WALLET_ERROR: 56ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com case DialogNotification::AUTOCHECKOUT_ERROR: 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::DEVELOPER_WARNING: 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::SECURITY_WARNING: 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::VALIDATION_ERROR: 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::NONE: 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return GetBackgroundColor(); 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com NOTREACHED(); 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_ColorTRANSPARENT; 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 67ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 68961ddb04a0a7aba843032d829ab867518e52559ereed@google.comSkColor DialogNotification::GetTextColor() const { 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (type_) { 70ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com case DialogNotification::REQUIRED_ACTION: 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::WALLET_ERROR: 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::AUTOCHECKOUT_ERROR: 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::AUTOCHECKOUT_SUCCESS: 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::EXPLANATORY_MESSAGE: 75b602b8e5334edc0bfcdf086c2ea58e2b5d5f1f3breed@android.com case DialogNotification::WALLET_USAGE_CONFIRMATION: 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkColorSetRGB(102, 102, 102); 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::DEVELOPER_WARNING: 788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::SECURITY_WARNING: 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::VALIDATION_ERROR: 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_ColorWHITE; 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case DialogNotification::NONE: 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_ColorTRANSPARENT; 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com NOTREACHED(); 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_ColorTRANSPARENT; 878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 88ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool DialogNotification::HasArrow() const { 90961ddb04a0a7aba843032d829ab867518e52559ereed@google.com return type_ == DialogNotification::EXPLANATORY_MESSAGE || 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com type_ == DialogNotification::WALLET_ERROR || 928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com type_ == DialogNotification::WALLET_USAGE_CONFIRMATION; 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool DialogNotification::HasCheckbox() const { 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 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 250AutofillMetrics::DialogUiEvent DialogSectionToUiEditEvent( 251 DialogSection section) { 252 switch (section) { 253 case SECTION_EMAIL: 254 return AutofillMetrics::DIALOG_UI_EMAIL_EDIT_UI_SHOWN; 255 256 case SECTION_BILLING: 257 return AutofillMetrics::DIALOG_UI_BILLING_EDIT_UI_SHOWN; 258 259 case SECTION_CC_BILLING: 260 return AutofillMetrics::DIALOG_UI_CC_BILLING_EDIT_UI_SHOWN; 261 262 case SECTION_SHIPPING: 263 return AutofillMetrics::DIALOG_UI_SHIPPING_EDIT_UI_SHOWN; 264 265 case SECTION_CC: 266 return AutofillMetrics::DIALOG_UI_CC_EDIT_UI_SHOWN; 267 } 268 269 NOTREACHED(); 270 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; 271} 272 273AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( 274 DialogSection section) { 275 switch (section) { 276 case SECTION_EMAIL: 277 return AutofillMetrics::DIALOG_UI_EMAIL_ITEM_ADDED; 278 279 case SECTION_BILLING: 280 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED; 281 282 case SECTION_CC_BILLING: 283 return AutofillMetrics::DIALOG_UI_CC_BILLING_ITEM_ADDED; 284 285 case SECTION_SHIPPING: 286 return AutofillMetrics::DIALOG_UI_SHIPPING_ITEM_ADDED; 287 288 case SECTION_CC: 289 return AutofillMetrics::DIALOG_UI_CC_ITEM_ADDED; 290 } 291 292 NOTREACHED(); 293 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; 294} 295 296AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent( 297 DialogSection section) { 298 switch (section) { 299 case SECTION_EMAIL: 300 return AutofillMetrics::DIALOG_UI_EMAIL_SELECTED_SUGGESTION_CHANGED; 301 302 case SECTION_BILLING: 303 return AutofillMetrics::DIALOG_UI_BILLING_SELECTED_SUGGESTION_CHANGED; 304 305 case SECTION_CC_BILLING: 306 return AutofillMetrics::DIALOG_UI_CC_BILLING_SELECTED_SUGGESTION_CHANGED; 307 308 case SECTION_SHIPPING: 309 return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED; 310 311 case SECTION_CC: 312 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED; 313 } 314 315 NOTREACHED(); 316 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; 317} 318 319} // namespace autofill 320