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 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); | 200 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); |
186 | 201 |
187 view->SetLayoutManager(new views::BoxLayout( | 202 view->SetLayoutManager(new views::BoxLayout( |
188 views::BoxLayout::kVertical, 0, 0, | 203 views::BoxLayout::kVertical, 0, 0, |
189 provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_VERTICAL))); | 204 provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_VERTICAL))); |
190 | 205 |
191 // Add the card type icon, last four digits and expiration date. | 206 // Add the card type icon, last four digits and expiration date. |
192 views::View* description_view = new views::View(); | 207 views::View* description_view = new views::View(); |
193 description_view->SetLayoutManager(new views::BoxLayout( | 208 description_view->SetLayoutManager(new views::BoxLayout( |
194 views::BoxLayout::kHorizontal, 0, 0, | 209 views::BoxLayout::kHorizontal, 0, 0, |
195 provider->GetDistanceMetric(views::DISTANCE_RELATED_BUTTON_HORIZONTAL))); | 210 provider->GetDistanceMetric(views::DISTANCE_RELATED_BUTTON_HORIZONTAL))); |
196 view->AddChildView(description_view); | 211 view->AddChildView(description_view); |
197 | 212 |
198 const CreditCard& card = controller_->GetCard(); | 213 const CreditCard& card = controller_->GetCard(); |
199 views::ImageView* card_type_icon = new views::ImageView(); | 214 views::ImageView* card_type_icon = new views::ImageView(); |
200 card_type_icon->SetImage( | 215 card_type_icon->SetImage( |
201 ResourceBundle::GetSharedInstance() | 216 ResourceBundle::GetSharedInstance() |
202 .GetImageNamed(CreditCard::IconResourceId(card.network())) | 217 .GetImageNamed(CreditCard::IconResourceId(card.network())) |
203 .AsImageSkia()); | 218 .AsImageSkia()); |
204 card_type_icon->SetTooltipText(card.NetworkForDisplay()); | 219 card_type_icon->SetTooltipText(card.NetworkForDisplay()); |
205 card_type_icon->SetBorder( | 220 card_type_icon->SetBorder( |
206 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); | 221 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); |
207 description_view->AddChildView(card_type_icon); | 222 description_view->AddChildView(card_type_icon); |
208 | 223 |
209 description_view->AddChildView(new views::Label( | 224 description_view->AddChildView(new views::Label( |
210 base::string16(kMidlineEllipsis) + card.LastFourDigits())); | 225 base::string16(kMidlineEllipsis) + card.LastFourDigits())); |
211 description_view->AddChildView( | 226 description_view->AddChildView( |
212 new views::Label(card.AbbreviatedExpirationDateForDisplay())); | 227 new views::Label(card.AbbreviatedExpirationDateForDisplay())); |
213 | 228 |
214 // Optionally add CVC request field if CVC was missing. | |
215 if (controller_->ShouldRequestCvcFromUser()) | |
216 view->AddChildView(CreateRequestCvcView().release()); | |
217 | |
218 // Optionally add label that will contain an explanation for upload. | 229 // Optionally add label that will contain an explanation for upload. |
219 base::string16 explanation = controller_->GetExplanatoryMessage(); | 230 base::string16 explanation = controller_->GetExplanatoryMessage(); |
220 if (!explanation.empty()) { | 231 if (!explanation.empty()) { |
221 views::Label* explanation_label = new views::Label(explanation); | 232 views::Label* explanation_label = new views::Label(explanation); |
222 explanation_label->SetMultiLine(true); | 233 explanation_label->SetMultiLine(true); |
223 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 234 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
224 view->AddChildView(explanation_label); | 235 view->AddChildView(explanation_label); |
225 } | 236 } |
226 | 237 |
227 return view; | 238 return view; |
228 } | 239 } |
229 | 240 |
230 std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() { | 241 std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() { |
231 std::unique_ptr<View> request_cvc_view = base::MakeUnique<views::View>(); | 242 auto request_cvc_view = base::MakeUnique<views::View>(); |
232 request_cvc_view->SetLayoutManager( | 243 request_cvc_view->set_background( |
| 244 views::Background::CreateThemedSolidBackground( |
| 245 request_cvc_view.get(), ui::NativeTheme::kColorId_BubbleBackground)); |
| 246 views::BoxLayout* layout = |
233 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, | 247 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, |
234 ChromeLayoutProvider::Get()->GetDistanceMetric( | 248 ChromeLayoutProvider::Get()->GetDistanceMetric( |
235 views::DISTANCE_RELATED_BUTTON_HORIZONTAL))); | 249 views::DISTANCE_RELATED_BUTTON_HORIZONTAL)); |
| 250 layout->set_cross_axis_alignment( |
| 251 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
| 252 request_cvc_view->SetLayoutManager(layout); |
236 | 253 |
237 DCHECK(!cvc_textfield_); | 254 DCHECK(!cvc_textfield_); |
238 cvc_textfield_ = CreateCvcTextfield(); | 255 cvc_textfield_ = CreateCvcTextfield(); |
239 cvc_textfield_->set_controller(this); | 256 cvc_textfield_->set_controller(this); |
240 request_cvc_view->AddChildView(cvc_textfield_); | 257 request_cvc_view->AddChildView(cvc_textfield_); |
241 | 258 |
242 views::ImageView* cvc_image = new views::ImageView(); | 259 views::ImageView* cvc_image = new views::ImageView(); |
243 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 260 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
244 cvc_image->SetImage( | 261 cvc_image->SetImage( |
245 rb.GetImageSkiaNamed(controller_->GetCvcImageResourceId())); | 262 rb.GetImageSkiaNamed(controller_->GetCvcImageResourceId())); |
246 request_cvc_view->AddChildView(cvc_image); | 263 request_cvc_view->AddChildView(cvc_image); |
247 | 264 |
248 request_cvc_view->AddChildView(new views::Label( | 265 request_cvc_view->AddChildView(new views::Label( |
249 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC))); | 266 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC))); |
| 267 |
250 return request_cvc_view; | 268 return request_cvc_view; |
251 } | 269 } |
252 | 270 |
253 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const { | 271 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const { |
254 if (button == ui::DIALOG_BUTTON_CANCEL) | 272 if (button == ui::DIALOG_BUTTON_CANCEL) |
255 return true; | 273 return true; |
256 | 274 |
257 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button); | 275 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button); |
258 return !cvc_textfield_ || | 276 return !cvc_textfield_ || |
259 controller_->InputCvcIsValid(cvc_textfield_->text()); | 277 controller_->InputCvcIsValid(cvc_textfield_->text()); |
260 } | 278 } |
261 | 279 |
262 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender, | 280 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender, |
263 const base::string16& new_contents) { | 281 const base::string16& new_contents) { |
264 DCHECK_EQ(cvc_textfield_, sender); | 282 DCHECK_EQ(cvc_textfield_, sender); |
265 GetDialogClientView()->UpdateDialogButtons(); | 283 GetDialogClientView()->UpdateDialogButtons(); |
266 } | 284 } |
267 | 285 |
268 void SaveCardBubbleViews::Init() { | 286 void SaveCardBubbleViews::Init() { |
269 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 287 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
270 AddChildView(CreateMainContentView().release()); | 288 view_stack_ = new ViewStack(); |
| 289 view_stack_->set_background(views::Background::CreateThemedSolidBackground( |
| 290 view_stack_, ui::NativeTheme::kColorId_BubbleBackground)); |
| 291 view_stack_->Push(CreateMainContentView(), /*animate=*/false); |
| 292 AddChildView(view_stack_); |
271 } | 293 } |
272 | 294 |
273 } // namespace autofill | 295 } // namespace autofill |
OLD | NEW |