autofill_dialog_types.cc revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
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(0x47, 0x89, 0xfa); 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::GetTextColor() const { 49 switch (type_) { 50 case DialogNotification::REQUIRED_ACTION: 51 case DialogNotification::WALLET_ERROR: 52 case DialogNotification::AUTOCHECKOUT_ERROR: 53 return SK_ColorBLACK; 54 case DialogNotification::AUTOCHECKOUT_SUCCESS: 55 case DialogNotification::DEVELOPER_WARNING: 56 case DialogNotification::EXPLANATORY_MESSAGE: 57 case DialogNotification::WALLET_USAGE_CONFIRMATION: 58 case DialogNotification::SECURITY_WARNING: 59 case DialogNotification::VALIDATION_ERROR: 60 return SK_ColorWHITE; 61 case DialogNotification::NONE: 62 return SK_ColorTRANSPARENT; 63 } 64 65 NOTREACHED(); 66 return SK_ColorTRANSPARENT; 67} 68 69bool DialogNotification::HasArrow() const { 70 return type_ == DialogNotification::EXPLANATORY_MESSAGE || 71 type_ == DialogNotification::WALLET_ERROR || 72 type_ == DialogNotification::WALLET_USAGE_CONFIRMATION; 73} 74 75bool DialogNotification::HasCheckbox() const { 76 return type_ == DialogNotification::WALLET_USAGE_CONFIRMATION; 77} 78 79DialogAutocheckoutStep::DialogAutocheckoutStep(AutocheckoutStepType type, 80 AutocheckoutStepStatus status) 81 : type_(type), 82 status_(status) {} 83 84SkColor DialogAutocheckoutStep::GetTextColor() const { 85 switch (status_) { 86 case AUTOCHECKOUT_STEP_UNSTARTED: 87 return SK_ColorGRAY; 88 89 case AUTOCHECKOUT_STEP_STARTED: 90 case AUTOCHECKOUT_STEP_COMPLETED: 91 return SK_ColorBLACK; 92 93 case AUTOCHECKOUT_STEP_FAILED: 94 return SK_ColorRED; 95 } 96 97 NOTREACHED(); 98 return SK_ColorTRANSPARENT; 99} 100 101gfx::Font DialogAutocheckoutStep::GetTextFont() const { 102 gfx::Font::FontStyle font_style = gfx::Font::NORMAL; 103 switch (status_) { 104 case AUTOCHECKOUT_STEP_UNSTARTED: 105 case AUTOCHECKOUT_STEP_STARTED: 106 font_style = gfx::Font::NORMAL; 107 break; 108 109 case AUTOCHECKOUT_STEP_COMPLETED: 110 case AUTOCHECKOUT_STEP_FAILED: 111 font_style = gfx::Font::BOLD; 112 break; 113 } 114 115 return ui::ResourceBundle::GetSharedInstance().GetFont( 116 ui::ResourceBundle::BaseFont).DeriveFont(0, font_style); 117} 118 119bool DialogAutocheckoutStep::IsIconVisible() const { 120 return status_ == AUTOCHECKOUT_STEP_COMPLETED; 121} 122 123string16 DialogAutocheckoutStep::GetDisplayText() const { 124 int description_id = -1; 125 switch (status_) { 126 case AUTOCHECKOUT_STEP_UNSTARTED: 127 switch (type_) { 128 case AUTOCHECKOUT_STEP_SHIPPING: 129 description_id = IDS_AUTOFILL_STEP_SHIPPING_DETAILS_UNSTARTED; 130 break; 131 132 case AUTOCHECKOUT_STEP_DELIVERY: 133 description_id = IDS_AUTOFILL_STEP_DELIVERY_DETAILS_UNSTARTED; 134 break; 135 136 case AUTOCHECKOUT_STEP_BILLING: 137 description_id = IDS_AUTOFILL_STEP_BILLING_DETAILS_UNSTARTED; 138 break; 139 140 case AUTOCHECKOUT_STEP_PROXY_CARD: 141 description_id = IDS_AUTOFILL_STEP_PROXY_CARD_UNSTARTED; 142 break; 143 } 144 break; 145 146 case AUTOCHECKOUT_STEP_STARTED: 147 switch (type_) { 148 case AUTOCHECKOUT_STEP_SHIPPING: 149 description_id = IDS_AUTOFILL_STEP_SHIPPING_DETAILS_STARTED; 150 break; 151 152 case AUTOCHECKOUT_STEP_DELIVERY: 153 description_id = IDS_AUTOFILL_STEP_DELIVERY_DETAILS_STARTED; 154 break; 155 156 case AUTOCHECKOUT_STEP_BILLING: 157 description_id = IDS_AUTOFILL_STEP_BILLING_DETAILS_STARTED; 158 break; 159 160 case AUTOCHECKOUT_STEP_PROXY_CARD: 161 description_id = IDS_AUTOFILL_STEP_PROXY_CARD_STARTED; 162 break; 163 } 164 break; 165 166 case AUTOCHECKOUT_STEP_COMPLETED: 167 switch (type_) { 168 case AUTOCHECKOUT_STEP_SHIPPING: 169 description_id = IDS_AUTOFILL_STEP_SHIPPING_DETAILS_COMPLETE; 170 break; 171 172 case AUTOCHECKOUT_STEP_DELIVERY: 173 description_id = IDS_AUTOFILL_STEP_DELIVERY_DETAILS_COMPLETE; 174 break; 175 176 case AUTOCHECKOUT_STEP_BILLING: 177 description_id = IDS_AUTOFILL_STEP_BILLING_DETAILS_COMPLETE; 178 break; 179 180 case AUTOCHECKOUT_STEP_PROXY_CARD: 181 description_id = IDS_AUTOFILL_STEP_PROXY_CARD_COMPLETE; 182 break; 183 } 184 break; 185 186 case AUTOCHECKOUT_STEP_FAILED: 187 switch (type_) { 188 case AUTOCHECKOUT_STEP_SHIPPING: 189 description_id = IDS_AUTOFILL_STEP_SHIPPING_DETAILS_FAILED; 190 break; 191 192 case AUTOCHECKOUT_STEP_DELIVERY: 193 description_id = IDS_AUTOFILL_STEP_DELIVERY_DETAILS_FAILED; 194 break; 195 196 case AUTOCHECKOUT_STEP_BILLING: 197 description_id = IDS_AUTOFILL_STEP_BILLING_DETAILS_FAILED; 198 break; 199 200 case AUTOCHECKOUT_STEP_PROXY_CARD: 201 description_id = IDS_AUTOFILL_STEP_PROXY_CARD_FAILED; 202 break; 203 } 204 break; 205 } 206 207 return l10n_util::GetStringUTF16(description_id); 208} 209 210SkColor const kWarningColor = SkColorSetRGB(0xde, 0x49, 0x32); 211 212SuggestionState::SuggestionState(const string16& text, 213 gfx::Font::FontStyle text_style, 214 const gfx::Image& icon, 215 const string16& extra_text, 216 const gfx::Image& extra_icon) 217 : text(text), 218 text_style(text_style), 219 icon(icon), 220 extra_text(extra_text), 221 extra_icon(extra_icon) {} 222SuggestionState::~SuggestionState() {} 223 224DialogOverlayString::DialogOverlayString() : alignment(gfx::ALIGN_LEFT) {} 225DialogOverlayString::~DialogOverlayString() {} 226 227DialogOverlayState::DialogOverlayState() {} 228DialogOverlayState::~DialogOverlayState() {} 229 230AutofillMetrics::DialogUiEvent DialogSectionToUiEditEvent( 231 DialogSection section) { 232 switch (section) { 233 case SECTION_EMAIL: 234 return AutofillMetrics::DIALOG_UI_EMAIL_EDIT_UI_SHOWN; 235 236 case SECTION_BILLING: 237 return AutofillMetrics::DIALOG_UI_BILLING_EDIT_UI_SHOWN; 238 239 case SECTION_CC_BILLING: 240 return AutofillMetrics::DIALOG_UI_CC_BILLING_EDIT_UI_SHOWN; 241 242 case SECTION_SHIPPING: 243 return AutofillMetrics::DIALOG_UI_SHIPPING_EDIT_UI_SHOWN; 244 245 case SECTION_CC: 246 return AutofillMetrics::DIALOG_UI_CC_EDIT_UI_SHOWN; 247 } 248 249 NOTREACHED(); 250 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; 251} 252 253AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( 254 DialogSection section) { 255 switch (section) { 256 case SECTION_EMAIL: 257 return AutofillMetrics::DIALOG_UI_EMAIL_ITEM_ADDED; 258 259 case SECTION_BILLING: 260 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED; 261 262 case SECTION_CC_BILLING: 263 return AutofillMetrics::DIALOG_UI_CC_BILLING_ITEM_ADDED; 264 265 case SECTION_SHIPPING: 266 return AutofillMetrics::DIALOG_UI_SHIPPING_ITEM_ADDED; 267 268 case SECTION_CC: 269 return AutofillMetrics::DIALOG_UI_CC_ITEM_ADDED; 270 } 271 272 NOTREACHED(); 273 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; 274} 275 276AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent( 277 DialogSection section) { 278 switch (section) { 279 case SECTION_EMAIL: 280 return AutofillMetrics::DIALOG_UI_EMAIL_SELECTED_SUGGESTION_CHANGED; 281 282 case SECTION_BILLING: 283 return AutofillMetrics::DIALOG_UI_BILLING_SELECTED_SUGGESTION_CHANGED; 284 285 case SECTION_CC_BILLING: 286 return AutofillMetrics::DIALOG_UI_CC_BILLING_SELECTED_SUGGESTION_CHANGED; 287 288 case SECTION_SHIPPING: 289 return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED; 290 291 case SECTION_CC: 292 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED; 293 } 294 295 NOTREACHED(); 296 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; 297} 298 299} // namespace autofill 300