Index: chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc |
diff --git a/chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc b/chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc |
index 1d9f307a1688c879005be781a31ea7817e42c97c..23027d43beb4a29895187bc2169f154db08cd43a 100644 |
--- a/chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc |
+++ b/chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc |
@@ -27,6 +27,7 @@ |
#include "ui/views/controls/combobox/combobox.h" |
#include "ui/views/controls/image_view.h" |
#include "ui/views/controls/label.h" |
+#include "ui/views/controls/link.h" |
#include "ui/views/controls/throbber.h" |
#include "ui/views/layout/box_layout.h" |
#include "ui/views/widget/widget.h" |
@@ -57,6 +58,7 @@ CardUnmaskPromptViews::CardUnmaskPromptViews( |
cvc_input_(nullptr), |
month_input_(nullptr), |
year_input_(nullptr), |
+ new_card_link_(nullptr), |
error_icon_(nullptr), |
error_label_(nullptr), |
storage_row_(nullptr), |
@@ -116,11 +118,16 @@ void CardUnmaskPromptViews::GotVerificationResult( |
if (allow_retry) { |
SetInputsEnabled(true); |
- // If there is more than one input showing, don't mark anything as |
- // invalid since we don't know the location of the problem. |
- if (!controller_->ShouldRequestExpirationDate()) |
+ if (!controller_->ShouldRequestExpirationDate()) { |
+ // If there is more than one input showing, don't mark anything as |
+ // invalid since we don't know the location of the problem. |
cvc_input_->SetInvalid(true); |
+ // Show a "New card?" link, which when clicked will cause us to ask |
+ // for expiration date. |
+ ShowNewCardLink(); |
+ } |
+ |
// TODO(estade): When do we hide |error_label_|? |
SetRetriableErrorMessage(error_message); |
} else { |
@@ -134,6 +141,21 @@ void CardUnmaskPromptViews::GotVerificationResult( |
Layout(); |
} |
+void CardUnmaskPromptViews::LinkClicked(views::Link* source, int event_flags) { |
+ DCHECK_EQ(source, new_card_link_); |
+ controller_->NewCardLinkClicked(); |
+ for (int i = 0; i < input_row_->child_count(); ++i) { |
sky
2015/05/14 22:05:59
nit: no {}
Evan Stade
2015/05/14 22:38:22
Done.
|
+ input_row_->child_at(i)->SetVisible(true); |
+ } |
+ new_card_link_->SetVisible(false); |
+ input_row_->InvalidateLayout(); |
sky
2015/05/14 22:05:59
I don't see an explicit layout anywhere. Who trigg
Evan Stade
2015/05/14 22:38:22
see ^ below
|
+ cvc_input_->SetInvalid(false); |
+ cvc_input_->SetText(base::string16()); |
+ GetDialogClientView()->UpdateDialogButtons(); |
+ GetWidget()->UpdateWindowTitle(); |
+ SetRetriableErrorMessage(base::string16()); |
+} |
+ |
void CardUnmaskPromptViews::SetRetriableErrorMessage( |
const base::string16& message) { |
if (message.empty()) { |
@@ -162,10 +184,17 @@ void CardUnmaskPromptViews::SetInputsEnabled(bool enabled) { |
cvc_input_->SetEnabled(enabled); |
if (storage_checkbox_) |
storage_checkbox_->SetEnabled(enabled); |
- if (month_input_) |
- month_input_->SetEnabled(enabled); |
- if (year_input_) |
- year_input_->SetEnabled(enabled); |
+ month_input_->SetEnabled(enabled); |
+ year_input_->SetEnabled(enabled); |
+} |
+ |
+void CardUnmaskPromptViews::ShowNewCardLink() { |
+ new_card_link_ = new views::Link( |
sky
2015/05/14 22:05:59
I assume you can never hit this more than once, ri
Evan Stade
2015/05/14 22:38:23
Yes, that's the case, but it is still a pretty fra
|
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_NEW_CARD_LINK)); |
+ new_card_link_->SetBorder(views::Border::CreateEmptyBorder(0, 7, 0, 0)); |
+ new_card_link_->SetUnderline(false); |
+ new_card_link_->set_listener(this); |
+ input_row_->AddChildView(new_card_link_); |
} |
views::View* CardUnmaskPromptViews::GetContentsView() { |
@@ -290,10 +319,12 @@ bool CardUnmaskPromptViews::Accept() { |
controller_->OnUnmaskResponse( |
cvc_input_->text(), |
- month_input_ ? month_input_->GetTextForRow(month_input_->selected_index()) |
- : base::string16(), |
- year_input_ ? year_input_->GetTextForRow(year_input_->selected_index()) |
- : base::string16(), |
+ month_input_->visible() |
+ ? month_input_->GetTextForRow(month_input_->selected_index()) |
+ : base::string16(), |
+ year_input_->visible() |
+ ? year_input_->GetTextForRow(year_input_->selected_index()) |
+ : base::string16(), |
storage_checkbox_ ? storage_checkbox_->checked() : false); |
return false; |
} |
@@ -377,18 +408,22 @@ void CardUnmaskPromptViews::InitIfNecessary() { |
new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5)); |
controls_container->AddChildView(input_row_); |
- if (controller_->ShouldRequestExpirationDate()) { |
- month_input_ = new views::Combobox(&month_combobox_model_); |
- month_input_->set_listener(this); |
- input_row_->AddChildView(month_input_); |
- views::Label* separator = new views::Label(l10n_util::GetStringUTF16( |
- IDS_AUTOFILL_CARD_UNMASK_EXPIRATION_DATE_SEPARATOR)); |
- separator->SetEnabledColor(kGreyTextColor); |
- input_row_->AddChildView(separator); |
- year_input_ = new views::Combobox(&year_combobox_model_); |
- year_input_->set_listener(this); |
- input_row_->AddChildView(year_input_); |
- input_row_->AddChildView(new views::Label(base::ASCIIToUTF16(" "))); |
+ month_input_ = new views::Combobox(&month_combobox_model_); |
+ month_input_->set_listener(this); |
+ input_row_->AddChildView(month_input_); |
+ views::Label* separator = new views::Label(l10n_util::GetStringUTF16( |
+ IDS_AUTOFILL_CARD_UNMASK_EXPIRATION_DATE_SEPARATOR)); |
+ separator->SetEnabledColor(kGreyTextColor); |
+ input_row_->AddChildView(separator); |
+ year_input_ = new views::Combobox(&year_combobox_model_); |
+ year_input_->set_listener(this); |
+ input_row_->AddChildView(year_input_); |
+ input_row_->AddChildView(new views::Label(base::ASCIIToUTF16(" "))); |
+ // Hide all of the above as appropriate. |
+ if (!controller_->ShouldRequestExpirationDate()) { |
+ for (int i = 0; i < input_row_->child_count(); ++i) { |
sky
2015/05/14 22:05:59
nit: no {}
Evan Stade
2015/05/14 22:38:22
Done.
|
+ input_row_->child_at(i)->SetVisible(false); |
+ } |
} |
cvc_input_ = new DecoratedTextfield( |