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

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

Issue 2923533002: [Merge M60][Payments] Do not select an address if the merchant doesn't support it (Closed)
Patch Set: Created 3 years, 6 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"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "ui/views/layout/grid_layout.h" 45 #include "ui/views/layout/grid_layout.h"
46 #include "ui/views/layout/layout_provider.h" 46 #include "ui/views/layout/layout_provider.h"
47 #include "ui/views/painter.h" 47 #include "ui/views/painter.h"
48 #include "ui/views/view.h" 48 #include "ui/views/view.h"
49 49
50 namespace payments { 50 namespace payments {
51 51
52 namespace { 52 namespace {
53 53
54 // |s1|, |s2|, and |s3| are lines identifying the profile. |s1| is the 54 // |s1|, |s2|, and |s3| are lines identifying the profile. |s1| is the
55 // "headline" which may be emphasized depending on |type|. If |disabled_state| 55 // "headline" which may be emphasized depending on |type|. If |enabled| is
56 // is true, the labels will look disabled. 56 // false, the labels will look disabled.
57 std::unique_ptr<views::View> GetBaseProfileLabel(AddressStyleType type, 57 std::unique_ptr<views::View> GetBaseProfileLabel(AddressStyleType type,
58 const base::string16& s1, 58 const base::string16& s1,
59 const base::string16& s2, 59 const base::string16& s2,
60 const base::string16& s3, 60 const base::string16& s3,
61 bool disabled_state = false) { 61 bool enabled = true) {
62 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 62 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
63 std::unique_ptr<views::BoxLayout> layout = 63 std::unique_ptr<views::BoxLayout> layout =
64 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); 64 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0);
65 layout->set_cross_axis_alignment( 65 layout->set_cross_axis_alignment(
66 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); 66 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
67 container->SetLayoutManager(layout.release()); 67 container->SetLayoutManager(layout.release());
68 68
69 if (!s1.empty()) { 69 if (!s1.empty()) {
70 const int text_style = type == AddressStyleType::DETAILED 70 const int text_style = type == AddressStyleType::DETAILED
71 ? static_cast<int>(STYLE_EMPHASIZED) 71 ? static_cast<int>(STYLE_EMPHASIZED)
72 : static_cast<int>(views::style::STYLE_PRIMARY); 72 : static_cast<int>(views::style::STYLE_PRIMARY);
73 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( 73 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(
74 s1, views::style::CONTEXT_LABEL, text_style); 74 s1, views::style::CONTEXT_LABEL, text_style);
75 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1)); 75 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1));
76 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 76 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
77 if (disabled_state) { 77 if (!enabled) {
78 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( 78 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
79 ui::NativeTheme::kColorId_LabelDisabledColor)); 79 ui::NativeTheme::kColorId_LabelDisabledColor));
80 } 80 }
81 container->AddChildView(label.release()); 81 container->AddChildView(label.release());
82 } 82 }
83 83
84 if (!s2.empty()) { 84 if (!s2.empty()) {
85 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s2); 85 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s2);
86 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_2)); 86 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_2));
87 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 87 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
88 if (disabled_state) { 88 if (!enabled) {
89 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( 89 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
90 ui::NativeTheme::kColorId_LabelDisabledColor)); 90 ui::NativeTheme::kColorId_LabelDisabledColor));
91 } 91 }
92 container->AddChildView(label.release()); 92 container->AddChildView(label.release());
93 } 93 }
94 94
95 if (!s3.empty()) { 95 if (!s3.empty()) {
96 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s3); 96 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s3);
97 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_3)); 97 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_3));
98 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 98 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
99 if (disabled_state) { 99 if (!enabled) {
100 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( 100 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
101 ui::NativeTheme::kColorId_LabelDisabledColor)); 101 ui::NativeTheme::kColorId_LabelDisabledColor));
102 } 102 }
103 container->AddChildView(label.release()); 103 container->AddChildView(label.release());
104 } 104 }
105 return container; 105 return container;
106 } 106 }
107 107
108 // Returns a label representing the |profile| as a shipping address. See 108 // Returns a label representing the |profile| as a shipping address. See
109 // GetBaseProfileLabel() for more documentation. 109 // GetBaseProfileLabel() for more documentation.
110 std::unique_ptr<views::View> GetShippingAddressLabel( 110 std::unique_ptr<views::View> GetShippingAddressLabel(
111 AddressStyleType type, 111 AddressStyleType type,
112 const std::string& locale, 112 const std::string& locale,
113 const autofill::AutofillProfile& profile, 113 const autofill::AutofillProfile& profile,
114 bool disabled_state) { 114 bool enabled) {
115 base::string16 name = 115 base::string16 name =
116 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); 116 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale);
117 117
118 base::string16 address = 118 base::string16 address =
119 GetShippingAddressLabelFormAutofillProfile(profile, locale); 119 GetShippingAddressLabelFormAutofillProfile(profile, locale);
120 120
121 base::string16 phone = 121 base::string16 phone =
122 data_util::GetFormattedPhoneNumberForDisplay(profile, locale); 122 data_util::GetFormattedPhoneNumberForDisplay(profile, locale);
123 123
124 return GetBaseProfileLabel(type, name, address, phone, disabled_state); 124 return GetBaseProfileLabel(type, name, address, phone, enabled);
125 } 125 }
126 126
127 std::unique_ptr<views::Label> GetLabelForMissingInformation( 127 std::unique_ptr<views::Label> GetLabelForMissingInformation(
128 const base::string16& missing_info) { 128 const base::string16& missing_info) {
129 std::unique_ptr<views::Label> label = 129 std::unique_ptr<views::Label> label =
130 base::MakeUnique<views::Label>(missing_info, CONTEXT_DEPRECATED_SMALL); 130 base::MakeUnique<views::Label>(missing_info, CONTEXT_DEPRECATED_SMALL);
131 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR)); 131 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR));
132 // Missing information typically has a nice shade of blue. 132 // Missing information typically has a nice shade of blue.
133 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( 133 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
134 ui::NativeTheme::kColorId_LinkEnabled)); 134 ui::NativeTheme::kColorId_LinkEnabled));
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 chrome_logo->set_can_process_events_within_subtree(false); 253 chrome_logo->set_can_process_events_within_subtree(false);
254 chrome_logo->SetImage(ResourceBundle::GetSharedInstance() 254 chrome_logo->SetImage(ResourceBundle::GetSharedInstance()
255 .GetImageNamed(IDR_PRODUCT_LOGO_NAME_22) 255 .GetImageNamed(IDR_PRODUCT_LOGO_NAME_22)
256 .AsImageSkia()); 256 .AsImageSkia());
257 chrome_logo->SetTooltipText(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 257 chrome_logo->SetTooltipText(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
258 content_view->AddChildView(chrome_logo.release()); 258 content_view->AddChildView(chrome_logo.release());
259 259
260 return content_view; 260 return content_view;
261 } 261 }
262 262
263 std::unique_ptr<views::View> GetShippingAddressLabelWithError(
264 AddressStyleType type,
265 const std::string& locale,
266 const autofill::AutofillProfile& profile,
267 const base::string16& error,
268 bool disabled_state) {
269 std::unique_ptr<views::View> base_label =
270 GetShippingAddressLabel(type, locale, profile, disabled_state);
271
272 if (!error.empty()) {
273 std::unique_ptr<views::Label> label =
274 base::MakeUnique<views::Label>(error, CONTEXT_DEPRECATED_SMALL);
275 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR));
276 // Error information is typically in red.
277 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
278 ui::NativeTheme::kColorId_AlertSeverityHigh));
279 base_label->AddChildView(label.release());
280 }
281 return base_label;
282 }
283
284 std::unique_ptr<views::View> GetShippingAddressLabelWithMissingInfo( 263 std::unique_ptr<views::View> GetShippingAddressLabelWithMissingInfo(
285 AddressStyleType type, 264 AddressStyleType type,
286 const std::string& locale, 265 const std::string& locale,
287 const autofill::AutofillProfile& profile, 266 const autofill::AutofillProfile& profile,
288 const PaymentsProfileComparator& comp) { 267 const PaymentsProfileComparator& comp,
268 bool enabled) {
289 std::unique_ptr<views::View> base_label = 269 std::unique_ptr<views::View> base_label =
290 GetShippingAddressLabel(type, locale, profile, /*disabled_state=*/false); 270 GetShippingAddressLabel(type, locale, profile, enabled);
291 271
292 base::string16 missing = comp.GetStringForMissingShippingFields(profile); 272 base::string16 missing = comp.GetStringForMissingShippingFields(profile);
293 if (!missing.empty()) { 273 if (!missing.empty()) {
294 base_label->AddChildView(GetLabelForMissingInformation(missing).release()); 274 base_label->AddChildView(GetLabelForMissingInformation(missing).release());
295 } 275 }
296 return base_label; 276 return base_label;
297 } 277 }
298 278
299 // TODO(anthonyvd): unit test the label layout. 279 // TODO(anthonyvd): unit test the label layout.
300 std::unique_ptr<views::View> GetContactInfoLabel( 280 std::unique_ptr<views::View> GetContactInfoLabel(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 amount_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 358 amount_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
379 amount_label->set_id( 359 amount_label->set_id(
380 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT)); 360 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT));
381 container->AddChildView(amount_label.release()); 361 container->AddChildView(amount_label.release());
382 } 362 }
383 363
384 return container; 364 return container;
385 } 365 }
386 366
387 } // namespace payments 367 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698