Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2358)

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 14129005: Remove "Use billing for shipping" checkbox in favor of item in suggestions menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bad merge Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a3671c09034e8cb003f9808d4120798efae90374 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.
+ 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.
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_ADD_CREDIT_CARD));
Dan Beam 2013/04/16 03:01:14 ^ hmm, where's IDS_AUTOFILL_DIALOG_MANAGE_CREDIT_C
Evan Stade 2013/04/16 19:06:20 good catch, done.
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()) {
+ 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() &&
Dan Beam 2013/04/16 03:01:14 when is key empty now? why not DCHECK(!key.empty(
Evan Stade 2013/04/16 19:06:20 GetKeyForCheckedItem will return an empty string i
+ key != kAddNewItemKey &&
+ key != kManageItemsKey &&
+ key != kSameAsBillingKey;
Dan Beam 2013/04/16 03:01:14 nit: return !key.empty() && key != kAd
Evan Stade 2013/04/16 19:06:20 that is harsher on my eyes, which have grown accus
}
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_ =

Powered by Google App Engine
This is Rietveld 408576698