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

Unified Diff: chrome/browser/ui/views/autofill/save_card_bubble_views.cc

Issue 2883273005: Use ViewStack to convert card upload request CVC experiment to 2-step flow (Closed)
Patch Set: Addressing code review comments Created 3 years, 7 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
« no previous file with comments | « chrome/browser/ui/views/autofill/save_card_bubble_views.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/autofill/save_card_bubble_views.cc
diff --git a/chrome/browser/ui/views/autofill/save_card_bubble_views.cc b/chrome/browser/ui/views/autofill/save_card_bubble_views.cc
index 56b4018f702a2f715a871771167ce74207939e36..c17f9041f331c03af36a4d1ec77eae2f15eb954b 100644
--- a/chrome/browser/ui/views/autofill/save_card_bubble_views.cc
+++ b/chrome/browser/ui/views/autofill/save_card_bubble_views.cc
@@ -54,9 +54,7 @@ SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view,
content::WebContents* web_contents,
SaveCardBubbleController* controller)
: LocationBarBubbleDelegateView(anchor_view, web_contents),
- controller_(controller),
- cvc_textfield_(nullptr),
- learn_more_link_(nullptr) {
+ controller_(controller) {
DCHECK(controller);
views::BubbleDialogDelegateView::CreateBubble(this);
chrome::RecordDialogCreation(chrome::DialogIdentifier::SAVE_CARD);
@@ -98,6 +96,23 @@ views::View* SaveCardBubbleViews::CreateFootnoteView() {
}
bool SaveCardBubbleViews::Accept() {
+ // The main content ViewStack for local save and happy-path upload save should
+ // only ever have 1 View on it. Upload save can have a second View if CVC
+ // needs to be requested. Assert that the ViewStack has no more than 2 Views
+ // and that if it *does* have 2, it's because CVC is being requested.
+ DCHECK_LE(view_stack_->size(), 2U);
+ DCHECK(view_stack_->size() == 1 || controller_->ShouldRequestCvcFromUser());
+ if (controller_->ShouldRequestCvcFromUser() && view_stack_->size() == 1) {
+ // If user accepted upload but more info is needed, push the next view onto
+ // the stack.
+ view_stack_->Push(CreateRequestCvcView(), /*animate=*/true);
+ // Disable the Save button until a valid CVC is entered:
+ GetDialogClientView()->UpdateDialogButtons();
+ // Resize the bubble if it's grown larger:
+ SizeToContents();
+ return false;
+ }
+ // Otherwise, close the bubble as normal.
if (controller_)
controller_->OnSaveButton(cvc_textfield_ ? cvc_textfield_->text()
: base::string16());
@@ -181,7 +196,7 @@ void SaveCardBubbleViews::StyledLabelLinkClicked(views::StyledLabel* label,
// Create view containing everything except for the footnote.
std::unique_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() {
- std::unique_ptr<View> view(new View());
+ auto view = base::MakeUnique<views::View>();
view->SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kVertical, 0, 0,
views::kUnrelatedControlVerticalSpacing));
@@ -208,10 +223,6 @@ std::unique_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() {
description_view->AddChildView(
new views::Label(card.AbbreviatedExpirationDateForDisplay()));
- // Optionally add CVC request field if CVC was missing.
- if (controller_->ShouldRequestCvcFromUser())
- view->AddChildView(CreateRequestCvcView().release());
-
// Optionally add label that will contain an explanation for upload.
base::string16 explanation = controller_->GetExplanatoryMessage();
if (!explanation.empty()) {
@@ -225,23 +236,32 @@ std::unique_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() {
}
std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() {
- std::unique_ptr<View> request_cvc_view = base::MakeUnique<views::View>();
- request_cvc_view->SetLayoutManager(new views::BoxLayout(
+ auto request_cvc_view = base::MakeUnique<views::View>();
+ request_cvc_view->set_background(
+ views::Background::CreateThemedSolidBackground(
+ request_cvc_view.get(), ui::NativeTheme::kColorId_BubbleBackground));
+ request_cvc_view->SetLayoutManager(
+ new views::BoxLayout(views::BoxLayout::kVertical, 0, 0,
+ views::kUnrelatedControlVerticalSpacing));
+ auto inner_request_cvc_view = base::MakeUnique<views::View>();
Evan Stade 2017/05/23 23:21:08 can you explain why you need this inner view? It l
Jared Saul 2017/05/23 23:57:50 Yep, added a comment. The reason is because if on
Evan Stade 2017/05/24 00:20:06 It sounds like you just need to use a different Bo
Jared Saul 2017/05/24 00:45:23 Thanks! That kept it from stretching.
+ inner_request_cvc_view->SetLayoutManager(new views::BoxLayout(
views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing));
DCHECK(!cvc_textfield_);
cvc_textfield_ = CreateCvcTextfield();
cvc_textfield_->set_controller(this);
- request_cvc_view->AddChildView(cvc_textfield_);
+ inner_request_cvc_view->AddChildView(cvc_textfield_);
views::ImageView* cvc_image = new views::ImageView();
Evan Stade 2017/05/23 23:21:08 this is inconsistent with the smart pointer for in
Jared Saul 2017/05/23 23:57:50 +1 for consistency, but can you elaborate on what
Evan Stade 2017/05/24 00:20:06 yes, this is my preference. Thanks.
Jared Saul 2017/05/24 00:45:24 Acknowledged (inner_request_cvc_view went away any
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
cvc_image->SetImage(
rb.GetImageSkiaNamed(controller_->GetCvcImageResourceId()));
- request_cvc_view->AddChildView(cvc_image);
+ inner_request_cvc_view->AddChildView(cvc_image);
- request_cvc_view->AddChildView(new views::Label(
+ inner_request_cvc_view->AddChildView(new views::Label(
l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC)));
+
+ request_cvc_view->AddChildView(inner_request_cvc_view.release());
return request_cvc_view;
}
@@ -262,7 +282,11 @@ void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender,
void SaveCardBubbleViews::Init() {
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
- AddChildView(CreateMainContentView().release());
+ view_stack_ = new ViewStack();
+ view_stack_->set_background(views::Background::CreateThemedSolidBackground(
+ view_stack_, ui::NativeTheme::kColorId_BubbleBackground));
+ view_stack_->Push(CreateMainContentView(), /*animate=*/false);
+ AddChildView(view_stack_);
}
} // namespace autofill
« no previous file with comments | « chrome/browser/ui/views/autofill/save_card_bubble_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698