Commit a4808cd7 authored by Tommy Steimel's avatar Tommy Steimel Committed by Commit Bot

GMC: Hide Chromium icons shown in notification header

This CL adds the ability to hide the app icon view in Message Center's
NotificationHeaderView. This allows the Global Media Controls dialog to
hide the unnecessary Chromium icon that appears before the URL.

Bug: 1011047
Change-Id: Ic3e5a8e57ecfc14698697370e4fc0d5840c28ff0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1875276Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708760}
parent 4d9ad321
...@@ -25,7 +25,8 @@ MediaNotificationContainerImpl::MediaNotificationContainerImpl( ...@@ -25,7 +25,8 @@ MediaNotificationContainerImpl::MediaNotificationContainerImpl(
std::move(item), std::move(item),
control_buttons_view_.get(), control_buttons_view_.get(),
message_center::MessageCenter::Get()->GetSystemNotificationAppName(), message_center::MessageCenter::Get()->GetSystemNotificationAppName(),
message_center::kNotificationWidth) { message_center::kNotificationWidth,
/*should_show_icon=*/true) {
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
// Since we own these, we don't want Views to destroy them when their parent // Since we own these, we don't want Views to destroy them when their parent
......
...@@ -93,7 +93,7 @@ MediaNotificationContainerImplView::MediaNotificationContainerImplView( ...@@ -93,7 +93,7 @@ MediaNotificationContainerImplView::MediaNotificationContainerImplView(
view_ = std::make_unique<media_message_center::MediaNotificationView>( view_ = std::make_unique<media_message_center::MediaNotificationView>(
this, std::move(item), dismiss_button_container_.get(), base::string16(), this, std::move(item), dismiss_button_container_.get(), base::string16(),
kWidth); kWidth, /*should_show_icon=*/false);
view_->set_owned_by_client(); view_->set_owned_by_client();
ForceExpandedState(); ForceExpandedState();
......
...@@ -44,9 +44,10 @@ constexpr double kMediaImageMaxWidthExpandedPct = 0.4; ...@@ -44,9 +44,10 @@ constexpr double kMediaImageMaxWidthExpandedPct = 0.4;
constexpr gfx::Size kMediaButtonSize = gfx::Size(36, 36); constexpr gfx::Size kMediaButtonSize = gfx::Size(36, 36);
constexpr int kMediaButtonRowSeparator = 8; constexpr int kMediaButtonRowSeparator = 8;
constexpr gfx::Insets kMediaTitleArtistInsets = gfx::Insets(8, 8, 0, 8); constexpr gfx::Insets kMediaTitleArtistInsets = gfx::Insets(8, 8, 0, 8);
constexpr int kMediaNotificationHeaderTopInset = 6; constexpr gfx::Insets kIconlessMediaNotificationHeaderInsets =
constexpr int kMediaNotificationHeaderRightInset = 6; gfx::Insets(6, 14, 0, 6);
constexpr int kMediaNotificationHeaderInset = 0; constexpr gfx::Insets kIconMediaNotificationHeaderInsets =
gfx::Insets(6, 0, 0, 6);
constexpr gfx::Size kMediaNotificationButtonRowSize = constexpr gfx::Size kMediaNotificationButtonRowSize =
gfx::Size(124, kMediaButtonSize.height()); gfx::Size(124, kMediaButtonSize.height());
...@@ -100,7 +101,8 @@ MediaNotificationView::MediaNotificationView( ...@@ -100,7 +101,8 @@ MediaNotificationView::MediaNotificationView(
base::WeakPtr<MediaNotificationItem> item, base::WeakPtr<MediaNotificationItem> item,
views::View* header_row_controls_view, views::View* header_row_controls_view,
const base::string16& default_app_name, const base::string16& default_app_name,
int notification_width) int notification_width,
bool should_show_icon)
: container_(container), : container_(container),
item_(std::move(item)), item_(std::move(item)),
header_row_controls_view_(header_row_controls_view), header_row_controls_view_(header_row_controls_view),
...@@ -118,12 +120,17 @@ MediaNotificationView::MediaNotificationView( ...@@ -118,12 +120,17 @@ MediaNotificationView::MediaNotificationView(
header_row->AddChildView(header_row_controls_view_); header_row->AddChildView(header_row_controls_view_);
header_row->SetAppName(default_app_name_); header_row->SetAppName(default_app_name_);
header_row->ClearAppIcon();
header_row->SetProperty( if (should_show_icon) {
views::kMarginsKey, header_row->ClearAppIcon();
gfx::Insets(kMediaNotificationHeaderTopInset, header_row->SetProperty(views::kMarginsKey,
kMediaNotificationHeaderInset, kMediaNotificationHeaderInset, kIconMediaNotificationHeaderInsets);
kMediaNotificationHeaderRightInset)); } else {
header_row->HideAppIcon();
header_row->SetProperty(views::kMarginsKey,
kIconlessMediaNotificationHeaderInsets);
}
header_row_ = AddChildView(std::move(header_row)); header_row_ = AddChildView(std::move(header_row));
// |main_row_| holds the main content of the notification. // |main_row_| holds the main content of the notification.
......
...@@ -66,7 +66,8 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationView ...@@ -66,7 +66,8 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationView
base::WeakPtr<MediaNotificationItem> item, base::WeakPtr<MediaNotificationItem> item,
views::View* header_row_controls_view, views::View* header_row_controls_view,
const base::string16& default_app_name, const base::string16& default_app_name,
int notification_width); int notification_width,
bool should_show_icon);
~MediaNotificationView() override; ~MediaNotificationView() override;
void SetExpanded(bool expanded); void SetExpanded(bool expanded);
......
...@@ -204,8 +204,13 @@ class MediaNotificationViewTest : public views::ViewsTestBase { ...@@ -204,8 +204,13 @@ class MediaNotificationViewTest : public views::ViewsTestBase {
return media_controller_.get(); return media_controller_.get();
} }
message_center::NotificationHeaderView* GetHeaderRow(
MediaNotificationView* view) const {
return view->header_row_;
}
message_center::NotificationHeaderView* header_row() const { message_center::NotificationHeaderView* header_row() const {
return view()->header_row_; return GetHeaderRow(view());
} }
const base::string16& accessible_name() const { const base::string16& accessible_name() const {
...@@ -306,7 +311,8 @@ class MediaNotificationViewTest : public views::ViewsTestBase { ...@@ -306,7 +311,8 @@ class MediaNotificationViewTest : public views::ViewsTestBase {
auto view = std::make_unique<MediaNotificationView>( auto view = std::make_unique<MediaNotificationView>(
&container_, item_->GetWeakPtr(), &container_, item_->GetWeakPtr(),
nullptr /* header_row_controls_view */, nullptr /* header_row_controls_view */,
base::ASCIIToUTF16(kTestDefaultAppName), kViewWidth); base::ASCIIToUTF16(kTestDefaultAppName), kViewWidth,
/*should_show_icon=*/true);
view->SetSize(kViewSize); view->SetSize(kViewSize);
view->set_owned_by_client(); view->set_owned_by_client();
...@@ -1282,4 +1288,18 @@ TEST_F(MAYBE_MediaNotificationViewTest, ForcedExpandedState) { ...@@ -1282,4 +1288,18 @@ TEST_F(MAYBE_MediaNotificationViewTest, ForcedExpandedState) {
EXPECT_TRUE(IsActuallyExpanded()); EXPECT_TRUE(IsActuallyExpanded());
} }
TEST_F(MAYBE_MediaNotificationViewTest, AllowsHidingOfAppIcon) {
MediaNotificationView shows_icon(&container(), nullptr, nullptr,
base::string16(), kViewWidth,
/*should_show_icon=*/true);
MediaNotificationView hides_icon(&container(), nullptr, nullptr,
base::string16(), kViewWidth,
/*should_show_icon=*/false);
EXPECT_TRUE(
GetHeaderRow(&shows_icon)->app_icon_view_for_testing()->GetVisible());
EXPECT_FALSE(
GetHeaderRow(&hides_icon)->app_icon_view_for_testing()->GetVisible());
}
} // namespace media_message_center } // namespace media_message_center
...@@ -385,6 +385,10 @@ void NotificationHeaderView::SetSubpixelRenderingEnabled(bool enabled) { ...@@ -385,6 +385,10 @@ void NotificationHeaderView::SetSubpixelRenderingEnabled(bool enabled) {
timestamp_view_->SetSubpixelRenderingEnabled(enabled); timestamp_view_->SetSubpixelRenderingEnabled(enabled);
} }
void NotificationHeaderView::HideAppIcon() {
app_icon_view_->SetVisible(false);
}
const base::string16& NotificationHeaderView::app_name_for_testing() const { const base::string16& NotificationHeaderView::app_name_for_testing() const {
return app_name_view_->GetText(); return app_name_view_->GetText();
} }
......
...@@ -53,6 +53,9 @@ class MESSAGE_CENTER_EXPORT NotificationHeaderView : public views::Button { ...@@ -53,6 +53,9 @@ 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.
void HideAppIcon();
// views::View: // views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
...@@ -64,6 +67,10 @@ class MESSAGE_CENTER_EXPORT NotificationHeaderView : public views::Button { ...@@ -64,6 +67,10 @@ class MESSAGE_CENTER_EXPORT NotificationHeaderView : public views::Button {
return summary_text_view_; return summary_text_view_;
} }
const views::ImageView* app_icon_view_for_testing() const {
return app_icon_view_;
}
const base::string16& app_name_for_testing() const; const base::string16& app_name_for_testing() const;
const gfx::ImageSkia& app_icon_for_testing() const; const gfx::ImageSkia& app_icon_for_testing() const;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/test/views_test_base.h" #include "ui/views/test/views_test_base.h"
namespace message_center { namespace message_center {
...@@ -82,4 +83,15 @@ TEST_F(NotificationHeaderViewTest, UpdatesTimestampOverTime) { ...@@ -82,4 +83,15 @@ TEST_F(NotificationHeaderViewTest, UpdatesTimestampOverTime) {
notification_header_view_->timestamp_for_testing()); notification_header_view_->timestamp_for_testing());
} }
TEST_F(NotificationHeaderViewTest, AllowsHidingOfAppIcon) {
// The icon should be shown by default.
EXPECT_TRUE(
notification_header_view_->app_icon_view_for_testing()->IsDrawn());
// Though it can be explicitly hidden.
notification_header_view_->HideAppIcon();
EXPECT_FALSE(
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