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> |
11 #include <unordered_map> | 11 #include <unordered_map> |
12 #include <utility> | 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | |
18 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" | 19 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" |
19 #include "chrome/browser/ui/views/payments/validation_delegate.h" | 20 #include "chrome/browser/ui/views/payments/validation_delegate.h" |
20 #include "components/autofill/core/browser/field_types.h" | 21 #include "components/autofill/core/browser/field_types.h" |
21 #include "ui/views/controls/combobox/combobox_listener.h" | 22 #include "ui/views/controls/combobox/combobox_listener.h" |
22 #include "ui/views/controls/textfield/textfield_controller.h" | 23 #include "ui/views/controls/textfield/textfield_controller.h" |
23 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
24 | 25 |
25 namespace ui { | 26 namespace ui { |
26 class ComboboxModel; | 27 class ComboboxModel; |
27 } | 28 } |
28 | 29 |
29 namespace views { | 30 namespace views { |
30 class GridLayout; | 31 class GridLayout; |
31 class Label; | 32 class Label; |
32 class Textfield; | 33 class Textfield; |
33 class View; | 34 class View; |
34 } // namespace views | 35 } // namespace views |
35 | 36 |
36 namespace payments { | 37 namespace payments { |
37 | 38 |
38 class PaymentRequestSpec; | 39 class PaymentRequestSpec; |
39 class PaymentRequestState; | 40 class PaymentRequestState; |
40 class PaymentRequestDialogView; | |
41 class ValidatingCombobox; | 41 class ValidatingCombobox; |
42 class ValidatingTextfield; | 42 class ValidatingTextfield; |
43 | 43 |
44 // Field definition for an editor field, used to build the UI. | 44 // Field definition for an editor field, used to build the UI. |
45 struct EditorField { | 45 struct EditorField { |
46 enum class LengthHint : int { HINT_LONG, HINT_SHORT }; | 46 enum class LengthHint : int { HINT_LONG, HINT_SHORT }; |
47 enum class ControlType : int { TEXTFIELD, COMBOBOX }; | 47 enum class ControlType : int { TEXTFIELD, COMBOBOX }; |
48 | 48 |
49 EditorField(autofill::ServerFieldType type, | 49 EditorField(autofill::ServerFieldType type, |
50 base::string16 label, | 50 base::string16 label, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 public views::ComboboxListener { | 82 public views::ComboboxListener { |
83 public: | 83 public: |
84 using TextFieldsMap = | 84 using TextFieldsMap = |
85 std::unordered_map<ValidatingTextfield*, const EditorField>; | 85 std::unordered_map<ValidatingTextfield*, const EditorField>; |
86 using ComboboxMap = | 86 using ComboboxMap = |
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 // |back_navigation_type| identify which other view to navigate to when the | |
Mathieu
2017/05/04 20:29:19
*identifies what sort of back navigation should be
MAD
2017/05/05 00:50:07
Done.
| |
93 // editing is completed successfully (as opposed to the back arrow which | |
94 // always go back a single step). | |
92 EditorViewController(PaymentRequestSpec* spec, | 95 EditorViewController(PaymentRequestSpec* spec, |
93 PaymentRequestState* state, | 96 PaymentRequestState* state, |
94 PaymentRequestDialogView* dialog); | 97 PaymentRequestDialogView* dialog, |
98 BackNavigationType back_navigation_type); | |
95 ~EditorViewController() override; | 99 ~EditorViewController() override; |
96 | 100 |
97 // Will display |error_message| alongside the input field represented by | 101 // Will display |error_message| alongside the input field represented by |
98 // |field|. | 102 // |field|. |
99 void DisplayErrorMessageForField(const EditorField& field, | 103 void DisplayErrorMessageForField(const EditorField& field, |
100 const base::string16& error_message); | 104 const base::string16& error_message); |
101 | 105 |
102 const ComboboxMap& comboboxes() const { return comboboxes_; } | 106 const ComboboxMap& comboboxes() const { return comboboxes_; } |
103 const TextFieldsMap& text_fields() const { return text_fields_; } | 107 const TextFieldsMap& text_fields() const { return text_fields_; } |
104 | 108 |
105 protected: | 109 protected: |
106 virtual std::unique_ptr<views::View> CreateHeaderView() = 0; | 110 virtual std::unique_ptr<views::View> CreateHeaderView() = 0; |
111 virtual std::unique_ptr<views::View> CreateCustomFieldsView() = 0; | |
107 // Returns the field definitions used to build the UI. | 112 // Returns the field definitions used to build the UI. |
108 virtual std::vector<EditorField> GetFieldDefinitions() = 0; | 113 virtual std::vector<EditorField> GetFieldDefinitions() = 0; |
109 virtual base::string16 GetInitialValueForType( | 114 virtual base::string16 GetInitialValueForType( |
110 autofill::ServerFieldType type) = 0; | 115 autofill::ServerFieldType type) = 0; |
111 // Validates the data entered and attempts to save; returns true on success. | 116 // Validates the data entered and attempts to save; returns true on success. |
112 virtual bool ValidateModelAndSave() = 0; | 117 virtual bool ValidateModelAndSave() = 0; |
113 // Creates a ValidationDelegate which knows how to validate for a given | 118 // Creates a ValidationDelegate which knows how to validate for a given |
114 // |field| definition. | 119 // |field| definition. |
115 virtual std::unique_ptr<ValidationDelegate> CreateValidationDelegate( | 120 virtual std::unique_ptr<ValidationDelegate> CreateValidationDelegate( |
116 const EditorField& field) = 0; | 121 const EditorField& field) = 0; |
117 virtual std::unique_ptr<ui::ComboboxModel> GetComboboxModelForType( | 122 virtual std::unique_ptr<ui::ComboboxModel> GetComboboxModelForType( |
118 const autofill::ServerFieldType& type) = 0; | 123 const autofill::ServerFieldType& type) = 0; |
119 | 124 |
120 // PaymentRequestSheetController; | 125 // PaymentRequestSheetController; |
121 std::unique_ptr<views::Button> CreatePrimaryButton() override; | 126 std::unique_ptr<views::Button> CreatePrimaryButton() override; |
122 void FillContentView(views::View* content_view) override; | 127 void FillContentView(views::View* content_view) override; |
123 std::unique_ptr<views::View> CreateExtraFooterView() override; | 128 std::unique_ptr<views::View> CreateExtraFooterView() override; |
124 | 129 |
125 // views::ComboboxListener: | 130 // views::ComboboxListener: |
126 void OnPerformAction(views::Combobox* combobox) override; | 131 void OnPerformAction(views::Combobox* combobox) override; |
127 | 132 |
128 // Update the editor view by removing all it's child views and recreating | 133 // Update the editor view by removing all it's child views and recreating |
129 // the input fields returned by GetFieldDefinitions. Note that | 134 // the input fields returned by GetFieldDefinitions. Note that |
130 // CreateEditorView MUST have been called at least once before calling | 135 // CreateEditorView MUST have been called at least once before calling |
131 // UpdateEditorView. | 136 // UpdateEditorView. |
132 virtual void UpdateEditorView(); | 137 virtual void UpdateEditorView(); |
133 | 138 |
134 private: | |
135 // PaymentRequestSheetController: | 139 // PaymentRequestSheetController: |
136 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 140 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
137 | 141 |
142 // To allow derived classes to use the exact same values in their custom | |
143 // fields view. |kLabelInputFieldHorizontalPadding| sets the distance between | |
144 // intput fields and their label. | |
Mathieu
2017/05/04 20:29:19
*input
MAD
2017/05/05 00:50:07
Done.
| |
145 static constexpr int kLabelInputFieldHorizontalPadding = 16; | |
146 // The spacing in between input rows. | |
147 static constexpr int kInputRowSpacing = 6; | |
148 // |kMaximumLabelWidth| value was picked so that left + right label padding | |
149 // bring the label to half-way in the dialog (~225). | |
150 static constexpr int kMaximumLabelWidth = 192; | |
151 | |
152 private: | |
138 // views::TextfieldController: | 153 // views::TextfieldController: |
139 void ContentsChanged(views::Textfield* sender, | 154 void ContentsChanged(views::Textfield* sender, |
140 const base::string16& new_contents) override; | 155 const base::string16& new_contents) override; |
141 | 156 |
142 // Creates the whole editor view to go within the editor dialog. It | 157 // Creates the whole editor view to go within the editor dialog. It |
143 // encompasses all the input fields created by CreateInputField(). | 158 // encompasses all the input fields created by CreateInputField(). |
144 std::unique_ptr<views::View> CreateEditorView(); | 159 std::unique_ptr<views::View> CreateEditorView(); |
145 | 160 |
146 // Adds some views to |layout|, to represent an input field and its labels. | 161 // Adds some views to |layout|, to represent an input field and its labels. |
147 // |field| is the field definition, which contains the label and the hint | 162 // |field| is the field definition, which contains the label and the hint |
148 // about the length of the input field. A placeholder error label is also | 163 // about the length of the input field. A placeholder error label is also |
149 // added (see implementation). | 164 // added (see implementation). |
150 void CreateInputField(views::GridLayout* layout, const EditorField& field); | 165 void CreateInputField(views::GridLayout* layout, const EditorField& field); |
151 | 166 |
152 // Used to remember the association between the input field UI element and the | 167 // Used to remember the association between the input field UI element and the |
153 // original field definition. The ValidatingTextfield* and ValidatingCombobox* | 168 // original field definition. The ValidatingTextfield* and ValidatingCombobox* |
154 // are owned by their parent view, this only keeps a reference that is good as | 169 // are owned by their parent view, this only keeps a reference that is good as |
155 // long as the input field is visible. | 170 // long as the input field is visible. |
156 TextFieldsMap text_fields_; | 171 TextFieldsMap text_fields_; |
157 ComboboxMap comboboxes_; | 172 ComboboxMap comboboxes_; |
158 // Tracks the relationship between a field and its error label. | 173 // Tracks the relationship between a field and its error label. |
159 ErrorLabelMap error_labels_; | 174 ErrorLabelMap error_labels_; |
160 | 175 |
176 // Identifies where to go back when the editing completes successfully. | |
177 BackNavigationType back_navigation_type_; | |
178 | |
161 DISALLOW_COPY_AND_ASSIGN(EditorViewController); | 179 DISALLOW_COPY_AND_ASSIGN(EditorViewController); |
162 }; | 180 }; |
163 | 181 |
164 } // namespace payments | 182 } // namespace payments |
165 | 183 |
166 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ | 184 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ |
OLD | NEW |