| 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 <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" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 content_view->AddChildView(CreateEditorView().release()); | 70 content_view->AddChildView(CreateEditorView().release()); |
| 71 | 71 |
| 72 return CreatePaymentView( | 72 return CreatePaymentView( |
| 73 CreateSheetHeaderView( | 73 CreateSheetHeaderView( |
| 74 true, l10n_util::GetStringUTF16( | 74 true, l10n_util::GetStringUTF16( |
| 75 IDS_PAYMENT_REQUEST_CREDIT_CARD_EDITOR_ADD_TITLE), | 75 IDS_PAYMENT_REQUEST_CREDIT_CARD_EDITOR_ADD_TITLE), |
| 76 this), | 76 this), |
| 77 std::move(content_view)); | 77 std::move(content_view)); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void EditorViewController::DisplayErrorMessageForField( |
| 81 const EditorField& field, |
| 82 const base::string16& error_message) { |
| 83 const auto& label_it = error_labels_.find(field); |
| 84 DCHECK(label_it != error_labels_.end()); |
| 85 label_it->second->SetText(error_message); |
| 86 label_it->second->SchedulePaint(); |
| 87 dialog()->Layout(); |
| 88 } |
| 89 |
| 90 std::unique_ptr<views::Button> EditorViewController::CreatePrimaryButton() { |
| 91 std::unique_ptr<views::Button> button( |
| 92 views::MdTextButton::CreateSecondaryUiBlueButton( |
| 93 this, l10n_util::GetStringUTF16(IDS_DONE))); |
| 94 button->set_tag(static_cast<int>(EditorViewControllerTags::SAVE_BUTTON)); |
| 95 button->set_id(static_cast<int>(DialogViewID::EDITOR_SAVE_BUTTON)); |
| 96 return button; |
| 97 } |
| 98 |
| 80 // Adds the "required fields" label in disabled text, to obtain this result. | 99 // Adds the "required fields" label in disabled text, to obtain this result. |
| 81 // +---------------------------------------------------------+ | 100 // +---------------------------------------------------------+ |
| 82 // | "* indicates required fields" | CANCEL | DONE | | 101 // | "* indicates required fields" | CANCEL | DONE | |
| 83 // +---------------------------------------------------------+ | 102 // +---------------------------------------------------------+ |
| 84 std::unique_ptr<views::View> EditorViewController::CreateExtraFooterView() { | 103 std::unique_ptr<views::View> EditorViewController::CreateExtraFooterView() { |
| 85 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | 104 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); |
| 86 | 105 |
| 87 views::BoxLayout* layout = | 106 views::BoxLayout* layout = |
| 88 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 107 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
| 89 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | 108 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); |
| 90 layout->set_cross_axis_alignment( | 109 layout->set_cross_axis_alignment( |
| 91 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | 110 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); |
| 92 content_view->SetLayoutManager(layout); | 111 content_view->SetLayoutManager(layout); |
| 93 | 112 |
| 94 // Adds the "* indicates a required field" label in "disabled" grey text. | 113 // Adds the "* indicates a required field" label in "disabled" grey text. |
| 95 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( | 114 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( |
| 96 l10n_util::GetStringUTF16(IDS_PAYMENTS_REQUIRED_FIELD_MESSAGE)); | 115 l10n_util::GetStringUTF16(IDS_PAYMENTS_REQUIRED_FIELD_MESSAGE)); |
| 97 label->SetDisabledColor(label->GetNativeTheme()->GetSystemColor( | 116 label->SetDisabledColor(label->GetNativeTheme()->GetSystemColor( |
| 98 ui::NativeTheme::kColorId_LabelDisabledColor)); | 117 ui::NativeTheme::kColorId_LabelDisabledColor)); |
| 99 label->SetEnabled(false); | 118 label->SetEnabled(false); |
| 100 content_view->AddChildView(label.release()); | 119 content_view->AddChildView(label.release()); |
| 101 return content_view; | 120 return content_view; |
| 102 } | 121 } |
| 103 | 122 |
| 104 void EditorViewController::DisplayErrorMessageForField( | |
| 105 const EditorField& field, | |
| 106 const base::string16& error_message) { | |
| 107 const auto& label_it = error_labels_.find(field); | |
| 108 DCHECK(label_it != error_labels_.end()); | |
| 109 label_it->second->SetText(error_message); | |
| 110 label_it->second->SchedulePaint(); | |
| 111 dialog()->Layout(); | |
| 112 } | |
| 113 | |
| 114 std::unique_ptr<views::Button> EditorViewController::CreatePrimaryButton() { | |
| 115 std::unique_ptr<views::Button> button( | |
| 116 views::MdTextButton::CreateSecondaryUiBlueButton( | |
| 117 this, l10n_util::GetStringUTF16(IDS_DONE))); | |
| 118 button->set_tag(static_cast<int>(EditorViewControllerTags::SAVE_BUTTON)); | |
| 119 button->set_id(static_cast<int>(DialogViewID::EDITOR_SAVE_BUTTON)); | |
| 120 return button; | |
| 121 } | |
| 122 | |
| 123 void EditorViewController::ButtonPressed(views::Button* sender, | 123 void EditorViewController::ButtonPressed(views::Button* sender, |
| 124 const ui::Event& event) { | 124 const ui::Event& event) { |
| 125 switch (sender->tag()) { | 125 switch (sender->tag()) { |
| 126 case static_cast<int>(EditorViewControllerTags::SAVE_BUTTON): | 126 case static_cast<int>(EditorViewControllerTags::SAVE_BUTTON): |
| 127 if (ValidateModelAndSave()) | 127 if (ValidateModelAndSave()) |
| 128 dialog()->GoBack(); | 128 dialog()->GoBack(); |
| 129 break; | 129 break; |
| 130 default: | 130 default: |
| 131 PaymentRequestSheetController::ButtonPressed(sender, event); | 131 PaymentRequestSheetController::ButtonPressed(sender, event); |
| 132 break; | 132 break; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 error_label->SetFontList( | 235 error_label->SetFontList( |
| 236 error_label->GetDefaultFontList().DeriveWithSizeDelta(-1)); | 236 error_label->GetDefaultFontList().DeriveWithSizeDelta(-1)); |
| 237 error_label->SetEnabledColor(error_label->GetNativeTheme()->GetSystemColor( | 237 error_label->SetEnabledColor(error_label->GetNativeTheme()->GetSystemColor( |
| 238 ui::NativeTheme::kColorId_AlertSeverityHigh)); | 238 ui::NativeTheme::kColorId_AlertSeverityHigh)); |
| 239 error_labels_[field] = error_label.get(); | 239 error_labels_[field] = error_label.get(); |
| 240 | 240 |
| 241 layout->AddView(error_label.release()); | 241 layout->AddView(error_label.release()); |
| 242 } | 242 } |
| 243 | 243 |
| 244 } // namespace payments | 244 } // namespace payments |
| OLD | NEW |