Commit 9a174f82 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Move StyledLabelListener override into LegalMessageView.

Instead of requiring consumers to use this, have them pass in a
callback, and call it with the correct URL directly.

This will facilitate further cleanups/simplifications later, e.g. the
replacement of StyledLabelListener with setting a callback directly.

Bug: none
Change-Id: Ia45310b19b6df915739d5a3c9c5567afff029d57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2384078
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803090}
parent aa5001b2
......@@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include "base/bind.h"
#include "base/i18n/message_formatter.h"
#include "base/location.h"
#include "base/macros.h"
......@@ -45,7 +46,6 @@
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/separator.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/controls/styled_label_listener.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/style/typography.h"
#include "ui/views/widget/widget.h"
......@@ -268,8 +268,7 @@ std::unique_ptr<views::View> CreateFeedbackContentView(
// horizontal separator, and legal message. It is used by
// LocalCardMigrationDialogView class when it offers the user the
// option to upload all browser-saved credit cards.
class LocalCardMigrationOfferView : public views::View,
public views::StyledLabelListener {
class LocalCardMigrationOfferView : public views::View {
public:
LocalCardMigrationOfferView(LocalCardMigrationDialogController* controller,
LocalCardMigrationDialogView* dialog_view)
......@@ -306,8 +305,11 @@ class LocalCardMigrationOfferView : public views::View,
AddChildView(new views::Separator());
legal_message_container_ =
new LegalMessageView(controller->GetLegalMessageLines(), this);
legal_message_container_ = new LegalMessageView(
controller->GetLegalMessageLines(),
base::BindRepeating(
&LocalCardMigrationDialogController::OnLegalMessageLinkClicked,
base::Unretained(controller_)));
legal_message_container_->SetBorder(
views::CreateEmptyBorder(kMigrationDialogInsets));
AddChildView(legal_message_container_);
......@@ -315,14 +317,6 @@ class LocalCardMigrationOfferView : public views::View,
~LocalCardMigrationOfferView() override {}
// views::StyledLabelListener:
void StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) override {
controller_->OnLegalMessageLinkClicked(
legal_message_container_->GetUrlForLink(label, range));
}
const std::vector<std::string> GetSelectedCardGuids() const {
std::vector<std::string> selected_cards;
for (views::View* child : card_list_view_->children()) {
......
......@@ -130,22 +130,21 @@ std::unique_ptr<views::Textfield> CreateCvcTextfield() {
}
LegalMessageView::LegalMessageView(const LegalMessageLines& legal_message_lines,
views::StyledLabelListener* listener)
: legal_message_lines_(legal_message_lines) {
LinkClickedCallback callback)
: legal_message_lines_(legal_message_lines),
callback_(std::move(callback)) {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
for (const LegalMessageLine& line : legal_message_lines) {
AddChildView(CreateLegalMessageLineLabel(line, listener).release());
AddChildView(CreateLegalMessageLineLabel(line).release());
}
}
LegalMessageView::~LegalMessageView() {}
std::unique_ptr<views::StyledLabel>
LegalMessageView::CreateLegalMessageLineLabel(
const LegalMessageLine& line,
views::StyledLabelListener* listener) {
auto label = std::make_unique<views::StyledLabel>(listener);
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);
......@@ -156,8 +155,9 @@ LegalMessageView::CreateLegalMessageLineLabel(
return label;
}
const GURL LegalMessageView::GetUrlForLink(views::StyledLabel* label,
const gfx::Range& range) {
void LegalMessageView::StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) {
// Index of |label| within its parent's view hierarchy is the same as the
// legal message line index. DCHECK this assumption to guard against future
// layout changes.
......@@ -167,12 +167,12 @@ const GURL LegalMessageView::GetUrlForLink(views::StyledLabel* label,
legal_message_lines_[label->parent()->GetIndexOf(label)].links();
for (const LegalMessageLine::Link& link : links) {
if (link.range == range) {
return link.url;
callback_.Run(link.url);
return;
}
}
// |range| was not found.
NOTREACHED();
return GURL();
}
PaymentsBubbleClosedReason GetPaymentsBubbleClosedReasonFromWidgetClosedReason(
......
......@@ -43,20 +43,25 @@ std::unique_ptr<views::Textfield> CreateCvcTextfield();
// Defines a view with legal message. This class handles the legal message
// parsing and the links clicking events.
class LegalMessageView : public views::View {
class LegalMessageView : public views::View, public views::StyledLabelListener {
public:
using LinkClickedCallback = base::RepeatingCallback<void(const GURL&)>;
explicit LegalMessageView(const LegalMessageLines& legal_message_lines,
views::StyledLabelListener* listener);
LinkClickedCallback callback);
~LegalMessageView() override;
const GURL GetUrlForLink(views::StyledLabel* label, const gfx::Range& range);
// views::StyledLabelListener:
void StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) override;
private:
std::unique_ptr<views::StyledLabel> CreateLegalMessageLineLabel(
const LegalMessageLine& line,
views::StyledLabelListener* listener);
const LegalMessageLine& line);
LegalMessageLines legal_message_lines_;
const LegalMessageLines legal_message_lines_;
const LinkClickedCallback callback_;
};
PaymentsBubbleClosedReason GetPaymentsBubbleClosedReasonFromWidgetClosedReason(
......
......@@ -6,6 +6,7 @@
#include <memory>
#include "base/bind.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
......@@ -51,11 +52,11 @@ const int kTooltipIconSize = 12;
std::unique_ptr<LegalMessageView> CreateLegalMessageView(
const LegalMessageLines& message_lines,
views::StyledLabelListener* listener) {
LegalMessageView::LinkClickedCallback callback) {
if (message_lines.empty())
return nullptr;
return std::make_unique<LegalMessageView>(message_lines, listener);
return std::make_unique<LegalMessageView>(message_lines, std::move(callback));
}
} // namespace
......@@ -66,8 +67,10 @@ SaveCardOfferBubbleViews::SaveCardOfferBubbleViews(
SaveCardBubbleController* controller)
: SaveCardBubbleViews(anchor_view, web_contents, controller) {
SetButtons(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL);
legal_message_view_ = SetFootnoteView(
CreateLegalMessageView(controller->GetLegalMessageLines(), this));
legal_message_view_ = SetFootnoteView(CreateLegalMessageView(
controller->GetLegalMessageLines(),
base::BindRepeating(&SaveCardOfferBubbleViews::LinkClicked,
base::Unretained(this))));
if (legal_message_view_)
InitFootnoteView(legal_message_view_);
}
......@@ -130,16 +133,6 @@ bool SaveCardOfferBubbleViews::IsDialogButtonEnabled(
return true;
}
void SaveCardOfferBubbleViews::StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) {
if (!controller())
return;
controller()->OnLegalMessageLinkClicked(
legal_message_view_->GetUrlForLink(label, range));
}
void SaveCardOfferBubbleViews::ContentsChanged(
views::Textfield* sender,
const base::string16& new_contents) {
......@@ -321,4 +314,9 @@ SaveCardOfferBubbleViews::CreateUploadExplanationView() {
return upload_explanation_tooltip;
}
void SaveCardOfferBubbleViews::LinkClicked(const GURL& url) {
if (controller())
controller()->OnLegalMessageLinkClicked(url);
}
} // namespace autofill
......@@ -9,7 +9,6 @@
#include "chrome/browser/ui/views/autofill/payments/payments_view_util.h"
#include "chrome/browser/ui/views/autofill/payments/save_card_bubble_views.h"
#include "ui/views/controls/combobox/combobox_listener.h"
#include "ui/views/controls/styled_label_listener.h"
#include "ui/views/controls/textfield/textfield_controller.h"
namespace content {
......@@ -24,7 +23,6 @@ namespace autofill {
// and an [Save] button. (Non-material UI's include a [No Thanks] button).
class SaveCardOfferBubbleViews : public SaveCardBubbleViews,
public views::ComboboxListener,
public views::StyledLabelListener,
public views::TextfieldController {
public:
// Bubble will be anchored to |anchor_view|.
......@@ -37,11 +35,6 @@ class SaveCardOfferBubbleViews : public SaveCardBubbleViews,
bool Accept() override;
bool IsDialogButtonEnabled(ui::DialogButton button) const override;
// views::StyledLabelListener:
void StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) override;
// views::TextfieldController:
void ContentsChanged(views::Textfield* sender,
const base::string16& new_contents) override;
......@@ -55,6 +48,8 @@ class SaveCardOfferBubbleViews : public SaveCardBubbleViews,
std::unique_ptr<views::View> CreateRequestExpirationDateView();
std::unique_ptr<views::View> CreateUploadExplanationView();
void LinkClicked(const GURL& url);
~SaveCardOfferBubbleViews() override;
views::Textfield* cardholder_name_textfield_ = nullptr;
......
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