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

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

Issue 2709093006: Adding new shipping address editor view to payment flow. (Closed)
Patch Set: CR comments 1 Created 3 years, 9 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 <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); 61 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
62 layout->set_cross_axis_alignment( 62 layout->set_cross_axis_alignment(
63 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); 63 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
64 content_view->SetLayoutManager(layout); 64 content_view->SetLayoutManager(layout);
65 // No insets. Child views below are responsible for their padding. 65 // No insets. Child views below are responsible for their padding.
66 66
67 // An editor can optionally have a header view specific to it. 67 // An editor can optionally have a header view specific to it.
68 content_view->AddChildView(CreateHeaderView().release()); 68 content_view->AddChildView(CreateHeaderView().release());
69 69
70 // The heart of the editor dialog: all the input fields with their labels. 70 // The heart of the editor dialog: all the input fields with their labels.
71 content_view->AddChildView(CreateEditorView().release()); 71 CreateEditorView();
72 content_view->AddChildView(editor_view_.get());
72 73
73 return CreatePaymentView( 74 return CreatePaymentView(
74 CreateSheetHeaderView( 75 CreateSheetHeaderView(
75 true, l10n_util::GetStringUTF16(GetViewHeaderTitleId()), this), 76 true, l10n_util::GetStringUTF16(GetViewHeaderTitleId()), this),
76 std::move(content_view)); 77 std::move(content_view));
77 } 78 }
78 79
79 void EditorViewController::DisplayErrorMessageForField( 80 void EditorViewController::DisplayErrorMessageForField(
80 const EditorField& field, 81 const EditorField& field,
81 const base::string16& error_message) { 82 const base::string16& error_message) {
(...skipping 30 matching lines...) Expand all
112 // Adds the "* indicates a required field" label in "disabled" grey text. 113 // Adds the "* indicates a required field" label in "disabled" grey text.
113 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( 114 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(
114 l10n_util::GetStringUTF16(IDS_PAYMENTS_REQUIRED_FIELD_MESSAGE)); 115 l10n_util::GetStringUTF16(IDS_PAYMENTS_REQUIRED_FIELD_MESSAGE));
115 label->SetDisabledColor(label->GetNativeTheme()->GetSystemColor( 116 label->SetDisabledColor(label->GetNativeTheme()->GetSystemColor(
116 ui::NativeTheme::kColorId_LabelDisabledColor)); 117 ui::NativeTheme::kColorId_LabelDisabledColor));
117 label->SetEnabled(false); 118 label->SetEnabled(false);
118 content_view->AddChildView(label.release()); 119 content_view->AddChildView(label.release());
119 return content_view; 120 return content_view;
120 } 121 }
121 122
122 void EditorViewController::ButtonPressed(views::Button* sender, 123 void EditorViewController::UpdateEditorView() {
123 const ui::Event& event) { 124 DCHECK_NE(nullptr, editor_view_.get());
124 switch (sender->tag()) { 125 text_fields_.clear();
125 case static_cast<int>(EditorViewControllerTags::SAVE_BUTTON): 126 comboboxes_.clear();
126 if (ValidateModelAndSave()) 127 editor_view_->RemoveAllChildViews(true);
127 dialog()->GoBack();
128 break;
129 default:
130 PaymentRequestSheetController::ButtonPressed(sender, event);
131 break;
132 }
133 }
134 128
135 void EditorViewController::ContentsChanged(views::Textfield* sender, 129 views::GridLayout* editor_layout = new views::GridLayout(editor_view_.get());
anthonyvd 2017/03/21 21:18:24 For consistency, this should be a unique_ptr creat
MAD 2017/03/22 20:15:42 Done.
136 const base::string16& new_contents) {
137 static_cast<ValidatingTextfield*>(sender)->OnContentsChanged();
138 }
139
140 void EditorViewController::OnPerformAction(views::Combobox* sender) {
141 static_cast<ValidatingCombobox*>(sender)->OnContentsChanged();
142 }
143
144 std::unique_ptr<views::View> EditorViewController::CreateEditorView() {
145 std::unique_ptr<views::View> editor_view = base::MakeUnique<views::View>();
146
147 views::GridLayout* editor_layout = new views::GridLayout(editor_view.get());
148 130
149 // The editor grid layout is padded vertically from the top and bottom, and 131 // The editor grid layout is padded vertically from the top and bottom, and
150 // horizontally inset like other content views. The top padding needs to be 132 // horizontally inset like other content views. The top padding needs to be
151 // added to the top padding of the first row. 133 // added to the top padding of the first row.
152 constexpr int kEditorVerticalInset = 16; 134 constexpr int kEditorVerticalInset = 16;
153 editor_layout->SetInsets( 135 editor_layout->SetInsets(
154 kEditorVerticalInset, payments::kPaymentRequestRowHorizontalInsets, 136 kEditorVerticalInset, payments::kPaymentRequestRowHorizontalInsets,
155 kEditorVerticalInset, payments::kPaymentRequestRowHorizontalInsets); 137 kEditorVerticalInset, payments::kPaymentRequestRowHorizontalInsets);
156 138
157 editor_view->SetLayoutManager(editor_layout); 139 editor_view_->SetLayoutManager(editor_layout);
158 views::ColumnSet* columns = editor_layout->AddColumnSet(0); 140 views::ColumnSet* columns = editor_layout->AddColumnSet(0);
159 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, 141 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
160 views::GridLayout::USE_PREF, 0, 0); 142 views::GridLayout::USE_PREF, 0, 0);
161 143
162 // This is the horizontal padding between the label and the input field. 144 // This is the horizontal padding between the label and the input field.
163 constexpr int kLabelInputFieldHorizontalPadding = 16; 145 constexpr int kLabelInputFieldHorizontalPadding = 16;
164 columns->AddPaddingColumn(0, kLabelInputFieldHorizontalPadding); 146 columns->AddPaddingColumn(0, kLabelInputFieldHorizontalPadding);
165 147
166 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, 148 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
167 views::GridLayout::USE_PREF, 0, 0); 149 views::GridLayout::USE_PREF, 0, 0);
168 150
169 std::vector<EditorField> fields = GetFieldDefinitions(); 151 std::vector<EditorField> fields = GetFieldDefinitions();
170 for (const auto& field : fields) { 152 for (const auto& field : fields) {
171 CreateInputField(editor_layout, field); 153 CreateInputField(editor_layout, field);
172 } 154 }
155 editor_view_->Layout();
156 // TODO(mad): Find how to update the view bounds so that the vertical
157 // scrollbar size gets updated.
158 }
173 159
174 return editor_view; 160 void EditorViewController::ButtonPressed(views::Button* sender,
161 const ui::Event& event) {
162 switch (sender->tag()) {
163 case static_cast<int>(EditorViewControllerTags::SAVE_BUTTON):
164 if (ValidateModelAndSave())
165 dialog()->GoBack();
166 break;
167 default:
168 PaymentRequestSheetController::ButtonPressed(sender, event);
169 break;
170 }
171 }
172
173 void EditorViewController::ContentsChanged(views::Textfield* sender,
174 const base::string16& new_contents) {
175 static_cast<ValidatingTextfield*>(sender)->OnContentsChanged();
176 }
177
178 void EditorViewController::OnPerformAction(views::Combobox* sender) {
179 static_cast<ValidatingCombobox*>(sender)->OnContentsChanged();
180 }
181
182 void EditorViewController::CreateEditorView() {
183 editor_view_ = base::MakeUnique<views::View>();
184 editor_view_->set_owned_by_client();
185
186 UpdateEditorView();
175 } 187 }
176 188
177 // Each input field is a 4-quadrant grid. 189 // Each input field is a 4-quadrant grid.
178 // +----------------------------------------------------------+ 190 // +----------------------------------------------------------+
179 // | Field Label | Input field (textfield/combobox) | 191 // | Field Label | Input field (textfield/combobox) |
180 // |_______________________|__________________________________| 192 // |_______________________|__________________________________|
181 // | (empty) | Error label | 193 // | (empty) | Error label |
182 // +----------------------------------------------------------+ 194 // +----------------------------------------------------------+
183 void EditorViewController::CreateInputField(views::GridLayout* layout, 195 void EditorViewController::CreateInputField(views::GridLayout* layout,
184 const EditorField& field) { 196 const EditorField& field) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 error_label->SetFontList( 246 error_label->SetFontList(
235 error_label->GetDefaultFontList().DeriveWithSizeDelta(-1)); 247 error_label->GetDefaultFontList().DeriveWithSizeDelta(-1));
236 error_label->SetEnabledColor(error_label->GetNativeTheme()->GetSystemColor( 248 error_label->SetEnabledColor(error_label->GetNativeTheme()->GetSystemColor(
237 ui::NativeTheme::kColorId_AlertSeverityHigh)); 249 ui::NativeTheme::kColorId_AlertSeverityHigh));
238 error_labels_[field] = error_label.get(); 250 error_labels_[field] = error_label.get();
239 251
240 layout->AddView(error_label.release()); 252 layout->AddView(error_label.release());
241 } 253 }
242 254
243 } // namespace payments 255 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698