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

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

Issue 2668063003: [Web Payments] Add Cancel button to all sheets (Closed)
Patch Set: 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
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_request_views_util.h" 5 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/app/vector_icons/vector_icons.h" 12 #include "chrome/app/vector_icons/vector_icons.h"
13 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" 13 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h"
14 #include "components/autofill/core/browser/autofill_profile.h" 14 #include "components/autofill/core/browser/autofill_profile.h"
15 #include "components/autofill/core/browser/autofill_type.h" 15 #include "components/autofill/core/browser/autofill_type.h"
16 #include "components/autofill/core/browser/field_types.h" 16 #include "components/autofill/core/browser/field_types.h"
17 #include "components/strings/grit/components_strings.h"
17 #include "third_party/skia/include/core/SkColor.h" 18 #include "third_party/skia/include/core/SkColor.h"
19 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/geometry/insets.h" 21 #include "ui/gfx/geometry/insets.h"
20 #include "ui/gfx/geometry/point_f.h" 22 #include "ui/gfx/geometry/point_f.h"
21 #include "ui/gfx/paint_vector_icon.h" 23 #include "ui/gfx/paint_vector_icon.h"
22 #include "ui/views/background.h" 24 #include "ui/views/background.h"
23 #include "ui/views/border.h" 25 #include "ui/views/border.h"
24 #include "ui/views/bubble/bubble_frame_view.h" 26 #include "ui/views/bubble/bubble_frame_view.h"
25 #include "ui/views/controls/button/button.h" 27 #include "ui/views/controls/button/button.h"
28 #include "ui/views/controls/button/md_text_button.h"
26 #include "ui/views/controls/button/vector_icon_button.h" 29 #include "ui/views/controls/button/vector_icon_button.h"
27 #include "ui/views/controls/label.h" 30 #include "ui/views/controls/label.h"
28 #include "ui/views/controls/styled_label.h" 31 #include "ui/views/controls/styled_label.h"
32 #include "ui/views/layout/box_layout.h"
29 #include "ui/views/layout/grid_layout.h" 33 #include "ui/views/layout/grid_layout.h"
30 #include "ui/views/painter.h" 34 #include "ui/views/painter.h"
31 #include "ui/views/view.h" 35 #include "ui/views/view.h"
32 36
33 namespace { 37 namespace {
34 38
35 // TODO(tmartino): Consider combining this with the Android equivalent in 39 // TODO(tmartino): Consider combining this with the Android equivalent in
36 // PersonalDataManager.java 40 // PersonalDataManager.java
37 base::string16 GetAddressFromProfile(const autofill::AutofillProfile& profile, 41 base::string16 GetAddressFromProfile(const autofill::AutofillProfile& profile,
38 const std::string& locale) { 42 const std::string& locale) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 views::Label* title_label = new views::Label(title); 115 views::Label* title_label = new views::Label(title);
112 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 116 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
113 layout->AddView(title_label); 117 layout->AddView(title_label);
114 118
115 return container; 119 return container;
116 } 120 }
117 121
118 122
119 std::unique_ptr<views::View> CreatePaymentView( 123 std::unique_ptr<views::View> CreatePaymentView(
120 std::unique_ptr<views::View> header_view, 124 std::unique_ptr<views::View> header_view,
121 std::unique_ptr<views::View> content_view) { 125 std::unique_ptr<views::View> content_view,
126 std::unique_ptr<views::View> buttons_view) {
122 std::unique_ptr<views::View> view = base::MakeUnique<views::View>(); 127 std::unique_ptr<views::View> view = base::MakeUnique<views::View>();
123 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); 128 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE));
124 129
125 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a 130 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a
126 // layer) won't do proper clipping. 131 // layer) won't do proper clipping.
127 view->SetPaintToLayer(); 132 view->SetPaintToLayer();
128 133
129 views::GridLayout* layout = new views::GridLayout(view.get()); 134 views::GridLayout* layout = new views::GridLayout(view.get());
130 view->SetLayoutManager(layout); 135 view->SetLayoutManager(layout);
131 136
132 constexpr int kTopInsetSize = 9; 137 constexpr int kTopInsetSize = 9;
133 constexpr int kBottomInsetSize = 18; 138 constexpr int kBottomInsetSize = 18;
134 layout->SetInsets(kTopInsetSize, 0, kBottomInsetSize, 0); 139 layout->SetInsets(kTopInsetSize, 0, kBottomInsetSize, 0);
135 views::ColumnSet* columns = layout->AddColumnSet(0); 140 views::ColumnSet* columns = layout->AddColumnSet(0);
136 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 141 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
137 1, views::GridLayout::USE_PREF, 0, 0); 142 1, views::GridLayout::USE_PREF, 0, 0);
138 143
139 layout->StartRow(0, 0); 144 layout->StartRow(0, 0);
140 // |header_view| will be deleted when |view| is. 145 // |header_view| will be deleted when |view| is.
141 layout->AddView(header_view.release()); 146 layout->AddView(header_view.release());
142 147
143 layout->StartRow(0, 0); 148 layout->StartRow(0, 0);
144 // |content_view| will be deleted when |view| is. 149 // |content_view| will be deleted when |view| is.
145 layout->AddView(content_view.release()); 150 layout->AddView(content_view.release());
146 151
152 layout->AddPaddingRow(1, 0);
153 layout->StartRow(0, 0);
154 layout->AddView(buttons_view.release());
155
147 return view; 156 return view;
148 } 157 }
149 158
150 std::unique_ptr<views::View> GetShippingAddressLabel( 159 std::unique_ptr<views::View> GetShippingAddressLabel(
151 AddressStyleType type, 160 AddressStyleType type,
152 const std::string& locale, 161 const std::string& locale,
153 const autofill::AutofillProfile& profile) { 162 const autofill::AutofillProfile& profile) {
154 base::string16 name_value = 163 base::string16 name_value =
155 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); 164 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale);
156 165
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 223 }
215 224
216 // Creates a views::Border object that can paint the gray horizontal ruler used 225 // Creates a views::Border object that can paint the gray horizontal ruler used
217 // as a separator between items in the Payment Request dialog. 226 // as a separator between items in the Payment Request dialog.
218 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() { 227 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() {
219 return views::CreateBorderPainter( 228 return views::CreateBorderPainter(
220 base::MakeUnique<PaymentRequestRowBorderPainter>(), 229 base::MakeUnique<PaymentRequestRowBorderPainter>(),
221 gfx::Insets()); 230 gfx::Insets());
222 } 231 }
223 232
233 std::unique_ptr<views::View> CreateButtonsView(
234 PaymentRequestSheetController* controller) {
235 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
236
237 views::GridLayout* layout = new views::GridLayout(container.get());
238 container->SetLayoutManager(layout);
239
240 views::ColumnSet* columns = layout->AddColumnSet(0);
241 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
242 0, views::GridLayout::USE_PREF, 0, 0);
243 columns->AddPaddingColumn(1, 0);
244 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
245 0, views::GridLayout::USE_PREF, 0, 0);
246
247 layout->StartRow(0, 0);
248 std::unique_ptr<views::View> leading_buttons_container =
249 base::MakeUnique<views::View>();
250
251 // TODO(anthonyvd): Add the other buttons that can eventually go into this
252 // footer.
253
254 layout->AddView(leading_buttons_container.release());
255
256 std::unique_ptr<views::View> trailing_buttons_container =
257 base::MakeUnique<views::View>();
258
259 constexpr int kButtonSpacing = 10;
260 trailing_buttons_container->SetLayoutManager(new views::BoxLayout(
261 views::BoxLayout::kHorizontal,
262 kPaymentRequestRowHorizontalInsets,
263 kPaymentRequestRowVerticalInsets,
264 kButtonSpacing));
265
266 views::LabelButton* button = views::MdTextButton::CreateSecondaryUiButton(
267 controller,
268 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CANCEL_BUTTON_LABEL));
269 button->set_tag(static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG));
270 trailing_buttons_container->AddChildView(button);
271
272 layout->AddView(trailing_buttons_container.release());
273
274 return container;
275 }
276
224 } // namespace payments 277 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698