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

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

Issue 2689363004: [Payments] Add combobox support to editors. (Closed)
Patch Set: re-enable test, addressed comments 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 #include "chrome/browser/ui/views/payments/editor_view_controller.h" 5 #include "chrome/browser/ui/views/payments/editor_view_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" 12 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
14 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 14 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
15 #include "chrome/browser/ui/views/payments/validating_combobox.h"
16 #include "chrome/browser/ui/views/payments/validating_textfield.h"
15 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
16 #include "components/payments/payment_request.h" 18 #include "components/payments/payment_request.h"
17 #include "components/strings/grit/components_strings.h" 19 #include "components/strings/grit/components_strings.h"
18 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/views/border.h" 21 #include "ui/views/border.h"
20 #include "ui/views/controls/button/label_button.h" 22 #include "ui/views/controls/button/label_button.h"
21 #include "ui/views/controls/button/md_text_button.h" 23 #include "ui/views/controls/button/md_text_button.h"
22 #include "ui/views/controls/label.h" 24 #include "ui/views/controls/label.h"
23 #include "ui/views/controls/styled_label.h" 25 #include "ui/views/controls/styled_label.h"
24 #include "ui/views/controls/textfield/textfield.h" 26 #include "ui/views/controls/textfield/textfield.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 PaymentRequestSheetController::ButtonPressed(sender, event); 95 PaymentRequestSheetController::ButtonPressed(sender, event);
94 break; 96 break;
95 } 97 }
96 } 98 }
97 99
98 void EditorViewController::ContentsChanged(views::Textfield* sender, 100 void EditorViewController::ContentsChanged(views::Textfield* sender,
99 const base::string16& new_contents) { 101 const base::string16& new_contents) {
100 static_cast<ValidatingTextfield*>(sender)->OnContentsChanged(); 102 static_cast<ValidatingTextfield*>(sender)->OnContentsChanged();
101 } 103 }
102 104
105 void EditorViewController::OnPerformAction(views::Combobox* sender) {
106 static_cast<ValidatingCombobox*>(sender)->OnContentsChanged();
107 }
108
103 std::unique_ptr<views::View> EditorViewController::CreateInputField( 109 std::unique_ptr<views::View> EditorViewController::CreateInputField(
104 const EditorField& field) { 110 const EditorField& field) {
105 std::unique_ptr<views::View> row = base::MakeUnique<views::View>(); 111 std::unique_ptr<views::View> row = base::MakeUnique<views::View>();
106 112
107 row->SetBorder(payments::CreatePaymentRequestRowBorder()); 113 row->SetBorder(payments::CreatePaymentRequestRowBorder());
108 114
109 views::GridLayout* layout = new views::GridLayout(row.get()); 115 views::GridLayout* layout = new views::GridLayout(row.get());
110 116
111 // The vertical spacing for these rows is slightly different than the spacing 117 // The vertical spacing for these rows is slightly different than the spacing
112 // spacing for clickable rows, so don't use kPaymentRequestRowVerticalInsets. 118 // spacing for clickable rows, so don't use kPaymentRequestRowVerticalInsets.
113 constexpr int kRowVerticalInset = 12; 119 constexpr int kRowVerticalInset = 12;
114 layout->SetInsets( 120 layout->SetInsets(
115 kRowVerticalInset, payments::kPaymentRequestRowHorizontalInsets, 121 kRowVerticalInset, payments::kPaymentRequestRowHorizontalInsets,
116 kRowVerticalInset, payments::kPaymentRequestRowHorizontalInsets); 122 kRowVerticalInset, payments::kPaymentRequestRowHorizontalInsets);
117 123
118 row->SetLayoutManager(layout); 124 row->SetLayoutManager(layout);
119 views::ColumnSet* columns = layout->AddColumnSet(0); 125 views::ColumnSet* columns = layout->AddColumnSet(0);
120 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, 126 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
121 views::GridLayout::USE_PREF, 0, 0); 127 views::GridLayout::USE_PREF, 0, 0);
122 columns->AddPaddingColumn(1, 0); 128 columns->AddPaddingColumn(1, 0);
123 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, 129 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0,
124 views::GridLayout::USE_PREF, 0, 0); 130 views::GridLayout::USE_PREF, 0, 0);
125 131
126 layout->StartRow(0, 0); 132 layout->StartRow(0, 0);
127 layout->AddView(new views::Label(field.label)); 133 layout->AddView(new views::Label(field.label));
128 134
129 ValidatingTextfield* text_field = 135 if (field.control_type == EditorField::ControlType::TEXTFIELD) {
130 new ValidatingTextfield(CreateValidationDelegate(field)); 136 ValidatingTextfield* text_field =
131 text_field->set_controller(this); 137 new ValidatingTextfield(CreateValidationDelegate(field));
132 // Using autofill field type as a view ID (for testing). 138 text_field->set_controller(this);
133 text_field->set_id(static_cast<int>(field.type)); 139 // Using autofill field type as a view ID (for testing).
134 text_field->set_default_width_in_chars( 140 text_field->set_id(static_cast<int>(field.type));
135 field.length_hint == EditorField::LengthHint::HINT_SHORT 141 text_field->set_default_width_in_chars(
136 ? kNumCharactersInShortField 142 field.length_hint == EditorField::LengthHint::HINT_SHORT
137 : kNumCharactersInLongField); 143 ? kNumCharactersInShortField
144 : kNumCharactersInLongField);
138 145
139 text_fields_.insert(std::make_pair(text_field, field)); 146 text_fields_.insert(std::make_pair(text_field, field));
140 // |text_field| will now be owned by the layout. 147 // |text_field| will now be owned by |row|.
141 layout->AddView(text_field); 148 layout->AddView(text_field);
149 } else if (field.control_type == EditorField::ControlType::COMBOBOX) {
150 ValidatingCombobox* combobox = new ValidatingCombobox(
151 GetComboboxModelForType(field.type), CreateValidationDelegate(field));
152 // Using autofill field type as a view ID (for testing).
153 combobox->set_id(static_cast<int>(field.type));
154 combobox->set_listener(this);
155 comboboxes_.insert(std::make_pair(combobox, field));
156 // |combobox| will now be owned by |row|.
157 layout->AddView(combobox);
158 } else {
159 NOTREACHED();
160 }
142 161
143 return row; 162 return row;
144 } 163 }
145 164
146 } // namespace payments 165 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698