| 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 470ed592422b101c95b04f39881bd880615ef62e..7419be14eaab801dad380865f4ceae7b02f5a31a 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) {
|
| @@ -409,11 +413,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(
|
| @@ -1327,9 +1350,15 @@ 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));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -1625,6 +1654,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.
|
|
|
| @@ -1650,9 +1683,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();
|
| @@ -1689,19 +1727,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));
|
| 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();
|
| @@ -1820,6 +1873,12 @@ 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_)
|
| @@ -1886,17 +1945,19 @@ bool AutofillDialogControllerImpl::IsManuallyEditingSection(
|
| DialogSection section) {
|
| return section_editing_state_[section] ||
|
| SuggestionsMenuModelForSection(section)->
|
| - GetItemKeyForCheckedItem().empty();
|
| + GetItemKeyForCheckedItem() == kAddNewItemKey;
|
| }
|
|
|
| -bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() {
|
| - // If the user is editing or inputting data, ask the view.
|
| - if (IsManuallyEditingSection(SECTION_SHIPPING))
|
| - return view_->UseBillingForShipping();
|
| +bool AutofillDialogControllerImpl::IsASuggestionItemKey(
|
| + const std::string& key) {
|
| + return !key.empty() &&
|
| + key != kAddNewItemKey &&
|
| + key != kManageItemsKey &&
|
| + key != kSameAsBillingKey;
|
| +}
|
|
|
| - // Otherwise, the checkbox should be hidden so its state is irrelevant.
|
| - // Always use the shipping suggestion model.
|
| - return false;
|
| +bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() {
|
| + return suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey;
|
| }
|
|
|
| bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() {
|
| @@ -1928,7 +1989,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 =
|
| @@ -1944,7 +2005,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_ =
|
|
|