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

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: 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
please use gerrit instead 2017/01/25 16:22:55 Need to override the parent destructor.
anthonyvd 2017/01/25 17:56:33 Good catch! Done here and in the other classes thi
58 protected:
please use gerrit instead 2017/01/25 16:22:55 This class has no children, so it's OK to make Get
anthonyvd 2017/01/25 17:56:33 Done.
59 gfx::Size GetMinimumSize() const override {
60 return gfx::Size(2 * payments::kPaymentRequestRowHorizontalInsets, 1);
61 }
62
63 void Paint(gfx::Canvas* canvas, const gfx::Size& size) override {
64 int line_height = size.height() - 1;
65 canvas->DrawLine(
66 gfx::PointF(payments::kPaymentRequestRowHorizontalInsets, line_height),
67 gfx::PointF(size.width() - payments::kPaymentRequestRowHorizontalInsets,
68 line_height),
69 SK_ColorLTGRAY);
70 }
71
72 private:
73 DISALLOW_COPY_AND_ASSIGN(PaymentRequestRowBorderPainter);
74 };
75
45 } // namespace 76 } // namespace
46 77
47 namespace payments { 78 namespace payments {
48 79
49 std::unique_ptr<views::View> CreateSheetHeaderView( 80 std::unique_ptr<views::View> CreateSheetHeaderView(
50 bool show_back_arrow, 81 bool show_back_arrow,
51 const base::string16& title, 82 const base::string16& title,
52 views::VectorIconButtonDelegate* delegate) { 83 views::VectorIconButtonDelegate* delegate) {
53 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 84 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
54 views::GridLayout* layout = new views::GridLayout(container.get()); 85 views::GridLayout* layout = new views::GridLayout(container.get());
55 container->SetLayoutManager(layout); 86 container->SetLayoutManager(layout);
87 layout->SetInsets(0, kPaymentRequestRowHorizontalInsets,
88 0, kPaymentRequestRowHorizontalInsets);
56 89
57 views::ColumnSet* columns = layout->AddColumnSet(0); 90 views::ColumnSet* columns = layout->AddColumnSet(0);
58 // A column for the optional back arrow. 91 // A column for the optional back arrow.
59 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 92 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
60 0, views::GridLayout::USE_PREF, 0, 0); 93 0, views::GridLayout::USE_PREF, 0, 0);
61 // A column for the title. 94 // A column for the title.
62 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 95 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
63 1, views::GridLayout::USE_PREF, 0, 0); 96 1, views::GridLayout::USE_PREF, 0, 0);
64 97
65 layout->StartRow(0, 0); 98 layout->StartRow(0, 0);
(...skipping 24 matching lines...) Expand all
90 123
91 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a 124 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a
92 // layer) won't do proper clipping. 125 // layer) won't do proper clipping.
93 view->SetPaintToLayer(true); 126 view->SetPaintToLayer(true);
94 127
95 views::GridLayout* layout = new views::GridLayout(view.get()); 128 views::GridLayout* layout = new views::GridLayout(view.get());
96 view->SetLayoutManager(layout); 129 view->SetLayoutManager(layout);
97 130
98 constexpr int kTopInsetSize = 9; 131 constexpr int kTopInsetSize = 9;
99 constexpr int kBottomInsetSize = 18; 132 constexpr int kBottomInsetSize = 18;
100 constexpr int kSideInsetSize = 14; 133 layout->SetInsets(kTopInsetSize, 0, kBottomInsetSize, 0);
101 layout->SetInsets(
102 kTopInsetSize, kSideInsetSize, kBottomInsetSize, kSideInsetSize);
103 views::ColumnSet* columns = layout->AddColumnSet(0); 134 views::ColumnSet* columns = layout->AddColumnSet(0);
104 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 135 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
105 1, views::GridLayout::USE_PREF, 0, 0); 136 1, views::GridLayout::USE_PREF, 0, 0);
106 137
107 layout->StartRow(0, 0); 138 layout->StartRow(0, 0);
108 // |header_view| will be deleted when |view| is. 139 // |header_view| will be deleted when |view| is.
109 layout->AddView(header_view.release()); 140 layout->AddView(header_view.release());
110 141
111 layout->StartRow(0, 0); 142 layout->StartRow(0, 0);
112 // |content_view| will be deleted when |view| is. 143 // |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); 205 values.push_back(name_value);
175 if (!phone_value.empty()) 206 if (!phone_value.empty())
176 values.push_back(phone_value); 207 values.push_back(phone_value);
177 if (!email_value.empty()) 208 if (!email_value.empty())
178 values.push_back(email_value); 209 values.push_back(email_value);
179 210
180 return base::MakeUnique<views::StyledLabel>( 211 return base::MakeUnique<views::StyledLabel>(
181 base::JoinString(values, base::ASCIIToUTF16("\n")), nullptr); 212 base::JoinString(values, base::ASCIIToUTF16("\n")), nullptr);
182 } 213 }
183 214
215 // Creates a views::Border object that can paint the gray horizontal ruler used
216 // as a separator between items in the Payment Request dialog.
217 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() {
218 return views::CreateBorderPainter(
219 base::MakeUnique<PaymentRequestRowBorderPainter>(),
220 gfx::Insets());
221 }
222
184 } // namespace payments 223 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698