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

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

Issue 2901763002: Revert of Remove uses of FontList::Derive*(..) in views payments dialogs. (Closed)
Patch Set: Created 3 years, 7 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/browser/ui/views/harmony/chrome_typography.h"
13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 12 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
14 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" 13 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h"
15 #include "chrome/grit/chromium_strings.h" 14 #include "chrome/grit/chromium_strings.h"
16 #include "chrome/grit/theme_resources.h" 15 #include "chrome/grit/theme_resources.h"
17 #include "components/autofill/core/browser/autofill_data_util.h" 16 #include "components/autofill/core/browser/autofill_data_util.h"
18 #include "components/autofill/core/browser/autofill_profile.h" 17 #include "components/autofill/core/browser/autofill_profile.h"
19 #include "components/autofill/core/browser/autofill_type.h" 18 #include "components/autofill/core/browser/autofill_type.h"
20 #include "components/autofill/core/browser/credit_card.h" 19 #include "components/autofill/core/browser/credit_card.h"
21 #include "components/autofill/core/browser/field_types.h" 20 #include "components/autofill/core/browser/field_types.h"
22 #include "components/payments/core/payment_options_provider.h" 21 #include "components/payments/core/payment_options_provider.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 const base::string16& s3, 74 const base::string16& s3,
76 bool disabled_state = false) { 75 bool disabled_state = false) {
77 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 76 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
78 std::unique_ptr<views::BoxLayout> layout = 77 std::unique_ptr<views::BoxLayout> layout =
79 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); 78 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0);
80 layout->set_cross_axis_alignment( 79 layout->set_cross_axis_alignment(
81 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); 80 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
82 container->SetLayoutManager(layout.release()); 81 container->SetLayoutManager(layout.release());
83 82
84 if (!s1.empty()) { 83 if (!s1.empty()) {
85 const int text_style = type == AddressStyleType::DETAILED 84 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s1);
86 ? STYLE_EMPHASIZED 85 if (type == AddressStyleType::DETAILED) {
87 : views::style::STYLE_PRIMARY; 86 const gfx::FontList& font_list = label->font_list();
88 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( 87 label->SetFontList(font_list.DeriveWithWeight(gfx::Font::Weight::BOLD));
89 s1, views::style::CONTEXT_LABEL, text_style); 88 }
90 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1)); 89 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1));
91 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 90 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
92 if (disabled_state) { 91 if (disabled_state) {
93 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( 92 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
94 ui::NativeTheme::kColorId_LabelDisabledColor)); 93 ui::NativeTheme::kColorId_LabelDisabledColor));
95 } 94 }
96 container->AddChildView(label.release()); 95 container->AddChildView(label.release());
97 } 96 }
98 97
99 if (!s2.empty()) { 98 if (!s2.empty()) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 133
135 base::string16 phone = profile.GetInfo( 134 base::string16 phone = profile.GetInfo(
136 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); 135 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale);
137 136
138 return GetBaseProfileLabel(type, name, address, phone, disabled_state); 137 return GetBaseProfileLabel(type, name, address, phone, disabled_state);
139 } 138 }
140 139
141 std::unique_ptr<views::Label> GetLabelForMissingInformation( 140 std::unique_ptr<views::Label> GetLabelForMissingInformation(
142 const base::string16& missing_info) { 141 const base::string16& missing_info) {
143 std::unique_ptr<views::Label> label = 142 std::unique_ptr<views::Label> label =
144 base::MakeUnique<views::Label>(missing_info, CONTEXT_DEPRECATED_SMALL); 143 base::MakeUnique<views::Label>(missing_info);
145 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR)); 144 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR));
145 label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1));
146 // Missing information typically has a nice shade of blue. 146 // Missing information typically has a nice shade of blue.
147 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( 147 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
148 ui::NativeTheme::kColorId_LinkEnabled)); 148 ui::NativeTheme::kColorId_LinkEnabled));
149 return label; 149 return label;
150 } 150 }
151 151
152 // Paints the gray horizontal line that doesn't span the entire width of the 152 // Paints the gray horizontal line that doesn't span the entire width of the
153 // dialog at the bottom of the view it borders. 153 // dialog at the bottom of the view it borders.
154 class PaymentRequestRowBorderPainter : public views::Painter { 154 class PaymentRequestRowBorderPainter : public views::Painter {
155 public: 155 public:
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 views::SetImageFromVectorIcon(back_arrow, ui::kBackArrowIcon); 219 views::SetImageFromVectorIcon(back_arrow, ui::kBackArrowIcon);
220 constexpr int kBackArrowSize = 16; 220 constexpr int kBackArrowSize = 16;
221 back_arrow->SetSize(gfx::Size(kBackArrowSize, kBackArrowSize)); 221 back_arrow->SetSize(gfx::Size(kBackArrowSize, kBackArrowSize));
222 back_arrow->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); 222 back_arrow->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
223 back_arrow->set_tag(static_cast<int>( 223 back_arrow->set_tag(static_cast<int>(
224 PaymentRequestCommonTags::BACK_BUTTON_TAG)); 224 PaymentRequestCommonTags::BACK_BUTTON_TAG));
225 back_arrow->set_id(static_cast<int>(DialogViewID::BACK_BUTTON)); 225 back_arrow->set_id(static_cast<int>(DialogViewID::BACK_BUTTON));
226 layout->AddView(back_arrow); 226 layout->AddView(back_arrow);
227 } 227 }
228 228
229 views::Label* title_label = 229 views::Label* title_label = new views::Label(title);
230 new views::Label(title, views::style::CONTEXT_DIALOG_TITLE);
231 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 230 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
231 title_label->SetFontList(
232 title_label->GetDefaultFontList().DeriveWithSizeDelta(
233 ui::kTitleFontSizeDelta));
232 layout->AddView(title_label); 234 layout->AddView(title_label);
233 235
234 return container; 236 return container;
235 } 237 }
236 238
237 std::unique_ptr<views::ImageView> CreateInstrumentIconView( 239 std::unique_ptr<views::ImageView> CreateInstrumentIconView(
238 int icon_resource_id, 240 int icon_resource_id,
239 const base::string16& tooltip_text) { 241 const base::string16& tooltip_text) {
240 std::unique_ptr<views::ImageView> card_icon_view = 242 std::unique_ptr<views::ImageView> card_icon_view =
241 base::MakeUnique<views::ImageView>(); 243 base::MakeUnique<views::ImageView>();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 std::unique_ptr<views::View> GetShippingAddressLabelWithError( 275 std::unique_ptr<views::View> GetShippingAddressLabelWithError(
274 AddressStyleType type, 276 AddressStyleType type,
275 const std::string& locale, 277 const std::string& locale,
276 const autofill::AutofillProfile& profile, 278 const autofill::AutofillProfile& profile,
277 const base::string16& error, 279 const base::string16& error,
278 bool disabled_state) { 280 bool disabled_state) {
279 std::unique_ptr<views::View> base_label = 281 std::unique_ptr<views::View> base_label =
280 GetShippingAddressLabel(type, locale, profile, disabled_state); 282 GetShippingAddressLabel(type, locale, profile, disabled_state);
281 283
282 if (!error.empty()) { 284 if (!error.empty()) {
283 std::unique_ptr<views::Label> label = 285 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(error);
284 base::MakeUnique<views::Label>(error, CONTEXT_DEPRECATED_SMALL);
285 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR)); 286 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR));
287 label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1));
286 // Error information is typically in red. 288 // Error information is typically in red.
287 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( 289 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
288 ui::NativeTheme::kColorId_AlertSeverityHigh)); 290 ui::NativeTheme::kColorId_AlertSeverityHigh));
289 base_label->AddChildView(label.release()); 291 base_label->AddChildView(label.release());
290 } 292 }
291 return base_label; 293 return base_label;
292 } 294 }
293 295
294 std::unique_ptr<views::View> GetShippingAddressLabelWithMissingInfo( 296 std::unique_ptr<views::View> GetShippingAddressLabelWithMissingInfo(
295 AddressStyleType type, 297 AddressStyleType type,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 } 344 }
343 345
344 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder( 346 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder(
345 SkColor color, 347 SkColor color,
346 const gfx::Insets& insets) { 348 const gfx::Insets& insets) {
347 return views::CreateBorderPainter( 349 return views::CreateBorderPainter(
348 base::MakeUnique<PaymentRequestRowBorderPainter>(color), insets); 350 base::MakeUnique<PaymentRequestRowBorderPainter>(color), insets);
349 } 351 }
350 352
351 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) { 353 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) {
352 return base::MakeUnique<views::Label>(text, views::style::CONTEXT_LABEL, 354 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text);
353 STYLE_EMPHASIZED);
354 }
355 355
356 std::unique_ptr<views::Label> CreateMediumLabel(const base::string16& text) { 356 label->SetFontList(
357 // TODO(tapted): This should refer to a style in the Chrome typography spec. 357 label->font_list().DeriveWithWeight(gfx::Font::Weight::BOLD));
358 // Also, it needs to handle user setups where the default font is BOLD already 358
359 // since asking for a MEDIUM font will give a lighter font.
360 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text);
361 label->SetFontList(ResourceBundle::GetSharedInstance().GetFontListWithDelta(
362 ui::kLabelFontSizeDelta, gfx::Font::NORMAL, gfx::Font::Weight::MEDIUM));
363 return label; 359 return label;
364 } 360 }
365 361
366 std::unique_ptr<views::View> CreateShippingOptionLabel( 362 std::unique_ptr<views::View> CreateShippingOptionLabel(
367 payments::mojom::PaymentShippingOption* shipping_option, 363 payments::mojom::PaymentShippingOption* shipping_option,
368 const base::string16& formatted_amount, 364 const base::string16& formatted_amount,
369 bool emphasize_label) { 365 bool emphasize_label) {
370 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 366 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
371 367
372 std::unique_ptr<views::BoxLayout> layout = 368 std::unique_ptr<views::BoxLayout> layout =
373 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); 369 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0);
374 layout->set_cross_axis_alignment( 370 layout->set_cross_axis_alignment(
375 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); 371 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
376 container->SetLayoutManager(layout.release()); 372 container->SetLayoutManager(layout.release());
377 373
378 if (shipping_option) { 374 if (shipping_option) {
379 const base::string16& text = base::UTF8ToUTF16(shipping_option->label);
380 std::unique_ptr<views::Label> shipping_label = 375 std::unique_ptr<views::Label> shipping_label =
381 emphasize_label ? CreateMediumLabel(text) 376 base::MakeUnique<views::Label>(
382 : base::MakeUnique<views::Label>(text); 377 base::UTF8ToUTF16(shipping_option->label));
383 shipping_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 378 shipping_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
384 shipping_label->set_id( 379 shipping_label->set_id(
385 static_cast<int>(DialogViewID::SHIPPING_OPTION_DESCRIPTION)); 380 static_cast<int>(DialogViewID::SHIPPING_OPTION_DESCRIPTION));
381 if (emphasize_label) {
382 shipping_label->SetFontList(shipping_label->font_list().DeriveWithWeight(
383 gfx::Font::Weight::MEDIUM));
384 }
386 container->AddChildView(shipping_label.release()); 385 container->AddChildView(shipping_label.release());
387 386
388 std::unique_ptr<views::Label> amount_label = 387 std::unique_ptr<views::Label> amount_label =
389 base::MakeUnique<views::Label>(formatted_amount); 388 base::MakeUnique<views::Label>(formatted_amount);
390 amount_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 389 amount_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
391 amount_label->set_id( 390 amount_label->set_id(
392 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT)); 391 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT));
393 container->AddChildView(amount_label.release()); 392 container->AddChildView(amount_label.release());
394 } 393 }
395 394
396 return container; 395 return container;
397 } 396 }
398 397
399 } // namespace payments 398 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698