Commit 84cc8ac5 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Change ButtonPressed overrides to callbacks: .../media_message_center/

Bug: 772945
Change-Id: Iacbc74f727e4535ea1289b0fc7fe8d326dfe6501
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490083
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820295}
parent d74848fb
...@@ -218,7 +218,11 @@ MediaNotificationViewImpl::MediaNotificationViewImpl( ...@@ -218,7 +218,11 @@ MediaNotificationViewImpl::MediaNotificationViewImpl(
IDS_MEDIA_MESSAGE_CENTER_MEDIA_NOTIFICATION_ACTION_SEEK_BACKWARD)); IDS_MEDIA_MESSAGE_CENTER_MEDIA_NOTIFICATION_ACTION_SEEK_BACKWARD));
// |play_pause_button_| toggles playback. // |play_pause_button_| toggles playback.
auto play_pause_button = views::CreateVectorToggleImageButton(this); auto play_pause_button =
views::CreateVectorToggleImageButton(views::Button::PressedCallback());
play_pause_button->SetCallback(
base::BindRepeating(&MediaNotificationViewImpl::ButtonPressed,
base::Unretained(this), play_pause_button.get()));
play_pause_button->set_tag(static_cast<int>(MediaSessionAction::kPlay)); play_pause_button->set_tag(static_cast<int>(MediaSessionAction::kPlay));
play_pause_button->SetPreferredSize(kMediaButtonSize); play_pause_button->SetPreferredSize(kMediaButtonSize);
play_pause_button->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); play_pause_button->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
...@@ -259,7 +263,11 @@ MediaNotificationViewImpl::MediaNotificationViewImpl( ...@@ -259,7 +263,11 @@ MediaNotificationViewImpl::MediaNotificationViewImpl(
pip_button_separator_view_ = pip_button_separator_view_ =
button_row_->AddChildView(std::move(pip_button_separator_view)); button_row_->AddChildView(std::move(pip_button_separator_view));
auto picture_in_picture_button = views::CreateVectorToggleImageButton(this); auto picture_in_picture_button =
views::CreateVectorToggleImageButton(views::Button::PressedCallback());
picture_in_picture_button->SetCallback(base::BindRepeating(
&MediaNotificationViewImpl::ButtonPressed, base::Unretained(this),
picture_in_picture_button.get()));
picture_in_picture_button->set_tag( picture_in_picture_button->set_tag(
static_cast<int>(MediaSessionAction::kEnterPictureInPicture)); static_cast<int>(MediaSessionAction::kEnterPictureInPicture));
picture_in_picture_button->SetPreferredSize(kMediaButtonSize); picture_in_picture_button->SetPreferredSize(kMediaButtonSize);
...@@ -344,12 +352,6 @@ void MediaNotificationViewImpl::GetAccessibleNodeData( ...@@ -344,12 +352,6 @@ void MediaNotificationViewImpl::GetAccessibleNodeData(
node_data->SetName(accessible_name_); node_data->SetName(accessible_name_);
} }
void MediaNotificationViewImpl::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (item_)
item_->OnMediaSessionActionButtonPressed(GetActionFromButtonTag(*sender));
}
void MediaNotificationViewImpl::UpdateWithMediaSessionInfo( void MediaNotificationViewImpl::UpdateWithMediaSessionInfo(
const media_session::mojom::MediaSessionInfoPtr& session_info) { const media_session::mojom::MediaSessionInfoPtr& session_info) {
bool playing = bool playing =
...@@ -576,7 +578,11 @@ void MediaNotificationViewImpl::UpdateViewForExpandedState() { ...@@ -576,7 +578,11 @@ void MediaNotificationViewImpl::UpdateViewForExpandedState() {
void MediaNotificationViewImpl::CreateMediaButton( void MediaNotificationViewImpl::CreateMediaButton(
MediaSessionAction action, MediaSessionAction action,
const base::string16& accessible_name) { const base::string16& accessible_name) {
auto button = views::CreateVectorImageButton(this); auto button =
views::CreateVectorImageButton(views::Button::PressedCallback());
button->SetCallback(
base::BindRepeating(&MediaNotificationViewImpl::ButtonPressed,
base::Unretained(this), button.get()));
button->set_tag(static_cast<int>(action)); button->set_tag(static_cast<int>(action));
button->SetPreferredSize(kMediaButtonSize); button->SetPreferredSize(kMediaButtonSize);
button->SetAccessibleName(accessible_name); button->SetAccessibleName(accessible_name);
...@@ -686,6 +692,11 @@ void MediaNotificationViewImpl::UpdateForegroundColor() { ...@@ -686,6 +692,11 @@ void MediaNotificationViewImpl::UpdateForegroundColor() {
container_->OnColorsChanged(theme.enabled_icon_color, background); container_->OnColorsChanged(theme.enabled_icon_color, background);
} }
void MediaNotificationViewImpl::ButtonPressed(views::Button* button) {
if (item_)
item_->OnMediaSessionActionButtonPressed(GetActionFromButtonTag(*button));
}
std::vector<views::View*> MediaNotificationViewImpl::GetButtons() { std::vector<views::View*> MediaNotificationViewImpl::GetButtons() {
auto buttons = button_row_->children(); auto buttons = button_row_->children();
buttons.insert(buttons.cbegin(), buttons.insert(buttons.cbegin(),
...@@ -702,4 +713,5 @@ std::vector<views::View*> MediaNotificationViewImpl::GetButtons() { ...@@ -702,4 +713,5 @@ std::vector<views::View*> MediaNotificationViewImpl::GetButtons() {
buttons.end()); buttons.end());
return buttons; return buttons;
} }
} // namespace media_message_center } // namespace media_message_center
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/optional.h" #include "base/optional.h"
#include "components/media_message_center/media_notification_view.h" #include "components/media_message_center/media_notification_view.h"
#include "services/media_session/public/mojom/media_session.mojom.h" #include "services/media_session/public/mojom/media_session.mojom.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/controls/label.h" #include "ui/views/controls/label.h"
...@@ -20,6 +19,7 @@ class NotificationHeaderView; ...@@ -20,6 +19,7 @@ class NotificationHeaderView;
namespace views { namespace views {
class BoxLayout; class BoxLayout;
class Button;
class ToggleImageButton; class ToggleImageButton;
} // namespace views } // namespace views
...@@ -38,8 +38,7 @@ struct COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) NotificationTheme { ...@@ -38,8 +38,7 @@ struct COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) NotificationTheme {
}; };
class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewImpl class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewImpl
: public MediaNotificationView, : public MediaNotificationView {
public views::ButtonListener {
public: public:
// The name of the histogram used when recorded whether the artwork was // The name of the histogram used when recorded whether the artwork was
// present. // present.
...@@ -73,9 +72,6 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewImpl ...@@ -73,9 +72,6 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewImpl
// views::View: // views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// MediaNotificationView: // MediaNotificationView:
void SetExpanded(bool expanded) override; void SetExpanded(bool expanded) override;
void UpdateCornerRadius(int top_radius, int bottom_radius) override; void UpdateCornerRadius(int top_radius, int bottom_radius) override;
...@@ -131,6 +127,8 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewImpl ...@@ -131,6 +127,8 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewImpl
void UpdateForegroundColor(); void UpdateForegroundColor();
void ButtonPressed(views::Button* button);
// Returns the buttons contained in the button row and playback button // Returns the buttons contained in the button row and playback button
// container. // container.
std::vector<views::View*> GetButtons(); std::vector<views::View*> GetButtons();
......
...@@ -249,8 +249,11 @@ MediaNotificationViewModernImpl::MediaNotificationViewModernImpl( ...@@ -249,8 +249,11 @@ MediaNotificationViewModernImpl::MediaNotificationViewModernImpl(
{ {
// The picture-in-picture button appears directly under the media // The picture-in-picture button appears directly under the media
// labels. // labels.
auto picture_in_picture_button = auto picture_in_picture_button = views::CreateVectorToggleImageButton(
views::CreateVectorToggleImageButton(this); views::Button::PressedCallback());
picture_in_picture_button->SetCallback(base::BindRepeating(
&MediaNotificationViewModernImpl::ButtonPressed,
base::Unretained(this), picture_in_picture_button.get()));
picture_in_picture_button->set_tag( picture_in_picture_button->set_tag(
static_cast<int>(MediaSessionAction::kEnterPictureInPicture)); static_cast<int>(MediaSessionAction::kEnterPictureInPicture));
picture_in_picture_button->SetPreferredSize(kPipButtonSize); picture_in_picture_button->SetPreferredSize(kPipButtonSize);
...@@ -321,7 +324,11 @@ MediaNotificationViewModernImpl::MediaNotificationViewModernImpl( ...@@ -321,7 +324,11 @@ MediaNotificationViewModernImpl::MediaNotificationViewModernImpl(
IDS_MEDIA_MESSAGE_CENTER_MEDIA_NOTIFICATION_ACTION_SEEK_BACKWARD)); IDS_MEDIA_MESSAGE_CENTER_MEDIA_NOTIFICATION_ACTION_SEEK_BACKWARD));
{ {
auto play_pause_button = views::CreateVectorToggleImageButton(this); auto play_pause_button = views::CreateVectorToggleImageButton(
views::Button::PressedCallback());
play_pause_button->SetCallback(
base::BindRepeating(&MediaNotificationViewModernImpl::ButtonPressed,
base::Unretained(this), play_pause_button.get()));
play_pause_button->set_tag(static_cast<int>(MediaSessionAction::kPlay)); play_pause_button->set_tag(static_cast<int>(MediaSessionAction::kPlay));
play_pause_button->SetPreferredSize(kMediaButtonSize); play_pause_button->SetPreferredSize(kMediaButtonSize);
play_pause_button->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); play_pause_button->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
...@@ -376,13 +383,6 @@ void MediaNotificationViewModernImpl::GetAccessibleNodeData( ...@@ -376,13 +383,6 @@ void MediaNotificationViewModernImpl::GetAccessibleNodeData(
node_data->SetName(accessible_name_); node_data->SetName(accessible_name_);
} }
void MediaNotificationViewModernImpl::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (item_) {
item_->OnMediaSessionActionButtonPressed(GetActionFromButtonTag(*sender));
}
}
void MediaNotificationViewModernImpl::UpdateWithMediaSessionInfo( void MediaNotificationViewModernImpl::UpdateWithMediaSessionInfo(
const media_session::mojom::MediaSessionInfoPtr& session_info) { const media_session::mojom::MediaSessionInfoPtr& session_info) {
bool playing = bool playing =
...@@ -523,7 +523,11 @@ void MediaNotificationViewModernImpl::CreateMediaButton( ...@@ -523,7 +523,11 @@ void MediaNotificationViewModernImpl::CreateMediaButton(
views::View* parent_view, views::View* parent_view,
MediaSessionAction action, MediaSessionAction action,
const base::string16& accessible_name) { const base::string16& accessible_name) {
auto button = views::CreateVectorImageButton(this); auto button =
views::CreateVectorImageButton(views::Button::PressedCallback());
button->SetCallback(
base::BindRepeating(&MediaNotificationViewModernImpl::ButtonPressed,
base::Unretained(this), button.get()));
button->set_tag(static_cast<int>(action)); button->set_tag(static_cast<int>(action));
button->SetPreferredSize(kMediaButtonSize); button->SetPreferredSize(kMediaButtonSize);
button->SetAccessibleName(accessible_name); button->SetAccessibleName(accessible_name);
...@@ -592,4 +596,9 @@ void MediaNotificationViewModernImpl::UpdateForegroundColor() { ...@@ -592,4 +596,9 @@ void MediaNotificationViewModernImpl::UpdateForegroundColor() {
container_->OnColorsChanged(foreground, background); container_->OnColorsChanged(foreground, background);
} }
void MediaNotificationViewModernImpl::ButtonPressed(views::Button* button) {
if (item_)
item_->OnMediaSessionActionButtonPressed(GetActionFromButtonTag(*button));
}
} // namespace media_message_center } // namespace media_message_center
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
#include "base/optional.h" #include "base/optional.h"
#include "components/media_message_center/media_notification_view.h" #include "components/media_message_center/media_notification_view.h"
#include "services/media_session/public/mojom/media_session.mojom.h" #include "services/media_session/public/mojom/media_session.mojom.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/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
namespace views { namespace views {
class Button;
class ToggleImageButton; class ToggleImageButton;
} // namespace views } // namespace views
...@@ -32,8 +32,7 @@ class MediaNotificationContainer; ...@@ -32,8 +32,7 @@ class MediaNotificationContainer;
class MediaNotificationItem; class MediaNotificationItem;
class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewModernImpl class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewModernImpl
: public MediaNotificationView, : public MediaNotificationView {
public views::ButtonListener {
public: public:
// The name of the histogram used when recording whether the artwork was // The name of the histogram used when recording whether the artwork was
// present. // present.
...@@ -69,9 +68,6 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewModernImpl ...@@ -69,9 +68,6 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewModernImpl
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
void OnThemeChanged() override; void OnThemeChanged() override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// MediaNotificationView // MediaNotificationView
void SetForcedExpandedState(bool* forced_expanded_state) override {} void SetForcedExpandedState(bool* forced_expanded_state) override {}
void SetExpanded(bool expanded) override {} void SetExpanded(bool expanded) override {}
...@@ -120,6 +116,8 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewModernImpl ...@@ -120,6 +116,8 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewModernImpl
void UpdateForegroundColor(); void UpdateForegroundColor();
void ButtonPressed(views::Button* button);
// Container that receives events. // Container that receives events.
MediaNotificationContainer* const container_; MediaNotificationContainer* const container_;
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "ui/message_center/views/notification_control_buttons_view.h" #include "ui/message_center/views/notification_control_buttons_view.h"
#include "ui/message_center/views/notification_header_view.h" #include "ui/message_center/views/notification_header_view.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/test/button_test_api.h"
#include "ui/views/test/views_test_base.h" #include "ui/views/test/views_test_base.h"
namespace media_message_center { namespace media_message_center {
...@@ -254,9 +255,9 @@ class MediaNotificationViewModernImplTest : public views::ViewsTestBase { ...@@ -254,9 +255,9 @@ class MediaNotificationViewModernImplTest : public views::ViewsTestBase {
views::Button* button = GetButtonForAction(action); views::Button* button = GetButtonForAction(action);
EXPECT_TRUE(button->GetVisible()); EXPECT_TRUE(button->GetVisible());
view()->ButtonPressed( views::test::ButtonTestApi(button).NotifyClick(
button, ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), 0, 0)); ui::EventTimeForNow(), 0, 0));
} }
void SimulateTab() { void SimulateTab() {
......
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