Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_sheet_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 return layout; | 187 return layout; |
| 188 } | 188 } |
| 189 | 189 |
| 190 } // namespace | 190 } // namespace |
| 191 | 191 |
| 192 PaymentSheetViewController::PaymentSheetViewController( | 192 PaymentSheetViewController::PaymentSheetViewController( |
| 193 PaymentRequestSpec* spec, | 193 PaymentRequestSpec* spec, |
| 194 PaymentRequestState* state, | 194 PaymentRequestState* state, |
| 195 PaymentRequestDialogView* dialog) | 195 PaymentRequestDialogView* dialog) |
| 196 : PaymentRequestSheetController(spec, state, dialog), | 196 : PaymentRequestSheetController(spec, state, dialog), |
| 197 container_view_(base::MakeUnique<views::View>()), | |
| 198 pay_button_(nullptr), | 197 pay_button_(nullptr), |
| 199 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) { | 198 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) { |
| 200 container_view_->set_owned_by_client(); | |
| 201 state->AddObserver(this); | 199 state->AddObserver(this); |
| 202 } | 200 } |
| 203 | 201 |
| 204 PaymentSheetViewController::~PaymentSheetViewController() { | 202 PaymentSheetViewController::~PaymentSheetViewController() { |
| 205 state()->RemoveObserver(this); | 203 state()->RemoveObserver(this); |
| 206 } | 204 } |
| 207 | 205 |
| 208 std::unique_ptr<views::View> PaymentSheetViewController::CreateView() { | |
| 209 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | |
| 210 content_view->SetLayoutManager(new views::FillLayout); | |
| 211 | |
| 212 UpdateContentView(); | |
| 213 content_view->AddChildView(container_view_.get()); | |
| 214 | |
| 215 return CreatePaymentView( | |
| 216 CreateSheetHeaderView( | |
| 217 false, | |
| 218 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE), | |
| 219 this), | |
| 220 std::move(content_view)); | |
| 221 } | |
| 222 | |
| 223 void PaymentSheetViewController::OnSelectedInformationChanged() { | 206 void PaymentSheetViewController::OnSelectedInformationChanged() { |
| 224 UpdatePayButtonState(state()->is_ready_to_pay()); | 207 UpdatePayButtonState(state()->is_ready_to_pay()); |
| 225 UpdateContentView(); | 208 UpdateContentView(); |
| 226 container_view_->Layout(); | |
| 227 } | 209 } |
| 228 | 210 |
| 229 std::unique_ptr<views::Button> | 211 std::unique_ptr<views::Button> |
| 230 PaymentSheetViewController::CreatePrimaryButton() { | 212 PaymentSheetViewController::CreatePrimaryButton() { |
| 231 std::unique_ptr<views::Button> button( | 213 std::unique_ptr<views::Button> button( |
| 232 views::MdTextButton::CreateSecondaryUiBlueButton( | 214 views::MdTextButton::CreateSecondaryUiBlueButton( |
| 233 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); | 215 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); |
| 234 button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG)); | 216 button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG)); |
| 235 button->set_id(static_cast<int>(DialogViewID::PAY_BUTTON)); | 217 button->set_id(static_cast<int>(DialogViewID::PAY_BUTTON)); |
| 236 pay_button_ = button.get(); | 218 pay_button_ = button.get(); |
| 237 UpdatePayButtonState(state()->is_ready_to_pay()); | 219 UpdatePayButtonState(state()->is_ready_to_pay()); |
| 238 return button; | 220 return button; |
| 239 } | 221 } |
| 240 | 222 |
| 223 bool PaymentSheetViewController::ShouldShowHeaderBackArrow() { | |
| 224 return false; | |
| 225 } | |
| 226 | |
| 227 base::string16 PaymentSheetViewController::GetSheetTitle() { | |
| 228 return l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE); | |
| 229 } | |
| 230 | |
| 231 void PaymentSheetViewController::FillContentView(views::View* content_view) { | |
| 232 views::GridLayout* layout = new views::GridLayout(content_view); | |
| 233 content_view->SetLayoutManager(layout); | |
| 234 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 235 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, | |
| 236 views::GridLayout::USE_PREF, 0, 0); | |
| 237 | |
| 238 // The shipping address and contact info rows are optional. | |
| 239 layout->StartRow(0, 0); | |
| 240 layout->AddView(CreatePaymentSheetSummaryRow().release()); | |
| 241 | |
| 242 if (spec()->request_shipping()) { | |
| 243 layout->StartRow(0, 0); | |
| 244 layout->AddView(CreateShippingRow().release()); | |
| 245 layout->StartRow(0, 0); | |
| 246 layout->AddView(CreateShippingOptionRow().release()); | |
| 247 } | |
| 248 layout->StartRow(0, 0); | |
| 249 layout->AddView(CreatePaymentMethodRow().release()); | |
| 250 if (spec()->request_payer_name() || spec()->request_payer_email() || | |
| 251 spec()->request_payer_phone()) { | |
| 252 layout->StartRow(0, 0); | |
| 253 layout->AddView(CreateContactInfoRow().release()); | |
| 254 } | |
| 255 } | |
| 256 | |
| 241 // Adds the product logo to the footer. | 257 // Adds the product logo to the footer. |
| 242 // +---------------------------------------------------------+ | 258 // +---------------------------------------------------------+ |
| 243 // | (•) chrome | PAY | CANCEL | | 259 // | (•) chrome | PAY | CANCEL | |
| 244 // +---------------------------------------------------------+ | 260 // +---------------------------------------------------------+ |
| 245 std::unique_ptr<views::View> | 261 std::unique_ptr<views::View> |
| 246 PaymentSheetViewController::CreateExtraFooterView() { | 262 PaymentSheetViewController::CreateExtraFooterView() { |
| 247 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | 263 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); |
| 248 | 264 |
| 249 views::BoxLayout* layout = | 265 views::BoxLayout* layout = |
| 250 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 266 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 default: | 312 default: |
| 297 PaymentRequestSheetController::ButtonPressed(sender, event); | 313 PaymentRequestSheetController::ButtonPressed(sender, event); |
| 298 break; | 314 break; |
| 299 } | 315 } |
| 300 } | 316 } |
| 301 | 317 |
| 302 void PaymentSheetViewController::UpdatePayButtonState(bool enabled) { | 318 void PaymentSheetViewController::UpdatePayButtonState(bool enabled) { |
| 303 pay_button_->SetEnabled(enabled); | 319 pay_button_->SetEnabled(enabled); |
| 304 } | 320 } |
| 305 | 321 |
| 306 void PaymentSheetViewController::UpdateContentView() { | |
|
Mathieu
2017/03/23 11:36:45
yisss
anthonyvd
2017/03/23 16:18:11
Yeah, this is much cleaner for all sheets!
| |
| 307 container_view_->RemoveAllChildViews(/*delete_children=*/true); | |
| 308 views::GridLayout* layout = new views::GridLayout(container_view_.get()); | |
| 309 container_view_->SetLayoutManager(layout); | |
| 310 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 311 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, | |
| 312 views::GridLayout::USE_PREF, 0, 0); | |
| 313 | |
| 314 // The shipping address and contact info rows are optional. | |
| 315 layout->StartRow(0, 0); | |
| 316 layout->AddView(CreatePaymentSheetSummaryRow().release()); | |
| 317 | |
| 318 if (spec()->request_shipping()) { | |
| 319 layout->StartRow(0, 0); | |
| 320 layout->AddView(CreateShippingRow().release()); | |
| 321 layout->StartRow(0, 0); | |
| 322 layout->AddView(CreateShippingOptionRow().release()); | |
| 323 } | |
| 324 layout->StartRow(0, 0); | |
| 325 layout->AddView(CreatePaymentMethodRow().release()); | |
| 326 if (spec()->request_payer_name() || spec()->request_payer_email() || | |
| 327 spec()->request_payer_phone()) { | |
| 328 layout->StartRow(0, 0); | |
| 329 layout->AddView(CreateContactInfoRow().release()); | |
| 330 } | |
| 331 } | |
| 332 | |
| 333 // Creates the Order Summary row, which contains an "Order Summary" label, | 322 // Creates the Order Summary row, which contains an "Order Summary" label, |
| 334 // an inline list of display items, a Total Amount label, and a Chevron. | 323 // an inline list of display items, a Total Amount label, and a Chevron. |
| 335 // +----------------------------------------------+ | 324 // +----------------------------------------------+ |
| 336 // | Order Summary Item 1 $ 1.34 | | 325 // | Order Summary Item 1 $ 1.34 | |
| 337 // | Item 2 $ 2.00 > | | 326 // | Item 2 $ 2.00 > | |
| 338 // | 2 more items... | | 327 // | 2 more items... | |
| 339 // | Total USD $12.34 | | 328 // | Total USD $12.34 | |
| 340 // +----------------------------------------------+ | 329 // +----------------------------------------------+ |
| 341 std::unique_ptr<views::Button> | 330 std::unique_ptr<views::Button> |
| 342 PaymentSheetViewController::CreatePaymentSheetSummaryRow() { | 331 PaymentSheetViewController::CreatePaymentSheetSummaryRow() { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 std::move(option_label), std::unique_ptr<views::View>(nullptr), | 520 std::move(option_label), std::unique_ptr<views::View>(nullptr), |
| 532 widest_name_column_view_width_); | 521 widest_name_column_view_width_); |
| 533 section->set_tag(static_cast<int>( | 522 section->set_tag(static_cast<int>( |
| 534 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); | 523 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); |
| 535 section->set_id( | 524 section->set_id( |
| 536 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); | 525 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); |
| 537 return section; | 526 return section; |
| 538 } | 527 } |
| 539 | 528 |
| 540 } // namespace payments | 529 } // namespace payments |
| OLD | NEW |