Chromium Code Reviews| 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/payment_method_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | |
| 11 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 12 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 11 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 12 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | |
| 13 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 13 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 14 #include "chrome/grit/generated_resources.h" | |
| 14 #include "components/payments/payment_request.h" | 15 #include "components/payments/payment_request.h" |
| 15 #include "components/strings/grit/components_strings.h" | 16 #include "components/strings/grit/components_strings.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/views/controls/button/label_button.h" | |
| 19 #include "ui/views/controls/button/md_text_button.h" | |
| 20 #include "ui/views/layout/fill_layout.h" | |
| 17 | 21 |
| 18 namespace payments { | 22 namespace payments { |
| 19 | 23 |
| 24 namespace { | |
| 25 | |
| 26 constexpr int kFirstTagValue = static_cast<int>( | |
| 27 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX); | |
| 28 | |
| 29 enum class PaymentMethodViewControllerTags : int { | |
| 30 // The tag for the button that triggers the "add card" flow. | |
| 31 ADD_CREDIT_CARD_BUTTON = kFirstTagValue, | |
|
sky
2017/02/06 17:05:11
Same comment about why this has to start at kFirst
Mathieu
2017/02/06 17:46:24
Done.
| |
| 32 }; | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 20 PaymentMethodViewController::PaymentMethodViewController( | 36 PaymentMethodViewController::PaymentMethodViewController( |
| 21 PaymentRequest* request, | 37 PaymentRequest* request, |
| 22 PaymentRequestDialogView* dialog) | 38 PaymentRequestDialogView* dialog) |
| 23 : PaymentRequestSheetController(request, dialog) {} | 39 : PaymentRequestSheetController(request, dialog) {} |
| 24 | 40 |
| 25 PaymentMethodViewController::~PaymentMethodViewController() {} | 41 PaymentMethodViewController::~PaymentMethodViewController() {} |
| 26 | 42 |
| 27 std::unique_ptr<views::View> PaymentMethodViewController::CreateView() { | 43 std::unique_ptr<views::View> PaymentMethodViewController::CreateView() { |
| 28 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | 44 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); |
| 29 | 45 |
| 30 // TODO(anthonyvd): populate this view. | 46 views::FillLayout* layout = new views::FillLayout(); |
| 47 content_view->SetLayoutManager(layout); | |
| 48 | |
| 49 // Create the "Add a card" button. | |
| 50 views::LabelButton* button = views::MdTextButton::CreateSecondaryUiButton( | |
| 51 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_ADD_CREDITCARD_CAPTION)); | |
| 52 button->set_tag(static_cast<int>( | |
| 53 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON)); | |
| 54 button->set_id( | |
| 55 static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_CARD_BUTTON)); | |
| 56 content_view->AddChildView(button); | |
| 31 | 57 |
| 32 return CreatePaymentView(CreateSheetHeaderView( | 58 return CreatePaymentView(CreateSheetHeaderView( |
| 33 true, | 59 true, |
| 34 l10n_util::GetStringUTF16( | 60 l10n_util::GetStringUTF16( |
| 35 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), | 61 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), |
| 36 this), | 62 this), |
| 37 std::move(content_view)); | 63 std::move(content_view)); |
| 38 } | 64 } |
| 39 | 65 |
| 40 void PaymentMethodViewController::ButtonPressed( | 66 void PaymentMethodViewController::ButtonPressed( |
| 41 views::Button* sender, const ui::Event& event) { | 67 views::Button* sender, const ui::Event& event) { |
| 42 switch (sender->tag()) { | 68 switch (sender->tag()) { |
| 69 case static_cast<int>( | |
| 70 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON): | |
| 71 dialog()->ShowCreditCardEditor(); | |
| 72 break; | |
| 43 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG): | 73 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG): |
| 44 dialog()->CloseDialog(); | 74 dialog()->CloseDialog(); |
| 45 break; | 75 break; |
| 46 case static_cast<int>(PaymentRequestCommonTags::BACK_BUTTON_TAG): | 76 case static_cast<int>(PaymentRequestCommonTags::BACK_BUTTON_TAG): |
| 47 dialog()->GoBack(); | 77 dialog()->GoBack(); |
| 48 break; | 78 break; |
| 49 default: | 79 default: |
| 50 NOTREACHED(); | 80 NOTREACHED(); |
| 51 } | 81 } |
| 52 } | 82 } |
| 53 | 83 |
| 54 } // namespace payments | 84 } // namespace payments |
| OLD | NEW |