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

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

Issue 2592833002: [WebPayments] Start populating the Payment Sheet. (Closed)
Patch Set: 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_sheet_view_controller.cc
diff --git a/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc b/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc
index 1992efaf4d9734a24c14d3a98de1653fe2424469..03d0c675fc4a4b5d8d9b19423929398c405db442 100644
--- a/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc
+++ b/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc
@@ -9,19 +9,105 @@
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/payments/payment_request_impl.h"
#include "chrome/browser/ui/views/payments/payment_request_dialog.h"
#include "chrome/browser/ui/views/payments/payment_request_views_util.h"
#include "chrome/grit/generated_resources.h"
+#include "components/strings/grit/components_strings.h"
+#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/gfx/color_utils.h"
+#include "ui/gfx/font.h"
+#include "ui/gfx/geometry/insets.h"
+#include "ui/gfx/paint_vector_icon.h"
+#include "ui/gfx/range/range.h"
+#include "ui/gfx/vector_icons/vector_icons.h"
+#include "ui/views/border.h"
+#include "ui/views/controls/button/custom_button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/md_text_button.h"
+#include "ui/views/controls/image_view.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/controls/styled_label.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/view.h"
namespace {
-// The tag for the button that navigates to the Order Summary sheet.
-constexpr int kOrderSummaryTag = 0;
+constexpr int kRowVerticalInset = 18;
+// The rows have extra inset compared to the header so that their right edge
+// lines up with the close button's X rather than its invisible right edge.
+constexpr int kRowExtraRightInset = 8;
+
+constexpr int kPaddingColumnsWidth = 25;
+
+enum PaymentSheetViewControllerTags {
+ // The tag for the button that navigates to the Order Summary sheet.
+ SHOW_ORDER_SUMMARY_BUTTON = payments::PAYMENT_REQUEST_COMMON_TAG_MAX,
+};
+
+// Creates a clickable row to be displayed in the Payment Sheet. It contains
+// a section name and some content, followed by a chevron as a clickability
+// affordance. Both, either, or none of |content_view| and |extra_content_view|
+// may be present, the difference between the two being that content is pinned
+// to the left and extra_content is pinned to the right.
+// The row also displays a light gray horizontal ruler on its lower boundary.
+// +----------------------------+
+// | Name | Content | Extra | > |
+// +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler
+class PaymentSheetRow : public views::CustomButton {
sky 2017/01/04 17:24:45 Do you really need to subclass here? Can't you cre
anthonyvd 2017/01/04 19:08:55 It's currently a subclass because the rows will ne
sky 2017/01/04 20:56:32 Indeed you are right. As you didn't override any f
+ public:
+ PaymentSheetRow(views::ButtonListener* listener,
+ const base::string16& section_name,
+ std::unique_ptr<views::View> content_view,
+ std::unique_ptr<views::View> extra_content_view)
+ : views::CustomButton(listener) {
+ SetBorder(views::CreateSolidSidedBorder(0, 0, 1, 0, SK_ColorLTGRAY));
+ views::GridLayout* layout = new views::GridLayout(this);
+ layout->SetInsets(
+ kRowVerticalInset, 0, kRowVerticalInset, kRowExtraRightInset);
+ SetLayoutManager(layout);
+
+ views::ColumnSet* columns = layout->AddColumnSet(0);
+ // A column for the section name.
+ columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
+ 0, views::GridLayout::USE_PREF, 0, 0);
+ // A column for the content.
+ columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
+ 1, views::GridLayout::USE_PREF, 0, 0);
+ // A column for the extra content.
+ columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
+ 0, views::GridLayout::USE_PREF, 0, 0);
+ columns->AddPaddingColumn(0, kPaddingColumnsWidth);
+ // A column for the chevron.
+ columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
+ 0, views::GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0, 0);
+ views::Label* name_label = new views::Label(section_name);
+ layout->AddView(name_label);
+
+ if (content_view) {
+ layout->AddView(content_view.release());
+ } else {
+ layout->SkipColumns(1);
+ }
+
+ if (extra_content_view) {
+ layout->AddView(extra_content_view.release());
+ } else {
+ layout->SkipColumns(1);
+ }
+
+ views::ImageView* chevron = new views::ImageView();
+ chevron->SetImage(gfx::CreateVectorIcon(
+ gfx::VectorIconId::SUBMENU_ARROW,
+ color_utils::DeriveDefaultIconColor(name_label->enabled_color())));
+ layout->AddView(chevron);
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(PaymentSheetRow);
+};
} // namespace
@@ -39,26 +125,53 @@ std::unique_ptr<views::View> PaymentSheetViewController::CreateView() {
views::GridLayout* layout = new views::GridLayout(content_view.get());
content_view->SetLayoutManager(layout);
views::ColumnSet* columns = layout->AddColumnSet(0);
- columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
- 0, views::GridLayout::USE_PREF, 0, 0);
+ columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
+ 1, views::GridLayout::USE_PREF, 0, 0);
layout->StartRow(0, 0);
- views::LabelButton* order_summary_button =
- views::MdTextButton::CreateSecondaryUiBlueButton(
- this, base::ASCIIToUTF16("Order Summary"));
- order_summary_button->set_tag(kOrderSummaryTag);
- layout->AddView(order_summary_button);
-
- return payments::CreatePaymentView(
- l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE),
+ layout->AddView(CreatePaymentSheetSummaryRow().release());
+
+ return CreatePaymentView(
+ CreateSheetHeaderView(
+ false,
+ l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE),
+ this),
std::move(content_view));
}
void PaymentSheetViewController::ButtonPressed(
views::Button* sender, const ui::Event& event) {
- DCHECK_EQ(kOrderSummaryTag, sender->tag());
+ if (sender->tag() == CLOSE_BUTTON_TAG) {
sky 2017/01/04 17:24:45 no {} optional: use a switch
anthonyvd 2017/01/04 19:08:55 Done.
+ dialog()->CloseDialog();
+ } else if (sender->tag() == SHOW_ORDER_SUMMARY_BUTTON) {
+ dialog()->ShowOrderSummary();
+ } else {
+ NOTREACHED();
+ }
+}
+
+std::unique_ptr<views::View>
+PaymentSheetViewController::CreateOrderSummarySectionContent() {
+ base::string16 label_value =
+ l10n_util::GetStringFUTF16(
+ IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT,
+ l10n_util::GetStringUTF16(
+ IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL),
+ base::ASCIIToUTF16(impl()->details()->total->amount->value),
+ base::ASCIIToUTF16(impl()->details()->total->amount->currency));
+
+ return base::MakeUnique<views::Label>(label_value);
+}
- dialog()->ShowOrderSummary();
+std::unique_ptr<views::View>
+PaymentSheetViewController::CreatePaymentSheetSummaryRow() {
+ std::unique_ptr<PaymentSheetRow> section = base::MakeUnique<PaymentSheetRow>(
+ this,
+ l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME),
+ std::unique_ptr<views::View>(nullptr),
+ CreateOrderSummarySectionContent());
+ section->set_tag(SHOW_ORDER_SUMMARY_BUTTON);
+ return section;
}
} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698