| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 | 1069 |
| 1070 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( | 1070 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( |
| 1071 DialogSection section) { | 1071 DialogSection section) { |
| 1072 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so | 1072 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so |
| 1073 // get the wrapper before this potentially happens below. | 1073 // get the wrapper before this potentially happens below. |
| 1074 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 1074 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 1075 | 1075 |
| 1076 // If the chosen item in |model| yields an empty suggestion text, it is | 1076 // If the chosen item in |model| yields an empty suggestion text, it is |
| 1077 // invalid. In this case, show the edit UI and highlight invalid fields. | 1077 // invalid. In this case, show the edit UI and highlight invalid fields. |
| 1078 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 1078 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 1079 string16 unused, unused2; |
| 1079 if (IsASuggestionItemKey(model->GetItemKeyForCheckedItem()) && | 1080 if (IsASuggestionItemKey(model->GetItemKeyForCheckedItem()) && |
| 1080 SuggestionTextForSection(section).empty()) { | 1081 !SuggestionTextForSection(section, &unused, &unused2)) { |
| 1081 SetEditingExistingData(section, true); | 1082 SetEditingExistingData(section, true); |
| 1082 } | 1083 } |
| 1083 | 1084 |
| 1084 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 1085 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 1085 if (wrapper && IsEditingExistingData(section)) | 1086 if (wrapper && IsEditingExistingData(section)) |
| 1086 wrapper->FillInputs(inputs); | 1087 wrapper->FillInputs(inputs); |
| 1087 | 1088 |
| 1088 for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { | 1089 for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { |
| 1089 it->editable = InputIsEditable(*it, section); | 1090 it->editable = InputIsEditable(*it, section); |
| 1090 } | 1091 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 case SECTION_SHIPPING: | 1295 case SECTION_SHIPPING: |
| 1295 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); | 1296 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); |
| 1296 default: | 1297 default: |
| 1297 NOTREACHED(); | 1298 NOTREACHED(); |
| 1298 return string16(); | 1299 return string16(); |
| 1299 } | 1300 } |
| 1300 } | 1301 } |
| 1301 | 1302 |
| 1302 SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection( | 1303 SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection( |
| 1303 DialogSection section) { | 1304 DialogSection section) { |
| 1304 return SuggestionState(SuggestionTextForSection(section), | 1305 string16 vertically_compact, horizontally_compact; |
| 1305 SuggestionTextStyleForSection(section), | 1306 bool show_suggestion = SuggestionTextForSection(section, |
| 1307 &vertically_compact, |
| 1308 &horizontally_compact); |
| 1309 return SuggestionState(show_suggestion, |
| 1310 vertically_compact, |
| 1311 horizontally_compact, |
| 1306 SuggestionIconForSection(section), | 1312 SuggestionIconForSection(section), |
| 1307 ExtraSuggestionTextForSection(section), | 1313 ExtraSuggestionTextForSection(section), |
| 1308 ExtraSuggestionIconForSection(section)); | 1314 ExtraSuggestionIconForSection(section)); |
| 1309 } | 1315 } |
| 1310 | 1316 |
| 1311 string16 AutofillDialogControllerImpl::SuggestionTextForSection( | 1317 bool AutofillDialogControllerImpl::SuggestionTextForSection( |
| 1312 DialogSection section) { | 1318 DialogSection section, |
| 1313 string16 action_text = RequiredActionTextForSection(section); | 1319 base::string16* vertically_compact, |
| 1314 if (!action_text.empty()) | 1320 base::string16* horizontally_compact) { |
| 1315 return action_text; | 1321 base::string16 action_text = RequiredActionTextForSection(section); |
| 1322 if (!action_text.empty()) { |
| 1323 *vertically_compact = *horizontally_compact = action_text; |
| 1324 return true; |
| 1325 } |
| 1316 | 1326 |
| 1317 // When the user has clicked 'edit' or a suggestion is somehow invalid (e.g. a | 1327 // When the user has clicked 'edit' or a suggestion is somehow invalid (e.g. a |
| 1318 // user selects a credit card that has expired), don't show a suggestion (even | 1328 // user selects a credit card that has expired), don't show a suggestion (even |
| 1319 // though there is a profile selected in the model). | 1329 // though there is a profile selected in the model). |
| 1320 if (IsEditingExistingData(section)) | 1330 if (IsEditingExistingData(section)) |
| 1321 return string16(); | 1331 return false; |
| 1322 | 1332 |
| 1323 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 1333 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 1324 std::string item_key = model->GetItemKeyForCheckedItem(); | 1334 std::string item_key = model->GetItemKeyForCheckedItem(); |
| 1325 if (item_key == kSameAsBillingKey) { | 1335 if (item_key == kSameAsBillingKey) { |
| 1326 return l10n_util::GetStringUTF16( | 1336 *vertically_compact = *horizontally_compact = l10n_util::GetStringUTF16( |
| 1327 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING); | 1337 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING); |
| 1338 return true; |
| 1328 } | 1339 } |
| 1329 | 1340 |
| 1330 if (!IsASuggestionItemKey(item_key)) | 1341 if (!IsASuggestionItemKey(item_key)) |
| 1331 return string16(); | 1342 return false; |
| 1332 | 1343 |
| 1333 if (section == SECTION_EMAIL) | 1344 if (section == SECTION_EMAIL) { |
| 1334 return model->GetLabelAt(model->checked_item()); | 1345 *vertically_compact = *horizontally_compact = |
| 1346 model->GetLabelAt(model->checked_item()); |
| 1347 return true; |
| 1348 } |
| 1335 | 1349 |
| 1336 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 1350 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 1337 return wrapper->GetDisplayText(); | 1351 return wrapper->GetDisplayText(vertically_compact, horizontally_compact); |
| 1338 } | |
| 1339 | |
| 1340 gfx::Font::FontStyle | |
| 1341 AutofillDialogControllerImpl::SuggestionTextStyleForSection( | |
| 1342 DialogSection section) const { | |
| 1343 const SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | |
| 1344 if (model->GetItemKeyForCheckedItem() == kSameAsBillingKey) | |
| 1345 return gfx::Font::ITALIC; | |
| 1346 | |
| 1347 return gfx::Font::NORMAL; | |
| 1348 } | 1352 } |
| 1349 | 1353 |
| 1350 string16 AutofillDialogControllerImpl::RequiredActionTextForSection( | 1354 string16 AutofillDialogControllerImpl::RequiredActionTextForSection( |
| 1351 DialogSection section) const { | 1355 DialogSection section) const { |
| 1352 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 1356 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
| 1353 const wallet::WalletItems::MaskedInstrument* current_instrument = | 1357 const wallet::WalletItems::MaskedInstrument* current_instrument = |
| 1354 wallet_items_->GetInstrumentById(active_instrument_id_); | 1358 wallet_items_->GetInstrumentById(active_instrument_id_); |
| 1355 if (current_instrument) | 1359 if (current_instrument) |
| 1356 return current_instrument->TypeAndLastFourDigits(); | 1360 return current_instrument->TypeAndLastFourDigits(); |
| 1357 | 1361 |
| (...skipping 2110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3468 view_->GetUserInput(SECTION_CC_BILLING, &output); | 3472 view_->GetUserInput(SECTION_CC_BILLING, &output); |
| 3469 CreditCard card; | 3473 CreditCard card; |
| 3470 GetBillingInfoFromOutputs(output, &card, NULL, NULL); | 3474 GetBillingInfoFromOutputs(output, &card, NULL, NULL); |
| 3471 backing_last_four = card.TypeAndLastFourDigits(); | 3475 backing_last_four = card.TypeAndLastFourDigits(); |
| 3472 } | 3476 } |
| 3473 AutofillCreditCardBubbleController::ShowGeneratedCardUI( | 3477 AutofillCreditCardBubbleController::ShowGeneratedCardUI( |
| 3474 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); | 3478 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); |
| 3475 } | 3479 } |
| 3476 | 3480 |
| 3477 } // namespace autofill | 3481 } // namespace autofill |
| OLD | NEW |