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

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

Issue 2689363004: [Payments] Add combobox support to editors. (Closed)
Patch Set: Initial Created 3 years, 10 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 <memory> 8 #include <memory>
9 #include <unordered_map> 9 #include <unordered_map>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" 15 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h"
16 #include "chrome/browser/ui/views/payments/validating_textfield.h" 16 #include "chrome/browser/ui/views/payments/validation_delegate.h"
17 #include "components/autofill/core/browser/field_types.h" 17 #include "components/autofill/core/browser/field_types.h"
18 #include "ui/views/controls/button/vector_icon_button_delegate.h" 18 #include "ui/views/controls/button/vector_icon_button_delegate.h"
19 #include "ui/views/controls/combobox/combobox_listener.h"
19 #include "ui/views/controls/textfield/textfield_controller.h" 20 #include "ui/views/controls/textfield/textfield_controller.h"
20 21
22 namespace ui {
23 class ComboboxModel;
24 }
25
21 namespace views { 26 namespace views {
22 class Textfield; 27 class Textfield;
23 class View; 28 class View;
24 } // namespace views 29 } // namespace views
25 30
26 namespace payments { 31 namespace payments {
27 32
28 class PaymentRequest; 33 class PaymentRequest;
29 class PaymentRequestDialogView; 34 class PaymentRequestDialogView;
35 class ValidatingTextfield;
30 36
31 // Field definition for an editor field, used to build the UI. 37 // Field definition for an editor field, used to build the UI.
32 struct EditorField { 38 struct EditorField {
33 enum class LengthHint : int { HINT_LONG, HINT_SHORT }; 39 enum class LengthHint : int { HINT_LONG, HINT_SHORT };
40 enum class ControlType : int { TEXTFIELD, COMBOBOX };
34 41
35 EditorField(autofill::ServerFieldType type, 42 EditorField(autofill::ServerFieldType type,
36 const base::string16& label, 43 const base::string16& label,
37 LengthHint length_hint, 44 LengthHint length_hint,
38 bool required) 45 bool required,
46 ControlType control_type = ControlType::TEXTFIELD)
39 : type(type), 47 : type(type),
40 label(label), 48 label(label),
41 length_hint(length_hint), 49 length_hint(length_hint),
42 required(required) {} 50 required(required),
51 control_type(control_type) {}
43 52
44 // Data type in the field. 53 // Data type in the field.
45 const autofill::ServerFieldType type; 54 const autofill::ServerFieldType type;
46 // Label to be shown alongside the field. 55 // Label to be shown alongside the field.
47 const base::string16 label; 56 const base::string16 label;
48 // Hint about the length of this field's contents. 57 // Hint about the length of this field's contents.
49 LengthHint length_hint; 58 LengthHint length_hint;
50 // Whether the field is required. 59 // Whether the field is required.
51 bool required; 60 bool required;
61 // The control type.
62 ControlType control_type;
52 }; 63 };
53 64
54 // The PaymentRequestSheetController subtype for the editor screens of the 65 // The PaymentRequestSheetController subtype for the editor screens of the
55 // Payment Request flow. 66 // Payment Request flow.
56 class EditorViewController : public PaymentRequestSheetController, 67 class EditorViewController : public PaymentRequestSheetController,
57 public views::TextfieldController { 68 public views::TextfieldController,
69 public views::ComboboxListener {
58 public: 70 public:
59 using TextFieldsMap = 71 using TextFieldsMap =
60 std::unordered_map<ValidatingTextfield*, const EditorField>; 72 std::unordered_map<ValidatingTextfield*, const EditorField>;
61 73
62 // Does not take ownership of the arguments, which should outlive this object. 74 // Does not take ownership of the arguments, which should outlive this object.
63 EditorViewController(PaymentRequest* request, 75 EditorViewController(PaymentRequest* request,
64 PaymentRequestDialogView* dialog); 76 PaymentRequestDialogView* dialog);
65 ~EditorViewController() override; 77 ~EditorViewController() override;
66 78
67 // PaymentRequestSheetController: 79 // PaymentRequestSheetController:
68 std::unique_ptr<views::View> CreateView() override; 80 std::unique_ptr<views::View> CreateView() override;
69 81
70 // Returns the field definitions used to build the UI. 82 // Returns the field definitions used to build the UI.
71 virtual std::vector<EditorField> GetFieldDefinitions() = 0; 83 virtual std::vector<EditorField> GetFieldDefinitions() = 0;
72 // Validates the data entered and attempts to save; returns true on success. 84 // Validates the data entered and attempts to save; returns true on success.
73 virtual bool ValidateModelAndSave() = 0; 85 virtual bool ValidateModelAndSave() = 0;
74 // Creates a ValidatingTextfield::Delegate which knows how to validate for a 86 // Creates a ValidationDelegate which knows how to validate for a given
75 // given |field| definition. 87 // |field| definition.
76 virtual std::unique_ptr<ValidatingTextfield::Delegate> 88 virtual std::unique_ptr<ValidationDelegate> CreateValidationDelegate(
77 CreateValidationDelegate(const EditorField& field) = 0; 89 const EditorField& field) = 0;
90 virtual ui::ComboboxModel* GetComboboxModelForType(
91 const autofill::ServerFieldType& type) = 0;
78 92
79 const TextFieldsMap& text_fields() const { return text_fields_; } 93 const TextFieldsMap& text_fields() const { return text_fields_; }
80 94
81 protected: 95 protected:
82 // PaymentRequestSheetController; 96 // PaymentRequestSheetController;
83 std::unique_ptr<views::Button> CreatePrimaryButton() override; 97 std::unique_ptr<views::Button> CreatePrimaryButton() override;
84 98
85 private: 99 private:
86 // PaymentRequestSheetController: 100 // PaymentRequestSheetController:
87 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 101 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
88 102
89 // views::TextfieldController 103 // views::TextfieldController:
90 void ContentsChanged(views::Textfield* sender, 104 void ContentsChanged(views::Textfield* sender,
91 const base::string16& new_contents) override; 105 const base::string16& new_contents) override;
92 106
107 // views::ComboboxListener:
108 void OnPerformAction(views::Combobox* combobox) override;
109
93 // Creates a view for an input field to be added in the editor sheet. |field| 110 // Creates a view for an input field to be added in the editor sheet. |field|
94 // is the field definition, which contains the label and the hint about 111 // is the field definition, which contains the label and the hint about
95 // the length of the input field. 112 // the length of the input field.
96 std::unique_ptr<views::View> CreateInputField(const EditorField& field); 113 std::unique_ptr<views::View> CreateInputField(const EditorField& field);
97 114
98 // Used to remember the association between the input field UI element and the 115 // Used to remember the association between the input field UI element and the
99 // original field definition. The ValidatingTextfield* are owned by their 116 // original field definition. The ValidatingTextfield* are owned by their
100 // parent view, this only keeps a reference that is good as long as the 117 // parent view, this only keeps a reference that is good as long as the
101 // textfield is visible. 118 // textfield is visible.
102 TextFieldsMap text_fields_; 119 TextFieldsMap text_fields_;
103 120
104 DISALLOW_COPY_AND_ASSIGN(EditorViewController); 121 DISALLOW_COPY_AND_ASSIGN(EditorViewController);
105 }; 122 };
106 123
107 } // namespace payments 124 } // namespace payments
108 125
109 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ 126 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698