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

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

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 #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"
24 #include "ui/views/controls/combobox/combobox.h"
22 #include "ui/views/controls/label.h" 25 #include "ui/views/controls/label.h"
23 #include "ui/views/controls/styled_label.h" 26 #include "ui/views/controls/styled_label.h"
24 #include "ui/views/controls/textfield/textfield.h" 27 #include "ui/views/controls/textfield/textfield.h"
25 #include "ui/views/layout/box_layout.h" 28 #include "ui/views/layout/box_layout.h"
26 #include "ui/views/layout/grid_layout.h" 29 #include "ui/views/layout/grid_layout.h"
27 #include "ui/views/view.h" 30 #include "ui/views/view.h"
28 31
29 namespace payments { 32 namespace payments {
30 namespace { 33 namespace {
31 34
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 PaymentRequestSheetController::ButtonPressed(sender, event); 96 PaymentRequestSheetController::ButtonPressed(sender, event);
94 break; 97 break;
95 } 98 }
96 } 99 }
97 100
98 void EditorViewController::ContentsChanged(views::Textfield* sender, 101 void EditorViewController::ContentsChanged(views::Textfield* sender,
99 const base::string16& new_contents) { 102 const base::string16& new_contents) {
100 static_cast<ValidatingTextfield*>(sender)->OnContentsChanged(); 103 static_cast<ValidatingTextfield*>(sender)->OnContentsChanged();
101 } 104 }
102 105
106 void EditorViewController::OnPerformAction(views::Combobox* sender) {
107 static_cast<ValidatingCombobox*>(sender)->OnContentsChanged();
108 }
109
103 std::unique_ptr<views::View> EditorViewController::CreateInputField( 110 std::unique_ptr<views::View> EditorViewController::CreateInputField(
104 const EditorField& field) { 111 const EditorField& field) {
105 std::unique_ptr<views::View> row = base::MakeUnique<views::View>(); 112 std::unique_ptr<views::View> row = base::MakeUnique<views::View>();
106 113
107 row->SetBorder(payments::CreatePaymentRequestRowBorder()); 114 row->SetBorder(payments::CreatePaymentRequestRowBorder());
108 115
109 views::GridLayout* layout = new views::GridLayout(row.get()); 116 views::GridLayout* layout = new views::GridLayout(row.get());
110 117
111 // The vertical spacing for these rows is slightly different than the spacing 118 // The vertical spacing for these rows is slightly different than the spacing
112 // spacing for clickable rows, so don't use kPaymentRequestRowVerticalInsets. 119 // spacing for clickable rows, so don't use kPaymentRequestRowVerticalInsets.
113 constexpr int kRowVerticalInset = 12; 120 constexpr int kRowVerticalInset = 12;
114 layout->SetInsets( 121 layout->SetInsets(
115 kRowVerticalInset, payments::kPaymentRequestRowHorizontalInsets, 122 kRowVerticalInset, payments::kPaymentRequestRowHorizontalInsets,
116 kRowVerticalInset, payments::kPaymentRequestRowHorizontalInsets); 123 kRowVerticalInset, payments::kPaymentRequestRowHorizontalInsets);
117 124
118 row->SetLayoutManager(layout); 125 row->SetLayoutManager(layout);
119 views::ColumnSet* columns = layout->AddColumnSet(0); 126 views::ColumnSet* columns = layout->AddColumnSet(0);
120 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, 127 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
121 views::GridLayout::USE_PREF, 0, 0); 128 views::GridLayout::USE_PREF, 0, 0);
122 columns->AddPaddingColumn(1, 0); 129 columns->AddPaddingColumn(1, 0);
123 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, 130 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0,
124 views::GridLayout::USE_PREF, 0, 0); 131 views::GridLayout::USE_PREF, 0, 0);
125 132
126 layout->StartRow(0, 0); 133 layout->StartRow(0, 0);
127 layout->AddView(new views::Label(field.label)); 134 layout->AddView(new views::Label(field.label));
128 135
129 ValidatingTextfield* text_field = 136 if (field.control_type == EditorField::ControlType::TEXTFIELD) {
130 new ValidatingTextfield(CreateValidationDelegate(field)); 137 ValidatingTextfield* text_field =
131 text_field->set_controller(this); 138 new ValidatingTextfield(CreateValidationDelegate(field));
132 // Using autofill field type as a view ID (for testing). 139 text_field->set_controller(this);
133 text_field->set_id(static_cast<int>(field.type)); 140 // Using autofill field type as a view ID (for testing).
134 text_field->set_default_width_in_chars( 141 text_field->set_id(static_cast<int>(field.type));
135 field.length_hint == EditorField::LengthHint::HINT_SHORT 142 text_field->set_default_width_in_chars(
136 ? kNumCharactersInShortField 143 field.length_hint == EditorField::LengthHint::HINT_SHORT
137 : kNumCharactersInLongField); 144 ? kNumCharactersInShortField
145 : kNumCharactersInLongField);
138 146
139 text_fields_.insert(std::make_pair(text_field, field)); 147 text_fields_.insert(std::make_pair(text_field, field));
140 // |text_field| will now be owned by the layout. 148 // |text_field| will now be owned by the layout.
141 layout->AddView(text_field); 149 layout->AddView(text_field);
150 } else if (field.control_type == EditorField::ControlType::COMBOBOX) {
151 views::Combobox* combobox = new ValidatingCombobox(
152 GetComboboxModelForType(field.type), CreateValidationDelegate(field));
153 // Using autofill field type as a view ID (for testing).
154 combobox->set_id(static_cast<int>(field.type));
155 combobox->set_listener(this);
156 layout->AddView(combobox);
157 } else {
158 NOTREACHED();
159 }
142 160
143 return row; 161 return row;
144 } 162 }
145 163
146 } // namespace payments 164 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698