OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_SHIPPING_ADDRESS_EDITOR_VIEW_CONTROLLER
_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_SHIPPING_ADDRESS_EDITOR_VIEW_CONTROLLER
_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "chrome/browser/ui/views/payments/editor_view_controller.h" |
| 14 #include "chrome/browser/ui/views/payments/validating_textfield.h" |
| 15 |
| 16 namespace payments { |
| 17 |
| 18 class PaymentRequestSpec; |
| 19 class PaymentRequestState; |
| 20 class PaymentRequestDialogView; |
| 21 |
| 22 // Shipping Address editor screen of the Payment Request flow. |
| 23 class ShippingAddressEditorViewController : public EditorViewController { |
| 24 public: |
| 25 // Does not take ownership of the arguments, which should outlive this object. |
| 26 ShippingAddressEditorViewController(PaymentRequestSpec* spec, |
| 27 PaymentRequestState* state, |
| 28 PaymentRequestDialogView* dialog); |
| 29 ~ShippingAddressEditorViewController() override; |
| 30 |
| 31 // EditorViewController: |
| 32 std::unique_ptr<views::View> CreateHeaderView() override; |
| 33 int GetViewHeaderTitleId() const override; |
| 34 std::vector<EditorField> GetFieldDefinitions() override; |
| 35 bool ValidateModelAndSave() override; |
| 36 std::unique_ptr<ValidationDelegate> CreateValidationDelegate( |
| 37 const EditorField& field) override; |
| 38 std::unique_ptr<ui::ComboboxModel> GetComboboxModelForType( |
| 39 const autofill::ServerFieldType& type) override; |
| 40 void OnPerformAction(views::Combobox* combobox) override; |
| 41 void UpdateEditorView() override; |
| 42 |
| 43 private: |
| 44 class ShippingAddressValidationDelegate : public ValidationDelegate { |
| 45 public: |
| 46 ShippingAddressValidationDelegate( |
| 47 ShippingAddressEditorViewController* parent, |
| 48 const EditorField& field); |
| 49 ~ShippingAddressValidationDelegate() override; |
| 50 |
| 51 // ValidationDelegate: |
| 52 bool ValidateTextfield(views::Textfield* textfield) override; |
| 53 bool ValidateCombobox(views::Combobox* combobox) override; |
| 54 |
| 55 private: |
| 56 bool ValidateValue(const base::string16& value); |
| 57 |
| 58 EditorField field_; |
| 59 // TODO(mad): Bring back when needed. |
| 60 // ShippingAddressEditorViewController* parent_{nullptr}; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(ShippingAddressValidationDelegate); |
| 63 }; |
| 64 friend class ShippingAddressValidationDelegate; |
| 65 |
| 66 // List of fields, reset everytime the current country changes. |
| 67 std::vector<EditorField> editor_fields_; |
| 68 |
| 69 // The currently chosen country. Defaults to 0 as the first entry in the |
| 70 // combobox, which is the generated default value received from |
| 71 // autofill::CountryComboboxModel::countries() which is documented to always |
| 72 // have the default country at the top as well as within the sorted list. |
| 73 size_t chosen_country_index_{0}; |
| 74 |
| 75 // The list of country codes as ordered in the country combobox model. |
| 76 std::vector<std::string> country_codes_; |
| 77 |
| 78 // Updates |editor_fields_| based on the current country. |
| 79 void UpdateEditorFields(); |
| 80 |
| 81 // Called by the validation delegate when the country combobox changed. |
| 82 void OnCountryChanged(views::Combobox* combobox); |
| 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(ShippingAddressEditorViewController); |
| 85 }; |
| 86 |
| 87 } // namespace payments |
| 88 |
| 89 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_SHIPPING_ADDRESS_EDITOR_VIEW_CONTROL
LER_H_ |
OLD | NEW |