| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 7 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
| 8 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" | 8 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" |
| 9 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" | 9 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" |
| 10 #include "chrome/browser/ui/views/autofill/decorated_textfield.h" | 10 #include "chrome/browser/ui/views/autofill/decorated_textfield.h" |
| 11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/constrained_window/constrained_window_views.h" | 12 #include "components/constrained_window/constrained_window_views.h" |
| 13 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/views/controls/button/checkbox.h" |
| 16 #include "ui/views/controls/combobox/combobox.h" | 17 #include "ui/views/controls/combobox/combobox.h" |
| 17 #include "ui/views/controls/combobox/combobox_listener.h" | 18 #include "ui/views/controls/combobox/combobox_listener.h" |
| 18 #include "ui/views/controls/image_view.h" | 19 #include "ui/views/controls/image_view.h" |
| 19 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
| 20 #include "ui/views/controls/textfield/textfield_controller.h" | 21 #include "ui/views/controls/textfield/textfield_controller.h" |
| 21 #include "ui/views/layout/box_layout.h" | 22 #include "ui/views/layout/box_layout.h" |
| 22 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 23 #include "ui/views/window/dialog_client_view.h" | 24 #include "ui/views/window/dialog_client_view.h" |
| 24 #include "ui/views/window/dialog_delegate.h" | 25 #include "ui/views/window/dialog_delegate.h" |
| 25 | 26 |
| 26 namespace autofill { | 27 namespace autofill { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 class CardUnmaskPromptViews : public CardUnmaskPromptView, | 31 class CardUnmaskPromptViews : public CardUnmaskPromptView, |
| 31 views::ComboboxListener, | 32 views::ComboboxListener, |
| 32 views::DialogDelegateView, | 33 views::DialogDelegateView, |
| 33 views::TextfieldController { | 34 views::TextfieldController { |
| 34 public: | 35 public: |
| 35 explicit CardUnmaskPromptViews(CardUnmaskPromptController* controller) | 36 explicit CardUnmaskPromptViews(CardUnmaskPromptController* controller) |
| 36 : controller_(controller), | 37 : controller_(controller), |
| 37 cvc_input_(nullptr), | 38 cvc_input_(nullptr), |
| 38 month_input_(nullptr), | 39 month_input_(nullptr), |
| 39 year_input_(nullptr), | 40 year_input_(nullptr), |
| 40 message_label_(nullptr) {} | 41 message_label_(nullptr), |
| 42 storage_checkbox_(nullptr) {} |
| 41 | 43 |
| 42 ~CardUnmaskPromptViews() override { | 44 ~CardUnmaskPromptViews() override { |
| 43 if (controller_) | 45 if (controller_) |
| 44 controller_->OnUnmaskDialogClosed(); | 46 controller_->OnUnmaskDialogClosed(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 void Show() { | 49 void Show() { |
| 48 constrained_window::ShowWebModalDialogViews(this, | 50 constrained_window::ShowWebModalDialogViews(this, |
| 49 controller_->GetWebContents()); | 51 controller_->GetWebContents()); |
| 50 } | 52 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 if (!controller_) | 153 if (!controller_) |
| 152 return true; | 154 return true; |
| 153 | 155 |
| 154 controller_->OnUnmaskResponse( | 156 controller_->OnUnmaskResponse( |
| 155 cvc_input_->text(), | 157 cvc_input_->text(), |
| 156 month_input_ | 158 month_input_ |
| 157 ? month_combobox_model_.GetItemAt(month_input_->selected_index()) | 159 ? month_combobox_model_.GetItemAt(month_input_->selected_index()) |
| 158 : base::string16(), | 160 : base::string16(), |
| 159 year_input_ | 161 year_input_ |
| 160 ? year_combobox_model_.GetItemAt(year_input_->selected_index()) | 162 ? year_combobox_model_.GetItemAt(year_input_->selected_index()) |
| 161 : base::string16()); | 163 : base::string16(), |
| 164 storage_checkbox_ ? storage_checkbox_->checked() : false); |
| 162 return false; | 165 return false; |
| 163 } | 166 } |
| 164 | 167 |
| 165 // views::TextfieldController | 168 // views::TextfieldController |
| 166 void ContentsChanged(views::Textfield* sender, | 169 void ContentsChanged(views::Textfield* sender, |
| 167 const base::string16& new_contents) override { | 170 const base::string16& new_contents) override { |
| 168 GetDialogClientView()->UpdateDialogButtons(); | 171 GetDialogClientView()->UpdateDialogButtons(); |
| 169 } | 172 } |
| 170 | 173 |
| 171 // views::ComboboxListener | 174 // views::ComboboxListener |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 views::ImageView* cvc_image = new views::ImageView(); | 214 views::ImageView* cvc_image = new views::ImageView(); |
| 212 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 215 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 213 | 216 |
| 214 cvc_image->SetImage(rb.GetImageSkiaNamed(controller_->GetCvcImageRid())); | 217 cvc_image->SetImage(rb.GetImageSkiaNamed(controller_->GetCvcImageRid())); |
| 215 | 218 |
| 216 input_row->AddChildView(cvc_image); | 219 input_row->AddChildView(cvc_image); |
| 217 | 220 |
| 218 message_label_ = new views::Label(); | 221 message_label_ = new views::Label(); |
| 219 input_row->AddChildView(message_label_); | 222 input_row->AddChildView(message_label_); |
| 220 message_label_->SetVisible(false); | 223 message_label_->SetVisible(false); |
| 224 |
| 225 bool storage_default = false; |
| 226 if (controller_->ShouldOfferToStoreLocally(&storage_default)) { |
| 227 storage_checkbox_ = new views::Checkbox(l10n_util::GetStringUTF16( |
| 228 IDS_AUTOFILL_CARD_UNMASK_PROMPT_STORAGE_CHECKBOX)); |
| 229 storage_checkbox_->SetChecked(storage_default); |
| 230 AddChildView(storage_checkbox_); |
| 231 } |
| 221 } | 232 } |
| 222 | 233 |
| 223 void ClosePrompt() { GetWidget()->Close(); } | 234 void ClosePrompt() { GetWidget()->Close(); } |
| 224 | 235 |
| 225 CardUnmaskPromptController* controller_; | 236 CardUnmaskPromptController* controller_; |
| 226 | 237 |
| 227 DecoratedTextfield* cvc_input_; | 238 DecoratedTextfield* cvc_input_; |
| 228 | 239 |
| 229 // These will be null when expiration date is not required. | 240 // These will be null when expiration date is not required. |
| 230 views::Combobox* month_input_; | 241 views::Combobox* month_input_; |
| 231 views::Combobox* year_input_; | 242 views::Combobox* year_input_; |
| 232 | 243 |
| 233 MonthComboboxModel month_combobox_model_; | 244 MonthComboboxModel month_combobox_model_; |
| 234 YearComboboxModel year_combobox_model_; | 245 YearComboboxModel year_combobox_model_; |
| 235 | 246 |
| 236 // TODO(estade): this is a temporary standin in place of some spinner UI | 247 // TODO(estade): this is a temporary standin in place of some spinner UI |
| 237 // as well as a better error message. | 248 // as well as a better error message. |
| 238 views::Label* message_label_; | 249 views::Label* message_label_; |
| 239 | 250 |
| 251 views::Checkbox* storage_checkbox_; |
| 252 |
| 240 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViews); | 253 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViews); |
| 241 }; | 254 }; |
| 242 | 255 |
| 243 } // namespace | 256 } // namespace |
| 244 | 257 |
| 245 // static | 258 // static |
| 246 CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow( | 259 CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow( |
| 247 CardUnmaskPromptController* controller) { | 260 CardUnmaskPromptController* controller) { |
| 248 CardUnmaskPromptViews* view = new CardUnmaskPromptViews(controller); | 261 CardUnmaskPromptViews* view = new CardUnmaskPromptViews(controller); |
| 249 view->Show(); | 262 view->Show(); |
| 250 return view; | 263 return view; |
| 251 } | 264 } |
| 252 | 265 |
| 253 } // namespace autofill | 266 } // namespace autofill |
| OLD | NEW |