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 // The main content ViewStack for local save and happy-path upload save should | |
100 // only ever have 1 View on it. Upload save can have a second View if CVC | |
101 // needs to be requested. Assert that the ViewStack has no more than 2 Views | |
102 // and that if it *does* have 2, it's because CVC is being requested. | |
103 DCHECK_LE(view_stack_->size(), 2U); | |
104 DCHECK(view_stack_->size() == 1 || controller_->ShouldRequestCvcFromUser()); | |
105 if (controller_->ShouldRequestCvcFromUser() && view_stack_->size() == 1) { | |
106 // If user accepted upload but more info is needed, push the next view onto | |
107 // the stack. | |
108 view_stack_->Push(CreateRequestCvcView(), /*animate=*/true); | |
109 // Disable the Save button until a valid CVC is entered: | |
110 GetDialogClientView()->UpdateDialogButtons(); | |
111 // Resize the bubble if it's grown larger: | |
112 SizeToContents(); | |
113 return false; | |
114 } | |
115 // Otherwise, close the bubble as normal. | |
101 if (controller_) | 116 if (controller_) |
102 controller_->OnSaveButton(cvc_textfield_ ? cvc_textfield_->text() | 117 controller_->OnSaveButton(cvc_textfield_ ? cvc_textfield_->text() |
103 : base::string16()); | 118 : base::string16()); |
104 return true; | 119 return true; |
105 } | 120 } |
106 | 121 |
107 bool SaveCardBubbleViews::Cancel() { | 122 bool SaveCardBubbleViews::Cancel() { |
108 if (controller_) | 123 if (controller_) |
109 controller_->OnCancelButton(); | 124 controller_->OnCancelButton(); |
110 return true; | 125 return true; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 return; | 189 return; |
175 } | 190 } |
176 } | 191 } |
177 | 192 |
178 // |range| was not found. | 193 // |range| was not found. |
179 NOTREACHED(); | 194 NOTREACHED(); |
180 } | 195 } |
181 | 196 |
182 // Create view containing everything except for the footnote. | 197 // Create view containing everything except for the footnote. |
183 std::unique_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() { | 198 std::unique_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() { |
184 std::unique_ptr<View> view(new View()); | 199 auto view = base::MakeUnique<views::View>(); |
185 view->SetLayoutManager( | 200 view->SetLayoutManager( |
186 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, | 201 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, |
187 views::kUnrelatedControlVerticalSpacing)); | 202 views::kUnrelatedControlVerticalSpacing)); |
188 | 203 |
189 // Add the card type icon, last four digits and expiration date. | 204 // Add the card type icon, last four digits and expiration date. |
190 views::View* description_view = new views::View(); | 205 views::View* description_view = new views::View(); |
191 description_view->SetLayoutManager(new views::BoxLayout( | 206 description_view->SetLayoutManager(new views::BoxLayout( |
192 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing)); | 207 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing)); |
193 view->AddChildView(description_view); | 208 view->AddChildView(description_view); |
194 | 209 |
195 const CreditCard& card = controller_->GetCard(); | 210 const CreditCard& card = controller_->GetCard(); |
196 views::ImageView* card_type_icon = new views::ImageView(); | 211 views::ImageView* card_type_icon = new views::ImageView(); |
197 card_type_icon->SetImage( | 212 card_type_icon->SetImage( |
198 ResourceBundle::GetSharedInstance() | 213 ResourceBundle::GetSharedInstance() |
199 .GetImageNamed(CreditCard::IconResourceId(card.network())) | 214 .GetImageNamed(CreditCard::IconResourceId(card.network())) |
200 .AsImageSkia()); | 215 .AsImageSkia()); |
201 card_type_icon->SetTooltipText(card.NetworkForDisplay()); | 216 card_type_icon->SetTooltipText(card.NetworkForDisplay()); |
202 card_type_icon->SetBorder( | 217 card_type_icon->SetBorder( |
203 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); | 218 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); |
204 description_view->AddChildView(card_type_icon); | 219 description_view->AddChildView(card_type_icon); |
205 | 220 |
206 description_view->AddChildView(new views::Label( | 221 description_view->AddChildView(new views::Label( |
207 base::string16(kMidlineEllipsis) + card.LastFourDigits())); | 222 base::string16(kMidlineEllipsis) + card.LastFourDigits())); |
208 description_view->AddChildView( | 223 description_view->AddChildView( |
209 new views::Label(card.AbbreviatedExpirationDateForDisplay())); | 224 new views::Label(card.AbbreviatedExpirationDateForDisplay())); |
210 | 225 |
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. | 226 // Optionally add label that will contain an explanation for upload. |
216 base::string16 explanation = controller_->GetExplanatoryMessage(); | 227 base::string16 explanation = controller_->GetExplanatoryMessage(); |
217 if (!explanation.empty()) { | 228 if (!explanation.empty()) { |
218 views::Label* explanation_label = new views::Label(explanation); | 229 views::Label* explanation_label = new views::Label(explanation); |
219 explanation_label->SetMultiLine(true); | 230 explanation_label->SetMultiLine(true); |
220 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 231 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
221 view->AddChildView(explanation_label); | 232 view->AddChildView(explanation_label); |
222 } | 233 } |
223 | 234 |
224 return view; | 235 return view; |
225 } | 236 } |
226 | 237 |
227 std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() { | 238 std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() { |
228 std::unique_ptr<View> request_cvc_view = base::MakeUnique<views::View>(); | 239 auto request_cvc_view = base::MakeUnique<views::View>(); |
229 request_cvc_view->SetLayoutManager(new views::BoxLayout( | 240 request_cvc_view->set_background( |
241 views::Background::CreateThemedSolidBackground( | |
242 request_cvc_view.get(), ui::NativeTheme::kColorId_BubbleBackground)); | |
243 request_cvc_view->SetLayoutManager( | |
244 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, | |
245 views::kUnrelatedControlVerticalSpacing)); | |
246 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.
| |
247 inner_request_cvc_view->SetLayoutManager(new views::BoxLayout( | |
230 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing)); | 248 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing)); |
231 | 249 |
232 DCHECK(!cvc_textfield_); | 250 DCHECK(!cvc_textfield_); |
233 cvc_textfield_ = CreateCvcTextfield(); | 251 cvc_textfield_ = CreateCvcTextfield(); |
234 cvc_textfield_->set_controller(this); | 252 cvc_textfield_->set_controller(this); |
235 request_cvc_view->AddChildView(cvc_textfield_); | 253 inner_request_cvc_view->AddChildView(cvc_textfield_); |
236 | 254 |
237 views::ImageView* cvc_image = new views::ImageView(); | 255 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
| |
238 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 256 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
239 cvc_image->SetImage( | 257 cvc_image->SetImage( |
240 rb.GetImageSkiaNamed(controller_->GetCvcImageResourceId())); | 258 rb.GetImageSkiaNamed(controller_->GetCvcImageResourceId())); |
241 request_cvc_view->AddChildView(cvc_image); | 259 inner_request_cvc_view->AddChildView(cvc_image); |
242 | 260 |
243 request_cvc_view->AddChildView(new views::Label( | 261 inner_request_cvc_view->AddChildView(new views::Label( |
244 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC))); | 262 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC))); |
263 | |
264 request_cvc_view->AddChildView(inner_request_cvc_view.release()); | |
245 return request_cvc_view; | 265 return request_cvc_view; |
246 } | 266 } |
247 | 267 |
248 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const { | 268 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const { |
249 if (button == ui::DIALOG_BUTTON_CANCEL) | 269 if (button == ui::DIALOG_BUTTON_CANCEL) |
250 return true; | 270 return true; |
251 | 271 |
252 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button); | 272 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button); |
253 return !cvc_textfield_ || | 273 return !cvc_textfield_ || |
254 controller_->InputCvcIsValid(cvc_textfield_->text()); | 274 controller_->InputCvcIsValid(cvc_textfield_->text()); |
255 } | 275 } |
256 | 276 |
257 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender, | 277 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender, |
258 const base::string16& new_contents) { | 278 const base::string16& new_contents) { |
259 DCHECK_EQ(cvc_textfield_, sender); | 279 DCHECK_EQ(cvc_textfield_, sender); |
260 GetDialogClientView()->UpdateDialogButtons(); | 280 GetDialogClientView()->UpdateDialogButtons(); |
261 } | 281 } |
262 | 282 |
263 void SaveCardBubbleViews::Init() { | 283 void SaveCardBubbleViews::Init() { |
264 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 284 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
265 AddChildView(CreateMainContentView().release()); | 285 view_stack_ = new ViewStack(); |
286 view_stack_->set_background(views::Background::CreateThemedSolidBackground( | |
287 view_stack_, ui::NativeTheme::kColorId_BubbleBackground)); | |
288 view_stack_->Push(CreateMainContentView(), /*animate=*/false); | |
289 AddChildView(view_stack_); | |
266 } | 290 } |
267 | 291 |
268 } // namespace autofill | 292 } // namespace autofill |
OLD | NEW |