OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 std::unordered_map<ValidatingCombobox*, const EditorField>; | 87 std::unordered_map<ValidatingCombobox*, const EditorField>; |
88 using ErrorLabelMap = | 88 using ErrorLabelMap = |
89 std::map<const EditorField, views::Label*, EditorField::Compare>; | 89 std::map<const EditorField, views::Label*, EditorField::Compare>; |
90 | 90 |
91 // Does not take ownership of the arguments, which should outlive this object. | 91 // Does not take ownership of the arguments, which should outlive this object. |
92 EditorViewController(PaymentRequestSpec* spec, | 92 EditorViewController(PaymentRequestSpec* spec, |
93 PaymentRequestState* state, | 93 PaymentRequestState* state, |
94 PaymentRequestDialogView* dialog); | 94 PaymentRequestDialogView* dialog); |
95 ~EditorViewController() override; | 95 ~EditorViewController() override; |
96 | 96 |
97 // PaymentRequestSheetController: | |
98 std::unique_ptr<views::View> CreateView() override; | |
99 | |
100 // Will display |error_message| alongside the input field represented by | 97 // Will display |error_message| alongside the input field represented by |
101 // |field|. | 98 // |field|. |
102 void DisplayErrorMessageForField(const EditorField& field, | 99 void DisplayErrorMessageForField(const EditorField& field, |
103 const base::string16& error_message); | 100 const base::string16& error_message); |
104 | 101 |
105 const ComboboxMap& comboboxes() const { return comboboxes_; } | 102 const ComboboxMap& comboboxes() const { return comboboxes_; } |
106 const TextFieldsMap& text_fields() const { return text_fields_; } | 103 const TextFieldsMap& text_fields() const { return text_fields_; } |
107 | 104 |
108 protected: | 105 protected: |
109 virtual std::unique_ptr<views::View> CreateHeaderView() = 0; | 106 virtual std::unique_ptr<views::View> CreateHeaderView() = 0; |
110 // Returns the resource id of the view header title. | |
111 virtual int GetViewHeaderTitleId() const = 0; | |
112 // Returns the field definitions used to build the UI. | 107 // Returns the field definitions used to build the UI. |
113 virtual std::vector<EditorField> GetFieldDefinitions() = 0; | 108 virtual std::vector<EditorField> GetFieldDefinitions() = 0; |
114 // Validates the data entered and attempts to save; returns true on success. | 109 // Validates the data entered and attempts to save; returns true on success. |
115 virtual bool ValidateModelAndSave() = 0; | 110 virtual bool ValidateModelAndSave() = 0; |
116 // Creates a ValidationDelegate which knows how to validate for a given | 111 // Creates a ValidationDelegate which knows how to validate for a given |
117 // |field| definition. | 112 // |field| definition. |
118 virtual std::unique_ptr<ValidationDelegate> CreateValidationDelegate( | 113 virtual std::unique_ptr<ValidationDelegate> CreateValidationDelegate( |
119 const EditorField& field) = 0; | 114 const EditorField& field) = 0; |
120 virtual std::unique_ptr<ui::ComboboxModel> GetComboboxModelForType( | 115 virtual std::unique_ptr<ui::ComboboxModel> GetComboboxModelForType( |
121 const autofill::ServerFieldType& type) = 0; | 116 const autofill::ServerFieldType& type) = 0; |
122 | 117 |
123 // PaymentRequestSheetController; | 118 // PaymentRequestSheetController; |
124 std::unique_ptr<views::Button> CreatePrimaryButton() override; | 119 std::unique_ptr<views::Button> CreatePrimaryButton() override; |
| 120 void FillContentView(views::View* content_view) override; |
125 std::unique_ptr<views::View> CreateExtraFooterView() override; | 121 std::unique_ptr<views::View> CreateExtraFooterView() override; |
126 | 122 |
127 // views::ComboboxListener: | 123 // views::ComboboxListener: |
128 void OnPerformAction(views::Combobox* combobox) override; | 124 void OnPerformAction(views::Combobox* combobox) override; |
129 | 125 |
130 // Update the editor view by removing all it's child views and recreating | 126 // Update the editor view by removing all it's child views and recreating |
131 // the input fields returned by GetFieldDefinitions. Note that | 127 // the input fields returned by GetFieldDefinitions. Note that |
132 // CreateEditorView MUST have been called at least once before calling | 128 // CreateEditorView MUST have been called at least once before calling |
133 // UpdateEditorView. | 129 // UpdateEditorView. |
134 virtual void UpdateEditorView(); | 130 virtual void UpdateEditorView(); |
135 | 131 |
136 private: | 132 private: |
137 // PaymentRequestSheetController: | 133 // PaymentRequestSheetController: |
138 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 134 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
139 | 135 |
140 // views::TextfieldController: | 136 // views::TextfieldController: |
141 void ContentsChanged(views::Textfield* sender, | 137 void ContentsChanged(views::Textfield* sender, |
142 const base::string16& new_contents) override; | 138 const base::string16& new_contents) override; |
143 | 139 |
144 // Creates the whole editor view to go within the editor dialog. It | 140 // Creates the whole editor view to go within the editor dialog. It |
145 // encompasses all the input fields created by CreateInputField(). | 141 // encompasses all the input fields created by CreateInputField(). |
146 void CreateEditorView(); | 142 std::unique_ptr<views::View> CreateEditorView(); |
147 | 143 |
148 // Adds some views to |layout|, to represent an input field and its labels. | 144 // Adds some views to |layout|, to represent an input field and its labels. |
149 // |field| is the field definition, which contains the label and the hint | 145 // |field| is the field definition, which contains the label and the hint |
150 // about the length of the input field. A placeholder error label is also | 146 // about the length of the input field. A placeholder error label is also |
151 // added (see implementation). | 147 // added (see implementation). |
152 void CreateInputField(views::GridLayout* layout, const EditorField& field); | 148 void CreateInputField(views::GridLayout* layout, const EditorField& field); |
153 | 149 |
154 // The implementation of UpdateEditorView which is also called from | |
155 // CreateEditorView. | |
156 void UpdateEditorViewImpl(); | |
157 | |
158 // The editor content view, owned by the client so the derived classes can | |
159 // refresh it when some user interactions cause layout changes by calling | |
160 // UpdateEditorView(). | |
161 std::unique_ptr<views::View> editor_view_; | |
162 | |
163 // Used to remember the association between the input field UI element and the | 150 // Used to remember the association between the input field UI element and the |
164 // original field definition. The ValidatingTextfield* and ValidatingCombobox* | 151 // original field definition. The ValidatingTextfield* and ValidatingCombobox* |
165 // are owned by their parent view, this only keeps a reference that is good as | 152 // are owned by their parent view, this only keeps a reference that is good as |
166 // long as the input field is visible. | 153 // long as the input field is visible. |
167 TextFieldsMap text_fields_; | 154 TextFieldsMap text_fields_; |
168 ComboboxMap comboboxes_; | 155 ComboboxMap comboboxes_; |
169 // Tracks the relationship between a field and its error label. | 156 // Tracks the relationship between a field and its error label. |
170 ErrorLabelMap error_labels_; | 157 ErrorLabelMap error_labels_; |
171 | 158 |
172 DISALLOW_COPY_AND_ASSIGN(EditorViewController); | 159 DISALLOW_COPY_AND_ASSIGN(EditorViewController); |
173 }; | 160 }; |
174 | 161 |
175 } // namespace payments | 162 } // namespace payments |
176 | 163 |
177 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ | 164 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ |
OLD | NEW |