Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/card_unmask_prompt_views.h" | 5 #include "chrome/browser/ui/views/autofill/card_unmask_prompt_views.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" | 9 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" |
| 10 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" | 10 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" |
| 11 #include "chrome/browser/ui/views/autofill/decorated_textfield.h" | 11 #include "chrome/browser/ui/views/autofill/decorated_textfield.h" |
| 12 #include "chrome/browser/ui/views/autofill/tooltip_icon.h" | 12 #include "chrome/browser/ui/views/autofill/tooltip_icon.h" |
| 13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
| 14 #include "components/constrained_window/constrained_window_views.h" | 14 #include "components/constrained_window/constrained_window_views.h" |
| 15 #include "components/web_modal/web_contents_modal_dialog_host.h" | 15 #include "components/web_modal/web_contents_modal_dialog_host.h" |
| 16 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 16 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 17 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 17 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
| 18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 19 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/compositor/compositing_recorder.h" | 22 #include "ui/compositor/compositing_recorder.h" |
| 23 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
| 24 #include "ui/gfx/geometry/safe_integer_conversions.h" | 24 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 25 #include "ui/views/background.h" | 25 #include "ui/views/background.h" |
| 26 #include "ui/views/controls/button/checkbox.h" | 26 #include "ui/views/controls/button/checkbox.h" |
| 27 #include "ui/views/controls/combobox/combobox.h" | 27 #include "ui/views/controls/combobox/combobox.h" |
| 28 #include "ui/views/controls/image_view.h" | 28 #include "ui/views/controls/image_view.h" |
| 29 #include "ui/views/controls/label.h" | 29 #include "ui/views/controls/label.h" |
| 30 #include "ui/views/controls/link.h" | |
| 30 #include "ui/views/controls/throbber.h" | 31 #include "ui/views/controls/throbber.h" |
| 31 #include "ui/views/layout/box_layout.h" | 32 #include "ui/views/layout/box_layout.h" |
| 32 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
| 33 #include "ui/views/window/dialog_client_view.h" | 34 #include "ui/views/window/dialog_client_view.h" |
| 34 | 35 |
| 35 namespace autofill { | 36 namespace autofill { |
| 36 | 37 |
| 37 // The number of pixels of blank space on the outer horizontal edges of the | 38 // The number of pixels of blank space on the outer horizontal edges of the |
| 38 // dialog. | 39 // dialog. |
| 39 const int kEdgePadding = 19; | 40 const int kEdgePadding = 19; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 50 | 51 |
| 51 CardUnmaskPromptViews::CardUnmaskPromptViews( | 52 CardUnmaskPromptViews::CardUnmaskPromptViews( |
| 52 CardUnmaskPromptController* controller) | 53 CardUnmaskPromptController* controller) |
| 53 : controller_(controller), | 54 : controller_(controller), |
| 54 main_contents_(nullptr), | 55 main_contents_(nullptr), |
| 55 permanent_error_label_(nullptr), | 56 permanent_error_label_(nullptr), |
| 56 input_row_(nullptr), | 57 input_row_(nullptr), |
| 57 cvc_input_(nullptr), | 58 cvc_input_(nullptr), |
| 58 month_input_(nullptr), | 59 month_input_(nullptr), |
| 59 year_input_(nullptr), | 60 year_input_(nullptr), |
| 61 new_card_link_(nullptr), | |
| 60 error_icon_(nullptr), | 62 error_icon_(nullptr), |
| 61 error_label_(nullptr), | 63 error_label_(nullptr), |
| 62 storage_row_(nullptr), | 64 storage_row_(nullptr), |
| 63 storage_checkbox_(nullptr), | 65 storage_checkbox_(nullptr), |
| 64 progress_overlay_(nullptr), | 66 progress_overlay_(nullptr), |
| 65 progress_throbber_(nullptr), | 67 progress_throbber_(nullptr), |
| 66 progress_label_(nullptr), | 68 progress_label_(nullptr), |
| 67 overlay_animation_(this), | 69 overlay_animation_(this), |
| 68 weak_ptr_factory_(this) { | 70 weak_ptr_factory_(this) { |
| 69 } | 71 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 // TODO(estade): it's somewhat jarring when the error comes back too | 111 // TODO(estade): it's somewhat jarring when the error comes back too |
| 110 // quickly. | 112 // quickly. |
| 111 overlay_animation_.Reset(); | 113 overlay_animation_.Reset(); |
| 112 if (storage_row_) | 114 if (storage_row_) |
| 113 storage_row_->SetAlpha(255); | 115 storage_row_->SetAlpha(255); |
| 114 progress_overlay_->SetVisible(false); | 116 progress_overlay_->SetVisible(false); |
| 115 | 117 |
| 116 if (allow_retry) { | 118 if (allow_retry) { |
| 117 SetInputsEnabled(true); | 119 SetInputsEnabled(true); |
| 118 | 120 |
| 119 // If there is more than one input showing, don't mark anything as | 121 if (!controller_->ShouldRequestExpirationDate()) { |
| 120 // invalid since we don't know the location of the problem. | 122 // If there is more than one input showing, don't mark anything as |
| 121 if (!controller_->ShouldRequestExpirationDate()) | 123 // invalid since we don't know the location of the problem. |
| 122 cvc_input_->SetInvalid(true); | 124 cvc_input_->SetInvalid(true); |
| 123 | 125 |
| 126 // Show a "New card?" link, which when clicked will cause us to ask | |
| 127 // for expiration date. | |
| 128 ShowNewCardLink(); | |
| 129 } | |
| 130 | |
| 124 // TODO(estade): When do we hide |error_label_|? | 131 // TODO(estade): When do we hide |error_label_|? |
| 125 SetRetriableErrorMessage(error_message); | 132 SetRetriableErrorMessage(error_message); |
| 126 } else { | 133 } else { |
| 127 permanent_error_label_->SetText(error_message); | 134 permanent_error_label_->SetText(error_message); |
| 128 permanent_error_label_->SetVisible(true); | 135 permanent_error_label_->SetVisible(true); |
| 129 SetRetriableErrorMessage(base::string16()); | 136 SetRetriableErrorMessage(base::string16()); |
| 130 } | 137 } |
| 131 GetDialogClientView()->UpdateDialogButtons(); | 138 GetDialogClientView()->UpdateDialogButtons(); |
| 132 } | 139 } |
| 133 | 140 |
| 134 Layout(); | 141 Layout(); |
| 135 } | 142 } |
| 136 | 143 |
| 144 void CardUnmaskPromptViews::LinkClicked(views::Link* source, int event_flags) { | |
| 145 DCHECK_EQ(source, new_card_link_); | |
| 146 controller_->NewCardLinkClicked(); | |
| 147 for (int i = 0; i < input_row_->child_count(); ++i) { | |
|
sky
2015/05/14 22:05:59
nit: no {}
Evan Stade
2015/05/14 22:38:22
Done.
| |
| 148 input_row_->child_at(i)->SetVisible(true); | |
| 149 } | |
| 150 new_card_link_->SetVisible(false); | |
| 151 input_row_->InvalidateLayout(); | |
|
sky
2015/05/14 22:05:59
I don't see an explicit layout anywhere. Who trigg
Evan Stade
2015/05/14 22:38:22
see ^ below
| |
| 152 cvc_input_->SetInvalid(false); | |
| 153 cvc_input_->SetText(base::string16()); | |
| 154 GetDialogClientView()->UpdateDialogButtons(); | |
| 155 GetWidget()->UpdateWindowTitle(); | |
| 156 SetRetriableErrorMessage(base::string16()); | |
| 157 } | |
| 158 | |
| 137 void CardUnmaskPromptViews::SetRetriableErrorMessage( | 159 void CardUnmaskPromptViews::SetRetriableErrorMessage( |
| 138 const base::string16& message) { | 160 const base::string16& message) { |
| 139 if (message.empty()) { | 161 if (message.empty()) { |
| 140 error_label_->SetMultiLine(false); | 162 error_label_->SetMultiLine(false); |
| 141 error_label_->SetText(base::ASCIIToUTF16(" ")); | 163 error_label_->SetText(base::ASCIIToUTF16(" ")); |
| 142 error_icon_->SetVisible(false); | 164 error_icon_->SetVisible(false); |
| 143 } else { | 165 } else { |
| 144 error_label_->SetMultiLine(true); | 166 error_label_->SetMultiLine(true); |
| 145 error_label_->SetText(message); | 167 error_label_->SetText(message); |
| 146 error_icon_->SetVisible(true); | 168 error_icon_->SetVisible(true); |
| 147 } | 169 } |
| 148 | 170 |
| 149 // Update the dialog's size. | 171 // Update the dialog's size. |
| 150 if (GetWidget() && controller_->GetWebContents()) { | 172 if (GetWidget() && controller_->GetWebContents()) { |
| 151 constrained_window::UpdateWebContentsModalDialogPosition( | 173 constrained_window::UpdateWebContentsModalDialogPosition( |
| 152 GetWidget(), web_modal::WebContentsModalDialogManager::FromWebContents( | 174 GetWidget(), web_modal::WebContentsModalDialogManager::FromWebContents( |
| 153 controller_->GetWebContents()) | 175 controller_->GetWebContents()) |
| 154 ->delegate() | 176 ->delegate() |
| 155 ->GetWebContentsModalDialogHost()); | 177 ->GetWebContentsModalDialogHost()); |
| 156 } | 178 } |
| 157 | 179 |
| 158 Layout(); | 180 Layout(); |
|
Evan Stade
2015/05/14 22:38:22
^
| |
| 159 } | 181 } |
| 160 | 182 |
| 161 void CardUnmaskPromptViews::SetInputsEnabled(bool enabled) { | 183 void CardUnmaskPromptViews::SetInputsEnabled(bool enabled) { |
| 162 cvc_input_->SetEnabled(enabled); | 184 cvc_input_->SetEnabled(enabled); |
| 163 if (storage_checkbox_) | 185 if (storage_checkbox_) |
| 164 storage_checkbox_->SetEnabled(enabled); | 186 storage_checkbox_->SetEnabled(enabled); |
| 165 if (month_input_) | 187 month_input_->SetEnabled(enabled); |
| 166 month_input_->SetEnabled(enabled); | 188 year_input_->SetEnabled(enabled); |
| 167 if (year_input_) | 189 } |
| 168 year_input_->SetEnabled(enabled); | 190 |
| 191 void CardUnmaskPromptViews::ShowNewCardLink() { | |
| 192 new_card_link_ = new views::Link( | |
|
sky
2015/05/14 22:05:59
I assume you can never hit this more than once, ri
Evan Stade
2015/05/14 22:38:23
Yes, that's the case, but it is still a pretty fra
| |
| 193 l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_NEW_CARD_LINK)); | |
| 194 new_card_link_->SetBorder(views::Border::CreateEmptyBorder(0, 7, 0, 0)); | |
| 195 new_card_link_->SetUnderline(false); | |
| 196 new_card_link_->set_listener(this); | |
| 197 input_row_->AddChildView(new_card_link_); | |
| 169 } | 198 } |
| 170 | 199 |
| 171 views::View* CardUnmaskPromptViews::GetContentsView() { | 200 views::View* CardUnmaskPromptViews::GetContentsView() { |
| 172 InitIfNecessary(); | 201 InitIfNecessary(); |
| 173 return this; | 202 return this; |
| 174 } | 203 } |
| 175 | 204 |
| 176 views::View* CardUnmaskPromptViews::CreateFootnoteView() { | 205 views::View* CardUnmaskPromptViews::CreateFootnoteView() { |
| 177 if (!controller_->CanStoreLocally()) | 206 if (!controller_->CanStoreLocally()) |
| 178 return nullptr; | 207 return nullptr; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 bool CardUnmaskPromptViews::Cancel() { | 312 bool CardUnmaskPromptViews::Cancel() { |
| 284 return true; | 313 return true; |
| 285 } | 314 } |
| 286 | 315 |
| 287 bool CardUnmaskPromptViews::Accept() { | 316 bool CardUnmaskPromptViews::Accept() { |
| 288 if (!controller_) | 317 if (!controller_) |
| 289 return true; | 318 return true; |
| 290 | 319 |
| 291 controller_->OnUnmaskResponse( | 320 controller_->OnUnmaskResponse( |
| 292 cvc_input_->text(), | 321 cvc_input_->text(), |
| 293 month_input_ ? month_input_->GetTextForRow(month_input_->selected_index()) | 322 month_input_->visible() |
| 294 : base::string16(), | 323 ? month_input_->GetTextForRow(month_input_->selected_index()) |
| 295 year_input_ ? year_input_->GetTextForRow(year_input_->selected_index()) | 324 : base::string16(), |
| 296 : base::string16(), | 325 year_input_->visible() |
| 326 ? year_input_->GetTextForRow(year_input_->selected_index()) | |
| 327 : base::string16(), | |
| 297 storage_checkbox_ ? storage_checkbox_->checked() : false); | 328 storage_checkbox_ ? storage_checkbox_->checked() : false); |
| 298 return false; | 329 return false; |
| 299 } | 330 } |
| 300 | 331 |
| 301 void CardUnmaskPromptViews::ContentsChanged( | 332 void CardUnmaskPromptViews::ContentsChanged( |
| 302 views::Textfield* sender, | 333 views::Textfield* sender, |
| 303 const base::string16& new_contents) { | 334 const base::string16& new_contents) { |
| 304 if (controller_->InputCvcIsValid(new_contents)) | 335 if (controller_->InputCvcIsValid(new_contents)) |
| 305 cvc_input_->SetInvalid(false); | 336 cvc_input_->SetInvalid(false); |
| 306 | 337 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 instructions->SetMultiLine(true); | 401 instructions->SetMultiLine(true); |
| 371 instructions->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 402 instructions->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 372 instructions->SetBorder(views::Border::CreateEmptyBorder(0, 0, 16, 0)); | 403 instructions->SetBorder(views::Border::CreateEmptyBorder(0, 0, 16, 0)); |
| 373 controls_container->AddChildView(instructions); | 404 controls_container->AddChildView(instructions); |
| 374 | 405 |
| 375 input_row_ = new views::View(); | 406 input_row_ = new views::View(); |
| 376 input_row_->SetLayoutManager( | 407 input_row_->SetLayoutManager( |
| 377 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5)); | 408 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5)); |
| 378 controls_container->AddChildView(input_row_); | 409 controls_container->AddChildView(input_row_); |
| 379 | 410 |
| 380 if (controller_->ShouldRequestExpirationDate()) { | 411 month_input_ = new views::Combobox(&month_combobox_model_); |
| 381 month_input_ = new views::Combobox(&month_combobox_model_); | 412 month_input_->set_listener(this); |
| 382 month_input_->set_listener(this); | 413 input_row_->AddChildView(month_input_); |
| 383 input_row_->AddChildView(month_input_); | 414 views::Label* separator = new views::Label(l10n_util::GetStringUTF16( |
| 384 views::Label* separator = new views::Label(l10n_util::GetStringUTF16( | 415 IDS_AUTOFILL_CARD_UNMASK_EXPIRATION_DATE_SEPARATOR)); |
| 385 IDS_AUTOFILL_CARD_UNMASK_EXPIRATION_DATE_SEPARATOR)); | 416 separator->SetEnabledColor(kGreyTextColor); |
| 386 separator->SetEnabledColor(kGreyTextColor); | 417 input_row_->AddChildView(separator); |
| 387 input_row_->AddChildView(separator); | 418 year_input_ = new views::Combobox(&year_combobox_model_); |
| 388 year_input_ = new views::Combobox(&year_combobox_model_); | 419 year_input_->set_listener(this); |
| 389 year_input_->set_listener(this); | 420 input_row_->AddChildView(year_input_); |
| 390 input_row_->AddChildView(year_input_); | 421 input_row_->AddChildView(new views::Label(base::ASCIIToUTF16(" "))); |
| 391 input_row_->AddChildView(new views::Label(base::ASCIIToUTF16(" "))); | 422 // Hide all of the above as appropriate. |
| 423 if (!controller_->ShouldRequestExpirationDate()) { | |
| 424 for (int i = 0; i < input_row_->child_count(); ++i) { | |
|
sky
2015/05/14 22:05:59
nit: no {}
Evan Stade
2015/05/14 22:38:22
Done.
| |
| 425 input_row_->child_at(i)->SetVisible(false); | |
| 426 } | |
| 392 } | 427 } |
| 393 | 428 |
| 394 cvc_input_ = new DecoratedTextfield( | 429 cvc_input_ = new DecoratedTextfield( |
| 395 base::string16(), | 430 base::string16(), |
| 396 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC), this); | 431 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC), this); |
| 397 cvc_input_->set_default_width_in_chars(8); | 432 cvc_input_->set_default_width_in_chars(8); |
| 398 input_row_->AddChildView(cvc_input_); | 433 input_row_->AddChildView(cvc_input_); |
| 399 | 434 |
| 400 views::ImageView* cvc_image = new views::ImageView(); | 435 views::ImageView* cvc_image = new views::ImageView(); |
| 401 cvc_image->SetImage(rb.GetImageSkiaNamed(controller_->GetCvcImageRid())); | 436 cvc_image->SetImage(rb.GetImageSkiaNamed(controller_->GetCvcImageRid())); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 views::View::OnPaint(canvas); | 513 views::View::OnPaint(canvas); |
| 479 canvas->Restore(); | 514 canvas->Restore(); |
| 480 } | 515 } |
| 481 | 516 |
| 482 void CardUnmaskPromptViews::FadeOutView::SetAlpha(uint8_t alpha) { | 517 void CardUnmaskPromptViews::FadeOutView::SetAlpha(uint8_t alpha) { |
| 483 alpha_ = alpha; | 518 alpha_ = alpha; |
| 484 SchedulePaint(); | 519 SchedulePaint(); |
| 485 } | 520 } |
| 486 | 521 |
| 487 } // namespace autofill | 522 } // namespace autofill |
| OLD | NEW |