Commit eba00a2f authored by Takumi Fujimoto's avatar Takumi Fujimoto Committed by Commit Bot

GMC+Cast: Show Cast icon in Cast notification items

Show a Cast icon at the top left corner of Cast notifications in Global
Media Controls to make it easier to distinguish Cast notifications from
local notifications, which have no icon.

Screenshot:
https://drive.google.com/file/d/1701V_-4ufHnYMF-e_pdD20AyC8V4HdC0/view?usp=sharing

Bug: 1042008
Change-Id: I244564bef86d4209656cd60b377684dc205f8d45
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2026413Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Commit-Queue: Takumi Fujimoto <takumif@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740368}
parent fed8149f
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/media_message_center/media_notification_controller.h" #include "components/media_message_center/media_notification_controller.h"
#include "components/media_message_center/media_notification_view.h" #include "components/media_message_center/media_notification_view.h"
#include "components/media_message_center/media_notification_view_impl.h" #include "components/media_message_center/media_notification_view_impl.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -169,6 +170,9 @@ CastMediaNotificationItem::~CastMediaNotificationItem() { ...@@ -169,6 +170,9 @@ CastMediaNotificationItem::~CastMediaNotificationItem() {
void CastMediaNotificationItem::SetView( void CastMediaNotificationItem::SetView(
media_message_center::MediaNotificationView* view) { media_message_center::MediaNotificationView* view) {
view_ = view; view_ = view;
if (view_)
view_->UpdateWithVectorIcon(vector_icons::kMediaRouterIdleIcon);
UpdateView(); UpdateView();
if (view_ && !recorded_metadata_metrics_) { if (view_ && !recorded_metadata_metrics_) {
recorded_metadata_metrics_ = true; recorded_metadata_metrics_ = true;
......
...@@ -9,10 +9,12 @@ ...@@ -9,10 +9,12 @@
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/media_message_center/media_notification_controller.h" #include "components/media_message_center/media_notification_controller.h"
#include "components/media_message_center/media_notification_view.h" #include "components/media_message_center/media_notification_view.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/vector_icon_types.h"
using media_router::mojom::MediaStatus; using media_router::mojom::MediaStatus;
using media_session::mojom::MediaPlaybackState; using media_session::mojom::MediaPlaybackState;
...@@ -74,6 +76,7 @@ class MockMediaNotificationView ...@@ -74,6 +76,7 @@ class MockMediaNotificationView
void(const base::flat_set<MediaSessionAction>&)); void(const base::flat_set<MediaSessionAction>&));
MOCK_METHOD1(UpdateWithMediaArtwork, void(const gfx::ImageSkia&)); MOCK_METHOD1(UpdateWithMediaArtwork, void(const gfx::ImageSkia&));
MOCK_METHOD1(UpdateWithFavicon, void(const gfx::ImageSkia&)); MOCK_METHOD1(UpdateWithFavicon, void(const gfx::ImageSkia&));
MOCK_METHOD1(UpdateWithVectorIcon, void(const gfx::VectorIcon& vector_icon));
}; };
class MockSessionController : public CastMediaSessionController { class MockSessionController : public CastMediaSessionController {
...@@ -104,6 +107,10 @@ class CastMediaNotificationItemTest : public testing::Test { ...@@ -104,6 +107,10 @@ class CastMediaNotificationItemTest : public testing::Test {
} }
void SetView() { void SetView() {
EXPECT_CALL(view_, UpdateWithVectorIcon(_))
.WillOnce([](const gfx::VectorIcon& vector_icon) {
EXPECT_EQ(vector_icons::kMediaRouterIdleIcon.reps, vector_icon.reps);
});
EXPECT_CALL(view_, UpdateWithMediaSessionInfo(_)) EXPECT_CALL(view_, UpdateWithMediaSessionInfo(_))
.WillOnce([&](const MediaSessionInfoPtr& session_info) { .WillOnce([&](const MediaSessionInfoPtr& session_info) {
EXPECT_EQ(MediaSessionInfo::SessionState::kSuspended, EXPECT_EQ(MediaSessionInfo::SessionState::kSuspended,
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/vector_icon_types.h"
using media_router::MediaRoute; using media_router::MediaRoute;
using testing::_; using testing::_;
...@@ -55,6 +56,7 @@ class MockMediaNotificationView ...@@ -55,6 +56,7 @@ class MockMediaNotificationView
void(const base::flat_set<media_session::mojom::MediaSessionAction>&)); void(const base::flat_set<media_session::mojom::MediaSessionAction>&));
MOCK_METHOD1(UpdateWithMediaArtwork, void(const gfx::ImageSkia&)); MOCK_METHOD1(UpdateWithMediaArtwork, void(const gfx::ImageSkia&));
MOCK_METHOD1(UpdateWithFavicon, void(const gfx::ImageSkia&)); MOCK_METHOD1(UpdateWithFavicon, void(const gfx::ImageSkia&));
MOCK_METHOD1(UpdateWithVectorIcon, void(const gfx::VectorIcon& vector_icon));
}; };
class MockClosure { class MockClosure {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace gfx { namespace gfx {
class ImageSkia; class ImageSkia;
struct VectorIcon;
} // namespace gfx } // namespace gfx
namespace media_session { namespace media_session {
...@@ -39,7 +40,11 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationView ...@@ -39,7 +40,11 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationView
const base::flat_set<media_session::mojom::MediaSessionAction>& const base::flat_set<media_session::mojom::MediaSessionAction>&
actions) = 0; actions) = 0;
virtual void UpdateWithMediaArtwork(const gfx::ImageSkia& image) = 0; virtual void UpdateWithMediaArtwork(const gfx::ImageSkia& image) = 0;
// Updates the background color to match that of the favicon.
virtual void UpdateWithFavicon(const gfx::ImageSkia& icon) = 0; virtual void UpdateWithFavicon(const gfx::ImageSkia& icon) = 0;
// Sets the icon to be displayed in the notification's header section.
// |vector_icon| must outlive the MediaNotificationView.
virtual void UpdateWithVectorIcon(const gfx::VectorIcon& vector_icon) = 0;
}; };
} // namespace media_message_center } // namespace media_message_center
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/font.h" #include "ui/gfx/font.h"
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/message_center/public/cpp/message_center_constants.h"
#include "ui/message_center/views/notification_header_view.h" #include "ui/message_center/views/notification_header_view.h"
#include "ui/views/controls/button/image_button_factory.h" #include "ui/views/controls/button/image_button_factory.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
...@@ -132,7 +134,7 @@ MediaNotificationViewImpl::MediaNotificationViewImpl( ...@@ -132,7 +134,7 @@ MediaNotificationViewImpl::MediaNotificationViewImpl(
header_row->SetProperty(views::kMarginsKey, header_row->SetProperty(views::kMarginsKey,
kIconMediaNotificationHeaderInsets); kIconMediaNotificationHeaderInsets);
} else { } else {
header_row->HideAppIcon(); header_row->SetAppIconVisible(false);
header_row->SetProperty(views::kMarginsKey, header_row->SetProperty(views::kMarginsKey,
kIconlessMediaNotificationHeaderInsets); kIconlessMediaNotificationHeaderInsets);
} }
...@@ -438,6 +440,18 @@ void MediaNotificationViewImpl::UpdateWithFavicon(const gfx::ImageSkia& icon) { ...@@ -438,6 +440,18 @@ void MediaNotificationViewImpl::UpdateWithFavicon(const gfx::ImageSkia& icon) {
SchedulePaint(); SchedulePaint();
} }
void MediaNotificationViewImpl::UpdateWithVectorIcon(
const gfx::VectorIcon& vector_icon) {
vector_header_icon_ = &vector_icon;
const SkColor foreground =
GetMediaNotificationBackground()->GetForegroundColor(*this);
header_row_->SetAppIcon(gfx::CreateVectorIcon(
*vector_header_icon_, message_center::kSmallImageSizeMD, foreground));
header_row_->SetAppIconVisible(true);
header_row_->SetProperty(views::kMarginsKey,
kIconMediaNotificationHeaderInsets);
}
views::Button* MediaNotificationViewImpl::GetHeaderRowForTesting() const { views::Button* MediaNotificationViewImpl::GetHeaderRowForTesting() const {
return header_row_; return header_row_;
} }
...@@ -580,6 +594,10 @@ void MediaNotificationViewImpl::UpdateForegroundColor() { ...@@ -580,6 +594,10 @@ void MediaNotificationViewImpl::UpdateForegroundColor() {
title_label_->SetEnabledColor(foreground); title_label_->SetEnabledColor(foreground);
artist_label_->SetEnabledColor(foreground); artist_label_->SetEnabledColor(foreground);
header_row_->SetAccentColor(foreground); header_row_->SetAccentColor(foreground);
if (vector_header_icon_) {
header_row_->SetAppIcon(gfx::CreateVectorIcon(
*vector_header_icon_, message_center::kSmallImageSizeMD, foreground));
}
title_label_->SetBackgroundColor(background); title_label_->SetBackgroundColor(background);
artist_label_->SetBackgroundColor(background); artist_label_->SetBackgroundColor(background);
......
...@@ -80,6 +80,7 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewImpl ...@@ -80,6 +80,7 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewImpl
override; override;
void UpdateWithMediaArtwork(const gfx::ImageSkia& image) override; void UpdateWithMediaArtwork(const gfx::ImageSkia& image) override;
void UpdateWithFavicon(const gfx::ImageSkia& icon) override; void UpdateWithFavicon(const gfx::ImageSkia& icon) override;
void UpdateWithVectorIcon(const gfx::VectorIcon& vector_icon) override;
const views::Label* title_label_for_testing() const { return title_label_; } const views::Label* title_label_for_testing() const { return title_label_; }
...@@ -152,6 +153,7 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewImpl ...@@ -152,6 +153,7 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationViewImpl
views::View* main_row_ = nullptr; views::View* main_row_ = nullptr;
views::BoxLayout* title_artist_row_layout_ = nullptr; views::BoxLayout* title_artist_row_layout_ = nullptr;
const gfx::VectorIcon* vector_header_icon_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(MediaNotificationViewImpl); DISALLOW_COPY_AND_ASSIGN(MediaNotificationViewImpl);
}; };
......
...@@ -384,8 +384,8 @@ void NotificationHeaderView::SetSubpixelRenderingEnabled(bool enabled) { ...@@ -384,8 +384,8 @@ void NotificationHeaderView::SetSubpixelRenderingEnabled(bool enabled) {
timestamp_view_->SetSubpixelRenderingEnabled(enabled); timestamp_view_->SetSubpixelRenderingEnabled(enabled);
} }
void NotificationHeaderView::HideAppIcon() { void NotificationHeaderView::SetAppIconVisible(bool visible) {
app_icon_view_->SetVisible(false); app_icon_view_->SetVisible(visible);
} }
const base::string16& NotificationHeaderView::app_name_for_testing() const { const base::string16& NotificationHeaderView::app_name_for_testing() const {
......
...@@ -53,8 +53,8 @@ class MESSAGE_CENTER_EXPORT NotificationHeaderView : public views::Button { ...@@ -53,8 +53,8 @@ class MESSAGE_CENTER_EXPORT NotificationHeaderView : public views::Button {
void ClearProgress(); void ClearProgress();
void SetSubpixelRenderingEnabled(bool enabled); void SetSubpixelRenderingEnabled(bool enabled);
// Completely hides the app icon. // Shows or hides the app icon.
void HideAppIcon(); void SetAppIconVisible(bool visible);
// views::View: // views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
......
...@@ -84,14 +84,19 @@ TEST_F(NotificationHeaderViewTest, UpdatesTimestampOverTime) { ...@@ -84,14 +84,19 @@ TEST_F(NotificationHeaderViewTest, UpdatesTimestampOverTime) {
} }
TEST_F(NotificationHeaderViewTest, AllowsHidingOfAppIcon) { TEST_F(NotificationHeaderViewTest, AllowsHidingOfAppIcon) {
// The icon should be shown by default. // The icon should be shown by default...
EXPECT_TRUE( EXPECT_TRUE(
notification_header_view_->app_icon_view_for_testing()->IsDrawn()); notification_header_view_->app_icon_view_for_testing()->IsDrawn());
// Though it can be explicitly hidden. // ... though it can be explicitly hidden...
notification_header_view_->HideAppIcon(); notification_header_view_->SetAppIconVisible(false);
EXPECT_FALSE( EXPECT_FALSE(
notification_header_view_->app_icon_view_for_testing()->IsDrawn()); notification_header_view_->app_icon_view_for_testing()->IsDrawn());
// ... and shown again.
notification_header_view_->SetAppIconVisible(true);
EXPECT_TRUE(
notification_header_view_->app_icon_view_for_testing()->IsDrawn());
} }
} // namespace message_center } // namespace message_center
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