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

Unified Diff: chrome/browser/ui/views/payments/payment_request_dialog.cc

Issue 2579513002: [WebPayments] Factor out sheet-specific logic in Controllers. (Closed)
Patch Set: Add missing include and semicolon. Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/payments/payment_request_dialog.cc
diff --git a/chrome/browser/ui/views/payments/payment_request_dialog.cc b/chrome/browser/ui/views/payments/payment_request_dialog.cc
index e85c4290ae350c9d913620b28ede05e542399b2f..3f8daf32b5efc406805363a76e26f49b766fba6e 100644
--- a/chrome/browser/ui/views/payments/payment_request_dialog.cc
+++ b/chrome/browser/ui/views/payments/payment_request_dialog.cc
@@ -4,70 +4,34 @@
#include "chrome/browser/ui/views/payments/payment_request_dialog.h"
-#include "base/strings/utf_string_conversions.h"
+#include <utility>
+
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
#include "chrome/browser/payments/payment_request_impl.h"
+#include "chrome/browser/ui/views/payments/order_summary_view_controller.h"
+#include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
#include "chrome/grit/generated_resources.h"
#include "components/constrained_window/constrained_window_views.h"
#include "content/public/browser/browser_thread.h"
#include "ui/base/l10n/l10n_util.h"
-#include "ui/views/controls/button/md_text_button.h"
-#include "ui/views/controls/label.h"
#include "ui/views/layout/fill_layout.h"
-#include "ui/views/layout/grid_layout.h"
namespace {
-// The tag for the button that navigates back to the payment sheet.
-constexpr int kBackButtonTag = 0;
-
-// The tag for the button that navigates to the Order Summary sheet.
-constexpr int kOrderSummaryTag = 1;
-
-std::unique_ptr<views::View> CreateOrderSummaryView(
- views::ButtonListener* button_listener) {
- std::unique_ptr<views::View> view = base::MakeUnique<views::View>();
-
- views::GridLayout* layout = new views::GridLayout(view.get());
- view->SetLayoutManager(layout);
- views::ColumnSet* columns = layout->AddColumnSet(0);
- columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
- 0, views::GridLayout::USE_PREF, 0, 0);
-
- layout->StartRow(0, 0);
- layout->AddView(new views::Label(
- l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE)));
-
- layout->StartRow(0, 0);
- views::LabelButton* back_button =
- views::MdTextButton::CreateSecondaryUiBlueButton(
- button_listener, base::ASCIIToUTF16("Back"));
- back_button->set_tag(kBackButtonTag);
- layout->AddView(back_button);
-
- return view;
-}
-
-std::unique_ptr<views::View> CreatePaymentSheetView(
- views::ButtonListener* button_listener) {
- std::unique_ptr<views::View> view = base::MakeUnique<views::View>();
-
- views::GridLayout* layout = new views::GridLayout(view.get());
- view->SetLayoutManager(layout);
- views::ColumnSet* columns = layout->AddColumnSet(0);
- columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
- 0, views::GridLayout::USE_PREF, 0, 0);
-
- layout->StartRow(0, 0);
- layout->AddView(new views::Label(
- l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE)));
-
- layout->StartRow(0, 0);
- views::LabelButton* order_summary_button =
- views::MdTextButton::CreateSecondaryUiBlueButton(
- button_listener, base::ASCIIToUTF16("Order Summary"));
- order_summary_button->set_tag(kOrderSummaryTag);
- layout->AddView(order_summary_button);
-
+// This function creates an instance of a PaymentRequestSheetController
+// subclass of concrete type |Controller|, passing it non-owned pointers to
+// |dialog| and the |impl| that initiated that dialog. |map| should be owned by
+// |dialog|.
+template<typename Controller>
+std::unique_ptr<views::View> CreateViewAndInstallController(
+ payments::ControllerMap* map,
+ payments::PaymentRequestImpl* impl,
+ payments::PaymentRequestDialog* dialog) {
+ std::unique_ptr<Controller> controller =
+ base::MakeUnique<Controller>(impl, dialog);
+ std::unique_ptr<views::View> view = controller->CreateView();
+ (*map)[view.get()] = std::move(controller);
return view;
}
@@ -101,34 +65,42 @@ ui::ModalType PaymentRequestDialog::GetModalType() const {
return ui::MODAL_TYPE_CHILD;
}
-gfx::Size PaymentRequestDialog::GetPreferredSize() const {
- return gfx::Size(300, 300);
-}
-
bool PaymentRequestDialog::Cancel() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
impl_->Cancel();
return true;
}
-void PaymentRequestDialog::ShowInitialPaymentSheet() {
- view_stack_.Push(CreatePaymentSheetView(this), false);
+void PaymentRequestDialog::GoBack() {
+ view_stack_.Pop();
}
void PaymentRequestDialog::ShowOrderSummary() {
- view_stack_.Push(CreateOrderSummaryView(this), true);
+ view_stack_.Push(
+ CreateViewAndInstallController<OrderSummaryViewController>(
+ &controller_map_, impl_, this),
+ true);
}
-void PaymentRequestDialog::GoBack() {
- view_stack_.Pop();
+void PaymentRequestDialog::ShowInitialPaymentSheet() {
+ view_stack_.Push(
+ CreateViewAndInstallController<PaymentSheetViewController>(
+ &controller_map_, impl_, this),
+ false);
+}
+
+gfx::Size PaymentRequestDialog::GetPreferredSize() const {
+ return gfx::Size(450, 450);
}
-void PaymentRequestDialog::ButtonPressed(
- views::Button* sender, const ui::Event& event) {
- if (sender->tag() == kBackButtonTag) {
- GoBack();
- } else if (sender->tag() == kOrderSummaryTag) {
- ShowOrderSummary();
+void PaymentRequestDialog::ViewHierarchyChanged(
+ const ViewHierarchyChangedDetails& details) {
+ // When a view that is associated with a controller is removed from this
+ // view's descendants, dispose of the controller.
+ if (!details.is_add &&
+ controller_map_.find(details.child) != controller_map_.end()) {
+ DCHECK(!details.move_view);
+ controller_map_.erase(details.child);
}
}

Powered by Google App Engine
This is Rietveld 408576698