Commit a0396164 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Change ButtonPressed overrides to callbacks: c/b/ui/views/profiles/

Bug: 772945
Change-Id: I37a96a2d68d72a3aba691ce073f9841a36b5e3c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2454403
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814442}
parent 8e98caa6
...@@ -159,12 +159,12 @@ gfx::ImageSkia SizeImageModel(const ui::ImageModel& image_model, ...@@ -159,12 +159,12 @@ gfx::ImageSkia SizeImageModel(const ui::ImageModel& image_model,
class CircularImageButton : public views::ImageButton { class CircularImageButton : public views::ImageButton {
public: public:
CircularImageButton(views::ButtonListener* listener, CircularImageButton(PressedCallback callback,
const gfx::VectorIcon& icon, const gfx::VectorIcon& icon,
const base::string16& text, const base::string16& text,
SkColor background_profile_color = SK_ColorTRANSPARENT, SkColor background_profile_color = SK_ColorTRANSPARENT,
bool show_border = false) bool show_border = false)
: ImageButton(listener), : ImageButton(std::move(callback)),
icon_(icon), icon_(icon),
background_profile_color_(background_profile_color), background_profile_color_(background_profile_color),
show_border_(show_border) { show_border_(show_border) {
...@@ -266,7 +266,7 @@ class AvatarImageView : public views::ImageView { ...@@ -266,7 +266,7 @@ class AvatarImageView : public views::ImageView {
} }
} }
// views::ImageVIew: // views::ImageView:
void OnThemeChanged() override { void OnThemeChanged() override {
ImageView::OnThemeChanged(); ImageView::OnThemeChanged();
constexpr int kBadgePadding = 1; constexpr int kBadgePadding = 1;
...@@ -304,9 +304,11 @@ class AvatarImageView : public views::ImageView { ...@@ -304,9 +304,11 @@ class AvatarImageView : public views::ImageView {
class SyncButton : public HoverButton { class SyncButton : public HoverButton {
public: public:
SyncButton(ProfileMenuViewBase* root_view, SyncButton(PressedCallback callback,
ProfileMenuViewBase* root_view,
const base::string16& clickable_text) const base::string16& clickable_text)
: HoverButton(root_view, clickable_text), root_view_(root_view) {} : HoverButton(std::move(callback), clickable_text),
root_view_(root_view) {}
// HoverButton: // HoverButton:
void OnThemeChanged() override { void OnThemeChanged() override {
...@@ -572,15 +574,18 @@ void ProfileMenuViewBase::SetProfileIdentityInfo( ...@@ -572,15 +574,18 @@ void ProfileMenuViewBase::SetProfileIdentityInfo(
heading_container_->SetBackground( heading_container_->SetBackground(
views::CreateSolidBackground(kBackgroundColor)); views::CreateSolidBackground(kBackgroundColor));
views::LabelButton* heading_button = heading_container_->AddChildView( views::LabelButton* heading_button =
std::make_unique<HoverButton>(this, profile_name)); heading_container_->AddChildView(std::make_unique<HoverButton>(
base::BindRepeating(&ProfileMenuViewBase::ButtonPressed,
base::Unretained(this),
std::move(edit_button_params->edit_action)),
profile_name));
heading_button->SetEnabledTextColors(views::style::GetColor( heading_button->SetEnabledTextColors(views::style::GetColor(
*this, views::style::CONTEXT_LABEL, views::style::STYLE_SECONDARY)); *this, views::style::CONTEXT_LABEL, views::style::STYLE_SECONDARY));
heading_button->SetTooltipText(edit_button_params->edit_tooltip_text); heading_button->SetTooltipText(edit_button_params->edit_tooltip_text);
heading_button->SetHorizontalAlignment(gfx::ALIGN_CENTER); heading_button->SetHorizontalAlignment(gfx::ALIGN_CENTER);
heading_button->SetBorder( heading_button->SetBorder(
views::CreateEmptyBorder(gfx::Insets(kDefaultMargin))); views::CreateEmptyBorder(gfx::Insets(kDefaultMargin)));
RegisterClickAction(heading_button, edit_button_params->edit_action);
} }
identity_info_container_->AddChildView(std::move(avatar_image_view)); identity_info_container_->AddChildView(std::move(avatar_image_view));
...@@ -615,10 +620,11 @@ void ProfileMenuViewBase::SetProfileIdentityInfo( ...@@ -615,10 +620,11 @@ void ProfileMenuViewBase::SetProfileIdentityInfo(
std::unique_ptr<views::View> edit_button; std::unique_ptr<views::View> edit_button;
if (edit_button_params.has_value()) { if (edit_button_params.has_value()) {
edit_button = std::make_unique<CircularImageButton>( edit_button = std::make_unique<CircularImageButton>(
this, *edit_button_params->edit_icon, base::BindRepeating(&ProfileMenuViewBase::ButtonPressed,
edit_button_params->edit_tooltip_text, base::Unretained(this),
std::move(edit_button_params->edit_action)),
*edit_button_params->edit_icon, edit_button_params->edit_tooltip_text,
background_color.value_or(SK_ColorTRANSPARENT)); background_color.value_or(SK_ColorTRANSPARENT));
RegisterClickAction(edit_button.get(), edit_button_params->edit_action);
} }
BuildProfileBackgroundContainer( BuildProfileBackgroundContainer(
...@@ -653,9 +659,10 @@ void ProfileMenuViewBase::SetSyncInfo(const SyncInfo& sync_info, ...@@ -653,9 +659,10 @@ void ProfileMenuViewBase::SetSyncInfo(const SyncInfo& sync_info,
views::BoxLayout::Orientation::kVertical, gfx::Insets(), kInsidePadding)); views::BoxLayout::Orientation::kVertical, gfx::Insets(), kInsidePadding));
if (description.empty()) { if (description.empty()) {
views::Button* sync_button = sync_info_container_->AddChildView( sync_info_container_->AddChildView(std::make_unique<SyncButton>(
std::make_unique<SyncButton>(this, clickable_text)); base::BindRepeating(&ProfileMenuViewBase::ButtonPressed,
RegisterClickAction(sync_button, std::move(action)); base::Unretained(this), std::move(action)),
this, clickable_text));
return; return;
} }
...@@ -692,10 +699,12 @@ void ProfileMenuViewBase::SetSyncInfo(const SyncInfo& sync_info, ...@@ -692,10 +699,12 @@ void ProfileMenuViewBase::SetSyncInfo(const SyncInfo& sync_info,
label->SetHandlesTooltips(false); label->SetHandlesTooltips(false);
// Add the prominent button at the bottom. // Add the prominent button at the bottom.
auto button = std::make_unique<views::MdTextButton>(this, clickable_text); auto* button =
sync_info_container_->AddChildView(std::make_unique<views::MdTextButton>(
base::BindRepeating(&ProfileMenuViewBase::ButtonPressed,
base::Unretained(this), std::move(action)),
clickable_text));
button->SetProminent(true); button->SetProminent(true);
RegisterClickAction(sync_info_container_->AddChildView(std::move(button)),
std::move(action));
} }
void ProfileMenuViewBase::AddShortcutFeatureButton( void ProfileMenuViewBase::AddShortcutFeatureButton(
...@@ -718,12 +727,12 @@ void ProfileMenuViewBase::AddShortcutFeatureButton( ...@@ -718,12 +727,12 @@ void ProfileMenuViewBase::AddShortcutFeatureButton(
} }
views::Button* button = shortcut_features_container_->AddChildView( views::Button* button = shortcut_features_container_->AddChildView(
std::make_unique<CircularImageButton>(this, icon, text, std::make_unique<CircularImageButton>(
SK_ColorTRANSPARENT, base::BindRepeating(&ProfileMenuViewBase::ButtonPressed,
/*show_border=*/true)); base::Unretained(this), std::move(action)),
icon, text, SK_ColorTRANSPARENT,
/*show_border=*/true));
button->EnableCanvasFlippingForRTLUI(false); button->EnableCanvasFlippingForRTLUI(false);
RegisterClickAction(button, std::move(action));
} }
void ProfileMenuViewBase::AddFeatureButton(const base::string16& text, void ProfileMenuViewBase::AddFeatureButton(const base::string16& text,
...@@ -738,16 +747,18 @@ void ProfileMenuViewBase::AddFeatureButton(const base::string16& text, ...@@ -738,16 +747,18 @@ void ProfileMenuViewBase::AddFeatureButton(const base::string16& text,
views::View* button; views::View* button;
if (&icon == &gfx::kNoneIcon) { if (&icon == &gfx::kNoneIcon) {
button = features_container_->AddChildView( button = features_container_->AddChildView(std::make_unique<HoverButton>(
std::make_unique<HoverButton>(this, text)); base::BindRepeating(&ProfileMenuViewBase::ButtonPressed,
base::Unretained(this), std::move(action)),
text));
} else { } else {
auto icon_view = auto icon_view =
std::make_unique<FeatureButtonIconView>(icon, icon_to_image_ratio); std::make_unique<FeatureButtonIconView>(icon, icon_to_image_ratio);
button = features_container_->AddChildView( button = features_container_->AddChildView(std::make_unique<HoverButton>(
std::make_unique<HoverButton>(this, std::move(icon_view), text)); base::BindRepeating(&ProfileMenuViewBase::ButtonPressed,
base::Unretained(this), std::move(action)),
std::move(icon_view), text));
} }
RegisterClickAction(button, std::move(action));
} }
void ProfileMenuViewBase::SetProfileManagementHeading( void ProfileMenuViewBase::SetProfileManagementHeading(
...@@ -795,12 +806,13 @@ void ProfileMenuViewBase::AddSelectableProfile( ...@@ -795,12 +806,13 @@ void ProfileMenuViewBase::AddSelectableProfile(
kSelectableProfileImageSize); kSelectableProfileImageSize);
views::Button* button = selectable_profiles_container_->AddChildView( views::Button* button = selectable_profiles_container_->AddChildView(
std::make_unique<HoverButton>(this, sized_image, name)); std::make_unique<HoverButton>(
base::BindRepeating(&ProfileMenuViewBase::ButtonPressed,
base::Unretained(this), std::move(action)),
sized_image, name));
if (!is_guest && !first_profile_button_) if (!is_guest && !first_profile_button_)
first_profile_button_ = button; first_profile_button_ = button;
RegisterClickAction(button, std::move(action));
} }
void ProfileMenuViewBase::AddProfileManagementShortcutFeatureButton( void ProfileMenuViewBase::AddProfileManagementShortcutFeatureButton(
...@@ -815,11 +827,11 @@ void ProfileMenuViewBase::AddProfileManagementShortcutFeatureButton( ...@@ -815,11 +827,11 @@ void ProfileMenuViewBase::AddProfileManagementShortcutFeatureButton(
gfx::Insets(0, 0, 0, /*right=*/kMenuEdgeMargin))); gfx::Insets(0, 0, 0, /*right=*/kMenuEdgeMargin)));
} }
views::Button* button = profile_mgmt_shortcut_features_container_->AddChildView(
profile_mgmt_shortcut_features_container_->AddChildView( std::make_unique<CircularImageButton>(
std::make_unique<CircularImageButton>(this, icon, text)); base::BindRepeating(&ProfileMenuViewBase::ButtonPressed,
base::Unretained(this), std::move(action)),
RegisterClickAction(button, std::move(action)); icon, text));
} }
void ProfileMenuViewBase::AddProfileManagementFeatureButton( void ProfileMenuViewBase::AddProfileManagementFeatureButton(
...@@ -834,10 +846,10 @@ void ProfileMenuViewBase::AddProfileManagementFeatureButton( ...@@ -834,10 +846,10 @@ void ProfileMenuViewBase::AddProfileManagementFeatureButton(
} }
auto icon_button = std::make_unique<ProfileManagementIconView>(icon); auto icon_button = std::make_unique<ProfileManagementIconView>(icon);
views::Button* button = profile_mgmt_features_container_->AddChildView( profile_mgmt_features_container_->AddChildView(std::make_unique<HoverButton>(
std::make_unique<HoverButton>(this, std::move(icon_button), text)); base::BindRepeating(&ProfileMenuViewBase::ButtonPressed,
base::Unretained(this), std::move(action)),
RegisterClickAction(button, std::move(action)); std::move(icon_button), text));
} }
gfx::ImageSkia ProfileMenuViewBase::ColoredImageForMenu( gfx::ImageSkia ProfileMenuViewBase::ColoredImageForMenu(
...@@ -867,7 +879,6 @@ int ProfileMenuViewBase::GetMaxHeight() const { ...@@ -867,7 +879,6 @@ int ProfileMenuViewBase::GetMaxHeight() const {
} }
void ProfileMenuViewBase::Reset() { void ProfileMenuViewBase::Reset() {
click_actions_.clear();
RemoveAllChildViews(/*delete_childen=*/true); RemoveAllChildViews(/*delete_childen=*/true);
auto components = std::make_unique<views::View>(); auto components = std::make_unique<views::View>();
...@@ -972,17 +983,10 @@ bool ProfileMenuViewBase::HandleContextMenu( ...@@ -972,17 +983,10 @@ bool ProfileMenuViewBase::HandleContextMenu(
return true; return true;
} }
void ProfileMenuViewBase::ButtonPressed(views::Button* button, void ProfileMenuViewBase::ButtonPressed(base::RepeatingClosure action) {
const ui::Event& event) { DCHECK(action);
DCHECK(!click_actions_[button].is_null());
signin_ui_util::RecordProfileMenuClick(browser()->profile()); signin_ui_util::RecordProfileMenuClick(browser()->profile());
click_actions_[button].Run(); action.Run();
}
void ProfileMenuViewBase::RegisterClickAction(views::View* clickable_view,
base::RepeatingClosure action) {
DCHECK(click_actions_.count(clickable_view) == 0);
click_actions_[clickable_view] = std::move(action);
} }
void ProfileMenuViewBase::UpdateSyncInfoContainerBackground() { void ProfileMenuViewBase::UpdateSyncInfoContainerBackground() {
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h" #include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/style/typography.h" #include "ui/views/style/typography.h"
...@@ -36,8 +35,7 @@ class ImageModel; ...@@ -36,8 +35,7 @@ class ImageModel;
// This class provides the UI for different menus that are created by user // This class provides the UI for different menus that are created by user
// clicking the avatar button. // clicking the avatar button.
class ProfileMenuViewBase : public content::WebContentsDelegate, class ProfileMenuViewBase : public content::WebContentsDelegate,
public views::BubbleDialogDelegateView, public views::BubbleDialogDelegateView {
public views::ButtonListener {
public: public:
// Enumeration of all actionable items in the profile menu. // Enumeration of all actionable items in the profile menu.
// These values are persisted to logs. Entries should not be renumbered and // These values are persisted to logs. Entries should not be renumbered and
...@@ -188,11 +186,7 @@ class ProfileMenuViewBase : public content::WebContentsDelegate, ...@@ -188,11 +186,7 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
bool HandleContextMenu(content::RenderFrameHost* render_frame_host, bool HandleContextMenu(content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params) override; const content::ContextMenuParams& params) override;
// views::ButtonListener: void ButtonPressed(base::RepeatingClosure action);
void ButtonPressed(views::Button* button, const ui::Event& event) final;
void RegisterClickAction(views::View* clickable_view,
base::RepeatingClosure action);
void UpdateSyncInfoContainerBackground(); void UpdateSyncInfoContainerBackground();
...@@ -200,8 +194,6 @@ class ProfileMenuViewBase : public content::WebContentsDelegate, ...@@ -200,8 +194,6 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
views::Button* const anchor_button_; views::Button* const anchor_button_;
std::map<views::View*, base::RepeatingClosure> click_actions_;
// Component containers. // Component containers.
views::View* heading_container_ = nullptr; views::View* heading_container_ = nullptr;
views::View* identity_info_container_ = nullptr; views::View* identity_info_container_ = 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