Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1613)

Side by Side Diff: chrome/browser/ui/views/payments/editor_view_controller.h

Issue 2895473005: [Payments] Have expiration date be on the same line in CC editor (Closed)
Patch Set: addressed comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 base::string16 label, 55 base::string16 label,
56 LengthHint length_hint, 56 LengthHint length_hint,
57 bool required, 57 bool required,
58 ControlType control_type = ControlType::TEXTFIELD) 58 ControlType control_type = ControlType::TEXTFIELD)
59 : type(type), 59 : type(type),
60 label(std::move(label)), 60 label(std::move(label)),
61 length_hint(length_hint), 61 length_hint(length_hint),
62 required(required), 62 required(required),
63 control_type(control_type) {} 63 control_type(control_type) {}
64 64
65 struct Compare {
66 bool operator()(const EditorField& lhs, const EditorField& rhs) const {
67 return std::tie(lhs.type, lhs.label) < std::tie(rhs.type, rhs.label);
68 }
69 };
70
71 // Data type in the field. 65 // Data type in the field.
72 autofill::ServerFieldType type; 66 autofill::ServerFieldType type;
73 // Label to be shown alongside the field. 67 // Label to be shown alongside the field.
74 base::string16 label; 68 base::string16 label;
75 // Hint about the length of this field's contents. 69 // Hint about the length of this field's contents.
76 LengthHint length_hint; 70 LengthHint length_hint;
77 // Whether the field is required. 71 // Whether the field is required.
78 bool required; 72 bool required;
79 // The control type. 73 // The control type.
80 ControlType control_type; 74 ControlType control_type;
81 }; 75 };
82 76
83 // The PaymentRequestSheetController subtype for the editor screens of the 77 // The PaymentRequestSheetController subtype for the editor screens of the
84 // Payment Request flow. 78 // Payment Request flow.
85 class EditorViewController : public PaymentRequestSheetController, 79 class EditorViewController : public PaymentRequestSheetController,
86 public views::TextfieldController, 80 public views::TextfieldController,
87 public views::ComboboxListener { 81 public views::ComboboxListener {
88 public: 82 public:
89 using TextFieldsMap = 83 using TextFieldsMap =
90 std::unordered_map<ValidatingTextfield*, const EditorField>; 84 std::unordered_map<ValidatingTextfield*, const EditorField>;
91 using ComboboxMap = 85 using ComboboxMap =
92 std::unordered_map<ValidatingCombobox*, const EditorField>; 86 std::unordered_map<ValidatingCombobox*, const EditorField>;
93 using ErrorLabelMap = 87 using ErrorLabelMap = std::map<autofill::ServerFieldType, views::View*>;
94 std::map<const EditorField, views::View*, EditorField::Compare>;
95 88
96 // Does not take ownership of the arguments, which should outlive this object. 89 // Does not take ownership of the arguments, which should outlive this object.
97 // |back_navigation_type| identifies what sort of back navigation should be 90 // |back_navigation_type| identifies what sort of back navigation should be
98 // done when editing is successful. This is independent of the back arrow 91 // done when editing is successful. This is independent of the back arrow
99 // which always goes back one step. 92 // which always goes back one step.
100 EditorViewController(PaymentRequestSpec* spec, 93 EditorViewController(PaymentRequestSpec* spec,
101 PaymentRequestState* state, 94 PaymentRequestState* state,
102 PaymentRequestDialogView* dialog, 95 PaymentRequestDialogView* dialog,
103 BackNavigationType back_navigation_type); 96 BackNavigationType back_navigation_type);
104 ~EditorViewController() override; 97 ~EditorViewController() override;
105 98
106 // Will display |error_message| alongside the input field represented by 99 // Will display |error_message| alongside the input field represented by
107 // |field|. 100 // field |type|.
108 void DisplayErrorMessageForField(const EditorField& field, 101 void DisplayErrorMessageForField(autofill::ServerFieldType type,
109 const base::string16& error_message); 102 const base::string16& error_message);
110 103
111 const ComboboxMap& comboboxes() const { return comboboxes_; } 104 const ComboboxMap& comboboxes() const { return comboboxes_; }
112 const TextFieldsMap& text_fields() const { return text_fields_; } 105 const TextFieldsMap& text_fields() const { return text_fields_; }
113 106
107 // Returns the View ID that can be used to lookup the input field for |type|.
108 static int GetInputFieldViewId(autofill::ServerFieldType type);
109
114 protected: 110 protected:
115 // Create a header view to be inserted before all fields. 111 // Create a header view to be inserted before all fields.
116 virtual std::unique_ptr<views::View> CreateHeaderView(); 112 virtual std::unique_ptr<views::View> CreateHeaderView();
117 // |focusable_field| is to be set with a pointer to the view that should get 113 // |focusable_field| is to be set with a pointer to the view that should get
118 // default focus within the custom view. 114 // default focus within the custom view. |valid| should be set to the initial
115 // validity state of the custom view.
119 virtual std::unique_ptr<views::View> CreateCustomFieldView( 116 virtual std::unique_ptr<views::View> CreateCustomFieldView(
120 autofill::ServerFieldType type, 117 autofill::ServerFieldType type,
121 views::View** focusable_field); 118 views::View** focusable_field,
119 bool* valid);
122 // Create an extra view to go to the right of the field with |type|, which 120 // Create an extra view to go to the right of the field with |type|, which
123 // can either be a textfield, combobox, or custom view. 121 // can either be a textfield, combobox, or custom view.
124 virtual std::unique_ptr<views::View> CreateExtraViewForField( 122 virtual std::unique_ptr<views::View> CreateExtraViewForField(
125 autofill::ServerFieldType type); 123 autofill::ServerFieldType type);
126 124
127 // Returns the field definitions used to build the UI. 125 // Returns the field definitions used to build the UI.
128 virtual std::vector<EditorField> GetFieldDefinitions() = 0; 126 virtual std::vector<EditorField> GetFieldDefinitions() = 0;
129 virtual base::string16 GetInitialValueForType( 127 virtual base::string16 GetInitialValueForType(
130 autofill::ServerFieldType type) = 0; 128 autofill::ServerFieldType type) = 0;
131 // Validates the data entered and attempts to save; returns true on success. 129 // Validates the data entered and attempts to save; returns true on success.
(...skipping 15 matching lines...) Expand all
147 // Update the editor view by removing all it's child views and recreating 145 // Update the editor view by removing all it's child views and recreating
148 // the input fields returned by GetFieldDefinitions. Note that 146 // the input fields returned by GetFieldDefinitions. Note that
149 // CreateEditorView MUST have been called at least once before calling 147 // CreateEditorView MUST have been called at least once before calling
150 // UpdateEditorView. 148 // UpdateEditorView.
151 virtual void UpdateEditorView(); 149 virtual void UpdateEditorView();
152 150
153 // PaymentRequestSheetController: 151 // PaymentRequestSheetController:
154 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 152 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
155 views::View* GetFirstFocusedView() override; 153 views::View* GetFirstFocusedView() override;
156 154
155 // Will create a combobox according to the |field| definition. Will also keep
156 // track of this field to populate the edited model on save.
157 std::unique_ptr<ValidatingCombobox> CreateComboboxForField(
158 const EditorField& field);
159
157 private: 160 private:
158 // views::TextfieldController: 161 // views::TextfieldController:
159 void ContentsChanged(views::Textfield* sender, 162 void ContentsChanged(views::Textfield* sender,
160 const base::string16& new_contents) override; 163 const base::string16& new_contents) override;
161 164
162 // Creates the whole editor view to go within the editor dialog. It 165 // Creates the whole editor view to go within the editor dialog. It
163 // encompasses all the input fields created by CreateInputField(). 166 // encompasses all the input fields created by CreateInputField().
164 std::unique_ptr<views::View> CreateEditorView(); 167 std::unique_ptr<views::View> CreateEditorView();
165 168
166 // Adds some views to |layout|, to represent an input field and its labels. 169 // Adds some views to |layout|, to represent an input field and its labels.
(...skipping 24 matching lines...) Expand all
191 194
192 // Identifies where to go back when the editing completes successfully. 195 // Identifies where to go back when the editing completes successfully.
193 BackNavigationType back_navigation_type_; 196 BackNavigationType back_navigation_type_;
194 197
195 DISALLOW_COPY_AND_ASSIGN(EditorViewController); 198 DISALLOW_COPY_AND_ASSIGN(EditorViewController);
196 }; 199 };
197 200
198 } // namespace payments 201 } // namespace payments
199 202
200 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ 203 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698