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