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/profile_list_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/profile_list_view_controller.h" |
6 | 6 |
7 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 7 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
9 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 9 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
10 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 10 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
12 #include "components/payments/content/payment_request_spec.h" | 12 #include "components/payments/content/payment_request_spec.h" |
13 #include "components/payments/content/payment_request_state.h" | 13 #include "components/payments/content/payment_request_state.h" |
| 14 #include "components/payments/core/profile_util.h" |
14 #include "components/payments/core/strings_util.h" | 15 #include "components/payments/core/strings_util.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" |
17 #include "ui/views/controls/button/label_button.h" | 18 #include "ui/views/controls/button/label_button.h" |
18 #include "ui/views/controls/button/md_text_button.h" | 19 #include "ui/views/controls/button/md_text_button.h" |
19 #include "ui/views/controls/image_view.h" | 20 #include "ui/views/controls/image_view.h" |
20 #include "ui/views/layout/box_layout.h" | 21 #include "ui/views/layout/box_layout.h" |
21 #include "ui/views/layout/fill_layout.h" | 22 #include "ui/views/layout/fill_layout.h" |
22 #include "ui/views/layout/grid_layout.h" | 23 #include "ui/views/layout/grid_layout.h" |
23 | 24 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 69 } |
69 | 70 |
70 void SelectedStateChanged() override { | 71 void SelectedStateChanged() override { |
71 if (selected()) { | 72 if (selected()) { |
72 parent_view_->SelectProfile(profile_); | 73 parent_view_->SelectProfile(profile_); |
73 dialog_->GoBack(); | 74 dialog_->GoBack(); |
74 } | 75 } |
75 } | 76 } |
76 | 77 |
77 bool CanBeSelected() const override { | 78 bool CanBeSelected() const override { |
78 // TODO(crbug.com/709454): Check for profile completeness. Currently a giant | 79 return parent_view_->ValidateProfile(profile_); |
79 // hack to test the UI. | |
80 return !profile_->GetRawInfo(autofill::ADDRESS_HOME_ZIP).empty(); | |
81 } | 80 } |
82 | 81 |
83 void PerformSelectionFallback() override { | 82 void PerformSelectionFallback() override { |
84 parent_view_->ShowEditor(profile_); | 83 parent_view_->ShowEditor(profile_); |
85 } | 84 } |
86 | 85 |
87 ProfileListViewController* parent_view_; | 86 ProfileListViewController* parent_view_; |
88 autofill::AutofillProfile* profile_; | 87 autofill::AutofillProfile* profile_; |
89 PaymentRequestDialogView* dialog_; | 88 PaymentRequestDialogView* dialog_; |
90 | 89 |
(...skipping 10 matching lines...) Expand all Loading... |
101 : ProfileListViewController(spec, state, dialog) { | 100 : ProfileListViewController(spec, state, dialog) { |
102 PopulateList(); | 101 PopulateList(); |
103 } | 102 } |
104 ~ShippingProfileViewController() override {} | 103 ~ShippingProfileViewController() override {} |
105 | 104 |
106 protected: | 105 protected: |
107 // ProfileListViewController: | 106 // ProfileListViewController: |
108 std::unique_ptr<views::View> GetLabel( | 107 std::unique_ptr<views::View> GetLabel( |
109 autofill::AutofillProfile* profile) override { | 108 autofill::AutofillProfile* profile) override { |
110 return GetShippingAddressLabel(AddressStyleType::DETAILED, | 109 return GetShippingAddressLabel(AddressStyleType::DETAILED, |
111 state()->GetApplicationLocale(), *profile); | 110 state()->GetApplicationLocale(), *profile, |
| 111 *spec(), *(state()->profile_comparator())); |
112 } | 112 } |
113 | 113 |
114 void SelectProfile(autofill::AutofillProfile* profile) override { | 114 void SelectProfile(autofill::AutofillProfile* profile) override { |
115 state()->SetSelectedShippingProfile(profile); | 115 state()->SetSelectedShippingProfile(profile); |
116 } | 116 } |
117 | 117 |
118 void ShowEditor(autofill::AutofillProfile* profile) override { | 118 void ShowEditor(autofill::AutofillProfile* profile) override { |
119 dialog()->ShowShippingAddressEditor( | 119 dialog()->ShowShippingAddressEditor( |
120 /*on_edited=*/base::BindOnce( | 120 /*on_edited=*/base::BindOnce( |
121 &PaymentRequestState::SetSelectedShippingProfile, | 121 &PaymentRequestState::SetSelectedShippingProfile, |
122 base::Unretained(state()), profile), | 122 base::Unretained(state()), profile), |
123 /*on_added=*/ | 123 /*on_added=*/ |
124 base::BindOnce(&PaymentRequestState::AddAutofillShippingProfile, | 124 base::BindOnce(&PaymentRequestState::AddAutofillShippingProfile, |
125 base::Unretained(state()), /*selected=*/true), | 125 base::Unretained(state()), /*selected=*/true), |
126 profile); | 126 profile); |
127 } | 127 } |
128 | 128 |
129 autofill::AutofillProfile* GetSelectedProfile() override { | 129 autofill::AutofillProfile* GetSelectedProfile() override { |
130 return state()->selected_shipping_profile(); | 130 return state()->selected_shipping_profile(); |
131 } | 131 } |
132 | 132 |
| 133 bool ValidateProfile(autofill::AutofillProfile* profile) override { |
| 134 return state()->profile_comparator()->IsShippingComplete(profile); |
| 135 } |
| 136 |
133 std::vector<autofill::AutofillProfile*> GetProfiles() override { | 137 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
134 return state()->shipping_profiles(); | 138 return state()->shipping_profiles(); |
135 } | 139 } |
136 | 140 |
137 DialogViewID GetDialogViewId() override { | 141 DialogViewID GetDialogViewId() override { |
138 return DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW; | 142 return DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW; |
139 } | 143 } |
140 | 144 |
141 base::string16 GetSheetTitle() override { | 145 base::string16 GetSheetTitle() override { |
142 return GetShippingAddressSectionString(spec()->shipping_type()); | 146 return GetShippingAddressSectionString(spec()->shipping_type()); |
(...skipping 25 matching lines...) Expand all Loading... |
168 PopulateList(); | 172 PopulateList(); |
169 } | 173 } |
170 ~ContactProfileViewController() override {} | 174 ~ContactProfileViewController() override {} |
171 | 175 |
172 protected: | 176 protected: |
173 // ProfileListViewController: | 177 // ProfileListViewController: |
174 std::unique_ptr<views::View> GetLabel( | 178 std::unique_ptr<views::View> GetLabel( |
175 autofill::AutofillProfile* profile) override { | 179 autofill::AutofillProfile* profile) override { |
176 return GetContactInfoLabel(AddressStyleType::DETAILED, | 180 return GetContactInfoLabel(AddressStyleType::DETAILED, |
177 state()->GetApplicationLocale(), *profile, | 181 state()->GetApplicationLocale(), *profile, |
178 *spec()); | 182 *spec(), *(state()->profile_comparator())); |
179 } | 183 } |
180 | 184 |
181 void SelectProfile(autofill::AutofillProfile* profile) override { | 185 void SelectProfile(autofill::AutofillProfile* profile) override { |
182 state()->SetSelectedContactProfile(profile); | 186 state()->SetSelectedContactProfile(profile); |
183 } | 187 } |
184 | 188 |
185 void ShowEditor(autofill::AutofillProfile* profile) override { | 189 void ShowEditor(autofill::AutofillProfile* profile) override { |
186 dialog()->ShowContactInfoEditor(profile); | 190 dialog()->ShowContactInfoEditor(profile); |
187 } | 191 } |
188 | 192 |
189 autofill::AutofillProfile* GetSelectedProfile() override { | 193 autofill::AutofillProfile* GetSelectedProfile() override { |
190 return state()->selected_contact_profile(); | 194 return state()->selected_contact_profile(); |
191 } | 195 } |
192 | 196 |
| 197 bool ValidateProfile(autofill::AutofillProfile* profile) override { |
| 198 return state()->profile_comparator()->IsContactInfoComplete(profile); |
| 199 } |
| 200 |
193 std::vector<autofill::AutofillProfile*> GetProfiles() override { | 201 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
194 return state()->contact_profiles(); | 202 return state()->contact_profiles(); |
195 } | 203 } |
196 | 204 |
197 DialogViewID GetDialogViewId() override { | 205 DialogViewID GetDialogViewId() override { |
198 return DialogViewID::CONTACT_INFO_SHEET_LIST_VIEW; | 206 return DialogViewID::CONTACT_INFO_SHEET_LIST_VIEW; |
199 } | 207 } |
200 | 208 |
201 base::string16 GetSheetTitle() override { | 209 base::string16 GetSheetTitle() override { |
202 return l10n_util::GetStringUTF16( | 210 return l10n_util::GetStringUTF16( |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 293 |
286 void ProfileListViewController::ButtonPressed(views::Button* sender, | 294 void ProfileListViewController::ButtonPressed(views::Button* sender, |
287 const ui::Event& event) { | 295 const ui::Event& event) { |
288 if (sender->tag() == GetSecondaryButtonTag()) | 296 if (sender->tag() == GetSecondaryButtonTag()) |
289 ShowEditor(nullptr); | 297 ShowEditor(nullptr); |
290 else | 298 else |
291 PaymentRequestSheetController::ButtonPressed(sender, event); | 299 PaymentRequestSheetController::ButtonPressed(sender, event); |
292 } | 300 } |
293 | 301 |
294 } // namespace payments | 302 } // namespace payments |
OLD | NEW |