Commit 44c7f368 authored by Allen Bauer's avatar Allen Bauer Committed by Commit Bot

Removed use of ButtonListener in favor of callback.

Bug: 772945
Change-Id: Ibbbca14f5182b8f80c056ece9a9a63e74682ae9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2493086
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Auto-Submit: Allen Bauer <kylixrd@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820033}
parent f67b9d4d
...@@ -9,9 +9,11 @@ ...@@ -9,9 +9,11 @@
#include "ash/hud_display/hud_properties.h" #include "ash/hud_display/hud_properties.h"
#include "ash/hud_display/legend.h" #include "ash/hud_display/legend.h"
#include "ash/hud_display/solid_source_background.h" #include "ash/hud_display/solid_source_background.h"
#include "base/bind.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
...@@ -31,8 +33,8 @@ class MinMaxButton : public views::ImageButton { ...@@ -31,8 +33,8 @@ class MinMaxButton : public views::ImageButton {
public: public:
METADATA_HEADER(MinMaxButton); METADATA_HEADER(MinMaxButton);
explicit MinMaxButton(views::ButtonListener* listener) explicit MinMaxButton(views::Button::PressedCallback callback)
: views::ImageButton(listener) { : views::ImageButton(callback) {
SetBorder(views::CreateEmptyBorder(gfx::Insets(kMinMaxButtonBorder))); SetBorder(views::CreateEmptyBorder(gfx::Insets(kMinMaxButtonBorder)));
SetBackground(std::make_unique<SolidSourceBackground>(kHUDLegendBackground, SetBackground(std::make_unique<SolidSourceBackground>(kHUDLegendBackground,
/*radius=*/0)); /*radius=*/0));
...@@ -109,8 +111,9 @@ GraphPageViewBase::GraphPageViewBase() { ...@@ -109,8 +111,9 @@ GraphPageViewBase::GraphPageViewBase() {
views::CreateEmptyBorder(gfx::Insets(kLegendPositionOffset))); views::CreateEmptyBorder(gfx::Insets(kLegendPositionOffset)));
legend_container_->SetVisible(false); legend_container_->SetVisible(false);
legend_min_max_button_ = legend_min_max_button_ = legend_container_->AddChildView(
legend_container_->AddChildView(std::make_unique<MinMaxButton>(this)); std::make_unique<MinMaxButton>(base::BindRepeating(
&GraphPageViewBase::OnButtonPressed, base::Unretained(this))));
SetMinimizeIconToButton(legend_min_max_button_); SetMinimizeIconToButton(legend_min_max_button_);
} }
...@@ -118,7 +121,7 @@ GraphPageViewBase::~GraphPageViewBase() { ...@@ -118,7 +121,7 @@ GraphPageViewBase::~GraphPageViewBase() {
DCHECK_CALLED_ON_VALID_SEQUENCE(ui_sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(ui_sequence_checker_);
} }
void GraphPageViewBase::ButtonPressed(views::Button*, ui::Event const&) { void GraphPageViewBase::OnButtonPressed() {
if (legend_->GetVisible()) { if (legend_->GetVisible()) {
legend_->SetVisible(false); legend_->SetVisible(false);
SetRestoreIconToButton(legend_min_max_button_); SetRestoreIconToButton(legend_min_max_button_);
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "ash/hud_display/data_source.h" #include "ash/hud_display/data_source.h"
#include "ash/hud_display/legend.h" #include "ash/hud_display/legend.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace views { namespace views {
...@@ -22,7 +21,7 @@ class Grid; ...@@ -22,7 +21,7 @@ class Grid;
class Legend; class Legend;
// Interface for a single graph page. // Interface for a single graph page.
class GraphPageViewBase : public views::View, public views::ButtonListener { class GraphPageViewBase : public views::View {
public: public:
METADATA_HEADER(GraphPageViewBase); METADATA_HEADER(GraphPageViewBase);
...@@ -31,9 +30,6 @@ class GraphPageViewBase : public views::View, public views::ButtonListener { ...@@ -31,9 +30,6 @@ class GraphPageViewBase : public views::View, public views::ButtonListener {
GraphPageViewBase& operator=(const GraphPageViewBase&) = delete; GraphPageViewBase& operator=(const GraphPageViewBase&) = delete;
~GraphPageViewBase() override; ~GraphPageViewBase() override;
// views::ButtonListener
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Update page data from the new snapshot. // Update page data from the new snapshot.
virtual void UpdateData(const DataSource::Snapshot& snapshot) = 0; virtual void UpdateData(const DataSource::Snapshot& snapshot) = 0;
...@@ -54,6 +50,8 @@ class GraphPageViewBase : public views::View, public views::ButtonListener { ...@@ -54,6 +50,8 @@ class GraphPageViewBase : public views::View, public views::ButtonListener {
void RefreshLegendValues(); void RefreshLegendValues();
private: private:
void OnButtonPressed();
// Container for the Grid object. // Container for the Grid object.
views::View* grid_container_ = nullptr; // not owned views::View* grid_container_ = nullptr; // not owned
......
...@@ -135,9 +135,9 @@ HUDDisplayView::HUDDisplayView() { ...@@ -135,9 +135,9 @@ HUDDisplayView::HUDDisplayView() {
// Setup header. // Setup header.
// TODO: Add tab buttons via: // TODO: Add tab buttons via:
header_view_->tab_strip()->AddTabButton(this, DisplayMode::CPU_DISPLAY, header_view_->tab_strip()->AddTabButton(DisplayMode::CPU_DISPLAY,
base::ASCIIToUTF16("CPU")); base::ASCIIToUTF16("CPU"));
header_view_->tab_strip()->AddTabButton(this, DisplayMode::MEMORY_DISPLAY, header_view_->tab_strip()->AddTabButton(DisplayMode::MEMORY_DISPLAY,
base::ASCIIToUTF16("RAM")); base::ASCIIToUTF16("RAM"));
// Setup data. // Setup data.
...@@ -189,8 +189,7 @@ void HUDDisplayView::OnWidgetInitialized() { ...@@ -189,8 +189,7 @@ void HUDDisplayView::OnWidgetInitialized() {
} }
// There is only one button. // There is only one button.
void HUDDisplayView::ButtonPressed(views::Button* /*sender*/, void HUDDisplayView::OnSettingsToggle() {
const ui::Event& /*event*/) {
settings_view_->ToggleVisibility(); settings_view_->ToggleVisibility();
graphs_container_->SetVisible(!settings_view_->GetVisible()); graphs_container_->SetVisible(!settings_view_->GetVisible());
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define ASH_HUD_DISPLAY_HUD_DISPLAY_H_ #define ASH_HUD_DISPLAY_HUD_DISPLAY_H_
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "ui/views/controls/button/button.h" #include "ui/views/view.h"
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
namespace ash { namespace ash {
...@@ -18,8 +18,7 @@ class HUDHeaderView; ...@@ -18,8 +18,7 @@ class HUDHeaderView;
class HUDSettingsView; class HUDSettingsView;
// HUDDisplayView class can be used to display a system monitoring overview. // HUDDisplayView class can be used to display a system monitoring overview.
class HUDDisplayView : public views::WidgetDelegateView, class HUDDisplayView : public views::WidgetDelegateView {
public views::ButtonListener {
public: public:
METADATA_HEADER(HUDDisplayView); METADATA_HEADER(HUDDisplayView);
...@@ -33,9 +32,6 @@ class HUDDisplayView : public views::WidgetDelegateView, ...@@ -33,9 +32,6 @@ class HUDDisplayView : public views::WidgetDelegateView,
views::ClientView* CreateClientView(views::Widget* widget) override; views::ClientView* CreateClientView(views::Widget* widget) override;
void OnWidgetInitialized() override; void OnWidgetInitialized() override;
// views::ButtonListener
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Destroys global instance. // Destroys global instance.
static void Destroy(); static void Destroy();
...@@ -49,6 +45,9 @@ class HUDDisplayView : public views::WidgetDelegateView, ...@@ -49,6 +45,9 @@ class HUDDisplayView : public views::WidgetDelegateView,
// Changes UI display mode. // Changes UI display mode.
void SetDisplayMode(const DisplayMode display_mode); void SetDisplayMode(const DisplayMode display_mode);
// Callback from SettingsButton.
void OnSettingsToggle();
private: private:
HUDHeaderView* header_view_ = nullptr; // not owned HUDHeaderView* header_view_ = nullptr; // not owned
GraphsContainerView* graphs_container_ = nullptr; // not owned GraphsContainerView* graphs_container_ = nullptr; // not owned
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/layout_manager.h" #include "ui/views/layout/layout_manager.h"
...@@ -68,8 +69,8 @@ class SettingsButton : public views::ImageButton { ...@@ -68,8 +69,8 @@ class SettingsButton : public views::ImageButton {
public: public:
METADATA_HEADER(SettingsButton); METADATA_HEADER(SettingsButton);
explicit SettingsButton(views::ButtonListener* listener) explicit SettingsButton(views::Button::PressedCallback callback)
: views::ImageButton(listener) { : views::ImageButton(callback) {
SetImage(views::Button::ButtonState::STATE_NORMAL, SetImage(views::Button::ButtonState::STATE_NORMAL,
gfx::CreateVectorIcon(vector_icons::kSettingsIcon, gfx::CreateVectorIcon(vector_icons::kSettingsIcon,
kHUDSettingsIconSize, kHUDDefaultColor)); kHUDSettingsIconSize, kHUDDefaultColor));
...@@ -183,7 +184,9 @@ HUDHeaderView::HUDHeaderView(HUDDisplayView* hud) { ...@@ -183,7 +184,9 @@ HUDHeaderView::HUDHeaderView(HUDDisplayView* hud) {
gfx::Insets(kHUDInset, kHUDInset, 0, kHUDInset))); gfx::Insets(kHUDInset, kHUDInset, 0, kHUDInset)));
// Add buttons and tab strip. // Add buttons and tab strip.
header_buttons->AddChildView(std::make_unique<SettingsButton>(hud)); header_buttons->AddChildView(
std::make_unique<SettingsButton>(base::BindRepeating(
&HUDDisplayView::OnSettingsToggle, base::Unretained(hud))));
tab_strip_ = header_buttons->AddChildView(std::make_unique<HUDTabStrip>(hud)); tab_strip_ = header_buttons->AddChildView(std::make_unique<HUDTabStrip>(hud));
// Padding will take the rest of the header and draw bottom inner left // Padding will take the rest of the header and draw bottom inner left
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ash/hud_display/hud_display.h" #include "ash/hud_display/hud_display.h"
#include "ash/hud_display/hud_properties.h" #include "ash/hud_display/hud_properties.h"
#include "base/bind.h"
#include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkPath.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/text_constants.h" #include "ui/gfx/text_constants.h"
...@@ -76,10 +77,9 @@ BEGIN_METADATA(HUDTabButton, views::LabelButton) ...@@ -76,10 +77,9 @@ BEGIN_METADATA(HUDTabButton, views::LabelButton)
END_METADATA END_METADATA
HUDTabButton::HUDTabButton(Style style, HUDTabButton::HUDTabButton(Style style,
HUDTabStrip* tab_strip,
const DisplayMode display_mode, const DisplayMode display_mode,
const base::string16& text) const base::string16& text)
: views::LabelButton(tab_strip, text), : views::LabelButton(nullptr, text),
style_(style), style_(style),
display_mode_(display_mode) { display_mode_(display_mode) {
SetHorizontalAlignment(gfx::ALIGN_CENTER); SetHorizontalAlignment(gfx::ALIGN_CENTER);
...@@ -169,29 +169,28 @@ HUDTabStrip::HUDTabStrip(HUDDisplayView* hud) : hud_(hud) { ...@@ -169,29 +169,28 @@ HUDTabStrip::HUDTabStrip(HUDDisplayView* hud) : hud_(hud) {
HUDTabStrip::~HUDTabStrip() = default; HUDTabStrip::~HUDTabStrip() = default;
HUDTabButton* HUDTabStrip::AddTabButton(HUDDisplayView* hud, HUDTabButton* HUDTabStrip::AddTabButton(const DisplayMode display_mode,
const DisplayMode display_mode,
const base::string16& label) { const base::string16& label) {
CHECK_NE(static_cast<int>(display_mode), 0); CHECK_NE(static_cast<int>(display_mode), 0);
// Make first tab active by default. // Make first tab active by default.
HUDTabButton* tab_button = AddChildView(std::make_unique<HUDTabButton>( HUDTabButton* tab_button = AddChildView(std::make_unique<HUDTabButton>(
tabs_.size() ? HUDTabButton::Style::RIGHT : HUDTabButton::Style::ACTIVE, tabs_.size() ? HUDTabButton::Style::RIGHT : HUDTabButton::Style::ACTIVE,
this, display_mode, label)); display_mode, label));
tab_button->SetCallback(base::BindRepeating(
[](HUDTabButton* sender, HUDTabStrip* tab_strip) {
for (const auto* tab : tab_strip->tabs_) {
if (tab == sender) {
tab_strip->hud_->SetDisplayMode(tab->display_mode());
return;
}
}
NOTREACHED();
},
base::Unretained(tab_button), base::Unretained(this)));
tabs_.push_back(tab_button); tabs_.push_back(tab_button);
return tab_button; return tab_button;
} }
void HUDTabStrip::ButtonPressed(views::Button* sender,
const ui::Event& /*event*/) {
for (const auto* tab : tabs_) {
if (tab == sender) {
hud_->SetDisplayMode(tab->display_mode());
return;
}
}
NOTREACHED();
}
void HUDTabStrip::ActivateTab(const DisplayMode mode) { void HUDTabStrip::ActivateTab(const DisplayMode mode) {
// True if we find given active tab. // True if we find given active tab.
bool found = false; bool found = false;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
#include "ui/views/metadata/metadata_header_macros.h" #include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/view.h"
namespace gfx { namespace gfx {
class Canvas; class Canvas;
...@@ -36,7 +37,6 @@ class HUDTabButton : public views::LabelButton { ...@@ -36,7 +37,6 @@ class HUDTabButton : public views::LabelButton {
METADATA_HEADER(HUDTabButton); METADATA_HEADER(HUDTabButton);
HUDTabButton(Style style, HUDTabButton(Style style,
HUDTabStrip* tab_strip,
const DisplayMode display_mode, const DisplayMode display_mode,
const base::string16& text); const base::string16& text);
HUDTabButton(const HUDTabButton&) = delete; HUDTabButton(const HUDTabButton&) = delete;
...@@ -59,7 +59,7 @@ class HUDTabButton : public views::LabelButton { ...@@ -59,7 +59,7 @@ class HUDTabButton : public views::LabelButton {
DisplayMode display_mode_; DisplayMode display_mode_;
}; };
class HUDTabStrip : public views::View, public views::ButtonListener { class HUDTabStrip : public views::View {
public: public:
METADATA_HEADER(HUDTabStrip); METADATA_HEADER(HUDTabStrip);
...@@ -70,13 +70,9 @@ class HUDTabStrip : public views::View, public views::ButtonListener { ...@@ -70,13 +70,9 @@ class HUDTabStrip : public views::View, public views::ButtonListener {
~HUDTabStrip() override; ~HUDTabStrip() override;
HUDTabButton* AddTabButton(HUDDisplayView* hud, HUDTabButton* AddTabButton(const DisplayMode display_mode,
const DisplayMode display_mode,
const base::string16& label); const base::string16& label);
// views::ButtonListener
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Mark tabs around the active one need repaint to modify borders. // Mark tabs around the active one need repaint to modify borders.
void ActivateTab(DisplayMode mode); void ActivateTab(DisplayMode mode);
......
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