Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 // If upload save and more info is needed, push the next view onto the stack. | |
|
csashi
2017/05/18 17:42:25
s/upload save and/user accepted upload but/
Move
Jared Saul
2017/05/18 18:03:07
Done.
| |
| 100 if (controller_->ShouldRequestCvcFromUser() && view_stack_->size() == 1) { | |
|
csashi
2017/05/18 17:42:25
DCHECK_LE(view_stack_->size(), 1)?
When can we be
Jared Saul
2017/05/18 18:03:07
1) Done.
2) If missing CVC but on the second step
csashi
2017/05/18 19:29:48
For (2). If stack_size() > 1, should we DCHECK(con
Jared Saul
2017/05/18 19:51:36
Added check for <= 2 stack size at all times, as w
| |
| 101 view_stack_->Push(CreateRequestCvcView(), /*animate=*/true); | |
| 102 // Disable the Save button until a valid CVC is entered: | |
| 103 GetDialogClientView()->UpdateDialogButtons(); | |
| 104 // Resize the bubble if it's grown larger: | |
| 105 SizeToContents(); | |
| 106 return false; | |
|
csashi
2017/05/18 17:42:25
Do you need to update the documentation for Accept
Jared Saul
2017/05/18 18:03:07
Hmm, I don't think so. The current documentation
| |
| 107 } | |
| 108 // Otherwise, close the bubble as normal. | |
| 101 if (controller_) | 109 if (controller_) |
| 102 controller_->OnSaveButton(cvc_textfield_ ? cvc_textfield_->text() | 110 controller_->OnSaveButton(cvc_textfield_ ? cvc_textfield_->text() |
| 103 : base::string16()); | 111 : base::string16()); |
| 104 return true; | 112 return true; |
| 105 } | 113 } |
| 106 | 114 |
| 107 bool SaveCardBubbleViews::Cancel() { | 115 bool SaveCardBubbleViews::Cancel() { |
| 108 if (controller_) | 116 if (controller_) |
| 109 controller_->OnCancelButton(); | 117 controller_->OnCancelButton(); |
| 110 return true; | 118 return true; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 return; | 182 return; |
| 175 } | 183 } |
| 176 } | 184 } |
| 177 | 185 |
| 178 // |range| was not found. | 186 // |range| was not found. |
| 179 NOTREACHED(); | 187 NOTREACHED(); |
| 180 } | 188 } |
| 181 | 189 |
| 182 // Create view containing everything except for the footnote. | 190 // Create view containing everything except for the footnote. |
| 183 std::unique_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() { | 191 std::unique_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() { |
| 184 std::unique_ptr<View> view(new View()); | 192 std::unique_ptr<View> view(new View()); |
|
csashi
2017/05/18 17:42:25
MakeUnique?
Jared Saul
2017/05/18 18:03:07
Done.
| |
| 193 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); | |
| 185 view->SetLayoutManager( | 194 view->SetLayoutManager( |
| 186 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, | 195 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, |
| 187 views::kUnrelatedControlVerticalSpacing)); | 196 views::kUnrelatedControlVerticalSpacing)); |
| 188 | 197 |
| 189 // Add the card type icon, last four digits and expiration date. | 198 // Add the card type icon, last four digits and expiration date. |
| 190 views::View* description_view = new views::View(); | 199 views::View* description_view = new views::View(); |
| 191 description_view->SetLayoutManager(new views::BoxLayout( | 200 description_view->SetLayoutManager(new views::BoxLayout( |
| 192 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing)); | 201 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing)); |
| 193 view->AddChildView(description_view); | 202 view->AddChildView(description_view); |
| 194 | 203 |
| 195 const CreditCard& card = controller_->GetCard(); | 204 const CreditCard& card = controller_->GetCard(); |
| 196 views::ImageView* card_type_icon = new views::ImageView(); | 205 views::ImageView* card_type_icon = new views::ImageView(); |
| 197 card_type_icon->SetImage( | 206 card_type_icon->SetImage( |
| 198 ResourceBundle::GetSharedInstance() | 207 ResourceBundle::GetSharedInstance() |
| 199 .GetImageNamed(CreditCard::IconResourceId(card.network())) | 208 .GetImageNamed(CreditCard::IconResourceId(card.network())) |
| 200 .AsImageSkia()); | 209 .AsImageSkia()); |
| 201 card_type_icon->SetTooltipText(card.NetworkForDisplay()); | 210 card_type_icon->SetTooltipText(card.NetworkForDisplay()); |
| 202 card_type_icon->SetBorder( | 211 card_type_icon->SetBorder( |
| 203 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); | 212 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); |
| 204 description_view->AddChildView(card_type_icon); | 213 description_view->AddChildView(card_type_icon); |
| 205 | 214 |
| 206 description_view->AddChildView(new views::Label( | 215 description_view->AddChildView(new views::Label( |
| 207 base::string16(kMidlineEllipsis) + card.LastFourDigits())); | 216 base::string16(kMidlineEllipsis) + card.LastFourDigits())); |
| 208 description_view->AddChildView( | 217 description_view->AddChildView( |
| 209 new views::Label(card.AbbreviatedExpirationDateForDisplay())); | 218 new views::Label(card.AbbreviatedExpirationDateForDisplay())); |
| 210 | 219 |
| 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. | 220 // Optionally add label that will contain an explanation for upload. |
| 216 base::string16 explanation = controller_->GetExplanatoryMessage(); | 221 base::string16 explanation = controller_->GetExplanatoryMessage(); |
| 217 if (!explanation.empty()) { | 222 if (!explanation.empty()) { |
| 218 views::Label* explanation_label = new views::Label(explanation); | 223 views::Label* explanation_label = new views::Label(explanation); |
| 219 explanation_label->SetMultiLine(true); | 224 explanation_label->SetMultiLine(true); |
| 220 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 225 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 221 view->AddChildView(explanation_label); | 226 view->AddChildView(explanation_label); |
| 222 } | 227 } |
| 223 | 228 |
| 224 return view; | 229 return view; |
| 225 } | 230 } |
| 226 | 231 |
| 227 std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() { | 232 std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() { |
|
csashi
2017/05/18 17:42:25
Do you want to rename this function? We are return
Jared Saul
2017/05/18 18:03:07
I feel the name is still applicable as it's doing
| |
| 233 std::unique_ptr<View> overall_view = base::MakeUnique<views::View>(); | |
| 234 overall_view->set_background( | |
| 235 views::Background::CreateSolidBackground(SK_ColorWHITE)); | |
|
csashi
2017/05/18 17:42:25
Do you need this? Does the stack not inherit from
Jared Saul
2017/05/18 18:03:07
Without it, it doesn't cover up the item below it
| |
| 236 overall_view->SetLayoutManager( | |
| 237 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, | |
| 238 views::kUnrelatedControlVerticalSpacing)); | |
| 228 std::unique_ptr<View> request_cvc_view = base::MakeUnique<views::View>(); | 239 std::unique_ptr<View> request_cvc_view = base::MakeUnique<views::View>(); |
| 240 request_cvc_view->set_background( | |
| 241 views::Background::CreateSolidBackground(SK_ColorWHITE)); | |
| 229 request_cvc_view->SetLayoutManager(new views::BoxLayout( | 242 request_cvc_view->SetLayoutManager(new views::BoxLayout( |
| 230 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing)); | 243 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing)); |
| 231 | 244 |
| 232 DCHECK(!cvc_textfield_); | 245 DCHECK(!cvc_textfield_); |
| 233 cvc_textfield_ = CreateCvcTextfield(); | 246 cvc_textfield_ = CreateCvcTextfield(); |
| 234 cvc_textfield_->set_controller(this); | 247 cvc_textfield_->set_controller(this); |
| 235 request_cvc_view->AddChildView(cvc_textfield_); | 248 request_cvc_view->AddChildView(cvc_textfield_); |
| 236 | 249 |
| 237 views::ImageView* cvc_image = new views::ImageView(); | 250 views::ImageView* cvc_image = new views::ImageView(); |
| 238 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 251 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 239 cvc_image->SetImage( | 252 cvc_image->SetImage( |
| 240 rb.GetImageSkiaNamed(controller_->GetCvcImageResourceId())); | 253 rb.GetImageSkiaNamed(controller_->GetCvcImageResourceId())); |
| 241 request_cvc_view->AddChildView(cvc_image); | 254 request_cvc_view->AddChildView(cvc_image); |
| 242 | 255 |
| 243 request_cvc_view->AddChildView(new views::Label( | 256 request_cvc_view->AddChildView(new views::Label( |
| 244 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC))); | 257 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC))); |
| 245 return request_cvc_view; | 258 |
| 259 overall_view->AddChildView(request_cvc_view.release()); | |
| 260 return overall_view; | |
| 246 } | 261 } |
| 247 | 262 |
| 248 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const { | 263 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const { |
| 249 if (button == ui::DIALOG_BUTTON_CANCEL) | 264 if (button == ui::DIALOG_BUTTON_CANCEL) |
| 250 return true; | 265 return true; |
| 251 | 266 |
| 252 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button); | 267 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button); |
| 253 return !cvc_textfield_ || | 268 return !cvc_textfield_ || |
| 254 controller_->InputCvcIsValid(cvc_textfield_->text()); | 269 controller_->InputCvcIsValid(cvc_textfield_->text()); |
| 255 } | 270 } |
| 256 | 271 |
| 257 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender, | 272 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender, |
| 258 const base::string16& new_contents) { | 273 const base::string16& new_contents) { |
| 259 DCHECK_EQ(cvc_textfield_, sender); | 274 DCHECK_EQ(cvc_textfield_, sender); |
| 260 GetDialogClientView()->UpdateDialogButtons(); | 275 GetDialogClientView()->UpdateDialogButtons(); |
| 261 } | 276 } |
| 262 | 277 |
| 263 void SaveCardBubbleViews::Init() { | 278 void SaveCardBubbleViews::Init() { |
| 264 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 279 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 265 AddChildView(CreateMainContentView().release()); | 280 view_stack_ = base::MakeUnique<ViewStack>(); |
| 281 view_stack_->set_owned_by_client(); // Required else it'll be deleted twice. | |
| 282 view_stack_->Push(CreateMainContentView(), /*animate=*/false); | |
| 283 AddChildView(view_stack_.get()); | |
| 266 } | 284 } |
| 267 | 285 |
| 268 } // namespace autofill | 286 } // namespace autofill |
| OLD | NEW |