OLD | NEW |
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 <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 views::View** focusable_field, | 123 views::View** focusable_field, |
124 bool* valid) { | 124 bool* valid) { |
125 return nullptr; | 125 return nullptr; |
126 } | 126 } |
127 | 127 |
128 std::unique_ptr<views::View> EditorViewController::CreateExtraViewForField( | 128 std::unique_ptr<views::View> EditorViewController::CreateExtraViewForField( |
129 autofill::ServerFieldType type) { | 129 autofill::ServerFieldType type) { |
130 return nullptr; | 130 return nullptr; |
131 } | 131 } |
132 | 132 |
| 133 bool EditorViewController::ValidateInputFields() { |
| 134 for (const auto& field : text_fields()) { |
| 135 if (!field.first->IsValid()) |
| 136 return false; |
| 137 } |
| 138 for (const auto& field : comboboxes()) { |
| 139 if (!field.first->IsValid()) |
| 140 return false; |
| 141 } |
| 142 return true; |
| 143 } |
| 144 |
133 std::unique_ptr<views::Button> EditorViewController::CreatePrimaryButton() { | 145 std::unique_ptr<views::Button> EditorViewController::CreatePrimaryButton() { |
134 std::unique_ptr<views::Button> button( | 146 std::unique_ptr<views::Button> button( |
135 views::MdTextButton::CreateSecondaryUiBlueButton( | 147 views::MdTextButton::CreateSecondaryUiBlueButton( |
136 this, l10n_util::GetStringUTF16(IDS_DONE))); | 148 this, l10n_util::GetStringUTF16(IDS_DONE))); |
137 button->set_tag(static_cast<int>(EditorViewControllerTags::SAVE_BUTTON)); | 149 button->set_tag(static_cast<int>(EditorViewControllerTags::SAVE_BUTTON)); |
138 button->set_id(static_cast<int>(DialogViewID::EDITOR_SAVE_BUTTON)); | 150 button->set_id(static_cast<int>(DialogViewID::EDITOR_SAVE_BUTTON)); |
139 return button; | 151 return button; |
140 } | 152 } |
141 | 153 |
142 void EditorViewController::FillContentView(views::View* content_view) { | 154 void EditorViewController::FillContentView(views::View* content_view) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 } | 214 } |
203 // Using autofill field type as a view ID. | 215 // Using autofill field type as a view ID. |
204 combobox->set_id(GetInputFieldViewId(field.type)); | 216 combobox->set_id(GetInputFieldViewId(field.type)); |
205 combobox->set_listener(this); | 217 combobox->set_listener(this); |
206 comboboxes_.insert(std::make_pair(combobox.get(), field)); | 218 comboboxes_.insert(std::make_pair(combobox.get(), field)); |
207 return combobox; | 219 return combobox; |
208 } | 220 } |
209 | 221 |
210 void EditorViewController::ContentsChanged(views::Textfield* sender, | 222 void EditorViewController::ContentsChanged(views::Textfield* sender, |
211 const base::string16& new_contents) { | 223 const base::string16& new_contents) { |
212 static_cast<ValidatingTextfield*>(sender)->OnContentsChanged(); | 224 ValidatingTextfield* sender_cast = static_cast<ValidatingTextfield*>(sender); |
| 225 sender_cast->OnContentsChanged(); |
| 226 primary_button()->SetEnabled(ValidateInputFields()); |
213 } | 227 } |
214 | 228 |
215 void EditorViewController::OnPerformAction(views::Combobox* sender) { | 229 void EditorViewController::OnPerformAction(views::Combobox* sender) { |
216 static_cast<ValidatingCombobox*>(sender)->OnContentsChanged(); | 230 ValidatingCombobox* sender_cast = static_cast<ValidatingCombobox*>(sender); |
| 231 sender_cast->OnContentsChanged(); |
| 232 primary_button()->SetEnabled(ValidateInputFields()); |
217 } | 233 } |
218 | 234 |
219 std::unique_ptr<views::View> EditorViewController::CreateEditorView() { | 235 std::unique_ptr<views::View> EditorViewController::CreateEditorView() { |
220 std::unique_ptr<views::View> editor_view = base::MakeUnique<views::View>(); | 236 std::unique_ptr<views::View> editor_view = base::MakeUnique<views::View>(); |
221 text_fields_.clear(); | 237 text_fields_.clear(); |
222 comboboxes_.clear(); | 238 comboboxes_.clear(); |
223 initial_focus_field_view_ = nullptr; | 239 initial_focus_field_view_ = nullptr; |
224 | 240 |
225 // The editor view is padded horizontally. | 241 // The editor view is padded horizontally. |
226 editor_view->SetBorder(views::CreateEmptyBorder( | 242 editor_view->SetBorder(views::CreateEmptyBorder( |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 CreateInputField(editor_layout.get(), field, &valid); | 316 CreateInputField(editor_layout.get(), field, &valid); |
301 if (!first_field) | 317 if (!first_field) |
302 first_field = focusable_field; | 318 first_field = focusable_field; |
303 if (!initial_focus_field_view_ && !valid) | 319 if (!initial_focus_field_view_ && !valid) |
304 initial_focus_field_view_ = focusable_field; | 320 initial_focus_field_view_ = focusable_field; |
305 } | 321 } |
306 | 322 |
307 if (!initial_focus_field_view_) | 323 if (!initial_focus_field_view_) |
308 initial_focus_field_view_ = first_field; | 324 initial_focus_field_view_ = first_field; |
309 | 325 |
| 326 // Validate all fields and disable the primary (Done) button if necessary. |
| 327 primary_button()->SetEnabled(ValidateInputFields()); |
| 328 |
310 // Adds the "* indicates a required field" label in "disabled" grey text. | 329 // Adds the "* indicates a required field" label in "disabled" grey text. |
311 std::unique_ptr<views::Label> required_field = base::MakeUnique<views::Label>( | 330 std::unique_ptr<views::Label> required_field = base::MakeUnique<views::Label>( |
312 l10n_util::GetStringUTF16(IDS_PAYMENTS_REQUIRED_FIELD_MESSAGE)); | 331 l10n_util::GetStringUTF16(IDS_PAYMENTS_REQUIRED_FIELD_MESSAGE)); |
313 required_field->SetDisabledColor( | 332 required_field->SetDisabledColor( |
314 required_field->GetNativeTheme()->GetSystemColor( | 333 required_field->GetNativeTheme()->GetSystemColor( |
315 ui::NativeTheme::kColorId_LabelDisabledColor)); | 334 ui::NativeTheme::kColorId_LabelDisabledColor)); |
316 required_field->SetEnabled(false); | 335 required_field->SetEnabled(false); |
317 | 336 |
318 views::ColumnSet* required_field_columns = editor_layout->AddColumnSet(2); | 337 views::ColumnSet* required_field_columns = editor_layout->AddColumnSet(2); |
319 required_field_columns->AddColumn(views::GridLayout::LEADING, | 338 required_field_columns->AddColumn(views::GridLayout::LEADING, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 CreateExtraViewForField(field.type); | 461 CreateExtraViewForField(field.type); |
443 if (!extra_view) | 462 if (!extra_view) |
444 continue; | 463 continue; |
445 widest_column_width = | 464 widest_column_width = |
446 std::max(extra_view->GetPreferredSize().width(), widest_column_width); | 465 std::max(extra_view->GetPreferredSize().width(), widest_column_width); |
447 } | 466 } |
448 return widest_column_width; | 467 return widest_column_width; |
449 } | 468 } |
450 | 469 |
451 } // namespace payments | 470 } // namespace payments |
OLD | NEW |