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 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 | 1003 |
1004 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( | 1004 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( |
1005 DialogSection section) { | 1005 DialogSection section) { |
1006 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so | 1006 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so |
1007 // get the wrapper before this potentially happens below. | 1007 // get the wrapper before this potentially happens below. |
1008 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 1008 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
1009 | 1009 |
1010 // If the chosen item in |model| yields an empty suggestion text, it is | 1010 // If the chosen item in |model| yields an empty suggestion text, it is |
1011 // invalid. In this case, show the edit UI and highlight invalid fields. | 1011 // invalid. In this case, show the edit UI and highlight invalid fields. |
1012 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 1012 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 1013 string16 unused, unused2; |
1013 if (IsASuggestionItemKey(model->GetItemKeyForCheckedItem()) && | 1014 if (IsASuggestionItemKey(model->GetItemKeyForCheckedItem()) && |
1014 SuggestionTextForSection(section).empty()) { | 1015 !SuggestionTextForSection(section, &unused, &unused2)) { |
1015 SetEditingExistingData(section, true); | 1016 SetEditingExistingData(section, true); |
1016 } | 1017 } |
1017 | 1018 |
1018 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 1019 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
1019 if (wrapper && IsEditingExistingData(section)) | 1020 if (wrapper && IsEditingExistingData(section)) |
1020 wrapper->FillInputs(inputs); | 1021 wrapper->FillInputs(inputs); |
1021 | 1022 |
1022 for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { | 1023 for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { |
1023 it->editable = InputIsEditable(*it, section); | 1024 it->editable = InputIsEditable(*it, section); |
1024 } | 1025 } |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 case SECTION_SHIPPING: | 1230 case SECTION_SHIPPING: |
1230 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); | 1231 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); |
1231 default: | 1232 default: |
1232 NOTREACHED(); | 1233 NOTREACHED(); |
1233 return string16(); | 1234 return string16(); |
1234 } | 1235 } |
1235 } | 1236 } |
1236 | 1237 |
1237 SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection( | 1238 SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection( |
1238 DialogSection section) { | 1239 DialogSection section) { |
1239 return SuggestionState(SuggestionTextForSection(section), | 1240 string16 vertically_compact, horizontally_compact; |
1240 SuggestionTextStyleForSection(section), | 1241 bool show_suggestion = SuggestionTextForSection(section, |
| 1242 &vertically_compact, |
| 1243 &horizontally_compact); |
| 1244 return SuggestionState(show_suggestion, |
| 1245 vertically_compact, |
| 1246 horizontally_compact, |
1241 SuggestionIconForSection(section), | 1247 SuggestionIconForSection(section), |
1242 ExtraSuggestionTextForSection(section), | 1248 ExtraSuggestionTextForSection(section), |
1243 ExtraSuggestionIconForSection(section)); | 1249 ExtraSuggestionIconForSection(section)); |
1244 } | 1250 } |
1245 | 1251 |
1246 string16 AutofillDialogControllerImpl::SuggestionTextForSection( | 1252 bool AutofillDialogControllerImpl::SuggestionTextForSection( |
1247 DialogSection section) { | 1253 DialogSection section, |
1248 string16 action_text = RequiredActionTextForSection(section); | 1254 base::string16* vertically_compact, |
1249 if (!action_text.empty()) | 1255 base::string16* horizontally_compact) { |
1250 return action_text; | 1256 base::string16 action_text = RequiredActionTextForSection(section); |
| 1257 if (!action_text.empty()) { |
| 1258 *vertically_compact = *horizontally_compact = action_text; |
| 1259 return true; |
| 1260 } |
1251 | 1261 |
1252 // When the user has clicked 'edit' or a suggestion is somehow invalid (e.g. a | 1262 // When the user has clicked 'edit' or a suggestion is somehow invalid (e.g. a |
1253 // user selects a credit card that has expired), don't show a suggestion (even | 1263 // user selects a credit card that has expired), don't show a suggestion (even |
1254 // though there is a profile selected in the model). | 1264 // though there is a profile selected in the model). |
1255 if (IsEditingExistingData(section)) | 1265 if (IsEditingExistingData(section)) |
1256 return string16(); | 1266 return false; |
1257 | 1267 |
1258 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 1268 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
1259 std::string item_key = model->GetItemKeyForCheckedItem(); | 1269 std::string item_key = model->GetItemKeyForCheckedItem(); |
1260 if (item_key == kSameAsBillingKey) { | 1270 if (item_key == kSameAsBillingKey) { |
1261 return l10n_util::GetStringUTF16( | 1271 *vertically_compact = *horizontally_compact = l10n_util::GetStringUTF16( |
1262 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING); | 1272 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING); |
| 1273 return true; |
1263 } | 1274 } |
1264 | 1275 |
1265 if (!IsASuggestionItemKey(item_key)) | 1276 if (!IsASuggestionItemKey(item_key)) |
1266 return string16(); | 1277 return false; |
1267 | 1278 |
1268 if (section == SECTION_EMAIL) | 1279 if (section == SECTION_EMAIL) { |
1269 return model->GetLabelAt(model->checked_item()); | 1280 *vertically_compact = *horizontally_compact = |
| 1281 model->GetLabelAt(model->checked_item()); |
| 1282 return true; |
| 1283 } |
1270 | 1284 |
1271 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 1285 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
1272 return wrapper->GetDisplayText(); | 1286 return wrapper->GetDisplayText(vertically_compact, horizontally_compact); |
1273 } | |
1274 | |
1275 gfx::Font::FontStyle | |
1276 AutofillDialogControllerImpl::SuggestionTextStyleForSection( | |
1277 DialogSection section) const { | |
1278 const SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | |
1279 if (model->GetItemKeyForCheckedItem() == kSameAsBillingKey) | |
1280 return gfx::Font::ITALIC; | |
1281 | |
1282 return gfx::Font::NORMAL; | |
1283 } | 1287 } |
1284 | 1288 |
1285 string16 AutofillDialogControllerImpl::RequiredActionTextForSection( | 1289 string16 AutofillDialogControllerImpl::RequiredActionTextForSection( |
1286 DialogSection section) const { | 1290 DialogSection section) const { |
1287 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 1291 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
1288 const wallet::WalletItems::MaskedInstrument* current_instrument = | 1292 const wallet::WalletItems::MaskedInstrument* current_instrument = |
1289 wallet_items_->GetInstrumentById(active_instrument_id_); | 1293 wallet_items_->GetInstrumentById(active_instrument_id_); |
1290 if (current_instrument) | 1294 if (current_instrument) |
1291 return current_instrument->TypeAndLastFourDigits(); | 1295 return current_instrument->TypeAndLastFourDigits(); |
1292 | 1296 |
(...skipping 2163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3456 } | 3460 } |
3457 #if !defined(OS_ANDROID) | 3461 #if !defined(OS_ANDROID) |
3458 GeneratedCreditCardBubbleController::Show( | 3462 GeneratedCreditCardBubbleController::Show( |
3459 web_contents(), | 3463 web_contents(), |
3460 backing_last_four, | 3464 backing_last_four, |
3461 full_wallet_->TypeAndLastFourDigits()); | 3465 full_wallet_->TypeAndLastFourDigits()); |
3462 #endif | 3466 #endif |
3463 } | 3467 } |
3464 | 3468 |
3465 } // namespace autofill | 3469 } // namespace autofill |
OLD | NEW |