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

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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 base::string16 label, 50 base::string16 label,
51 LengthHint length_hint, 51 LengthHint length_hint,
52 bool required, 52 bool required,
53 ControlType control_type = ControlType::TEXTFIELD) 53 ControlType control_type = ControlType::TEXTFIELD)
54 : type(type), 54 : type(type),
55 label(std::move(label)), 55 label(std::move(label)),
56 length_hint(length_hint), 56 length_hint(length_hint),
57 required(required), 57 required(required),
58 control_type(control_type) {} 58 control_type(control_type) {}
59 59
60 struct Compare {
61 bool operator()(const EditorField& lhs, const EditorField& rhs) const {
62 return std::tie(lhs.type, lhs.label) < std::tie(rhs.type, rhs.label);
63 }
64 };
65
66 // Data type in the field. 60 // Data type in the field.
67 autofill::ServerFieldType type; 61 autofill::ServerFieldType type;
68 // Label to be shown alongside the field. 62 // Label to be shown alongside the field.
69 base::string16 label; 63 base::string16 label;
70 // Hint about the length of this field's contents. 64 // Hint about the length of this field's contents.
71 LengthHint length_hint; 65 LengthHint length_hint;
72 // Whether the field is required. 66 // Whether the field is required.
73 bool required; 67 bool required;
74 // The control type. 68 // The control type.
75 ControlType control_type; 69 ControlType control_type;
76 }; 70 };
77 71
78 // The PaymentRequestSheetController subtype for the editor screens of the 72 // The PaymentRequestSheetController subtype for the editor screens of the
79 // Payment Request flow. 73 // Payment Request flow.
80 class EditorViewController : public PaymentRequestSheetController, 74 class EditorViewController : public PaymentRequestSheetController,
81 public views::TextfieldController, 75 public views::TextfieldController,
82 public views::ComboboxListener { 76 public views::ComboboxListener {
83 public: 77 public:
84 using TextFieldsMap = 78 using TextFieldsMap =
85 std::unordered_map<ValidatingTextfield*, const EditorField>; 79 std::unordered_map<ValidatingTextfield*, const EditorField>;
86 using ComboboxMap = 80 using ComboboxMap =
87 std::unordered_map<ValidatingCombobox*, const EditorField>; 81 std::unordered_map<ValidatingCombobox*, const EditorField>;
88 using ErrorLabelMap = 82 using ErrorLabelMap = std::map<autofill::ServerFieldType, views::View*>;
89 std::map<const EditorField, views::View*, EditorField::Compare>;
90 83
91 // Does not take ownership of the arguments, which should outlive this object. 84 // Does not take ownership of the arguments, which should outlive this object.
92 // |back_navigation_type| identifies what sort of back navigation should be 85 // |back_navigation_type| identifies what sort of back navigation should be
93 // done when editing is successful. This is independent of the back arrow 86 // done when editing is successful. This is independent of the back arrow
94 // which always goes back one step. 87 // which always goes back one step.
95 EditorViewController(PaymentRequestSpec* spec, 88 EditorViewController(PaymentRequestSpec* spec,
96 PaymentRequestState* state, 89 PaymentRequestState* state,
97 PaymentRequestDialogView* dialog, 90 PaymentRequestDialogView* dialog,
98 BackNavigationType back_navigation_type); 91 BackNavigationType back_navigation_type);
99 ~EditorViewController() override; 92 ~EditorViewController() override;
100 93
101 // Will display |error_message| alongside the input field represented by 94 // Will display |error_message| alongside the input field represented by
102 // |field|. 95 // field |type|.
103 void DisplayErrorMessageForField(const EditorField& field, 96 void DisplayErrorMessageForField(autofill::ServerFieldType type,
104 const base::string16& error_message); 97 const base::string16& error_message);
105 98
106 const ComboboxMap& comboboxes() const { return comboboxes_; } 99 const ComboboxMap& comboboxes() const { return comboboxes_; }
107 const TextFieldsMap& text_fields() const { return text_fields_; } 100 const TextFieldsMap& text_fields() const { return text_fields_; }
108 101
102 // Returns the View ID that can be used to lookup the input field for |type|.
103 static int GetInputFieldViewId(autofill::ServerFieldType type);
104
109 protected: 105 protected:
110 // Create a header view to be inserted before all fields. 106 // Create a header view to be inserted before all fields.
111 virtual std::unique_ptr<views::View> CreateHeaderView(); 107 virtual std::unique_ptr<views::View> CreateHeaderView();
112 // Create a custom view for the specified |type|. 108 // Create a custom view for the specified |type|.
113 virtual std::unique_ptr<views::View> CreateCustomFieldView( 109 virtual std::unique_ptr<views::View> CreateCustomFieldView(
114 autofill::ServerFieldType type); 110 autofill::ServerFieldType type);
115 // Create an extra view to go to the right of the field with |type|, which 111 // Create an extra view to go to the right of the field with |type|, which
116 // can either be a textfield, combobox, or custom view. 112 // can either be a textfield, combobox, or custom view.
117 virtual std::unique_ptr<views::View> CreateExtraViewForField( 113 virtual std::unique_ptr<views::View> CreateExtraViewForField(
118 autofill::ServerFieldType type); 114 autofill::ServerFieldType type);
(...skipping 21 matching lines...) Expand all
140 // Update the editor view by removing all it's child views and recreating 136 // Update the editor view by removing all it's child views and recreating
141 // the input fields returned by GetFieldDefinitions. Note that 137 // the input fields returned by GetFieldDefinitions. Note that
142 // CreateEditorView MUST have been called at least once before calling 138 // CreateEditorView MUST have been called at least once before calling
143 // UpdateEditorView. 139 // UpdateEditorView.
144 virtual void UpdateEditorView(); 140 virtual void UpdateEditorView();
145 141
146 // PaymentRequestSheetController: 142 // PaymentRequestSheetController:
147 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 143 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
148 views::View* GetFirstFocusedView() override; 144 views::View* GetFirstFocusedView() override;
149 145
146 // Will create a combobox according to the |field| definition. Will also keep
147 // track of this field to populate the edited model on save.
148 std::unique_ptr<ValidatingCombobox> CreateComboboxForField(
149 const EditorField& field);
150
150 private: 151 private:
151 // views::TextfieldController: 152 // views::TextfieldController:
152 void ContentsChanged(views::Textfield* sender, 153 void ContentsChanged(views::Textfield* sender,
153 const base::string16& new_contents) override; 154 const base::string16& new_contents) override;
154 155
155 // Creates the whole editor view to go within the editor dialog. It 156 // Creates the whole editor view to go within the editor dialog. It
156 // encompasses all the input fields created by CreateInputField(). 157 // encompasses all the input fields created by CreateInputField().
157 std::unique_ptr<views::View> CreateEditorView(); 158 std::unique_ptr<views::View> CreateEditorView();
158 159
159 // Adds some views to |layout|, to represent an input field and its labels. 160 // Adds some views to |layout|, to represent an input field and its labels.
(...skipping 20 matching lines...) Expand all
180 181
181 // Identifies where to go back when the editing completes successfully. 182 // Identifies where to go back when the editing completes successfully.
182 BackNavigationType back_navigation_type_; 183 BackNavigationType back_navigation_type_;
183 184
184 DISALLOW_COPY_AND_ASSIGN(EditorViewController); 185 DISALLOW_COPY_AND_ASSIGN(EditorViewController);
185 }; 186 };
186 187
187 } // namespace payments 188 } // namespace payments
188 189
189 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ 190 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698