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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/autofill/save_card_bubble_views.h" 5 #include "chrome/browser/ui/views/autofill/save_card_bubble_views.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 return label; 48 return label;
49 } 49 }
50 50
51 } // namespace 51 } // namespace
52 52
53 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, 53 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view,
54 content::WebContents* web_contents, 54 content::WebContents* web_contents,
55 SaveCardBubbleController* controller) 55 SaveCardBubbleController* controller)
56 : LocationBarBubbleDelegateView(anchor_view, web_contents), 56 : LocationBarBubbleDelegateView(anchor_view, web_contents),
57 controller_(controller), 57 controller_(controller) {
58 cvc_textfield_(nullptr),
59 learn_more_link_(nullptr) {
60 DCHECK(controller); 58 DCHECK(controller);
61 views::BubbleDialogDelegateView::CreateBubble(this); 59 views::BubbleDialogDelegateView::CreateBubble(this);
62 chrome::RecordDialogCreation(chrome::DialogIdentifier::SAVE_CARD); 60 chrome::RecordDialogCreation(chrome::DialogIdentifier::SAVE_CARD);
63 } 61 }
64 62
65 SaveCardBubbleViews::~SaveCardBubbleViews() {} 63 SaveCardBubbleViews::~SaveCardBubbleViews() {}
66 64
67 void SaveCardBubbleViews::Show(DisplayReason reason) { 65 void SaveCardBubbleViews::Show(DisplayReason reason) {
68 ShowForReason(reason); 66 ShowForReason(reason);
69 } 67 }
(...skipping 21 matching lines...) Expand all
91 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 89 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
92 90
93 // Add a StyledLabel for each line of the legal message. 91 // Add a StyledLabel for each line of the legal message.
94 for (const LegalMessageLine& line : controller_->GetLegalMessageLines()) 92 for (const LegalMessageLine& line : controller_->GetLegalMessageLines())
95 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); 93 view->AddChildView(CreateLegalMessageLineLabel(line, this).release());
96 94
97 return view; 95 return view;
98 } 96 }
99 97
100 bool SaveCardBubbleViews::Accept() { 98 bool SaveCardBubbleViews::Accept() {
99 CHECK_LE(view_stack_->size(), static_cast<size_t>(2));
Evan Stade 2017/05/19 19:01:28 nit: 2U rather than casting
Evan Stade 2017/05/19 19:01:29 nit: make these DCHECKs
Jared Saul 2017/05/19 19:20:55 Done.
Jared Saul 2017/05/19 19:20:55 Done.
100 CHECK(view_stack_->size() == 1 || controller_->ShouldRequestCvcFromUser());
Evan Stade 2017/05/19 19:01:29 I don't think this check is super self-explanatory
Jared Saul 2017/05/19 19:20:55 Done; how's this?
101 if (controller_->ShouldRequestCvcFromUser() && view_stack_->size() == 1) {
102 // If user accepted upload but more info is needed, push the next view onto
103 // the stack.
104 view_stack_->Push(CreateRequestCvcView(), /*animate=*/true);
105 // Disable the Save button until a valid CVC is entered:
106 GetDialogClientView()->UpdateDialogButtons();
107 // Resize the bubble if it's grown larger:
108 SizeToContents();
109 return false;
110 }
111 // Otherwise, close the bubble as normal.
101 if (controller_) 112 if (controller_)
102 controller_->OnSaveButton(cvc_textfield_ ? cvc_textfield_->text() 113 controller_->OnSaveButton(cvc_textfield_ ? cvc_textfield_->text()
103 : base::string16()); 114 : base::string16());
104 return true; 115 return true;
105 } 116 }
106 117
107 bool SaveCardBubbleViews::Cancel() { 118 bool SaveCardBubbleViews::Cancel() {
108 if (controller_) 119 if (controller_)
109 controller_->OnCancelButton(); 120 controller_->OnCancelButton();
110 return true; 121 return true;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 return; 185 return;
175 } 186 }
176 } 187 }
177 188
178 // |range| was not found. 189 // |range| was not found.
179 NOTREACHED(); 190 NOTREACHED();
180 } 191 }
181 192
182 // Create view containing everything except for the footnote. 193 // Create view containing everything except for the footnote.
183 std::unique_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() { 194 std::unique_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() {
184 std::unique_ptr<View> view(new View()); 195 std::unique_ptr<View> view = base::MakeUnique<views::View>();
Evan Stade 2017/05/19 22:18:16 nit: great place to use auto
Jared Saul 2017/05/23 18:53:02 Done; replaced the other two "std::unique_ptr<View
196 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE));
185 view->SetLayoutManager( 197 view->SetLayoutManager(
186 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 198 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0,
187 views::kUnrelatedControlVerticalSpacing)); 199 views::kUnrelatedControlVerticalSpacing));
188 200
189 // Add the card type icon, last four digits and expiration date. 201 // Add the card type icon, last four digits and expiration date.
190 views::View* description_view = new views::View(); 202 views::View* description_view = new views::View();
191 description_view->SetLayoutManager(new views::BoxLayout( 203 description_view->SetLayoutManager(new views::BoxLayout(
192 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing)); 204 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing));
193 view->AddChildView(description_view); 205 view->AddChildView(description_view);
194 206
195 const CreditCard& card = controller_->GetCard(); 207 const CreditCard& card = controller_->GetCard();
196 views::ImageView* card_type_icon = new views::ImageView(); 208 views::ImageView* card_type_icon = new views::ImageView();
197 card_type_icon->SetImage( 209 card_type_icon->SetImage(
198 ResourceBundle::GetSharedInstance() 210 ResourceBundle::GetSharedInstance()
199 .GetImageNamed(CreditCard::IconResourceId(card.network())) 211 .GetImageNamed(CreditCard::IconResourceId(card.network()))
200 .AsImageSkia()); 212 .AsImageSkia());
201 card_type_icon->SetTooltipText(card.NetworkForDisplay()); 213 card_type_icon->SetTooltipText(card.NetworkForDisplay());
202 card_type_icon->SetBorder( 214 card_type_icon->SetBorder(
203 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); 215 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10)));
204 description_view->AddChildView(card_type_icon); 216 description_view->AddChildView(card_type_icon);
205 217
206 description_view->AddChildView(new views::Label( 218 description_view->AddChildView(new views::Label(
207 base::string16(kMidlineEllipsis) + card.LastFourDigits())); 219 base::string16(kMidlineEllipsis) + card.LastFourDigits()));
208 description_view->AddChildView( 220 description_view->AddChildView(
209 new views::Label(card.AbbreviatedExpirationDateForDisplay())); 221 new views::Label(card.AbbreviatedExpirationDateForDisplay()));
210 222
211 // Optionally add CVC request field if CVC was missing.
212 if (controller_->ShouldRequestCvcFromUser())
213 view->AddChildView(CreateRequestCvcView().release());
214
215 // Optionally add label that will contain an explanation for upload. 223 // Optionally add label that will contain an explanation for upload.
216 base::string16 explanation = controller_->GetExplanatoryMessage(); 224 base::string16 explanation = controller_->GetExplanatoryMessage();
217 if (!explanation.empty()) { 225 if (!explanation.empty()) {
218 views::Label* explanation_label = new views::Label(explanation); 226 views::Label* explanation_label = new views::Label(explanation);
219 explanation_label->SetMultiLine(true); 227 explanation_label->SetMultiLine(true);
220 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 228 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
221 view->AddChildView(explanation_label); 229 view->AddChildView(explanation_label);
222 } 230 }
223 231
224 return view; 232 return view;
225 } 233 }
226 234
227 std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() { 235 std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() {
228 std::unique_ptr<View> request_cvc_view = base::MakeUnique<views::View>(); 236 std::unique_ptr<View> request_cvc_view = base::MakeUnique<views::View>();
229 request_cvc_view->SetLayoutManager(new views::BoxLayout( 237 request_cvc_view->set_background(
238 views::Background::CreateSolidBackground(SK_ColorWHITE));
Evan Stade 2017/05/19 19:01:28 Why do you need to set this color? Why aren't we g
Jared Saul 2017/05/19 19:20:55 It's a limitation of ViewStack, see mathp@/anthony
Evan Stade 2017/05/19 22:18:17 What you need both here and there is CreateThemedS
Jared Saul 2017/05/23 18:53:03 Thanks for the tip; that worked! I also did have
239 request_cvc_view->SetLayoutManager(
240 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0,
241 views::kUnrelatedControlVerticalSpacing));
242 std::unique_ptr<View> inner_request_cvc_view =
243 base::MakeUnique<views::View>();
244 inner_request_cvc_view->set_background(
245 views::Background::CreateSolidBackground(SK_ColorWHITE));
246 inner_request_cvc_view->SetLayoutManager(new views::BoxLayout(
230 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing)); 247 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing));
231 248
232 DCHECK(!cvc_textfield_); 249 DCHECK(!cvc_textfield_);
233 cvc_textfield_ = CreateCvcTextfield(); 250 cvc_textfield_ = CreateCvcTextfield();
234 cvc_textfield_->set_controller(this); 251 cvc_textfield_->set_controller(this);
235 request_cvc_view->AddChildView(cvc_textfield_); 252 inner_request_cvc_view->AddChildView(cvc_textfield_);
236 253
237 views::ImageView* cvc_image = new views::ImageView(); 254 views::ImageView* cvc_image = new views::ImageView();
238 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 255 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
239 cvc_image->SetImage( 256 cvc_image->SetImage(
240 rb.GetImageSkiaNamed(controller_->GetCvcImageResourceId())); 257 rb.GetImageSkiaNamed(controller_->GetCvcImageResourceId()));
241 request_cvc_view->AddChildView(cvc_image); 258 inner_request_cvc_view->AddChildView(cvc_image);
242 259
243 request_cvc_view->AddChildView(new views::Label( 260 inner_request_cvc_view->AddChildView(new views::Label(
244 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC))); 261 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC)));
262
263 request_cvc_view->AddChildView(inner_request_cvc_view.release());
245 return request_cvc_view; 264 return request_cvc_view;
246 } 265 }
247 266
248 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const { 267 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const {
249 if (button == ui::DIALOG_BUTTON_CANCEL) 268 if (button == ui::DIALOG_BUTTON_CANCEL)
250 return true; 269 return true;
251 270
252 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button); 271 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button);
253 return !cvc_textfield_ || 272 return !cvc_textfield_ ||
254 controller_->InputCvcIsValid(cvc_textfield_->text()); 273 controller_->InputCvcIsValid(cvc_textfield_->text());
255 } 274 }
256 275
257 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender, 276 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender,
258 const base::string16& new_contents) { 277 const base::string16& new_contents) {
259 DCHECK_EQ(cvc_textfield_, sender); 278 DCHECK_EQ(cvc_textfield_, sender);
260 GetDialogClientView()->UpdateDialogButtons(); 279 GetDialogClientView()->UpdateDialogButtons();
261 } 280 }
262 281
263 void SaveCardBubbleViews::Init() { 282 void SaveCardBubbleViews::Init() {
264 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 283 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
265 AddChildView(CreateMainContentView().release()); 284 view_stack_ = base::MakeUnique<ViewStack>();
285 view_stack_->set_owned_by_client(); // Required else it'll be deleted twice.
Evan Stade 2017/05/19 19:01:28 are you sure this is required? Why not make view_s
Jared Saul 2017/05/19 19:20:55 See comment thread: https://codereview.chromium.or
Evan Stade 2017/05/19 22:18:17 I don't understand how making this a raw pointer n
Jared Saul 2017/05/23 18:53:03 Ah, you're right. I believe those problems stemme
286 view_stack_->Push(CreateMainContentView(), /*animate=*/false);
287 AddChildView(view_stack_.get());
266 } 288 }
267 289
268 } // namespace autofill 290 } // namespace autofill
OLDNEW
« 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