Commit 7aa59ab3 authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Fix SaveCardBubbleViews layout

Removes manual label-width calculations.

Bug: 1142902
Change-Id: Ibd09f522a3b2ce59ccc76281121974cec30190e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2503310
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821539}
parent 495634a0
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <memory> #include <memory>
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/views/autofill/payments/dialog_view_ids.h" #include "chrome/browser/ui/views/autofill/payments/dialog_view_ids.h"
...@@ -31,6 +30,7 @@ ...@@ -31,6 +30,7 @@
#include "ui/views/controls/styled_label.h" #include "ui/views/controls/styled_label.h"
#include "ui/views/controls/textfield/textfield.h" #include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/box_layout_view.h"
#include "ui/views/style/typography.h" #include "ui/views/style/typography.h"
namespace autofill { namespace autofill {
...@@ -136,71 +136,59 @@ SaveCardBubbleViews::~SaveCardBubbleViews() = default; ...@@ -136,71 +136,59 @@ SaveCardBubbleViews::~SaveCardBubbleViews() = default;
// Overridden // Overridden
std::unique_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() { std::unique_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() {
std::unique_ptr<views::View> view = std::make_unique<views::View>(); ChromeLayoutProvider* const provider = ChromeLayoutProvider::Get();
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
view->SetLayoutManager(std::make_unique<views::BoxLayout>( auto view = std::make_unique<views::BoxLayoutView>();
views::BoxLayout::Orientation::kVertical, gfx::Insets(), view->SetOrientation(views::BoxLayout::Orientation::kVertical);
provider->GetDistanceMetric(views::DISTANCE_UNRELATED_CONTROL_VERTICAL))); view->SetBetweenChildSpacing(
provider->GetDistanceMetric(views::DISTANCE_UNRELATED_CONTROL_VERTICAL));
// If applicable, add the upload explanation label. Appears above the card // If applicable, add the upload explanation label. Appears above the card
// info. // info.
base::string16 explanation = controller_->GetExplanatoryMessage(); base::string16 explanation = controller_->GetExplanatoryMessage();
if (!explanation.empty()) { if (!explanation.empty()) {
auto* explanation_label = auto* const explanation_label =
new views::Label(explanation, views::style::CONTEXT_DIALOG_BODY_TEXT, view->AddChildView(std::make_unique<views::Label>(
views::style::STYLE_SECONDARY); explanation, views::style::CONTEXT_DIALOG_BODY_TEXT,
views::style::STYLE_SECONDARY));
explanation_label->SetMultiLine(true); explanation_label->SetMultiLine(true);
explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
view->AddChildView(explanation_label);
} }
// Add the card network icon, last four digits and expiration date. // Add the card network icon, last four digits and expiration date.
auto* description_view = new views::View(); auto* description_view =
views::BoxLayout* box_layout = view->AddChildView(std::make_unique<views::BoxLayoutView>());
description_view->SetLayoutManager(std::make_unique<views::BoxLayout>( description_view->SetBetweenChildSpacing(
views::BoxLayout::Orientation::kHorizontal, gfx::Insets(), provider->GetDistanceMetric(views::DISTANCE_RELATED_BUTTON_HORIZONTAL));
provider->GetDistanceMetric(
views::DISTANCE_RELATED_BUTTON_HORIZONTAL)));
view->AddChildView(description_view);
const CreditCard& card = controller_->GetCard(); const CreditCard& card = controller_->GetCard();
auto* card_network_icon = new views::ImageView(); auto* const card_network_icon =
description_view->AddChildView(std::make_unique<views::ImageView>());
card_network_icon->SetImage( card_network_icon->SetImage(
ui::ResourceBundle::GetSharedInstance() ui::ResourceBundle::GetSharedInstance()
.GetImageNamed(CreditCard::IconResourceId(card.network())) .GetImageNamed(CreditCard::IconResourceId(card.network()))
.AsImageSkia()); .AsImageSkia());
card_network_icon->SetTooltipText(card.NetworkForDisplay()); card_network_icon->SetTooltipText(card.NetworkForDisplay());
description_view->AddChildView(card_network_icon);
views::Label* label = description_view->AddChildView(new views::Label( auto* const card_identifier_label =
description_view->AddChildView(std::make_unique<views::Label>(
GetCardIdentifierString(), views::style::CONTEXT_DIALOG_BODY_TEXT, GetCardIdentifierString(), views::style::CONTEXT_DIALOG_BODY_TEXT,
views::style::STYLE_PRIMARY)); views::style::STYLE_PRIMARY));
label->SetMultiLine(true); card_identifier_label->SetMultiLine(true);
label->SetHorizontalAlignment(gfx::ALIGN_LEFT); card_identifier_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
int label_width =
GetPreferredSize().width() -
card_network_icon->GetPreferredSize().width() -
provider->GetDistanceMetric(views::DISTANCE_RELATED_BUTTON_HORIZONTAL);
if (!card.IsExpired(base::Time::Now())) { // Flex |card_identifier_label| to fill up remaining space and tail align the
// The spacer will stretch to use the available horizontal space in the // expiry date.
// dialog, which will end-align the expiration date label. description_view->SetFlexForView(card_identifier_label, 1);
auto* spacer = new views::View();
description_view->AddChildView(spacer);
box_layout->SetFlexForView(spacer, /*flex=*/1);
auto* expiration_date_label = new views::Label( if (!card.IsExpired(base::Time::Now())) {
auto* expiration_date_label =
description_view->AddChildView(std::make_unique<views::Label>(
card.AbbreviatedExpirationDateForDisplay(false), card.AbbreviatedExpirationDateForDisplay(false),
views::style::CONTEXT_DIALOG_BODY_TEXT, views::style::STYLE_SECONDARY); views::style::CONTEXT_DIALOG_BODY_TEXT,
views::style::STYLE_SECONDARY));
expiration_date_label->SetID(DialogViewId::EXPIRATION_DATE_LABEL); expiration_date_label->SetID(DialogViewId::EXPIRATION_DATE_LABEL);
description_view->AddChildView(expiration_date_label);
constexpr int kExpirationDateLabelWidth = 60;
label_width -=
kExpirationDateLabelWidth +
provider->GetDistanceMetric(views::DISTANCE_RELATED_BUTTON_HORIZONTAL);
} }
label->SetMaximumWidth(label_width);
return view; return view;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment