| 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 <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 EditorViewController::EditorViewController(PaymentRequestSpec* spec, | 49 EditorViewController::EditorViewController(PaymentRequestSpec* spec, |
| 50 PaymentRequestState* state, | 50 PaymentRequestState* state, |
| 51 PaymentRequestDialogView* dialog) | 51 PaymentRequestDialogView* dialog) |
| 52 : PaymentRequestSheetController(spec, state, dialog) {} | 52 : PaymentRequestSheetController(spec, state, dialog) {} |
| 53 | 53 |
| 54 EditorViewController::~EditorViewController() {} | 54 EditorViewController::~EditorViewController() {} |
| 55 | 55 |
| 56 std::unique_ptr<views::View> EditorViewController::CreateView() { | |
| 57 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | |
| 58 | |
| 59 views::BoxLayout* layout = | |
| 60 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | |
| 61 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | |
| 62 layout->set_cross_axis_alignment( | |
| 63 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); | |
| 64 content_view->SetLayoutManager(layout); | |
| 65 // No insets. Child views below are responsible for their padding. | |
| 66 | |
| 67 // An editor can optionally have a header view specific to it. | |
| 68 content_view->AddChildView(CreateHeaderView().release()); | |
| 69 | |
| 70 // The heart of the editor dialog: all the input fields with their labels. | |
| 71 content_view->AddChildView(CreateEditorView().release()); | |
| 72 | |
| 73 return CreatePaymentView( | |
| 74 CreateSheetHeaderView( | |
| 75 true, l10n_util::GetStringUTF16(GetViewHeaderTitleId()), this), | |
| 76 std::move(content_view)); | |
| 77 } | |
| 78 | |
| 79 void EditorViewController::DisplayErrorMessageForField( | 56 void EditorViewController::DisplayErrorMessageForField( |
| 80 const EditorField& field, | 57 const EditorField& field, |
| 81 const base::string16& error_message) { | 58 const base::string16& error_message) { |
| 82 const auto& label_it = error_labels_.find(field); | 59 const auto& label_it = error_labels_.find(field); |
| 83 DCHECK(label_it != error_labels_.end()); | 60 DCHECK(label_it != error_labels_.end()); |
| 84 label_it->second->SetText(error_message); | 61 label_it->second->SetText(error_message); |
| 85 label_it->second->SchedulePaint(); | 62 label_it->second->SchedulePaint(); |
| 86 dialog()->Layout(); | 63 dialog()->Layout(); |
| 87 } | 64 } |
| 88 | 65 |
| 89 std::unique_ptr<views::Button> EditorViewController::CreatePrimaryButton() { | 66 std::unique_ptr<views::Button> EditorViewController::CreatePrimaryButton() { |
| 90 std::unique_ptr<views::Button> button( | 67 std::unique_ptr<views::Button> button( |
| 91 views::MdTextButton::CreateSecondaryUiBlueButton( | 68 views::MdTextButton::CreateSecondaryUiBlueButton( |
| 92 this, l10n_util::GetStringUTF16(IDS_DONE))); | 69 this, l10n_util::GetStringUTF16(IDS_DONE))); |
| 93 button->set_tag(static_cast<int>(EditorViewControllerTags::SAVE_BUTTON)); | 70 button->set_tag(static_cast<int>(EditorViewControllerTags::SAVE_BUTTON)); |
| 94 button->set_id(static_cast<int>(DialogViewID::EDITOR_SAVE_BUTTON)); | 71 button->set_id(static_cast<int>(DialogViewID::EDITOR_SAVE_BUTTON)); |
| 95 return button; | 72 return button; |
| 96 } | 73 } |
| 97 | 74 |
| 75 void EditorViewController::FillContentView(views::View* content_view) { |
| 76 views::BoxLayout* layout = |
| 77 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); |
| 78 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); |
| 79 layout->set_cross_axis_alignment( |
| 80 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); |
| 81 content_view->SetLayoutManager(layout); |
| 82 // No insets. Child views below are responsible for their padding. |
| 83 |
| 84 // An editor can optionally have a header view specific to it. |
| 85 content_view->AddChildView(CreateHeaderView().release()); |
| 86 |
| 87 // The heart of the editor dialog: all the input fields with their labels. |
| 88 content_view->AddChildView(CreateEditorView().release()); |
| 89 } |
| 90 |
| 98 // Adds the "required fields" label in disabled text, to obtain this result. | 91 // Adds the "required fields" label in disabled text, to obtain this result. |
| 99 // +---------------------------------------------------------+ | 92 // +---------------------------------------------------------+ |
| 100 // | "* indicates required fields" | CANCEL | DONE | | 93 // | "* indicates required fields" | CANCEL | DONE | |
| 101 // +---------------------------------------------------------+ | 94 // +---------------------------------------------------------+ |
| 102 std::unique_ptr<views::View> EditorViewController::CreateExtraFooterView() { | 95 std::unique_ptr<views::View> EditorViewController::CreateExtraFooterView() { |
| 103 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | 96 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); |
| 104 | 97 |
| 105 views::BoxLayout* layout = | 98 views::BoxLayout* layout = |
| 106 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 99 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
| 107 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | 100 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 error_label->SetFontList( | 227 error_label->SetFontList( |
| 235 error_label->GetDefaultFontList().DeriveWithSizeDelta(-1)); | 228 error_label->GetDefaultFontList().DeriveWithSizeDelta(-1)); |
| 236 error_label->SetEnabledColor(error_label->GetNativeTheme()->GetSystemColor( | 229 error_label->SetEnabledColor(error_label->GetNativeTheme()->GetSystemColor( |
| 237 ui::NativeTheme::kColorId_AlertSeverityHigh)); | 230 ui::NativeTheme::kColorId_AlertSeverityHigh)); |
| 238 error_labels_[field] = error_label.get(); | 231 error_labels_[field] = error_label.get(); |
| 239 | 232 |
| 240 layout->AddView(error_label.release()); | 233 layout->AddView(error_label.release()); |
| 241 } | 234 } |
| 242 | 235 |
| 243 } // namespace payments | 236 } // namespace payments |
| OLD | NEW |