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

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

Issue 2656853002: [Web Payments] Refactor the row display code. (Closed)
Patch Set: Rebase 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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/app/vector_icons/vector_icons.h" 12 #include "chrome/app/vector_icons/vector_icons.h"
12 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" 13 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h"
13 #include "components/autofill/core/browser/autofill_profile.h" 14 #include "components/autofill/core/browser/autofill_profile.h"
14 #include "components/autofill/core/browser/autofill_type.h" 15 #include "components/autofill/core/browser/autofill_type.h"
15 #include "components/autofill/core/browser/field_types.h" 16 #include "components/autofill/core/browser/field_types.h"
16 #include "third_party/skia/include/core/SkColor.h" 17 #include "third_party/skia/include/core/SkColor.h"
18 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/geometry/insets.h"
20 #include "ui/gfx/geometry/point_f.h"
21 #include "ui/gfx/paint_vector_icon.h"
17 #include "ui/views/background.h" 22 #include "ui/views/background.h"
23 #include "ui/views/border.h"
18 #include "ui/views/bubble/bubble_frame_view.h" 24 #include "ui/views/bubble/bubble_frame_view.h"
19 #include "ui/views/controls/button/button.h" 25 #include "ui/views/controls/button/button.h"
20 #include "ui/views/controls/button/vector_icon_button.h" 26 #include "ui/views/controls/button/vector_icon_button.h"
21 #include "ui/views/controls/label.h" 27 #include "ui/views/controls/label.h"
22 #include "ui/views/controls/styled_label.h" 28 #include "ui/views/controls/styled_label.h"
23 #include "ui/views/layout/grid_layout.h" 29 #include "ui/views/layout/grid_layout.h"
30 #include "ui/views/painter.h"
24 #include "ui/views/view.h" 31 #include "ui/views/view.h"
25 32
26 namespace { 33 namespace {
27 34
28 // TODO(tmartino): Consider combining this with the Android equivalent in 35 // TODO(tmartino): Consider combining this with the Android equivalent in
29 // PersonalDataManager.java 36 // PersonalDataManager.java
30 base::string16 GetAddressFromProfile(const autofill::AutofillProfile& profile, 37 base::string16 GetAddressFromProfile(const autofill::AutofillProfile& profile,
31 const std::string& locale) { 38 const std::string& locale) {
32 std::vector<autofill::ServerFieldType> fields; 39 std::vector<autofill::ServerFieldType> fields;
33 fields.push_back(autofill::COMPANY_NAME); 40 fields.push_back(autofill::COMPANY_NAME);
34 fields.push_back(autofill::ADDRESS_HOME_LINE1); 41 fields.push_back(autofill::ADDRESS_HOME_LINE1);
35 fields.push_back(autofill::ADDRESS_HOME_LINE2); 42 fields.push_back(autofill::ADDRESS_HOME_LINE2);
36 fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY); 43 fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY);
37 fields.push_back(autofill::ADDRESS_HOME_CITY); 44 fields.push_back(autofill::ADDRESS_HOME_CITY);
38 fields.push_back(autofill::ADDRESS_HOME_STATE); 45 fields.push_back(autofill::ADDRESS_HOME_STATE);
39 fields.push_back(autofill::ADDRESS_HOME_ZIP); 46 fields.push_back(autofill::ADDRESS_HOME_ZIP);
40 fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE); 47 fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE);
41 48
42 return profile.ConstructInferredLabel(fields, fields.size(), locale); 49 return profile.ConstructInferredLabel(fields, fields.size(), locale);
43 } 50 }
44 51
52 // Paints the gray horizontal line that doesn't span the entire width of the
53 // dialog at the bottom of the view it borders.
54 class PaymentRequestRowBorderPainter : public views::Painter {
55 public:
56 PaymentRequestRowBorderPainter() {}
57 ~PaymentRequestRowBorderPainter() override {}
58
59 // views::Painter:
60 gfx::Size GetMinimumSize() const override {
61 return gfx::Size(2 * payments::kPaymentRequestRowHorizontalInsets, 1);
62 }
63
64 void Paint(gfx::Canvas* canvas, const gfx::Size& size) override {
65 int line_height = size.height() - 1;
66 canvas->DrawLine(
67 gfx::PointF(payments::kPaymentRequestRowHorizontalInsets, line_height),
68 gfx::PointF(size.width() - payments::kPaymentRequestRowHorizontalInsets,
69 line_height),
70 SK_ColorLTGRAY);
71 }
72
73 private:
74 DISALLOW_COPY_AND_ASSIGN(PaymentRequestRowBorderPainter);
75 };
76
45 } // namespace 77 } // namespace
46 78
47 namespace payments { 79 namespace payments {
48 80
49 std::unique_ptr<views::View> CreateSheetHeaderView( 81 std::unique_ptr<views::View> CreateSheetHeaderView(
50 bool show_back_arrow, 82 bool show_back_arrow,
51 const base::string16& title, 83 const base::string16& title,
52 views::VectorIconButtonDelegate* delegate) { 84 views::VectorIconButtonDelegate* delegate) {
53 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 85 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
54 views::GridLayout* layout = new views::GridLayout(container.get()); 86 views::GridLayout* layout = new views::GridLayout(container.get());
55 container->SetLayoutManager(layout); 87 container->SetLayoutManager(layout);
88 layout->SetInsets(0, kPaymentRequestRowHorizontalInsets,
89 0, kPaymentRequestRowHorizontalInsets);
56 90
57 views::ColumnSet* columns = layout->AddColumnSet(0); 91 views::ColumnSet* columns = layout->AddColumnSet(0);
58 // A column for the optional back arrow. 92 // A column for the optional back arrow.
59 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 93 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
60 0, views::GridLayout::USE_PREF, 0, 0); 94 0, views::GridLayout::USE_PREF, 0, 0);
61 // A column for the title. 95 // A column for the title.
62 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 96 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
63 1, views::GridLayout::USE_PREF, 0, 0); 97 1, views::GridLayout::USE_PREF, 0, 0);
64 98
65 layout->StartRow(0, 0); 99 layout->StartRow(0, 0);
(...skipping 24 matching lines...) Expand all
90 124
91 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a 125 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a
92 // layer) won't do proper clipping. 126 // layer) won't do proper clipping.
93 view->SetPaintToLayer(); 127 view->SetPaintToLayer();
94 128
95 views::GridLayout* layout = new views::GridLayout(view.get()); 129 views::GridLayout* layout = new views::GridLayout(view.get());
96 view->SetLayoutManager(layout); 130 view->SetLayoutManager(layout);
97 131
98 constexpr int kTopInsetSize = 9; 132 constexpr int kTopInsetSize = 9;
99 constexpr int kBottomInsetSize = 18; 133 constexpr int kBottomInsetSize = 18;
100 constexpr int kSideInsetSize = 14; 134 layout->SetInsets(kTopInsetSize, 0, kBottomInsetSize, 0);
101 layout->SetInsets(
102 kTopInsetSize, kSideInsetSize, kBottomInsetSize, kSideInsetSize);
103 views::ColumnSet* columns = layout->AddColumnSet(0); 135 views::ColumnSet* columns = layout->AddColumnSet(0);
104 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 136 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
105 1, views::GridLayout::USE_PREF, 0, 0); 137 1, views::GridLayout::USE_PREF, 0, 0);
106 138
107 layout->StartRow(0, 0); 139 layout->StartRow(0, 0);
108 // |header_view| will be deleted when |view| is. 140 // |header_view| will be deleted when |view| is.
109 layout->AddView(header_view.release()); 141 layout->AddView(header_view.release());
110 142
111 layout->StartRow(0, 0); 143 layout->StartRow(0, 0);
112 // |content_view| will be deleted when |view| is. 144 // |content_view| will be deleted when |view| is.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 values.push_back(name_value); 206 values.push_back(name_value);
175 if (!phone_value.empty()) 207 if (!phone_value.empty())
176 values.push_back(phone_value); 208 values.push_back(phone_value);
177 if (!email_value.empty()) 209 if (!email_value.empty())
178 values.push_back(email_value); 210 values.push_back(email_value);
179 211
180 return base::MakeUnique<views::StyledLabel>( 212 return base::MakeUnique<views::StyledLabel>(
181 base::JoinString(values, base::ASCIIToUTF16("\n")), nullptr); 213 base::JoinString(values, base::ASCIIToUTF16("\n")), nullptr);
182 } 214 }
183 215
216 // Creates a views::Border object that can paint the gray horizontal ruler used
217 // as a separator between items in the Payment Request dialog.
218 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() {
219 return views::CreateBorderPainter(
220 base::MakeUnique<PaymentRequestRowBorderPainter>(),
221 gfx::Insets());
222 }
223
184 } // namespace payments 224 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698