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

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

Issue 2813203004: [Payments] Show what's missing for incomplete payment methods. (Closed)
Patch Set: Initial Created 3 years, 8 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/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 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/callback_forward.h" 13 #include "base/callback_forward.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" 16 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
17 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 17 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
18 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" 18 #include "chrome/browser/ui/views/payments/payment_request_row_view.h"
19 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 19 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
20 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
21 #include "components/payments/content/payment_request_state.h" 21 #include "components/payments/content/payment_request_state.h"
22 #include "components/payments/core/autofill_payment_instrument.h" 22 #include "components/payments/core/autofill_payment_instrument.h"
23 #include "components/payments/core/payment_instrument.h" 23 #include "components/payments/core/payment_instrument.h"
24 #include "components/strings/grit/components_strings.h" 24 #include "components/strings/grit/components_strings.h"
25 #include "third_party/skia/include/core/SkColor.h" 25 #include "third_party/skia/include/core/SkColor.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/gfx/paint_vector_icon.h" 27 #include "ui/gfx/paint_vector_icon.h"
28 #include "ui/native_theme/native_theme.h"
28 #include "ui/views/controls/button/label_button.h" 29 #include "ui/views/controls/button/label_button.h"
29 #include "ui/views/controls/button/md_text_button.h" 30 #include "ui/views/controls/button/md_text_button.h"
30 #include "ui/views/layout/box_layout.h" 31 #include "ui/views/layout/box_layout.h"
31 #include "ui/views/layout/fill_layout.h" 32 #include "ui/views/layout/fill_layout.h"
32 #include "ui/views/layout/grid_layout.h" 33 #include "ui/views/layout/grid_layout.h"
33 #include "ui/views/vector_icons.h" 34 #include "ui/views/vector_icons.h"
34 35
35 namespace payments { 36 namespace payments {
36 37
37 namespace { 38 namespace {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 base::MakeUnique<views::View>(); 76 base::MakeUnique<views::View>();
76 card_info_container->set_can_process_events_within_subtree(false); 77 card_info_container->set_can_process_events_within_subtree(false);
77 78
78 std::unique_ptr<views::BoxLayout> box_layout = 79 std::unique_ptr<views::BoxLayout> box_layout =
79 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 80 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0,
80 kPaymentRequestRowVerticalInsets, 0); 81 kPaymentRequestRowVerticalInsets, 0);
81 box_layout->set_cross_axis_alignment( 82 box_layout->set_cross_axis_alignment(
82 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); 83 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
83 card_info_container->SetLayoutManager(box_layout.release()); 84 card_info_container->SetLayoutManager(box_layout.release());
84 85
85 card_info_container->AddChildView(new views::Label(instrument_->label())); 86 if (!instrument_->label().empty())
86 card_info_container->AddChildView( 87 card_info_container->AddChildView(new views::Label(instrument_->label()));
87 new views::Label(instrument_->sublabel())); 88 if (!instrument_->sublabel().empty()) {
88 // TODO(anthonyvd): Add the "card is incomplete" label once the 89 card_info_container->AddChildView(
89 // completedness logic is implemented. 90 new views::Label(instrument_->sublabel()));
91 }
92 base::string16 missing_info;
93 if (!instrument_->IsCompleteForPayment(&missing_info)) {
94 std::unique_ptr<views::Label> missing_info_label =
95 base::MakeUnique<views::Label>(missing_info);
96 missing_info_label->SetFontList(
97 missing_info_label->GetDefaultFontList().DeriveWithSizeDelta(-1));
98 missing_info_label->SetEnabledColor(
99 missing_info_label->GetNativeTheme()->GetSystemColor(
100 ui::NativeTheme::kColorId_LinkEnabled));
101 card_info_container->AddChildView(missing_info_label.release());
102 }
103
90 return card_info_container; 104 return card_info_container;
91 } 105 }
92 106
93 void SelectedStateChanged() override { 107 void SelectedStateChanged() override {
94 if (selected()) { 108 if (selected()) {
95 state()->SetSelectedInstrument(instrument_); 109 state()->SetSelectedInstrument(instrument_);
96 dialog_->GoBack(); 110 dialog_->GoBack();
97 } 111 }
98 } 112 }
99 113
100 bool CanBeSelected() const override { 114 bool CanBeSelected() const override {
101 // If an instrument can't be selected, PerformSelectionFallback is called, 115 // If an instrument can't be selected, PerformSelectionFallback is called,
102 // where the instrument can be made complete. 116 // where the instrument can be made complete.
103 return instrument_->IsCompleteForPayment(); 117 return instrument_->IsCompleteForPayment(/*missing_info=*/nullptr);
104 } 118 }
105 119
106 void PerformSelectionFallback() override { 120 void PerformSelectionFallback() override {
107 switch (instrument_->type()) { 121 switch (instrument_->type()) {
108 case PaymentInstrument::Type::AUTOFILL: 122 case PaymentInstrument::Type::AUTOFILL:
109 // Since we are a list item, we only care about the on_edited callback. 123 // Since we are a list item, we only care about the on_edited callback.
110 dialog_->ShowCreditCardEditor( 124 dialog_->ShowCreditCardEditor(
111 /*on_edited=*/base::BindOnce( 125 /*on_edited=*/base::BindOnce(
112 &PaymentRequestState::SetSelectedInstrument, 126 &PaymentRequestState::SetSelectedInstrument,
113 base::Unretained(state()), instrument_), 127 base::Unretained(state()), instrument_),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 base::Unretained(state()), /*selected=*/true), 206 base::Unretained(state()), /*selected=*/true),
193 /*credit_card=*/nullptr); 207 /*credit_card=*/nullptr);
194 break; 208 break;
195 default: 209 default:
196 PaymentRequestSheetController::ButtonPressed(sender, event); 210 PaymentRequestSheetController::ButtonPressed(sender, event);
197 break; 211 break;
198 } 212 }
199 } 213 }
200 214
201 } // namespace payments 215 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698