| 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) |
| 148 input_row_->child_at(i)->SetVisible(true); |
| 149 |
| 150 new_card_link_->SetVisible(false); |
| 151 input_row_->InvalidateLayout(); |
| 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(); |
| 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 if (new_card_link_) |
| 193 return; |
| 194 |
| 195 new_card_link_ = new views::Link( |
| 196 l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_NEW_CARD_LINK)); |
| 197 new_card_link_->SetBorder(views::Border::CreateEmptyBorder(0, 7, 0, 0)); |
| 198 new_card_link_->SetUnderline(false); |
| 199 new_card_link_->set_listener(this); |
| 200 input_row_->AddChildView(new_card_link_); |
| 169 } | 201 } |
| 170 | 202 |
| 171 views::View* CardUnmaskPromptViews::GetContentsView() { | 203 views::View* CardUnmaskPromptViews::GetContentsView() { |
| 172 InitIfNecessary(); | 204 InitIfNecessary(); |
| 173 return this; | 205 return this; |
| 174 } | 206 } |
| 175 | 207 |
| 176 views::View* CardUnmaskPromptViews::CreateFootnoteView() { | 208 views::View* CardUnmaskPromptViews::CreateFootnoteView() { |
| 177 if (!controller_->CanStoreLocally()) | 209 if (!controller_->CanStoreLocally()) |
| 178 return nullptr; | 210 return nullptr; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 bool CardUnmaskPromptViews::Cancel() { | 315 bool CardUnmaskPromptViews::Cancel() { |
| 284 return true; | 316 return true; |
| 285 } | 317 } |
| 286 | 318 |
| 287 bool CardUnmaskPromptViews::Accept() { | 319 bool CardUnmaskPromptViews::Accept() { |
| 288 if (!controller_) | 320 if (!controller_) |
| 289 return true; | 321 return true; |
| 290 | 322 |
| 291 controller_->OnUnmaskResponse( | 323 controller_->OnUnmaskResponse( |
| 292 cvc_input_->text(), | 324 cvc_input_->text(), |
| 293 month_input_ ? month_input_->GetTextForRow(month_input_->selected_index()) | 325 month_input_->visible() |
| 294 : base::string16(), | 326 ? month_input_->GetTextForRow(month_input_->selected_index()) |
| 295 year_input_ ? year_input_->GetTextForRow(year_input_->selected_index()) | 327 : base::string16(), |
| 296 : base::string16(), | 328 year_input_->visible() |
| 329 ? year_input_->GetTextForRow(year_input_->selected_index()) |
| 330 : base::string16(), |
| 297 storage_checkbox_ ? storage_checkbox_->checked() : false); | 331 storage_checkbox_ ? storage_checkbox_->checked() : false); |
| 298 return false; | 332 return false; |
| 299 } | 333 } |
| 300 | 334 |
| 301 void CardUnmaskPromptViews::ContentsChanged( | 335 void CardUnmaskPromptViews::ContentsChanged( |
| 302 views::Textfield* sender, | 336 views::Textfield* sender, |
| 303 const base::string16& new_contents) { | 337 const base::string16& new_contents) { |
| 304 if (controller_->InputCvcIsValid(new_contents)) | 338 if (controller_->InputCvcIsValid(new_contents)) |
| 305 cvc_input_->SetInvalid(false); | 339 cvc_input_->SetInvalid(false); |
| 306 | 340 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 instructions->SetMultiLine(true); | 404 instructions->SetMultiLine(true); |
| 371 instructions->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 405 instructions->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 372 instructions->SetBorder(views::Border::CreateEmptyBorder(0, 0, 16, 0)); | 406 instructions->SetBorder(views::Border::CreateEmptyBorder(0, 0, 16, 0)); |
| 373 controls_container->AddChildView(instructions); | 407 controls_container->AddChildView(instructions); |
| 374 | 408 |
| 375 input_row_ = new views::View(); | 409 input_row_ = new views::View(); |
| 376 input_row_->SetLayoutManager( | 410 input_row_->SetLayoutManager( |
| 377 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5)); | 411 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5)); |
| 378 controls_container->AddChildView(input_row_); | 412 controls_container->AddChildView(input_row_); |
| 379 | 413 |
| 380 if (controller_->ShouldRequestExpirationDate()) { | 414 month_input_ = new views::Combobox(&month_combobox_model_); |
| 381 month_input_ = new views::Combobox(&month_combobox_model_); | 415 month_input_->set_listener(this); |
| 382 month_input_->set_listener(this); | 416 input_row_->AddChildView(month_input_); |
| 383 input_row_->AddChildView(month_input_); | 417 views::Label* separator = new views::Label(l10n_util::GetStringUTF16( |
| 384 views::Label* separator = new views::Label(l10n_util::GetStringUTF16( | 418 IDS_AUTOFILL_CARD_UNMASK_EXPIRATION_DATE_SEPARATOR)); |
| 385 IDS_AUTOFILL_CARD_UNMASK_EXPIRATION_DATE_SEPARATOR)); | 419 separator->SetEnabledColor(kGreyTextColor); |
| 386 separator->SetEnabledColor(kGreyTextColor); | 420 input_row_->AddChildView(separator); |
| 387 input_row_->AddChildView(separator); | 421 year_input_ = new views::Combobox(&year_combobox_model_); |
| 388 year_input_ = new views::Combobox(&year_combobox_model_); | 422 year_input_->set_listener(this); |
| 389 year_input_->set_listener(this); | 423 input_row_->AddChildView(year_input_); |
| 390 input_row_->AddChildView(year_input_); | 424 input_row_->AddChildView(new views::Label(base::ASCIIToUTF16(" "))); |
| 391 input_row_->AddChildView(new views::Label(base::ASCIIToUTF16(" "))); | 425 // Hide all of the above as appropriate. |
| 426 if (!controller_->ShouldRequestExpirationDate()) { |
| 427 for (int i = 0; i < input_row_->child_count(); ++i) |
| 428 input_row_->child_at(i)->SetVisible(false); |
| 392 } | 429 } |
| 393 | 430 |
| 394 cvc_input_ = new DecoratedTextfield( | 431 cvc_input_ = new DecoratedTextfield( |
| 395 base::string16(), | 432 base::string16(), |
| 396 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC), this); | 433 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC), this); |
| 397 cvc_input_->set_default_width_in_chars(8); | 434 cvc_input_->set_default_width_in_chars(8); |
| 398 input_row_->AddChildView(cvc_input_); | 435 input_row_->AddChildView(cvc_input_); |
| 399 | 436 |
| 400 views::ImageView* cvc_image = new views::ImageView(); | 437 views::ImageView* cvc_image = new views::ImageView(); |
| 401 cvc_image->SetImage(rb.GetImageSkiaNamed(controller_->GetCvcImageRid())); | 438 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); | 515 views::View::OnPaint(canvas); |
| 479 canvas->Restore(); | 516 canvas->Restore(); |
| 480 } | 517 } |
| 481 | 518 |
| 482 void CardUnmaskPromptViews::FadeOutView::SetAlpha(uint8_t alpha) { | 519 void CardUnmaskPromptViews::FadeOutView::SetAlpha(uint8_t alpha) { |
| 483 alpha_ = alpha; | 520 alpha_ = alpha; |
| 484 SchedulePaint(); | 521 SchedulePaint(); |
| 485 } | 522 } |
| 486 | 523 |
| 487 } // namespace autofill | 524 } // namespace autofill |
| OLD | NEW |