Index: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
index c548cbc9e9fe2558f0ec6496502c0e9c68022cf8..b10b7e0bc44c37a6036415d5e688a813a13e0564 100644 |
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
@@ -79,6 +79,10 @@ const bool kPayWithoutWalletDefault = false; |
const int kCartMax = 1850; |
const char kCartCurrency[] = "USD"; |
+const char kAddNewItemKey[] = "add-new-item"; |
+const char kManageItemsKey[] = "manage-items"; |
+const char kSameAsBillingKey[] = "same-as-billing"; |
+ |
// Returns true if |input| should be shown when |field| has been requested. |
bool InputTypeMatchesFieldType(const DetailInput& input, |
const AutofillField& field) { |
@@ -411,11 +415,6 @@ string16 AutofillDialogControllerImpl::EditSuggestionText() const { |
return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EDIT); |
} |
-string16 AutofillDialogControllerImpl::UseBillingForShippingText() const { |
- return l10n_util::GetStringUTF16( |
- IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING); |
-} |
- |
string16 AutofillDialogControllerImpl::CancelButtonText() const { |
return l10n_util::GetStringUTF16(IDS_CANCEL); |
} |
@@ -711,6 +710,7 @@ string16 AutofillDialogControllerImpl::LabelForSection(DialogSection section) |
SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection( |
DialogSection section) { |
return SuggestionState(SuggestionTextForSection(section), |
+ SuggestionTextStyleForSection(section), |
SuggestionIconForSection(section), |
ExtraSuggestionTextForSection(section), |
ExtraSuggestionIconForSection(section), |
@@ -730,7 +730,12 @@ string16 AutofillDialogControllerImpl::SuggestionTextForSection( |
SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
std::string item_key = model->GetItemKeyForCheckedItem(); |
- if (item_key.empty()) |
+ if (item_key == kSameAsBillingKey) { |
+ return l10n_util::GetStringUTF16( |
+ IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING); |
+ } |
+ |
+ if (!IsASuggestionItemKey(item_key)) |
return string16(); |
if (section == SECTION_EMAIL) |
@@ -740,6 +745,16 @@ string16 AutofillDialogControllerImpl::SuggestionTextForSection( |
return wrapper->GetDisplayText(); |
} |
+gfx::Font::FontStyle |
+ AutofillDialogControllerImpl::SuggestionTextStyleForSection( |
+ DialogSection section) const { |
+ const SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
+ if (model->GetItemKeyForCheckedItem() == kSameAsBillingKey) |
+ return gfx::Font::ITALIC; |
+ |
+ return gfx::Font::NORMAL; |
+} |
+ |
string16 AutofillDialogControllerImpl::RequiredActionTextForSection( |
DialogSection section) const { |
if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
@@ -843,7 +858,15 @@ gfx::Image AutofillDialogControllerImpl::ExtraSuggestionIconForSection( |
bool AutofillDialogControllerImpl::EditEnabledForSection( |
DialogSection section) const { |
- return section != SECTION_CC_BILLING || !IsSubmitPausedOn(wallet::VERIFY_CVV); |
+ if (SuggestionsMenuModelForSection(section)->GetItemKeyForCheckedItem() == |
+ kSameAsBillingKey) { |
+ return false; |
+ } |
+ |
+ if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) |
+ return false; |
+ |
+ return true; |
} |
void AutofillDialogControllerImpl::EditClickedForSection( |
@@ -1330,11 +1353,17 @@ void AutofillDialogControllerImpl::Observe( |
// SuggestionsMenuModelDelegate implementation. |
void AutofillDialogControllerImpl::SuggestionItemSelected( |
- const SuggestionsMenuModel& model) { |
- const DialogSection section = SectionForSuggestionsMenuModel(model); |
- EditCancelledForSection(section); |
+ SuggestionsMenuModel* model, |
+ const std::string& item_key) { |
+ if (item_key == kManageItemsKey) { |
+ // TODO(estade): show chrome://settings or a wallet URL. |
Dan Beam
2013/04/17 00:18:16
where's the bug for this and/or why can't we do th
Evan Stade
2013/04/17 21:54:38
don't you think this CL is large enough as it is?
|
+ return; |
+ } |
+ |
+ model->SetCheckedItem(item_key); |
+ EditCancelledForSection(SectionForSuggestionsMenuModel(*model)); |
- LogSuggestionItemSelectedMetric(model); |
+ LogSuggestionItemSelectedMetric(*model); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -1631,6 +1660,10 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() { |
suggested_shipping_.Reset(); |
HidePopup(); |
+ suggested_shipping_.AddKeyedItem( |
+ kSameAsBillingKey, |
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING)); |
+ |
if (IsPayingWithWallet()) { |
// TODO(estade): fill in the email address. |
@@ -1656,9 +1689,14 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() { |
instruments[i]->CardIcon()); |
} |
+ // TODO(estade): this should have a URL sublabel. |
Dan Beam
2013/04/17 00:18:16
what does this mean? that we should be able to lin
Evan Stade
2013/04/17 21:54:38
no. If you look at the mocks, you will see that th
|
suggested_cc_billing_.AddKeyedItem( |
- std::string(), |
+ kAddNewItemKey, |
l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); |
+ suggested_cc_billing_.AddKeyedItem( |
+ kManageItemsKey, |
+ l10n_util::GetStringUTF16( |
+ IDS_AUTOFILL_DIALOG_MANAGE_BILLING_DETAILS)); |
} |
} else { |
PersonalDataManager* manager = GetManager(); |
@@ -1695,19 +1733,34 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() { |
} |
suggested_cc_.AddKeyedItem( |
- std::string(), |
+ kAddNewItemKey, |
l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD)); |
+ suggested_cc_.AddKeyedItem( |
+ kManageItemsKey, |
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_CREDIT_CARD)); |
suggested_billing_.AddKeyedItem( |
- std::string(), |
+ kAddNewItemKey, |
l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_ADDRESS)); |
+ suggested_billing_.AddKeyedItem( |
+ kManageItemsKey, |
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_BILLING_ADDRESS)); |
} |
suggested_email_.AddKeyedItem( |
- std::string(), |
+ kAddNewItemKey, |
l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_EMAIL_ADDRESS)); |
+ if (!IsPayingWithWallet()) { |
Dan Beam
2013/04/17 00:18:16
if we're ever going to add this, add a TODO
Evan Stade
2013/04/17 21:54:38
don't think we are.
|
+ suggested_email_.AddKeyedItem( |
+ kManageItemsKey, |
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_EMAIL_ADDRESS)); |
+ } |
+ |
suggested_shipping_.AddKeyedItem( |
- std::string(), |
+ kAddNewItemKey, |
l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); |
+ suggested_shipping_.AddKeyedItem( |
+ kManageItemsKey, |
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_SHIPPING_ADDRESS)); |
if (view_) |
view_->ModelChanged(); |
@@ -1809,14 +1862,6 @@ void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { |
SuggestionsMenuModel* AutofillDialogControllerImpl:: |
SuggestionsMenuModelForSection(DialogSection section) { |
- const AutofillDialogControllerImpl* const_this = |
- static_cast<const AutofillDialogControllerImpl*>(this); |
- return const_cast<SuggestionsMenuModel*>( |
- const_this->SuggestionsMenuModelForSection(section)); |
-} |
- |
-const SuggestionsMenuModel* AutofillDialogControllerImpl:: |
- SuggestionsMenuModelForSection(DialogSection section) const { |
switch (section) { |
case SECTION_EMAIL: |
return &suggested_email_; |
@@ -1834,6 +1879,12 @@ const SuggestionsMenuModel* AutofillDialogControllerImpl:: |
return NULL; |
} |
+const SuggestionsMenuModel* AutofillDialogControllerImpl:: |
+ SuggestionsMenuModelForSection(DialogSection section) const { |
+ return const_cast<AutofillDialogControllerImpl*>(this)-> |
+ SuggestionsMenuModelForSection(section); |
+} |
+ |
DialogSection AutofillDialogControllerImpl::SectionForSuggestionsMenuModel( |
const SuggestionsMenuModel& model) { |
if (&model == &suggested_email_) |
@@ -1903,7 +1954,15 @@ bool AutofillDialogControllerImpl::IsManuallyEditingSection( |
section_editing_state_.find(section); |
return (it != section_editing_state_.end() && it->second) || |
SuggestionsMenuModelForSection(section)-> |
- GetItemKeyForCheckedItem().empty(); |
+ GetItemKeyForCheckedItem() == kAddNewItemKey; |
+} |
+ |
+bool AutofillDialogControllerImpl::IsASuggestionItemKey( |
+ const std::string& key) { |
+ return !key.empty() && |
+ key != kAddNewItemKey && |
+ key != kManageItemsKey && |
+ key != kSameAsBillingKey; |
} |
bool AutofillDialogControllerImpl::IsManuallyEditingAnySection() const { |
@@ -1933,13 +1992,7 @@ bool AutofillDialogControllerImpl::SectionIsValid( |
} |
bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { |
- // If the user is editing or inputting data, ask the view. |
- if (IsManuallyEditingSection(SECTION_SHIPPING)) |
- return view_->UseBillingForShipping(); |
- |
- // Otherwise, the checkbox should be hidden so its state is irrelevant. |
- // Always use the shipping suggestion model. |
- return false; |
+ return suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; |
} |
bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() { |
@@ -1973,7 +2026,7 @@ void AutofillDialogControllerImpl::SubmitWithWallet() { |
if (!section_editing_state_[SECTION_CC_BILLING]) { |
SuggestionsMenuModel* billing = |
SuggestionsMenuModelForSection(SECTION_CC_BILLING); |
- if (!billing->GetItemKeyForCheckedItem().empty() && |
+ if (IsASuggestionItemKey(billing->GetItemKeyForCheckedItem()) && |
billing->checked_item() < |
static_cast<int>(wallet_items_->instruments().size())) { |
const wallet::WalletItems::MaskedInstrument* active_instrument = |
@@ -1989,7 +2042,7 @@ void AutofillDialogControllerImpl::SubmitWithWallet() { |
if (!section_editing_state_[SECTION_SHIPPING] && active_address_id_.empty()) { |
SuggestionsMenuModel* shipping = |
SuggestionsMenuModelForSection(SECTION_SHIPPING); |
- if (!shipping->GetItemKeyForCheckedItem().empty() && |
+ if (IsASuggestionItemKey(shipping->GetItemKeyForCheckedItem()) && |
shipping->checked_item() < |
static_cast<int>(wallet_items_->addresses().size())) { |
active_address_id_ = |