Commit 05c7f958 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Inline various helpers to simplify overall code.

No functional changes, other than replacing a "320" with a Harmony
constant of the same value.

Bug: none
Change-Id: Ia948c2fd608be294d5e0feadec7790f26941075a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2385238
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarCaroline Rising <corising@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803622}
parent bbe6013d
......@@ -136,25 +136,20 @@ LegalMessageView::LegalMessageView(const LegalMessageLines& legal_message_lines,
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
for (const LegalMessageLine& line : legal_message_lines) {
AddChildView(CreateLegalMessageLineLabel(line).release());
views::StyledLabel* label =
AddChildView(std::make_unique<views::StyledLabel>(this));
label->SetText(line.text());
label->SetTextContext(views::style::CONTEXT_DIALOG_BODY_TEXT);
label->SetDefaultTextStyle(views::style::STYLE_SECONDARY);
for (const LegalMessageLine::Link& link : line.links()) {
label->AddStyleRange(link.range,
views::StyledLabel::RangeStyleInfo::CreateForLink());
}
}
}
LegalMessageView::~LegalMessageView() {}
std::unique_ptr<views::StyledLabel>
LegalMessageView::CreateLegalMessageLineLabel(const LegalMessageLine& line) {
auto label = std::make_unique<views::StyledLabel>(this);
label->SetText(line.text());
label->SetTextContext(views::style::CONTEXT_DIALOG_BODY_TEXT);
label->SetDefaultTextStyle(views::style::STYLE_SECONDARY);
for (const LegalMessageLine::Link& link : line.links()) {
label->AddStyleRange(link.range,
views::StyledLabel::RangeStyleInfo::CreateForLink());
}
return label;
}
void LegalMessageView::StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) {
......
......@@ -57,9 +57,6 @@ class LegalMessageView : public views::View, public views::StyledLabelListener {
int event_flags) override;
private:
std::unique_ptr<views::StyledLabel> CreateLegalMessageLineLabel(
const LegalMessageLine& line);
const LegalMessageLines legal_message_lines_;
const LinkClickedCallback callback_;
};
......
......@@ -46,33 +46,20 @@
namespace autofill {
namespace {
const int kTooltipBubbleWidth = 320;
const int kTooltipIconSize = 12;
std::unique_ptr<LegalMessageView> CreateLegalMessageView(
const LegalMessageLines& message_lines,
LegalMessageView::LinkClickedCallback callback) {
if (message_lines.empty())
return nullptr;
return std::make_unique<LegalMessageView>(message_lines, std::move(callback));
}
} // namespace
SaveCardOfferBubbleViews::SaveCardOfferBubbleViews(
views::View* anchor_view,
content::WebContents* web_contents,
SaveCardBubbleController* controller)
: SaveCardBubbleViews(anchor_view, web_contents, controller) {
SetButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL);
legal_message_view_ = SetFootnoteView(CreateLegalMessageView(
controller->GetLegalMessageLines(),
base::BindRepeating(&SaveCardOfferBubbleViews::LinkClicked,
base::Unretained(this))));
if (legal_message_view_)
const LegalMessageLines message_lines = controller->GetLegalMessageLines();
if (!message_lines.empty()) {
legal_message_view_ = SetFootnoteView(std::make_unique<LegalMessageView>(
message_lines,
base::BindRepeating(&SaveCardOfferBubbleViews::LinkClicked,
base::Unretained(this))));
InitFootnoteView(legal_message_view_);
}
}
void SaveCardOfferBubbleViews::Init() {
......@@ -190,6 +177,7 @@ std::unique_ptr<views::View> SaveCardOfferBubbleViews::CreateMainContentView() {
if (!prefilled_name.empty() &&
controller()->GetSyncState() !=
AutofillSyncSigninState::kSignedInAndWalletSyncTransportEnabled) {
constexpr int kTooltipIconSize = 12;
std::unique_ptr<views::TooltipIcon> cardholder_name_tooltip =
std::make_unique<views::TooltipIcon>(
l10n_util::GetStringUTF16(
......@@ -307,7 +295,9 @@ SaveCardOfferBubbleViews::CreateUploadExplanationView() {
!cardholder_name_textfield_->GetText().empty())
? IDS_AUTOFILL_SAVE_CARD_PROMPT_UPLOAD_EXPLANATION_AND_CARDHOLDER_NAME_TOOLTIP
: IDS_AUTOFILL_SAVE_CARD_PROMPT_UPLOAD_EXPLANATION_TOOLTIP));
upload_explanation_tooltip->set_bubble_width(kTooltipBubbleWidth);
upload_explanation_tooltip->set_bubble_width(
ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_BUBBLE_PREFERRED_WIDTH));
upload_explanation_tooltip->set_anchor_point_arrow(
views::BubbleBorder::Arrow::TOP_RIGHT);
upload_explanation_tooltip->SetID(DialogViewId::UPLOAD_EXPLANATION_TOOLTIP);
......
......@@ -119,23 +119,6 @@ base::string16 PrepareHelpTextWithOrigin(const SharingDialogData& data,
return text;
}
std::unique_ptr<views::StyledLabel> CreateHelpText(
const SharingDialogData& data,
views::StyledLabelListener* listener,
bool show_origin) {
DCHECK_NE(0, data.help_link_text_id);
const base::string16 link = l10n_util::GetStringUTF16(data.help_link_text_id);
size_t offset;
auto label = std::make_unique<views::StyledLabel>(listener);
label->SetText(show_origin
? PrepareHelpTextWithOrigin(data, link, &offset)
: PrepareHelpTextWithoutOrigin(data, link, &offset));
views::StyledLabel::RangeStyleInfo link_style =
views::StyledLabel::RangeStyleInfo::CreateForLink();
label->AddStyleRange(gfx::Range(offset, offset + link.length()), link_style);
return label;
}
std::unique_ptr<views::View> CreateOriginView(const SharingDialogData& data) {
DCHECK(data.initiating_origin);
DCHECK_NE(0, data.origin_text_id);
......@@ -153,22 +136,6 @@ std::unique_ptr<views::View> CreateOriginView(const SharingDialogData& data) {
return label;
}
std::unique_ptr<views::View> CreateHelpOrOriginView(
const SharingDialogData& data,
content::WebContents* web_contents,
views::StyledLabelListener* listener) {
bool show_origin = ShouldShowOrigin(data, web_contents);
switch (data.type) {
case SharingDialogType::kDialogWithoutDevicesWithApp:
return CreateHelpText(data, listener, show_origin);
case SharingDialogType::kDialogWithDevicesMaybeApps:
return show_origin ? CreateOriginView(data) : nullptr;
case SharingDialogType::kErrorDialog:
case SharingDialogType::kEducationalDialog:
return nullptr;
}
}
} // namespace
SharingDialogView::SharingDialogView(views::View* anchor_view,
......@@ -177,7 +144,14 @@ SharingDialogView::SharingDialogView(views::View* anchor_view,
: LocationBarBubbleDelegateView(anchor_view, web_contents),
data_(std::move(data)) {
SetButtons(ui::DIALOG_BUTTON_NONE);
SetFootnoteView(CreateHelpOrOriginView(data_, web_contents, this));
if (data_.type == SharingDialogType::kDialogWithoutDevicesWithApp) {
SetFootnoteView(CreateHelpText());
} else if ((data_.type == SharingDialogType::kDialogWithDevicesMaybeApps) &&
ShouldShowOrigin(data_, web_contents)) {
SetFootnoteView(CreateOriginView(data_));
}
set_close_on_main_frame_origin_navigation(true);
}
......@@ -291,7 +265,7 @@ void SharingDialogView::Init() {
InitErrorView();
break;
case SharingDialogType::kEducationalDialog:
InitEmptyView();
AddChildView(CreateHelpText());
break;
case SharingDialogType::kDialogWithoutDevicesWithApp:
case SharingDialogType::kDialogWithDevicesMaybeApps:
......@@ -378,11 +352,6 @@ void SharingDialogView::InitListView() {
}
}
void SharingDialogView::InitEmptyView() {
bool show_origin = ShouldShowOrigin(data_, web_contents());
AddChildView(CreateHelpText(data_, this, show_origin));
}
void SharingDialogView::InitErrorView() {
auto label = std::make_unique<views::Label>(data_.error_text,
views::style::CONTEXT_LABEL,
......@@ -391,3 +360,18 @@ void SharingDialogView::InitErrorView() {
label->SetMultiLine(true);
AddChildView(std::move(label));
}
std::unique_ptr<views::StyledLabel> SharingDialogView::CreateHelpText() {
DCHECK_NE(0, data_.help_link_text_id);
const base::string16 link =
l10n_util::GetStringUTF16(data_.help_link_text_id);
size_t offset;
auto label = std::make_unique<views::StyledLabel>(this);
label->SetText(ShouldShowOrigin(data_, web_contents())
? PrepareHelpTextWithOrigin(data_, link, &offset)
: PrepareHelpTextWithoutOrigin(data_, link, &offset));
views::StyledLabel::RangeStyleInfo link_style =
views::StyledLabel::RangeStyleInfo::CreateForLink();
label->AddStyleRange(gfx::Range(offset, offset + link.length()), link_style);
return label;
}
......@@ -74,11 +74,11 @@ class SharingDialogView : public SharingDialog,
// Populates the dialog view containing valid devices and apps.
void InitListView();
// Populates the dialog view containing no devices or apps.
void InitEmptyView();
// Populates the dialog view containing error help text.
void InitErrorView();
std::unique_ptr<views::StyledLabel> CreateHelpText();
SharingDialogData data_;
// References to device and app buttons views.
......
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