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

Side by Side Diff: chrome/browser/ui/views/payments/payment_request_sheet_controller.cc

Issue 2668063003: [Web Payments] Add Cancel button to all sheets (Closed)
Patch Set: Address feedback about footer row creation. Created 3 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h"
6
7 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
8 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
9 #include "components/strings/grit/components_strings.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/views/background.h"
12 #include "ui/views/controls/button/md_text_button.h"
13 #include "ui/views/layout/box_layout.h"
14 #include "ui/views/layout/grid_layout.h"
15
16
17 namespace payments {
18
19 PaymentRequestSheetController::PaymentRequestSheetController(
20 PaymentRequest* request, PaymentRequestDialogView* dialog)
21 : request_(request), dialog_(dialog) {
22 DCHECK(request_);
23 DCHECK(dialog_);
24 }
25
26 std::unique_ptr<views::Button>
27 PaymentRequestSheetController::CreatePrimaryButton() {
Mathieu 2017/02/02 21:04:58 should we make this abstract and ask every control
anthonyvd 2017/02/02 21:33:24 That's a good question, I was hesitating between t
Mathieu 2017/02/02 21:44:15 Yeah it certainly works and it's not a huge change
28 return std::unique_ptr<views::Button>();
29 }
30
31 void PaymentRequestSheetController::ButtonPressed(
32 views::Button* sender, const ui::Event& event) {
33 switch (sender->tag()) {
34 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG):
35 dialog()->CloseDialog();
36 break;
37 case static_cast<int>(PaymentRequestCommonTags::BACK_BUTTON_TAG):
38 dialog()->GoBack();
39 break;
40 default:
41 break;
42 }
43 }
44
45 std::unique_ptr<views::View> PaymentRequestSheetController::CreatePaymentView(
46 std::unique_ptr<views::View> header_view,
47 std::unique_ptr<views::View> content_view) {
48 std::unique_ptr<views::View> view = base::MakeUnique<views::View>();
49 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE));
50
51 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a
52 // layer) won't do proper clipping.
53 view->SetPaintToLayer();
54
55 views::GridLayout* layout = new views::GridLayout(view.get());
56 view->SetLayoutManager(layout);
57
58 constexpr int kTopInsetSize = 9;
59 constexpr int kBottomInsetSize = 18;
60 layout->SetInsets(kTopInsetSize, 0, kBottomInsetSize, 0);
61 views::ColumnSet* columns = layout->AddColumnSet(0);
62 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
63 1, views::GridLayout::USE_PREF, 0, 0);
64
65 layout->StartRow(0, 0);
66 // |header_view| will be deleted when |view| is.
67 layout->AddView(header_view.release());
68
69 layout->StartRow(0, 0);
70 // |content_view| will be deleted when |view| is.
71 layout->AddView(content_view.release());
72
73 layout->AddPaddingRow(1, 0);
74 layout->StartRow(0, 0);
75 layout->AddView(CreateFooterView().release());
76
77 return view;
78 }
79
80 std::unique_ptr<views::View> PaymentRequestSheetController::CreateFooterView() {
81 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
82
83 views::GridLayout* layout = new views::GridLayout(container.get());
84 container->SetLayoutManager(layout);
85
86 views::ColumnSet* columns = layout->AddColumnSet(0);
87 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
88 0, views::GridLayout::USE_PREF, 0, 0);
89 columns->AddPaddingColumn(1, 0);
90 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
91 0, views::GridLayout::USE_PREF, 0, 0);
92
93 layout->StartRow(0, 0);
94 std::unique_ptr<views::View> leading_buttons_container =
95 base::MakeUnique<views::View>();
96
97 // TODO(anthonyvd): Add the other buttons that can eventually go into this
98 // footer.
99
100 layout->AddView(leading_buttons_container.release());
101
102 std::unique_ptr<views::View> trailing_buttons_container =
103 base::MakeUnique<views::View>();
104
105 constexpr int kButtonSpacing = 10;
106 trailing_buttons_container->SetLayoutManager(new views::BoxLayout(
107 views::BoxLayout::kHorizontal,
108 kPaymentRequestRowHorizontalInsets,
109 kPaymentRequestRowVerticalInsets,
110 kButtonSpacing));
111
112 std::unique_ptr<views::Button> primary_button = CreatePrimaryButton();
113 if (primary_button)
114 trailing_buttons_container->AddChildView(primary_button.release());
115
116 views::LabelButton* button = views::MdTextButton::CreateSecondaryUiButton(
117 this, l10n_util::GetStringUTF16(IDS_CANCEL));
118 button->set_tag(static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG));
119 trailing_buttons_container->AddChildView(button);
120
121 layout->AddView(trailing_buttons_container.release());
122
123 return container;
124 }
125
126 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698