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

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

Issue 2621153002: [WebPayments] Add the Payment Method section in the Payment Sheet (Closed)
Patch Set: Initial patch Created 3 years, 11 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 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 d085b26e922c1f849152ad1e20dd51d91c05c81e..8199b9226e4d91d50dbb95613d6ac048ab1ce8c6 100644
--- a/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc
+++ b/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc
@@ -4,18 +4,25 @@
#include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
+#include <algorithm>
#include <memory>
#include <utility>
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/browser_process.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/autofill/core/browser/autofill_type.h"
+#include "components/autofill/core/browser/credit_card.h"
+#include "components/autofill/core/browser/field_types.h"
#include "components/payments/payment_request.h"
#include "components/strings/grit/components_strings.h"
+#include "content/public/browser/web_contents.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/font.h"
#include "ui/gfx/geometry/insets.h"
@@ -29,6 +36,7 @@
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/styled_label.h"
+#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/view.h"
@@ -39,6 +47,7 @@ enum class PaymentSheetViewControllerTags {
// The tag for the button that navigates to the Order Summary sheet.
SHOW_ORDER_SUMMARY_BUTTON = static_cast<int>(
payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX),
+ SHOW_PAYMENT_METHOD_BUTTON,
};
// Creates a clickable row to be displayed in the Payment Sheet. It contains
@@ -47,6 +56,7 @@ enum class PaymentSheetViewControllerTags {
// 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.
+// The name column has a fixed width equal to |name_column_width|.
// +----------------------------+
// | Name | Content | Extra | > |
// +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler
@@ -55,12 +65,13 @@ class PaymentSheetRow : public views::CustomButton {
PaymentSheetRow(views::ButtonListener* listener,
const base::string16& section_name,
std::unique_ptr<views::View> content_view,
- std::unique_ptr<views::View> extra_content_view)
+ std::unique_ptr<views::View> extra_content_view,
+ int name_column_width)
: views::CustomButton(listener) {
SetBorder(views::CreateSolidSidedBorder(0, 0, 1, 0, SK_ColorLTGRAY));
views::GridLayout* layout = new views::GridLayout(this);
- constexpr int kRowVerticalInset = 18;
+ constexpr int kRowVerticalInset = 8;
// 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;
@@ -70,16 +81,23 @@ class PaymentSheetRow : public views::CustomButton {
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);
+ columns->AddColumn(views::GridLayout::LEADING,
+ views::GridLayout::LEADING,
+ 0,
+ views::GridLayout::FIXED,
+ name_column_width,
+ 0);
+
+ constexpr int kPaddingColumnsWidth = 25;
+ columns->AddPaddingColumn(0, kPaddingColumnsWidth);
+
// A column for the content.
- columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
+ columns->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING,
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);
- constexpr int kPaddingColumnsWidth = 25;
columns->AddPaddingColumn(0, kPaddingColumnsWidth);
// A column for the chevron.
columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
@@ -116,7 +134,10 @@ class PaymentSheetRow : public views::CustomButton {
PaymentSheetViewController::PaymentSheetViewController(
PaymentRequest* request,
PaymentRequestDialog* dialog)
- : PaymentRequestSheetController(request, dialog) {}
+ : PaymentRequestSheetController(request, dialog),
+ widest_name_column_view_width_(0) {
+ InitWidestNameColumnViewWidth();
+}
PaymentSheetViewController::~PaymentSheetViewController() {}
@@ -131,6 +152,8 @@ std::unique_ptr<views::View> PaymentSheetViewController::CreateView() {
layout->StartRow(0, 0);
layout->AddView(CreatePaymentSheetSummaryRow().release());
+ layout->StartRow(0, 0);
+ layout->AddView(CreatePaymentMethodRow().release());
return CreatePaymentView(
CreateSheetHeaderView(
@@ -150,6 +173,10 @@ void PaymentSheetViewController::ButtonPressed(
PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON):
dialog()->ShowOrderSummary();
break;
+ case static_cast<int>(
+ PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON):
+ dialog()->ShowPaymentMethodSheet();
+ break;
default:
NOTREACHED();
}
@@ -172,10 +199,87 @@ PaymentSheetViewController::CreatePaymentSheetSummaryRow() {
this,
l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME),
std::unique_ptr<views::View>(nullptr),
- CreateOrderSummarySectionContent());
+ CreateOrderSummarySectionContent(),
+ widest_name_column_view_width_);
section->set_tag(static_cast<int>(
PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON));
return section;
}
+std::unique_ptr<views::Button>
+PaymentSheetViewController::CreatePaymentMethodRow() {
Mathieu 2017/01/12 21:27:11 I really like the ASCII art in the Java Impl, coul
anthonyvd 2017/01/13 16:09:19 Done here and above.
+ autofill::CreditCard* selected_card =
+ request()->GetCurrentlySelectedCreditCard();
+
+ std::unique_ptr<views::View> content_view;
+ std::unique_ptr<views::ImageView> card_icon_view;
+ if (selected_card) {
+ content_view = base::MakeUnique<views::View>();
+
+ views::GridLayout* layout = new views::GridLayout(content_view.get());
+ content_view->SetLayoutManager(layout);
+ views::ColumnSet* columns = layout->AddColumnSet(0);
+ columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
+ 1, views::GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0, 0);
+ layout->AddView(new views::Label(selected_card->TypeAndLastFourDigits()));
+ layout->StartRow(0, 0);
+ layout->AddView(new views::Label(
+ selected_card->GetInfo(
+ autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
+ g_browser_process->GetApplicationLocale())));
+
+ card_icon_view = base::MakeUnique<views::ImageView>();
+ card_icon_view->SetImage(
+ ResourceBundle::GetSharedInstance()
+ .GetImageNamed(autofill::CreditCard::PaymentRequestIconResourceId(
+ selected_card->type()))
+ .AsImageSkia());
+ card_icon_view->SetBorder(
+ views::CreateRoundedRectBorder(1, 3, SK_ColorLTGRAY));
+
+ constexpr gfx::Size kCardIconSize = gfx::Size(32, 20);
+ card_icon_view->SetImageSize(kCardIconSize);
+ }
+
+ std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>(
+ this,
+ l10n_util::GetStringUTF16(
+ IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
+ std::move(content_view),
+ std::move(card_icon_view),
+ widest_name_column_view_width_);
+ section->set_tag(static_cast<int>(
+ PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON));
+ return section;
+}
+
+void PaymentSheetViewController::InitWidestNameColumnViewWidth() {
+ DCHECK_EQ(0, widest_name_column_view_width_);
+
+ // The name colums in each row should all have the same width, large enough to
anthonyvd 2017/01/12 19:18:59 If anyone has a better idea to do this that doesn'
Mathieu 2017/01/12 21:27:11 Idea 1: https://cs.chromium.org/chromium/src/ui/gf
anthonyvd 2017/01/13 16:09:19 It looks like neither of those would take into acc
Mathieu 2017/01/13 16:40:16 Thanks for looking into it! Perhaps a views expert
+ // accomodate the longest piece of text they contain. Because of this, each
+ // row's GridLayout requires its first column to have a fixed width of the
+ // correct size. To measure the required size, layout a label with each
+ // section name, measure its width, then initialize
+ // |widest_name_column_view_width_| with the largest value.
+ // This should only be performed once, when this sheet is shown, because
+ // language/font size can't change while the dialog is open.
+ std::vector<int> section_names {
+ IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME,
+ IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME,
+ };
+
+ std::for_each(
+ section_names.begin(),
+ section_names.end(),
+ [=](const int& name) {
+ views::Label label(l10n_util::GetStringUTF16(name));
+ widest_name_column_view_width_ = std::max(
+ label.GetPreferredSize().width(),
+ widest_name_column_view_width_);
+ });
+}
+
} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698